ROS 2 control software for a four-wheel omniwheel robot running on a Raspberry Pi. The active package targets ROS 2 Jazzy and is located at ROS/colcon_workspace/src/rosbot. The ROS/rosbot.old__TMP!__migrating_to_ros2_!/ directory is a legacy ROS 1 archive; its nodes and launch files are not used by the ROS 2 build.
- ROS 2 Jazzy on Ubuntu. For Raspberry Pi installation, see the ROS 2 Raspberry Pi installation guide.
colconandrosdep.- On the robot: gpiozero for GPIO control.
- Optional devices: a Linux-compatible gamepad, a libcamera-supported Raspberry Pi camera with
camera_ros, and/or a Hokuyo URG-LX04-UG01 withurg_node.
Do these steps once for each computer or Raspberry Pi where you want to build or run the package.
git clone https://github.com/markusk/rosbot.git
cd rosbotIf the repository is already cloned, use its existing directory instead.
source /opt/ros/jazzy/setup.bash
cd ROS/colcon_workspace
rosdep install --from-paths src --ignore-src -r -y
colcon build --symlink-install --packages-select rosbotrosdep install installs the package dependencies, including the ROS joystick, camera, and laser drivers. Optional devices still need to be physically connected and configured. Re-run dependency installation if package dependencies change; rebuild after changing source code.
Motor GPIO access is enabled only when the system hostname is exactly rosbot. Set the hostname once on the robot and reboot if it changed:
sudo hostnamectl set-hostname rosbot
hostnameInstall gpiozero on the Raspberry Pi:
sudo apt-get update
sudo apt-get install python3-gpiozerogpiozero accesses GPIO directly through its selected pin factory and does not require a separate GPIO daemon or systemd service.
On any host whose name is not rosbot, the motor node does not access GPIO and simulates motor output. Do not set the robot hostname on a development computer.
- Joystick: Connect a supported gamepad to Linux. To diagnose the Linux device, install the
joystickpackage (sudo apt-get install joystick) and runjstest --normal /dev/input/js0. The ROSjoydriver is installed throughrosdep. - Camera: Connect a camera supported by the Pi's libcamera version. The
camera_rosdriver is installed throughrosdep. - Hokuyo laser: Connect the URG-LX04-UG01 over USB. Confirm its serial device and supported baud rate on the robot; prefer a stable path under
/dev/serial/by-id/when available.
Camera and laser launches are restricted to the host whose name is exactly rosbot. Their physical operation has not been verified; the scanner's base-to-laser transform must also be measured before use for navigation.
Do these steps in each new terminal session. No dependency installation or rebuild is needed unless dependencies or source code have changed.
source /opt/ros/jazzy/setup.bash
cd ~/rosbot/ROS/colcon_workspace
source install/setup.bashIf the repository is in a different location, replace ~/rosbot with its path.
ros2 launch rosbot rosbot_launch.pyThis starts the motor controller, command arbitrator, and keyboard teleoperation. The keyboard node needs an interactive terminal. Press ESC in that terminal or Ctrl+C in the launch terminal to stop all launched nodes. On the robot, make the first movement tests with the wheels raised and at low speed; the software watchdog is not a physical emergency stop.
Add launch arguments to the same command when you want to use an optional device:
ros2 launch rosbot rosbot_launch.py joystick_enabled:=true joy_device_id:=0
ros2 launch rosbot rosbot_launch.py camera_enabled:=true
ros2 launch rosbot rosbot_launch.py laser_enabled:=trueThe laser defaults to /dev/ttyACM0, baud 115200, and frame laser. Override the serial settings if needed:
ros2 launch rosbot rosbot_launch.py laser_enabled:=true laser_device:=/dev/serial/by-id/your-hokuyo laser_baud:=115200 laser_frame_id:=laserCombine multiple options in one launch command, for example joystick_enabled:=true camera_enabled:=true. The joystick requires a supported Linux device. Camera and laser nodes only start on the robot hostname rosbot.
From the workspace directory, rebuild and source the updated package in each terminal that will use it:
cd ~/rosbot/ROS/colcon_workspace
colcon build --symlink-install --packages-select rosbot
source install/setup.bashIf package.xml dependencies changed, run rosdep install --from-paths src --ignore-src -r -y before building.
The code uses BCM GPIO numbers. Physical pin numbers refer to positions on the Raspberry Pi's 40-pin header. Both numbers are listed below; do not confuse them. The GPIO assignments are unchanged from earlier Raspberry Pi models with the same 40-pin header.
| Wheel | L298N input | BCM GPIO | Physical Pi pin |
|---|---|---|---|
| Front left | IN A | 5 | 29 |
| Front left | IN B | 6 | 31 |
| Front left | ENA / PWM | 12 | 32 |
| Front right | IN A | 20 | 38 |
| Front right | IN B | 21 | 40 |
| Front right | ENB / PWM | 13 | 33 |
| Rear left | IN A | 23 | 16 |
| Rear left | IN B | 24 | 18 |
| Rear left | ENA / PWM | 18 | 12 |
| Rear right | IN A | 16 | 36 |
| Rear right | IN B | 26 | 37 |
| Rear right | ENB / PWM | 19 | 35 |
Remove the corresponding jumpers on the L298N modules when using PWM on ENA/ENB. GPIO 18 (physical pin 12) is assigned to the rear-left wheel's enable input; the separate LED PWM test uses the same GPIO and must not run at the same time as motor control.
Safety: Raspberry Pi GPIOs use 3.3 V logic and are not 5 V tolerant. Do not connect motors directly to the Pi; power them through the L298N drivers. The Pi and motor drivers must share a common ground. Check the wiring and header orientation before powering on; perform initial movement tests with the wheels raised and at low speed.
For more information about nodes, joystick control, and hardware limitations, see the package README.