LoginSignup
5
4

More than 1 year has passed since last update.

ROS2のWebotsでTurtlebot3のNavigationをする

Last updated at Posted at 2021-08-24

はじめに

Gazeboの代わりにROS2で使えるシミュレータを検討していたところWebotsというロボットシミュレータを知り、
ROS2のパッケージやドキュメントも充実していたので、ROS2 Foxyにインストールしてチュートリアル通りにTurtlebot3のNavigationをしてみた

Webotsについて

Webots自体についてはこちらの記事が詳しく書かれているので参照してください

動作環境

この記事は以下の環境で実行しています

CPU Ryzen5
OS Ubuntu20.04.02LTS
ROS2 Foxy Fitzroy

Webotsのインストール

こちらの通りにインストールする。
aptで一発で最新のWebots本体とROS2パッケージが入るので簡単。

インストール

$ sudo apt install ros-foxy-webots-ros2

Galacticの場合(動作未確認)

$ sudo apt install ros-galactic-webots-ros2

デモの実行

$ ros2 launch webots_ros2_demos armed_robots.launch.py

以下のようにアームロボットが動いているシミュレーションが実行できたら成功

Screenshot from 2021-08-23 22-04-19.png

Turtlebot3のNavigation

以下のチュートリアル通りに進める

turtlebot3_navigation2のインストール

$ sudo apt install ros-foxy-turtlebot3-navigation2

$ sudo sed -i 's/nav2\_bringup\_launch.\py/bringup\_launch.\py/g' /opt/ros/foxy/share/turtlebot3_navigation2/launch/navigation2.launch.py

ソースからビルドする場合

$ source /opt/ros/foxy/local_setup.bash

$ cd /path/to/ros2_ws
$ git clone -b foxy-devel https://github.com/ROBOTIS-GIT/turtlebot3.git src/turtlebot3

$ rosdep update
$ rosdep install --from-paths src --ignore-src --rosdistro foxy

$ colcon build --packages-up-to turtlebot3_navigation2
$ source install/local_setup.bash

Webotsの実行

$ ros2 launch webots_ros2_turtlebot robot_launch.py

Turtlebot3 Burgerが現れる
この状態で/cmd_velトピックを送るとTurtlebot3が動く

Screenshot from 2021-08-23 22-25-51.png

Navigation2の実行

$ export TURTLEBOT3_MODEL='burger' 
$ ros2 launch turtlebot3_navigation2 navigation2.launch.py \
    use_sim_time:=true \
    map:=$(ros2 pkg prefix webots_ros2_turtlebot --share)/resource/turtlebot3_burger_example_map.yaml

以下のコマンドでamclのinitialposeを初期化、
またはrviz2の2D Pose Estimateボタンをクリックして初期位置を指定。

$ ros2 topic pub --once /initialpose geometry_msgs/msg/PoseWithCovarianceStamped '{
    "header": { "frame_id": "map" },
    "pose": {
        "pose": {
            "position": { "x": 0.0, "y": 0.0, "z": 0.0 },
            "orientation": { "x": 0.0, "y": 0.0, "z": 0.0, "w": 1.0 }
        }
    }
}'

あとはrviz2のNavigation2 Goalをクリックしてマップ上のゴールを指定を指定するとTurtlebot3が指定した位置に向かって動き出す。

参考

webots_ros2

Webots公式サイト

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4