This project is licensed under MIT License. For previous licensing history, see LICENSE.previous.md
Hi everyone! Today I would like to share my project implementing a fundamental differential drive robot using ROS2 Jazzy Jalisco and Raspberry Pi 5, with features including Gazebo simulation, ros2_control, teleoperation, SLAM, and Navigation2.
This project also represents my learning journey following tutorials from Articulated Robotics:
- Forum: https://articulatedrobotics.xyz/tutorials/mobile-robot/project-overview/
- Tutorial playlist: https://youtube.com/playlist?list=PLunhqkrRNRhYAffV8JDiFOatQXuU-NnxT&si=1N9GNN6gRnet5heK
You can see the demo here
Before we start, make sure you are using Ubuntu 24.04 and have ROS 2 Jazzy Jalisco installed in your server machine (which is your desktop or laptop).
Make sure to install git:
sudo apt install git ros-dev-tools -y
Make sure VScode is installed, it can be found in Ubuntu App Center. Some extensions that I have installed are listed below:
- C/C++ Extension Pack (Microsoft)
- Python (Microsoft)
- ROS (Microsoft)
- YAML (Red Hat)
- Remote - SSH (Microsoft)
Additionally, consider to install Terminator, which is a useful tool to use with ROS 2.
Before we start, see ROS 2 Packages: A Brief Introduction for the differences between the binary installation and build from source
-
Open a terminal using
ctrl + alt + t
, create a workspace namedros_ws
with a folder namedsrc
:mkdir -p ~/ros_ws/src
- Replace
ros_ws
with the name you want to put as your workspace name.
- Replace
-
Follow to the insturction at Install ROS 2 Packages to install all the necessary packages.
- Although only the listed items under For simulation only are required for simulation, it is recommanded to install all of them.
-
Once Everything is set, go to
your_workspace
and source the workspace:cd ros_ws/ . install/setup.bash
- When a new terminal is opened, ensure that terminal sourced the workspace also:
-
Launch the simulation:
ros2 launch minibot sim.launch.py
- This will launch the
robot description
,gazebo
,rviz2
,ros2_control
etc.
- This will launch the
-
Launch Simulation Control and SLAM
The
sim_control_station.launch.py
will launch all control features for the simulation, inclduingteleop
,slam_toolbox
,nav2 stack
.-
To run the control with
online_async_slam
fromslam_toolbox
, open a new terminal, source the local workspace and enter:ros2 launch minibot sim_control_station.launch.py use_slam_option:=online_async_slam
-
For
mapper_params_localization
fromslam_toolbox
:ros2 launch minibot sim_control_station.launch.py use_slam_option:=mapper_params_localization
- To change the map to load, open the params file at
./src/minibot/config/mapper_params_localization.yaml
, replace the value correspondingmap_file_name
with the desired directory.
- To change the map to load, open the params file at
-
For
AMCL
fromnav2
:ros2 launch minibot sim_control_station.launch.py use_slam_option:=amcl map:=./src/minibot/maps/sample_map.yaml
- To change the map to load, replace the default value corresponding to
map
with the desired directory.
- To change the map to load, replace the default value corresponding to
-
-
Alternatively, we can just run the teleoperation only using:
ros2 launch minibot joystick_teleop.launch.py
Refer to:
- ros_gz_bridge if a topic could not be send or recived between ROS 2 and Gazebo.
- How a ROS 2 Topic Is Received By a Node if you suspect topics are not being published or subscribed to properly
- How to Check ROS 2 Node Parameter Name using Command Line if you want to check if the parameters from
.yaml
file is loaded to the node properly.
*IMPORTANT: Please exercise the proper safety for lipo battery, I have included some precautions at Lipo Battery Safety Precautions.
- Raspberry Pi 5
- RPLIDAR C1
- ESP32-vroom-32 development board
- ESP32 expansion board (be award whether the pinout match the ESP32 dev board)
- Cytron MDD3A motor driver
- 3S lipo battery
- Step down converter (DFRobot DRF0205 for example)
I only listed down the main electronics that I used, for more information, refer to Build a Mobile Robot with ROS: Bill of Materials by Articulated Robotics
see also: Recommanded Components for Wiring and Robot Chasis (Optional).
Make sure you are using Ubuntu 24.04 and have ROS 2 Jazzy Jalisco installed in the Raspberry Pi.
Install Ubuntu in Raspberry PI using rpi-imager
- Make sure you have a Micro SD Card with at least 32GB, but a Micro SD with 64GB or more is recommanded.
- The system has occupied about 24GB of my SD Card, including all everything needed to run the robot.
- If you never install Ubuntu 24.04 using rpi-imager before, see: RPI5: Flash Ubuntu to SD Card.
Install ROS 2 in Raspberry PI
- For ROS 2 installation, you can select
ROS-Base Install
instead ofDesktop Install
. - If you wish to run
RViz
in Raspberry Pi, considerDesktop Install
or binary install via bash usingsudo apt install ros-jazzy-rviz2
.
Creating a Workspace robot_ws
in Your SBC (Raspberry Pi)
-
Open a terminal using
ctrl + alt + t
, create a workspace namedrobot_ws
with a folder namedsrc
:mkdir -p ~/robot_ws/src
- Replace
robot_ws
with the name you want to put as your workspace name.
- Replace
-
Follow to the insturction at Install ROS 2 Packages to install all the necessary packages in Raspberry Pi.
- You need to install all the packages listed except
ros_gz
.
- You need to install all the packages listed except
Flashing Code to ESP32
In addition, you need to Flash the driver code to your ESP32, see Install and Flash Microcontroller Driver code
-
Ensure the Raspberry Pi USB device port number matched the value declared:
/dev/ttyUSB0
for the lidar serial; located at./src/minibot/launch/robot.launch.py/declare_lidar_serial_port
./dev/ttyUSB1
for the ESP32; located at./src/minibot/description/ros2_control.xacro/RobotSystem/device
.- To check or troubleshoot the USB connection in Raspberry Pi, see RPI5: Add USB Access for Raspberry Pi.
-
Connects to the Raspberry Pi from your server machine using
openssh-server
. Open a terminal in the server machine, enter:ssh <remote_username>@<remote_ip_address>
- If you never install or use
openssh-server
before,see SSH Access to Remote Machine- Connect Remote Machine via Terminal.
- If you never install or use
-
In order to let the nodes to be discoverable between the server and the remote machine, We need to set
ROS_DOMAIN_ID
to the same for both of the machine:# The ID is 0 by default, but can be any number between 0 between 101 export ROS_DOMAIN_ID=1
-
For the Raspberry Pi, we can add
export ROS_DOMAIN_ID = 1
to the.bashrc
file instead using:echo "export ROS_DOMAIN_ID=1" >> ~/.bashrc
-
To check the
ROS_DOMAIN_ID
set, enterecho ${ROS_DOMAIN_ID}
in terminal.
-
-
Once Everything is set, go to
your_workspace
and source the workspace:cd ros_ws/ . install/setup.bash
- When a new terminal is opened, ensure that terminal sourced the workspace also:
-
Run the robot:
ros2 launch minibot robot.launch.py
- This will launch
robot description
,ros2_control
,sllidar_c1_launch
etc.
- This will launch
-
Launch Robot Control with SLAM or Localization
The
robot_remote_station.launch.py
will launch all control features for the robot, inclduingteleop
,slam_toolbox
,nav2 stack
.-
To run the control with
online_async_slam
fromslam_toolbox
, open a new terminal in your server machine, source the local workspace and enter:ros2 launch minibot robot_remote_station.launch.py use_slam_option:=online_async_slam
-
For
mapper_params_localization
fromslam_toolbox
:ros2 launch minibot robot_remote_station.launch.py use_slam_option:=mapper_params_localization
- To change the map to load, open the params file at
./src/minibot/config/mapper_params_localization.yaml
, replace the value inmap_file_name
with the desired directory.
- To change the map to load, open the params file at
-
For
AMCL
fromnav2
:ros2 launch minibot robot_remote_station.launch.py use_slam_option:=amcl map:=./src/minibot/maps/sample_map.yaml
- To change the map to load, replace the default value of
map
with the desired directory.
- To change the map to load, replace the default value of
-
-
Alternatively, we can just run the teleoperation only using:
ros2 launch minibot joystick_teleop.launch.py
Some visual demostration:
global_costmap/global_costmap/ros__parameters/inflation_layer/cost_scaling_factor
= 1.0
global_costmap/global_costmap/ros__parameters/inflation_layer/inflation_radius
= 0.05
- Implement the hardware interface within this package instead.
- Explore the
slam_toolbox
andnav2
, or any equivalent. - Implement 3D slam at least in simulation using depth camera, if possible.