last updated: 2024-08-03
I want to update my TurtleBot3 Burger
to the latest ROS2. This will be Humble
because they don't exist in Jazzy
for now.
For more information about ROS2: https://www.weigu.lu/sb-computer/ros2_basics/index.html
First we need to know more about the TurtleBot3. As it comes from the firm ROBOTIS (robotis.com) we find all the infos in there emanual: https://emanual.robotis.com/docs/en/platform/turtlebot3/features/.
Special about TurtleBot3 are the smart actuators DYNAMIXEL, developed by ROBOTIS, for driving.
The main board is called OpenCR1.0
: https://emanual.robotis.com/docs/en/platform/turtlebot3/appendix_opencr1_0/. It contains an STM32F7 microcontroller and that can be flashed with the Arduino IDE. So let's first update the firmware:
Arduino needs to know the board, so we add the following string to the Additional boards manager URLs
in the File -> Preferences...
menu:
https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencrrelease/packageopencr_index.json
Next we install the board in the Boards manager, connect the board to the PC and choose the board and the right port under Tools
.
Under Files -> Examples
we find the ROS2_TurtleBot3 firmware for the Burger:
Before we compile we need to install the Dynamixel2Arduino
library, that we find in the library manager.
Than we compile and flash the firmware.
The first step is to install the packages for the TurtleBot 3. As stated we do this on Humble
(Ubuntu 22.04). I will use a Raspi4 for this. The installation of Ubuntu and ROS2 is described on ROS2_basics.
We have 2 types of ROS2 packages. Binary packages are in Ubuntu provided as debian packages (apt install
). Build-from-source packages can be provided by ROS2 or are programmed by ourselves. They have to reside in the src
folder of a ROS2 workspace.
In Humble the TurtleBot3 packages are not in the ROS2 package list. We can check with the following commands:
source /opt/ros/humble/setup.bash
ros2 pkg list | grep turtlebot3
But they exist as debian packages! We install them (on the PC and on the TurleBot3) with:
sudo apt install ros-humble-turtlebot3*
Now ros2 pkg list | grep turtlebot3
gives us the following packages:
turtlebot3
turtlebot3_bringup
turtlebot3_cartographer
turtlebot3_description
turtlebot3_example
turtlebot3_fake_node
turtlebot3_manipulation_cartographer
turtlebot3_manipulation_description
turtlebot3_manipulation_hardware
turtlebot3_manipulation_navigation2
turtlebot3_msgs
turtlebot3_navigation2
turtlebot3_node
turtlebot3_teleop
On the TurtleBot3 Raspi:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
Set the variables to variables to 0
, save (Ctrl+o) and exit (Ctrl+x).
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
Next we set the systemd to prevent boot-up delay and we disable Suspend and Hibernation:
sudo systemctl mask systemd-networkd-wait-online.service
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
The we set the udev rules for OpenCR:
sudo cp `ros2 pkg prefix turtlebot3_bringup`/share/turtlebot3_bringup/script/99-turtlebot3-cdc.rules /etc/udev/rules.d/
sudo reboot
The TurtleBot3 LDS has been updated (LDS-02) since 2022. I have the older LDS. We need to specify which LDS with an environment variable. ROS Domain ID must be the same on PC and bot. Default ID of TurtleBot3 is 30. And now we are able to start the TurtleBot3 (The battery and LDS must be connected!)
export TURTLEBOT3_MODEL=burger
echo 'export LDS_MODEL=LDS-01' >> ~/.bashrc
echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
source ~/.bashrc
ros2 launch turtlebot3_bringup robot.launch.py
On the main computer I tried to install gazebo to simulate the Turtlebot3, but for the moment this is not working on Raspi4.
The TurtleBot3 can be teleoperated by various remote controllers Let's start with a keyboard on the main computer.
We need to set up some environment variables and can then start a teleop_keyboard
node to control the TurtleBot3 with a keyboard:
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
source ~/.bashrc
ros2 run turtlebot3_teleop teleop_keyboard
ros2 topic list shows us the used topics:
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
source ~/.bashrc
ros2 run turtlebot3_teleop teleop_keyboard
We can see with ros2 topic list
that the teleop_keyboard node uses a topic called /cmd_vel
.
This topic is widely used to control robots.
---
linear:
x: 0.08
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: -0.5
---
To better understand the topic look at the ROS2 conventions.
Next step is to use my Xbox One S Controller (1708). First step was an update of the controller with a Windows app called Xbox accessories (You need updated Win10/11 and the app was only in the store when setting location to US).
ROS2 has two packages that make working with gamepads and joysticks easy. The first node (joy
)communicates with the Xbox controller through the Linux drivers and publishes a sensor_msgs/Joy
message. This is a list of buttons and axes, and we see in live what button or axes in manipulated. This data can than be used by other nodes.
The second node (teleop_node
) picks out the thumbstick values and publishes an appropriate Twist message (/cmd_vel
).
Using two nodes makes changing the joystick much more easy as not everything has to be rewritten for every joystick.
First I tried to use the controller with an USB cable, but this does not work. Apparently the cable is mainly used for charging and updates but not to use the controller with USB.
We power the Xbox controller on (X
button) and set it in bluetooth pairing mode ()))
button).
Raspi4 This is by far the easiest way, but you have to connect a Screen.
After switching the Xbox controller on we see it under bluetooth settings and are able to connect.
We test if the controller is ok with the joy node. Joyenumeratedevices should show the controller. We run the node and look at the topic in a second terminal:
ros2 run joy joy_enumerate_devices
ros2 run joy joy_node
ros2 topic echo /joy
We could the use in a second terminal ros2 run teleop_twist_joy teleop_node
but there is a better way to do it.
We stop the joy
node and use the following launch command to start teleop_twist_joy
. The launch
command also starts the joy
node (only one terminal) and has a parameter to define the controller.
ros2 launch teleop_twist_joy teleop-launch.py joy_config:='xbox'5
And here I had a problem, because the teleop node displayed Teleop enable button 2
. There is a button that has to be pressed to send messages from the thumbstick (dead man's switch) and none of the buttons corresponded to button2!
So I tested the buttons with the joy node and edited the config file:
/opt/ros/humble/share/teleop_twist_joy/config/xbox.config.yaml
and changed the following lines:
enable_button: 6 # Left trigger button
enable_turbo_button: 7 # Right trigger button
Now I was able to use the Xbox controller.
This is more complicated. A good documentation is here: https://www.baeldung.com/linux/bluetooth-via-terminal
we use the bluetoothctl
command and get an interactive shell to run the bluetooth commands.
show
shows us the controller (e.g. E4:5F:01:00:AD:21). If not powered on:power on
the controller, if not discoverable:discoverable on
list
if more than one controllerselect E4:5F:01:00:AD:21
if more controllerscan on
to find the Xbox controller (e.g. 98:7A:14:29:AA:94)devices
to show the devicespair 98:7A:14:29:AA:94
to pair the controllerconnect 98:7A:14:29:AA:94
to to connect to the controllerIf everything is ok we test with:
ros2 run joy joy_enumerate_devices
ros2 run joy joy_node
ros2 topic echo /joy
Then we sto the joy node and launch:
ros2 launch teleop_twist_joy teleop-launch.py joy_config:='xbox'5
Don't forget to change the buttons in the config file as described above.