Edit on GitHub

Simulation

NOTE:

  • This instructions were tested on Ubuntu 16.04 and ROS Kinetic Kame.
  • This instructions are supposed to be running on the remote PC. Please run the instructions below on your Remote PC.

TIP:

  • We are happy to announce a new ROS book: “ROS Robot Programming, A Handbook is written by TurtleBot3 Developers”. This book has been published in Korean, English, Chinese and Japanese. It contains the following:
    • ROS Kinetic Kame: Basic concept, instructions and tools
    • How to use sensor and actuator packages on ROS
    • Embedded board for ROS: OpenCR
    • SLAM & Navigation with TurtleBot3
    • How to program a delivery robot using ROS Java
    • OpenManipulator simulation using MoveIt! and Gazebo
  • Please refer to this book for more information on ROS, SLAM, and Navigation that are not covered in this e-manual. You can download the pdf of this book.

TurtleBot3 supports development environment that can be programmed and developed with a virtual robot in the simulation. There are two development environments to do this, one is using fake node and 3D visualization tool RViz and the other is using the 3D robot simulator Gazebo.

The fake node method is suitable for testing with the robot model and movement, but it can not use sensors. If you need to test SLAM and Navigation, we recommend using Gazebo, which can use sensors such as IMU, LDS, and camera in the simulation.

TurtleBot3 Simulation using Fake Node

To use turtlebot3_fake_node, you need the turtlebot3_simulation metapackage. Install the package as shown in the following command.

TIP: The terminal application can be found with the Ubuntu search icon on the top left corner of the screen. The shortcut key for running the terminal is Ctrl-Alt-T.

NOTE: The turtlebot3_simulation metapackage requires turtlebot3 metapackage and turtlebot3_msgs package as a prerequisite. If you did not install it in the Install Dependent ROS Packages of PC Setup section, install it first.

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

To launch the virtual robot, execute the turtlebot3_fake.launch file in the turtlebot3_fake package as shown below. The turtlebot3_fake is a very simple simulation node that can be run without having an actual robot. You can even control the virtual TurtleBot3 in RViz with a teleoperation node.

TIP: Before executing this command, you have to specify the model name of TurtleBot3. The ${TB3_MODEL} is the name of the model you are using in burger, waffle, waffle_pi. If you want to permanently set the export settings, please refer to Export TURTLEBOT3_MODEL page.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_fake turtlebot3_fake.launch
$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

TurtleBot3 Simulation using Gazebo

There are two ways to simulate using Gazebo. first method is to use with ROS through turtlebot3_gazebo package and second method is to use only gazebo and turtlebot3_gazebo_plugin plugin without using ROS.

If you want to use the first method, see the instructions below. For the second method, see the following instructions.

ROS packages for Gazebo

NOTE: If you are running Gazebo for the first time on your Remote PC, it takes a bit longer than usual.

Simulate in Various World

1) Empty World

The following command can be used to test the virtual TurtleBot3 on the empty world of the gazebo default environment.

TIP: Before executing this command, you have to specify the model name of TurtleBot3. The ${TB3_MODEL} is the name of the model you are using in burger, waffle, waffle_pi. If you want to permanently set the export settings, please refer to Export TURTLEBOT3_MODEL page.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch

2) TurtleBot3 World

TurtleBot3 world is a map consists of simple objects that makes up the shape of TurtleBot3 symbol. TurtleBot3 world is mainly used for testing such as SLAM and Navigation.  

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

3) TurtleBot3 House

TurtleBot3 House is a map made with house drawings. It is suitable for testing related to more complex task performance.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_house.launch

Drive TurtleBot3

1) Teleoperation on Gazebo

In order to control a TurtleBot3 with a keyboard, please launch teleoperation feature with below command in a new terminal window.

$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
2) Collision Avoidance

In order to autonomously drive a TurtleBot3 around the TurtleBot3 world, open a new terminal window and enter below command.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

Open a new terminal window and enter below command.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_simulation.launch

Execute RViz

RViz visualizes published topics while simulation is running. You can launch RViz in a new terminal window by entering below command.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch

Virtual SLAM with TurtleBot3

For virtual SLAM in Gazebo, instead of running the actual robot, you can select the various environments and robot models mentioned above, and the SLAM-related commands will use the ROS packages used in the SLAM section.

Virtual SLAM Execution Procedure

The following commands are examples of using the TurtleBot3 Waffle Pi model and the turtlebot3_world environment.

When you run the dependent packages and move the robot in virtual space and create a map as shown below, you can create a map as shown in figure below.

Virtual Navigation with TurtleBot3

For virtual Navigation in Gazebo, instead of running the actual robot, you can select the various environments and robot models mentioned above, and the Navigation-related commands will use the ROS packages used in the Navigation section.

Virtual Navigation Execution Procedure

Terminate all applications that were executed during the virtual SLAM practice and execute related packages in the following instruction, the robot will appear on the previously generated map. After setting the initial position of the robot on the map, set the destination to run the navigation as shown in figure below. The initial position only needs to be set once.

Virtual SLAM by Multiple TurtleBot3s

1) Call Three TurtleBot3s in TurtleBot3 House
$ roslaunch turtlebot3_gazebo multi_turtlebot3.launch

These loaded turtlebot3s are set initial position and orientation

2) Excute SLAM
$ ROS_NAMESPACE=tb3_0 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_0/base_footprint set_odom_frame:=tb3_0/odom set_map_frame:=tb3_0/map
$ ROS_NAMESPACE=tb3_1 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_1/base_footprint set_odom_frame:=tb3_1/odom set_map_frame:=tb3_1/map
$ ROS_NAMESPACE=tb3_2 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_2/base_footprint set_odom_frame:=tb3_2/odom set_map_frame:=tb3_2/map

3) Merge Map Data from each TurtleBot3’s Map Data

Before launch this nodes, please make sure arguments for position and orientation of turtlebot3s

$ sudo apt-get install ros-kinetic-multirobot-map-merge
$ roslaunch turtlebot3_gazebo multi_map_merge.launch
4) Excute RViz
$ rosrun rviz rviz -d `rospack find turtlebot3_gazebo`/rviz/multi_turtlebot3_slam.rviz
5) Teleoperation
$ ROS_NAMESPACE=tb3_0 rosrun turtlebot3_teleop turtlebot3_teleop_key
$ ROS_NAMESPACE=tb3_1 rosrun turtlebot3_teleop turtlebot3_teleop_key
$ ROS_NAMESPACE=tb3_2 rosrun turtlebot3_teleop turtlebot3_teleop_key
6) Save the Map
$ rosrun map_server map_saver -f ~/map

TurtleBot3 AutoRace with Gazebo

Go to AutoRace with Gazebo.

Turtlebot3 with OpenManipulator

Go to OpenManipulator with Gazebo

Standalone Gazebo Plugin

NOTE: This tutorial is developed only for user who want to simulate TurtleBot3 without ROS. However we highly recommend to simulate robots with ROS.

How to use Gazebo Plugin

1) Install Library for Gazebo7
$ sudo apt-get install libgazebo7-dev
2) Download Source Code from Github
$ git clone https://github.com/ROBOTIS-GIT/turtlebot3_gazebo_plugin
3) Add Gazebo Plugin Path in .bashrc File
$ nano ~/.bashrc

TIP: turtlebot3_gazebo_plugin path = ~/turtlebot3_gazebo_plugin

export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:${turtlebot3_gazebo_plugin path}/build
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:${turtlebot3_gazebo_plugin path}/models
4) Make and Build
$ cd ${turtlebot3_gazebo_plugin path}
$ mkdir build
$ cd build
$ cmake ..
$ make
5) Excute Plugin

TIP: Before executing this command, you have to specify the model name of TurtleBot3. The ${TB3_MODEL} is the name of the model you are using in burger, waffle, waffle_pi. If you want to permanently set the export settings, please refer to Export TURTLEBOT3_MODEL page.

$ cd ${turtlebot3_gazebo_plugin}
$ gazebo worlds/turtlebot3_${TB3_MODEL}.world

6) Teleoperation by Keyboard
w - set linear velocity up
x - set linear velocity down
d - set angular velocity up
a - set angular velocity down
s - set all velocity to zero
7) Topic Subscribe Command
$ gz topic -l
$ gz topic -e /gazebo/default/user/turtlebot3_${TB3_MODEL}/lidar/hls_lfcd_lds/scan

Waffle

$ gz topic -e /gazebo/default/user/turtlebot3_waffle/image/intel_realsense_r200/image

Waffle Pi

$ gz topic -e /gazebo/default/user/turtlebot3_waffle_pi/image/raspberry_pi_cam/image
8) Excute listener
$ cd ${turtlebot3_gazebo_plugin}/build
$ ./lidar_listener ${TB3_MODEL}

Open a new terminal window and enter below command.

$ cd ${turtlebot3_gazebo_plugin}/build
$ ./image_listener ${TB3_MODEL}
Reference