Skip to content

Kobuki setup with Raspberry Pi

Versions

Ubuntu: 22.04 LTS

ROS: Humble Hawksbill

Prerequisites

As well as your Kobuki robot, you will need

  • A Raspberry Pi 4 with power supply
  • A 64GB SD card
  • A USB-A to USB-B cable (supplied with the Kobuki)
  • A laptop
  • An accessible 2.4GHz wifi network

1. Install Ubuntu

At the time of writing, 22.04 is the latest supported release for ROS2.

Use the Raspberry Pi imager to format the SD card using the configuration settings below. You can change the example values to suit your own requirements. These values will be used in any example code shown here.

  • Hostname: kobuki
  • Username: ubuntu
  • Password: kobuki123
  • WiFi SSID: labwifi
  • WiFi password: labpw

Be sure to enable ssh on the Services tab

On first boot, Ubuntu performs an unattended update which may last up to half an hour. If the RPi is connected to a display via the HDMI port, you can check if the update is still going with

1
pgrep -al unattended

Otherwise, you will need to be patient! You may not be able to connect via ssh until the update is complete.

2. Connect via ssh

Your laptop and RPi need to be connected to the same 2.4GHz wifi network. Once both devices are connected, you can connect via ssh:

1
ssh ubuntu@kobuki

3. Update packages

Use the following two commands to perform the standard package update

1
2
sudo apt update
sudo apt upgrade

The update may take a long time - again, please be patient and make sure you are not constrained by time.

4. Make directory for ROS workspace

It is good practice to keep your files tidy. ROS encourages this through the use of workspaces. Use the command below to create a directory and set it as the current directory.

1
2
mkdir kobuki
cd kobuki

5. Install Eigen3 from source

Eigen3 is a C++ library for performing numerical calculations as numpy does in Python. There is a recent update that corrects for a restriction on memcpy where the object is not trivially copyable. The version of Eigen3 that is installed by ROS2 at the time of writing does not include this fix and therefore causes compilation errors. The solution is to ensure that the current version of Eigen3 is already installed. The steps are

  1. Clone the repository inside your ROS workspace:
    1
    git clone https://gitlab.com/libeigen/eigen.git
    
  2. Copy eigen directory to /usr/include/eigen3:
    1
    sudo cp -r Eigen/eigen /usr/include/eigen3
    

Using CMake to build the library places the eigen3 directory into /usr/local/include. This may or may not work - using /usr/include definitely does.

6. Install ROS2

At the time of writing, the most recent version of ROS2 that a) is compatible with the RPi 4 and b) has long-term support is Humble. Use the standard instructions for Debian packages and complete the talker-listener test.

These notes assume that you are installing the server version (ie with no graphical desktop or tools.

Note that to run ROS scripts, you need to have the appropriate environment variables set. The instructions describe how to do this with the command

1
source /opt/ros/humble/setup.bash

Step 15 explains how to call this script automatically.

7. Install dependencies

The Kobuki driver has to be built from source. This requires a C++ compiler and associated tools that are not installed by default:

  • g++ is the GNU C++ compiler.
  • rosdep is a tool for installing ROS dependencies
  • colcon improves the workflow of building, testing and using multiple software packages
  • kobuki-ros-interfaces allows the Kobuki to communicate as a ROS node
  • ros-humble-kobuki-velocity-smoother smooth velocity transitions to avoid jerky movements
  • sophus This is a c++ implementation of Lie groups commonly used for 2d and 3d geometric problems

Install these tools with

1
2
3
4
sudo sh -c 'echo "deb [arch=amd64,arm64] http://repo.ros2.org/ubuntu/main `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
sudo apt update
sudo apt install g++ build-essential python3-rosdep python3-colcon-common-extensions ros-humble-kobuki-ros-interfaces ros-humble-kobuki-velocity-smoother ros-humble-sophus

8. Prepare required packages

The following packages are needed to build the Kobuki driver. Each one needs to be cloned from its repository into your ROS2 workspace.

The following code will download them all in one go.

1
2
3
4
5
6
7
8
9
git clone https://github.com/ros2/ros_testing.git
git clone https://github.com/stonier/ecl_tools.git
git clone https://github.com/ros/angles.git
git clone https://github.com/ros/diagnostics.git
git clone https://github.com/kobuki-base/kobuki_core.git
git clone https://github.com/kobuki-base/kobuki_ros.git
git clone https://github.com/kobuki-base/cmd_vel_mux.git
git clone https://github.com/stonier/ecl_core.git
git clone https://github.com/stonier/ecl_lite.git

9. Add ROS dependencies

Use rosdep to install any missing dependencies using the command below.

1
rosdep install -i --from-path src --rosdistro humble -y

Please note that rosdep is not recursive! To be sure of covering all dependencies, you will need to run this command in all of the subdirectories in the workspace. This is a little tedious, especially when there are several src directories at different levels in the directory tree.

10. Build the Kobuki driver

Use the colcon build tool to compile the driver with the command below.

1
colcon build --symlink-install --executor sequential

11. Test the installation

Before testing, use the code below to add a udev rule to the operating system so that the Kobuki device file can be easily recognised. Without the rule, the robot will appear as /dev/ttyUSB0. The rule changes this to /dev/kobuki.

1
2
wget https://raw.githubusercontent.com/kobuki-base/kobuki_ftdi/devel/60-kobuki.rules
sudo cp 60-kobuki.rules /etc/udev/rules.d

The software environment should now be ready for testing. Connect the Kobuki to the RPi using the USB cable and power it on. You should hear a confirmation chirp and you should be able to see the /dev/kobuki device file.

You need some more environment variables to be set to use the Kobuki driver. The following command will do this.

1
source ./install/setup.bash

You can now display the robot configuration using

1
kobuki-version-info
ToDo: update firmware

Ideally, you would update the Kobuki firmware at this stage. However, at the time of writing, there is an issue with the current version of the flashing tool. These notes will be updated with a fix for this at some point.

You can also check that the robot and the RPi are communicating correctly by controlling the robot with the command

1
kobuki-simple-keyop

12. Configure login script

Both ROS and the Kobuki driver need environment variables to be set to ensure correct operation. This is tedious to do every time you open a new terminal and also easy to forget. You can set the required values automatically by adding the following lines to the /home/ubuntu/.bashrc file.

1
2
3
source /opt/ros/humble/setup.bash
source ~/kobuki/install/setup.bash
export ROS_DOMAIN_ID=1

The third line sets an additional variable which identifies the ROS domain. This will be needed later when the robot needs to communicate with other ROS nodes.

13. Configure teleoperation

In this step, you will run a second ROS node on your laptop and use it to control the Kobuki over wifi. To do this you need ROS2 installed on the laptop as well as on the RPi. A convenient way to install ROS2 in a desktop environment is to use Robostack. Installation on MacOS is covered on the Robostack page. Make sure that the ROS2 package ros-humble-teleop-twist-keyboardis installed.

With reference to step 12 above, make sure that the ROS_DOMAIN_ID variable is set on both the RPi and the laptop and that it has the same value. This will allow the ROS nodes on the two systems to recognise each other and communicate.

To fully understand how teleoperation works, you need to know about ROS topics and. Get up to speed with the official tutorials.

Figure 1 shows the node graph that we will be working with.

ROS teleop node graph

Figure 1: ROS teleop node graph

The kobuki_node package listens for messages on the /commands/velocity topic as shown. Start the node on the RPi with the command

1
ros2 launch kobuki_node kobuki_node-launch.py
The /teleop-twist-keyboard package publishes on the /cmd_vel topic by default. Topics can be remapped when the ROS package is launched as shown in the command below which should be run on the laptop.

1
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args --remap cmd_vel:=commands/velocity
  1. Configure ROS 2 teleoperation: https://idorobotics.com/2024/02/20/ros2-on-kobuki-turtlebot/

Further reading

 ROS 2 on Kobuki TurtleBot

 Kobuki ReadTheDocs