15
17

More than 3 years have passed since last update.

[Ubuntu20.04] ROS-noeticインストールからturtlebot3のSLAMシュミレーションまで

Last updated at Posted at 2020-11-14

ROS-noeticでSLAMシミュレーション

SLAMを試してみたいと思ったので、入り口としてお試し。

  • インストール
  • シミュレーション実行
  • SLAM、mapping

環境
ubuntu 20.04


ROSのインストール

ROS-noeticのインストールは、手っ取り早く行うには、ROBOTISのshellを使うといいと思います。

$ git clone https://github.com/ROBOTIS-GIT/robotis_tools.git
$ cd robotis_tools
$ chmod 755 ./install_ros_noetic.sh
$ bash ./install_ros_noetic.sh

この方法でインストールすると、~/.bashrcに
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
のショートカットが作成され便利です。
cs,cmは結構使います。
即座に反映させたい場合は

source ~/.bashrc

と打ち込んでください

ワークスペースの作成

上記のshellでインストールすればcatkin_wsというワークスペースができますので飛ばしてください。
それ以外の方法でインストールした人は、ワークスペースを作成します、名前(ここではcatkin_ws)はなんでもいいです。

cd
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
$ cd ~/catkin_ws && catkin_make

turtlebot3のシミュレーション環境の作成

branchをnoetic-devに指定して、パッケージをインストール

$ cd
$ cd ~/catkin_ws/src
$ git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
$ git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git
$ cd ~/catkin_ws && catkin_make

turtlebot3にはBurger, Waffle, Waffle Piの3種類あるので、指定しなけれなりません。どれでもいいですが、今回はBurgerを選ぶことにします。

毎度 export TURTLEBOT3_MODEL=burger を打ちたくないので、bashrcに書き込みます。
(エディターは使い慣れているもので)

$ gedit ~/.bashrc

最後の行に

export TURTLEBOT3_MODEL=burger

を書き込んで保存し閉じます。

$ source ~/.bashrc

で反映させます。(今後TURTLEBOT3_MODELが不明的なエラー出たらまたこれを実行してください)

turtlebot3のシミュレーターのインストール

$ cd ~/catkin_ws/src
$ git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
$ cd ~/catkin_ws && catkin_make

シミュレーターの実行[RViz]

$ roslaunch turtlebot3_fake turtlebot3_fake.launch

これでturtlebot3が立ち上がリます。

Screenshot from 2020-11-15 02-29-45.png

以下のコマンドでキーボード操作できるようになります、”新しいターミナルで”実行してください。

$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

シミュレーターの実行[Gazebo]

ターミナルをすべて終了して新規で立ち上げます。

次はGazeboでシミュレーションを実行します。RVizはデバッグツールですが、Gazeboでは任意の環境下でシミュレートできます。

ここでは定番(?)のポールの立った空間でシミュレートします。

$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

(turtlebot3_simulations/turtlebot3_gazebo/launch/ に様々な環境が用意されています。
何もない空間>>turtlebot3_empty_world.launch
家の中>>turtlebot3_house.launch)

Screenshot from 2020-11-15 02-49-06.png
Screenshot from 2020-11-15 02-49-50.png

次に障害物を避けて自動制御させます

$ roslaunch turtlebot3_gazebo turtlebot3_simulation.launch

これでgazeboをみると自立制御していることがわかります。

このとき、RVizを起動すれば、Turtlebot3がレーザーで距離を測っている様子を可視化できます。

$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch

Screenshot from 2020-11-15 03-02-54.png


最後にSLAMシミュレーション

ターミナルをすべて終了して新規で立ち上げます。
SLAMは自己位置推定とマップ生成を同時実行するものです。

SLAMのモジュールをインストールします。

$ sudo apt-get install ros-noetic-slam-gmapping

そしてもう一度先程のGazeboを起動させます。

$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

Gazeboが起動したら、早速SLAMを実行します。

$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping

Screenshot from 2020-11-15 03-11-56.png

これでマップ生成が始まります。

この空間全体のマップを生成するためには、先程の衝突しないプログラムを実行すれば良いです。

$ roslaunch turtlebot3_gazebo turtlebot3_simulation.launch

これでしばらく放っておけば、全体マップが作成できます。

Screenshot from 2020-11-15 03-31-06.png

マップを生成できたら保存したいです。
まずmap serverのインストールをします。

$ sudo apt-get install ros-noetic-map-server

保存したいフォルダ(ここではmaps)を作成し、そこに保存します。

$ mkdir ~/maps
$ cd ~/maps
$ rosrun map_server map_saver

エラーが出る場合: rosrun map_server map_server にしているかもしれません、2回目はsaverです。

map.pgmを開くと取得した地図を表示できます。

Screenshot from 2020-11-15 03-48-23.png


参考
How to Launch the TurtleBot3 Simulation With ROS
「ROS ロボットプログラミングバイブル」

15
17
1

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
15
17