Edit on GitHub

Simulation

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.

NOTE: This instructions were tested on Ubuntu 18.04 and ROS 2 Dashing Diatamata.

TurtleBot3 supports a development enviroment which can be programed and developed with a virtual robot in the simulation

There are two development enviroments: Fake Node and Gazebo.

Fake Node:

Gazebo:

TurtleBot3 Simulation using Fake Node

To use a virtual TurtleBot3, execute turtlebot3_fake_node.launch.py in a turtlebot3_fake_node package that is simple simulation node. Follow the instructions to bring TurtleBot3 into the virtual world using Fake Node.

  1. Execute turtlebot3_fake_node.launch.py file
      $ export TURTLEBOT3_MODEL=${TB3_MODEL}
      $ ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

    • You can control the virtual TurtleBot3 by using Teleoperation
      $ export TURTLEBOT3_MODEL=${TB3_MODEL}
      $ ros2 run turtlebot3_teleop teleop_keyboard
      

TurtleBot3 Simulation using Gazebo

In order to use Gazebo, choose either of two options:

  1. Use turtlebot3_gazebo package via ROS.
  2. Use turtlebot3_gazebo_plugin plugin without running ROS.

ROS packages for Gazebo

Add GAZEBO_MODEL_PATH.

$ echo 'export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models' >> ~/.bashrc
$ source ~/.bashrc

NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

Simulate in Various World

1) Empty World

Test the virtual TurtleBot3 on the empty world of the gazebo default environment.

  1. Open a terminal on Remote PC
  2. Bring Empty World using the following command.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo empty_world.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

  3. Load TurtleBot3 on TurtleBot3 world.
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.  

  1. Open a terminal on Remote PC
  2. Bring Empty World using the following command.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

3) TurtleBot3 House

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

  1. Open a terminal on Remote PC
  2. Bring TurtleBot3 House using the following command.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

Drive TurtleBot3

1) Teleoperation on Gazebo

In order to control TurtleBot3 using a keyboard, launch a teleoperation node.

  1. Open a terminal on Remote PC
  2. Run teleoperation node.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 run turtlebot3_teleop teleop_keyboard
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

2) Collision Avoidance

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

  1. Open a terminal on Remote PC
  2. Bring Empty World.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

  3. Open a new terminal on Remote PC
  4. Run the command below.
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 run turtlebot3_gazebo turtlebot3_drive
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

Execute RViz2

RViz visualizes published topics while simulation is running. Launch RViz by using a command below.

  1. Open a terminal on Remote PC
  2. Execute RViz2.
    $ ros2 launch turtlebot3_bringup rviz2.launch.py
    

Virtual SLAM with TurtleBot3

Use SLAM for a virtual robot in Gazebo.

Virtual SLAM Execution Procedure

The following commands are examples for TurtleBot3 Waffle Pi in a turtlebot3_world.

  1. Launch Gazebo
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
    
  2. Launch Cartographer SLAM
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
    
  3. Remotely Control TurtleBot3
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 run turtlebot3_teleop teleop_keyboard
    
  4. Save the Map
    $ ros2 run nav2_map_server map_saver -f ~/map
    

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

NOTE : You should set some parameters to use simulation time. If you need futher information about it, go on navigation2 repo

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.

  1. Execute Gazebo
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

  2. Execute Navigation
    $ export TURTLEBOT3_MODEL=${TB3_MODEL}
    $ ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=True map:=$HOME/map.yaml
    

    NOTE: Specify ${TB3_MODEL}: burger, waffle, waffle_pi before excuting the command. Set the permanent export setting by following Export TURTLEBOT3_MODEL instruction.

    • Click 2D Pose Estimate button in a menu bar, and then point exact pose of turtlebot3 on a map.
    • If TurtleBot3 is close to a costmap or nearby the map, click Navigation2 Goal button in a menu bar, and then point goal pose on the map.