Edit on GitHub

ROS2

NOTE:

  • This instructions were tested on Ubuntu 18.04 and ROS2 Crystal Clemmys.
  • This instructions are supposed to be running on the remote PC. Please run the instructions below on your [Remote PC]. However, the part marked [TurtleBot] is the content that runs on SBC of TurtleBot3.

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.

This chapter shows some demos using TurtleBot3 with ROS2 and Gazebo9. In order to implement these demos, you have to install some packages.

Setup

PC setup

NOTE: All demos have been tested in Ubuntu 18.04 and macOS High Sierra installed ROS2 Crystal Clemmys. If you got stuck during installation, please following ROS Answers or ROS2 Issue.

[Install Ubuntu on Remote PC]

[Install ROS2 on Remote PC]

[Install TurtleBot3 ROS2 Packages]

[Remote PC] Download turtlebot3 packages and install some dependencies for ROS2

# Install Cartographer dependencies
$ sudo apt install -y \
    google-mock \
    libceres-dev \
    liblua5.3-dev \
    libboost-dev \
    libboost-iostreams-dev \
    libprotobuf-dev \
    protobuf-compiler \
    libcairo2-dev \
    libpcl-dev \
    python3-sphinx
# Install Gazebo9
$ curl -sSL http://get.gazebosim.org | sh
# Install Navigation2 dependencies
$ sudo apt install -y \
    libsdl-image1.2 \
    libsdl-image1.2-dev \
    libsdl1.2debian \
    libsdl1.2-dev
$ mkdir -p ~/turtlebot3_ws/src
$ cd ~/turtlebot3_ws
$ wget https://raw.githubusercontent.com/ROBOTIS-GIT/turtlebot3/ros2/turtlebot3.repos
$ vcs import src < turtlebot3.repos
$ colcon build --symlink-install
$ echo 'source ~/turtlebot3_ws/install/setup.bash' >> ~/.bashrc
$ source ~/.bashrc

NOTE: If you get any build errors or warnings from dependencies, please refer to below documents.

SBC setup

[TurtleBot] Install Raspbian Stretch

  1. Download Raspbian Stretch with desktop and recommended software
  2. Unzip the download file and burn image to your microSD card(>8GB)
  3. Follow instruction that How to setup for TurtleBot3 with ROS2

OpenCR setup

[TurtleBot] Upload firmware for ROS2.

$ cd ~/turtlebot3
$ rm -rf ./opencr_update.tar.xz
$ wget https://github.com/ROBOTIS-GIT/OpenCR-Binaries/raw/master/turtlebot3/ROS2/latest/opencr_update.tar.bz2
$ tar -xf ./opencr_update.tar.bz2

$ export OPENCR_PORT=/dev/ttyACM0
$ export OPENCR_MODEL=burger
$ cd ./opencr_update
$ ./update.sh $OPENCR_PORT $OPENCR_MODEL.opencr

If uploading the firmware succeeds, below message will be displayed in the terminal.

armv7l
arm
OpenCR Update Start..
opencr_ld_shell ver 1.0.0
opencr_ld_main 
[  ] file name   	: burger.opencr 
[  ] file size   	: 168 KB
[  ] fw_name     	: burger 
[  ] fw_ver      	: V180903R1 
[OK] Open port   	: /dev/ttyACM0
[  ]
[  ] Board Name  	: OpenCR R1.0
[  ] Board Ver   	: 0x17020800
[  ] Board Rev   	: 0x00000000
[OK] flash_erase 	: 0.96s
[OK] flash_write 	: 1.92s 
[OK] CRC Check   	: 10E28C8 10E28C8 , 0.006000 sec
[OK] Download 
[OK] jump_to_fw 
$ cd ~/turtlebot3
$ rm -rf ./opencr_update.tar.xz
$ wget https://github.com/ROBOTIS-GIT/OpenCR_Binaries/raw/master/turtlebot3/ROS2/latest/opencr_update.tar.xz
$ tar -xf ./opencr_update.tar.xz

$ export OPENCR_PORT=/dev/ttyACM0
$ export OPENCR_MODEL=waffle
$ cd ./opencr_update
$ ./update.sh $OPENCR_PORT $OPENCR_MODEL.opencr

If uploading the firmware succeeds, below message will be displayed in the terminal.

armv7l
arm
OpenCR Update Start..
opencr_ld_shell ver 1.0.0
opencr_ld_main 
[  ] file name   	: waffle.opencr 
[  ] file size   	: 168 KB
[  ] fw_name     	: waffle 
[  ] fw_ver      	: V180903R1 
[OK] Open port   	: /dev/ttyACM0
[  ]
[  ] Board Name  	: OpenCR R1.0
[  ] Board Ver   	: 0x17020800
[  ] Board Rev   	: 0x00000000
[OK] flash_erase 	: 0.96s
[OK] flash_write 	: 1.92s 
[OK] CRC Check   	: 10E28C8 10E28C8 , 0.006000 sec
[OK] Download 
[OK] jump_to_fw 

[TurtleBot] Reset OpenCR using RESET button.

Bringup

[Bringup TurtleBot3]

[TurtleBot, RemotePC] Sync time between TurtleBot and RemotePC

$ sudo apt-get install ntpdate
$ sudo ntpdate ntp.ubuntu.com

[TurtleBot] Run Micro-XRCE-DDS Agent for OpenCR

$ cd ~/turtlebot3 && MicroXRCEAgent serial /dev/ttyACM0

[TurtleBot] Run Micro-XRCE-DDS Agent for Lidar

$ cd ~/turtlebot3 && MicroXRCEAgent udp 2018

[TurtleBot] Run Lidar application

$ ./turtlebot3/turtlebot3_lidar

[Remote PC] Launch robot includinf robot_state_publisher and turtlebot3_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][export_turtlebot3_model]{: .popup} page.

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_bringup robot.launch.py

If the node is successfully launched, the following instruction will be appeared to the terminal window.

[INFO] [launch]: process[robot_state_publisher-1]: started with pid [24824]
[INFO] [launch]: process[turtlebot3_ros-2]: started with pid [24825]
Initialize urdf model from file: /home/ost/turtlebot3_ws/install/turtlebot3_description/share/turtlebot3_description/urdf/turtlebot3_burger.urdf
Parsing robot urdf xml string.
Link base_link had 5 children
Link caster_back_link had 0 children
Link imu_link had 0 children
Link base_scan had 0 children
Link wheel_left_link had 0 children
Link wheel_right_link had 0 children
got segment base_footprint
got segment base_link
got segment base_scan
got segment caster_back_link
got segment imu_link
got segment wheel_left_link
got segment wheel_right_link
[INFO] [turtlebot3_node]: Init TurtleBot3 Node Main
Adding fixed segment from base_footprint to base_link
Adding fixed segment from base_link to caster_back_link
Adding fixed segment from base_link to imu_link
Adding fixed segment from base_link to base_scan
Adding moving segment from base_link to wheel_left_link
Adding moving segment from base_link to wheel_right_link

And you can check topic list as shown below

$ ros2 topic list
/cmd_vel
/imu
/joint_states
/motor_power
/odom
/parameter_events
/reset
/robot_description
/scan
/scan_half
/sensor_state
/sound
/tf
/tf_static
/time_sync
/version_info

Rviz2

[Remote PC] Run Rviz2

$ ros2 launch turtlebot3_bringup rviz2.launch.py

Teleoperation

[Remote PC] Run teleoperation node

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 run turtlebot3_teleop teleop_keyboard

If the node is successfully run, the following instruction will be appeared to the terminal window.

Control Your TurtleBot3!
---------------------------
Moving around:
        w
   a    s    d
        x

w/x : increase/decrease linear velocity (Burger : ~ 0.22, Waffle and Waffle Pi : ~ 0.26)
a/d : increase/decrease angular velocity (Burger : ~ 2.84, Waffle and Waffle Pi : ~ 1.82)

space key, s : force stop

CTRL-C to quit

Cartographer

The SLAM (Simultaneous Localization and Mapping) is a technique to draw a map by estimating current location in an arbitrary space. The SLAM is a well-known feature of TurtleBot from its predecessors. The video here shows you how accurately TurtleBot3 can draw a map with its compact and affordable platform.

[TurtleBot, RemotePC] Sync time between TurtleBot and RemotePC

$ sudo apt-get install ntpdate
$ sudo ntpdate ntp.ubuntu.com

[Remote PC]

$ cd ~/turtlebot3_ws && colcon build
$ ros2 launch turtlebot3_cartographer cartographer.launch.py

[Remote PC] Save the map

$ ros2 run nav2_map_server map_saver -f ~/map

Navigation is to move the robot from one location to the specified destination in a given environment. For this purpose, a map that contains geometry information of furniture, objects, and walls of the given environment is required. As described in the previous Cartographer section, the map was created with the distance information obtained by the sensor and the pose information of the robot itself.

The navigation enables a robot to move from the current pose to the designated goal pose on the map by using the map, robot’s encoder, IMU sensor, and distance sensor. The procedure for performing this task is as follows.

[Run Navigation2 Nodes]

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_navigation2 navigation2.launch.py

Simulation

[Remote PC] Add GAZEBO_MODEL_PATH

  $ echo '# Add gazebo model path' >> ~/.bashrc
  $ echo 'export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models' >> ~/.bashrc
  $ source ~/.bashrc

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][export_turtlebot3_model]{: .popup} page.

[Remote PC] Load TurtleBot3 on turtlebot3 world

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
$ ros2 param set /gazebo use_sim_time True

WARNING: If you got error messages about TF_OLD_DATA, you should retry to set use_sim_time parameter onto /gazebo node.

[Remote PC] Launch Cartographer

$ ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True

[Remote PC] Run teleoperation node

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 run turtlebot3_teleop teleop_keyboard

[Remote PC] Save the map

$ ros2 run nav2_map_server map_saver -f ~/map

[Remote PC] Load Navigation2

$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_navigation2 navigation2.launch.py

You should set some parameters to use simulation time. If you need futher information about it, please following navigation2 repo

$ ros2 param set /world_model use_sim_time True
$ ros2 param set /global_costmap/global_costmap use_sim_time True
$ ros2 param set /local_costmap/local_costmap use_sim_time True