Atlas Robotics
ROS2

Diff Robot — differential-drive robot for ROS2 mapping & navigation

Diff Robot — differential-drive robot for ROS2 mapping & navigation

A two-wheel differential-drive mobile robot for research on mapping and autonomous navigation with ROS2. Three-layer architecture: an Arduino/ESP32 reads the encoders and drives the motors at the low level; a Raspberry Pi 4 runs ROS2 for odometry, SLAM (Cartographer or SLAM Toolbox) and Nav2 at the compute level; RViz2 monitors the robot, its trajectory, the map and the Nav2 state at the application level.

View source on GitHub

Project gallery

Diff Robot — differential-drive robot for ROS2 mapping & navigation
Diff Robot — differential-drive robot for ROS2 mapping & navigation
Diff Robot — differential-drive robot for ROS2 mapping & navigation
Diff Robot — differential-drive robot for ROS2 mapping & navigation
Diff Robot — differential-drive robot for ROS2 mapping & navigation
Diff Robot — differential-drive robot for ROS2 mapping & navigation

Demo videos

Mapping — building a map of the environment with SLAM

Navigation2 — autonomous navigation and obstacle avoidance

Note: this is a research prototype used to validate the hardware/software architecture of a small autonomous mobile robot, not a finished commercial product.

How a differential-drive robot works and its kinematic model

Unlike Mecanum wheels, a differential-drive robot uses only 2 driven wheels on the same axis, turning independently, plus a free-swivelling caster wheel for balance. It is the most common mobile robot configuration thanks to its simple mechanics, low cost and better odometry than Mecanum (the wheels stay in continuous contact with the floor instead of rolling over separate rollers).

Differential-drive kinematic model

How the robot moves

  • Straight forward/backward: both wheels turn at the same speed in the same direction
  • Curving: both wheels turn in the same direction at different speeds (the inner wheel slower than the outer wheel)
  • Turning in place: the wheels turn in opposite directions at the same speed

Kinematic equations

v = (v_right + v_left) / 2          — linear velocity of the robot
ω = (v_right − v_left) / L          — angular velocity, L = distance between the wheels (wheelbase)

The inverse direction (from the desired /cmd_vel command to the speed each wheel needs) is exactly what the cmdvel_to_motorcommand.py node (package diff_serial_bridge) computes every time it receives a command:

v_left  = v − ω·L/2
v_right = v + ω·L/2

In short: a differential-drive robot cannot move sideways (strafe) like a Mecanum robot; to move in any direction it always has to turn first. In exchange, controlling only 2 motors (instead of 4) keeps the kinematic model simpler, and accumulated encoder odometry error is usually lower.

Serial communication between ROS2 and the Arduino/ESP32

The low level (Arduino Nano/ESP32) and the compute level (Raspberry Pi 4 running ROS2) exchange data over a 57600-baud serial UART using a small set of plain-text commands that are easy to debug straight from a terminal:

ROS2 ↔ Arduino communication over serial

Command sent to the ArduinoMeaning
o [pwm_left] [pwm_right]Set the PWM for the left/right motors
eRequest an encoder reading; the Arduino replies "e_left e_right"
rReset the encoder values to 0

Data is wrapped in custom message types defined in the diff_serial_mgs package (MotorCommand, EncoderVals, MotorVels) instead of standard ROS2 types, keeping the interfaces between nodes clear and meaningful. The full pipeline:

/cmd_vel (Twist)
     │
     ▼
cmdvel_to_motorcommand.py  →  compute v_left, v_right from the kinematic model
     │
     ▼
diff_serial_bridge.py  →  send "o [pwm] [pwm]" over serial to the Arduino
     │
     ▼
Arduino: read the command → output PWM to the motor driver
     │  (periodically sends back "e_left e_right")
     ▼
encoder_to_odom.py (package robot_kinematic)  →  compute odometry, publish /odom + TF

In short: all communication between the ROS2 "brain" and the motor hardware goes through a few simple text commands over serial. No complex driver is needed, and it is easy to test by hand while debugging (open a serial terminal, type o 100 100 and the motors spin right away).

LiDAR: two hardware options

The project supports 2 interchangeable LiDARs out of the box; both the ydlidar_ros2_driver and rplidar_launch packages are in the source code, so you can choose based on the hardware you have:

YDLIDAR X3 ProRPLIDAR A1 / A2
ManufacturerEAI (YDLIDAR)Slamtec
Measuring principleOptical triangulationOptical triangulation
Typical range~0.12 – 8m~0.15 – 12m (A2 reaches further than A1)
InterfaceUSB (via adapter board)USB (via adapter board)
ROS2 outputsensor_msgs/LaserScan on /scansensor_msgs/LaserScan on /scan

Both use the same triangulation principle: a laser diode shines on an object, the reflected light is focused onto an image sensor placed a fixed baseline away, and the position of the light spot on the image sensor gives the distance through triangle geometry. The emitter–receiver assembly spins 360°, and each revolution produces one scan of many (angle, distance) pairs, the main input for both SLAM and Nav2.

In short: because both drivers publish the same LaserScan standard, the rest of the system (SLAM, Nav2) does not change when switching LiDARs; you only switch to the matching sensor launch file.

SLAM fundamentals

SLAM (Simultaneous Localization and Mapping) solves two interdependent problems at once: you need a reliable map to localize accurately, but you need an accurate position to build a correct map. Every modern SLAM system splits the work into two layers:

  • Front-end: scan matching, aligning the current LiDAR scan with the existing local map to estimate the current position
  • Back-end: periodically optimizing the whole trajectory from the collected constraints, especially loop closure: when the robot returns to a place it has visited, the system recognizes it and "pulls" the trajectory back to the true position, removing the accumulated drift.

The project provides two SLAM options for building the map, described in the next section.

Cartographer and SLAM Toolbox: two ways to build the map

The robot_mapping package includes both cartographer.launch.py and slam_toolbox.launch.py, so you can compare the two most popular SLAM systems on ROS2 directly:

CriterionCartographerSLAM Toolbox
DeveloperGoogleThe ROS2 community team (Steve Macenski)
ArchitectureSubmaps + pose-graph optimization (Ceres Solver)Pose-graph optimization (Ceres/G2O), optimized for ROS2
Operating modesMainly online (live mapping)Online, offline and lifelong mapping (continue mapping on an existing map)
Saving stateExports an occupancy gridCan save the pose graph (.posegraph) to reload and keep mapping
Configuration complexityMany parameters, needs careful tuningFewer parameters, easier to get started
Dedicated localization modeNoYes (localization mode, localizing on an existing map; can replace AMCL)

In short: Cartographer suits cases that need high accuracy when you are comfortable tuning parameters; SLAM Toolbox suits fast development loops, saving mapping progress to continue later, or using one package for both mapping and localization.

Localization with AMCL (Adaptive Monte Carlo Localization)

Once a static map exists (from Cartographer or SLAM Toolbox), AMCL localizes the robot on that map. Unlike SLAM (building the map and localizing at the same time), AMCL assumes the map is fixed and only estimates the position.

AMCL gradually converging with a particle filter

AMCL uses a particle filter: each "particle" is a hypothesis about the robot's position (x, y, θ). The loop repeats 3 steps continuously:

  1. Predict: move each particle according to the motion model, based on the latest odometry
  2. Update weights: compare the LiDAR scan expected at each particle's position with the actual LiDAR scan; the better a particle's prediction matches reality, the higher its weight
  3. Resample: drop low-weight particles and duplicate high-weight particles around the most likely area

The "Adaptive" part comes from KLD-sampling: the number of particles is adjusted dynamically, with many particles while uncertainty is high (just started, position unknown) and fewer once it has converged, saving a lot of compute on limited hardware such as the Raspberry Pi 4.

In short: SLAM Toolbox in localization mode and AMCL solve the same problem (localizing on an existing map) in two different ways, and the project includes both so you can compare them.

Navigation2 fundamentals

Nav2 orchestrates the whole process of getting the robot to its goal, combining several specialized nodes listed in the README: map_server, amcl, controller_server, planner_server, smoother_server, bt_navigator, lifecycle_manager.

Main components

  • planner_server: computes the optimal path on the global costmap, ignoring instantaneous dynamics
  • smoother_server: post-processes the computed path to remove sharp corners, making the trajectory kinematically more feasible before the controller follows it
  • controller_server: follows the path in real time, constantly adjusting velocity to stay on the trajectory while avoiding new obstacles
  • bt_navigator: coordinates the whole flow with a Behavior Tree: compute the path → follow the path → on failure switch to recovery behaviors (spin, back up, wait) → try again

Lifecycle Manager: managing node lifecycles

Nav2's nodes are all managed/lifecycle nodes, a kind of ROS2 node with explicit states (unconfigured → inactive → active → finalized) instead of running as soon as they start. lifecycle_manager coordinates the state transitions across the whole Nav2 system: it makes sure map_server is ready before amcl starts, and amcl is active before planner_server/controller_server begin accepting commands. This avoids a node running before the node it depends on is ready, a common problem when starting a complex multi-node system.

System architecture

The system's three-layer architecture

The system is split into 3 layers, and each layer only talks to its neighbour:

  • Low-level control layer (Arduino Nano/ESP32): outputs PWM to the motor driver and reads the left/right encoder pulses in real time
  • Compute layer (Raspberry Pi 4, ROS2): diff_serial_bridge bridges serial ↔ ROS2, robot_kinematic computes odometry from the encoders, robot_mapping runs SLAM (Cartographer or SLAM Toolbox), robot_navigation runs Nav2 (AMCL, costmaps, planner, controller)
  • Application & monitoring layer (RViz2): visualizes the 3D robot, trajectory, map, TF tree and Nav2 state, usually on a separate laptop on the same ROS2 network (DDS) as the Raspberry Pi 4

Besides the real hardware, the source code includes a robot_simulation package (a URDF/xacro robot description and a Gazebo world), so algorithms can be developed and tested in simulation before deploying to real hardware, reducing the risk of damage when testing directly.

Basic calculations for the robot design

Unlike the Mecanum project (where motor specs had to be assumed), this project has real figures in the README: GA25 motors – 120RPM, 7.3 kg·cm stall torque, ~1.8A under load.

Theoretical top speed

Assuming 65mm wheels (a common size for robots with GA25 motors; it is not in the README, so a typical reference value is used):

ω = 2π × 120 / 60 ≈ 12.57 rad/s
v_max = ω × r = 12.57 × 0.0325 ≈ 0.41 m/s  (≈ 1.47 km/h)

Noticeably faster than the Mecanum robot (60RPM motors, ~0.19 m/s), which makes sense since these motors have twice the rated speed.

Torque check

With an assumed robot mass m ≈ 3kg, friction coefficient μ ≈ 0.6 and only 2 driven wheels (unlike the Mecanum robot's 4 driven wheels):

T_required = (m × g × μ × r) / n_driven_wheels
           = (3 × 9.8 × 0.6 × 0.0325) / 2
           ≈ 0.287 N·m ≈ 2.93 kgf·cm per wheel

The 7.3 kgf·cm stall torque is well above the required 2.93 kgf·cm, leaving a good margin. Note however that stall torque is the value at zero speed (with the motor blocked and not turning), not the continuous torque at rated speed, which is considerably lower along a DC motor's torque–speed curve. Comparing these two numbers directly is only a rough first check and does not replace measuring the real torque at operating speed.

Power consumption and battery selection

The README lists the power source as a "12V 10C battery". This is a common way of labelling RC-style lithium batteries (LiPo/Li-ion), where 10C is the discharge rate, not the capacity: a battery of capacity Q (Ah) labelled 10C can continuously deliver up to 10 × Q amps. The exact capacity (mAh) is not given in the README, so the calculation below uses a typical reference value for this class of robot (3S ~11.1V, 2200mAh) to illustrate the method.

Estimated current draw

ComponentCurrent draw
Raspberry Pi 4 (ROS2 + SLAM/Nav2)~1.5 – 2.5 A @ 5V
Arduino/ESP32~0.1 – 0.2 A @ 5V
LiDAR (X3 Pro/RPLIDAR)~0.3 – 0.4 A @ 5V
2× GA25 motors (per the README's "1.8A under load")1.8 A per motor @ 12V
P_compute  ≈ (2.5 + 0.2 + 0.4) × 5V  ≈ 15.5 W
P_motors (rated load)  ≈ 2 × 1.8 × 12V  ≈ 43.2 W
P_total (rated load, worst case)  ≈ 59 W

Since "1.8A under load" is most likely the current near heavy/rated load rather than the average current while cruising, the real figure in normal operation is usually lower; for example, with an estimated average of ~0.8A per motor:

P_motors (average)  ≈ 2 × 0.8 × 12V  ≈ 19.2 W
P_total (average)  ≈ 35 W

Can a 10C battery handle it

A 3S 2200mAh battery at 10C → maximum continuous discharge = 10 × 2.2A = 22A. The load calculated above (~59W in the worst case / 11.1V ≈ 5.3A) is far below the 22A allowed, so there is plenty of margin and the battery is not the limiting factor for discharge current.

Estimated runtime

Battery energy = 11.1V × 2.2Ah ≈ 24.4 Wh
T (rated load) ≈ (24.4 × 0.8 × 0.85) / 59  ≈ 0.28 h  (~17 minutes)
T (average load) ≈ (24.4 × 0.8 × 0.85) / 35  ≈ 0.47 h  (~28 minutes)

(0.8 = using only 80% of the capacity to protect the lithium battery's lifespan, 0.85 = conversion efficiency through the power modules)

In short: with a battery capacity typical for this class of robot, continuous runtime is about 17–28 minutes depending on how hard the robot works: enough for short test sessions, but a clear area to improve if development continues (see Next steps).

Testing and evaluation

The real mapping and navigation runs are recorded in the 2 demo videos at the top of the page (Demo videos section).

Main observations

  • With both Cartographer and SLAM Toolbox available, the project allows a direct comparison of the two SLAM systems on the same hardware, useful for judging map quality and how easy each is to tune
  • Since only 2 driven wheels stay in continuous contact with the floor (no rollers as on a Mecanum robot), encoder-only odometry is more stable, and SLAM/AMCL converge faster on flat floors
  • A differential-drive robot cannot strafe, so in tight spaces it has to turn more to avoid obstacles than an omnidirectional platform, which is clearly visible in the trajectory in the navigation video

Observed limitations

  • The short estimated battery runtime (~17–28 minutes) limits the length of each test session
  • There is no IMU yet, so odometry still depends entirely on the encoders and drifts easily when the wheels slip slightly on smooth surfaces
  • The Cartographer/SLAM Toolbox comparison in the repo currently stops at "both can be run to try"; there is no quantitative benchmark between the two

Summary and next steps

Summary

The project builds a complete differential-drive research prototype with a clear three-layer architecture (real-time control on the Arduino/ESP32, ROS2 computation on a Raspberry Pi 4, monitoring in RViz2), while offering flexibility that is rare in a small project: 2 LiDAR options (YDLIDAR X3 Pro / RPLIDAR A1-A2), 2 SLAM options (Cartographer / SLAM Toolbox), both real hardware and Gazebo simulation (the robot_simulation package), and an early integration of voice control (the robot_voice_control package). It is a test platform designed to be easy to extend, not just to run one fixed scenario.

Next steps

  • Add an IMU: fuse it with the encoders through an EKF (robot_localization) to improve odometry accuracy and stop relying entirely on the wheels
  • Quantitative Cartographer vs SLAM Toolbox benchmark: measure map error, loop closure convergence time and CPU usage on the same dataset, instead of only comparing qualitatively
  • Improve battery runtime: re-check the actual battery capacity in use and consider a larger battery for longer test sessions
  • Finish voice control: the robot_voice_control package already has a skeleton (voice_sender, voice_server, cmd_client) that can grow into an alternative control channel alongside teleop/Nav2 goals
  • Close the speed loop (PID) on the Arduino/ESP32 using the encoders, instead of only setting open-loop PWM, so wheel speed stays stable as the load changes

Specifications

Drive type
2-wheel differential drive
Microcontroller
Arduino Nano / ESP32 — encoder reading, motor control
Onboard computer
Raspberry Pi 4 (4GB/8GB RAM)
LiDAR sensor
YDLIDAR X3 Pro or RPLIDAR A1/A2
Motors
GA25 — 120RPM, 7.3kg·cm stall torque, ~1.8A under load
Motor driver
L298N / BTS7960 / Cytron
Power
12V 10C battery
Low-level link
Serial UART 57600 baud (Arduino ↔ ROS2)
Framework
ROS2
SLAM
Cartographer or SLAM Toolbox
Navigation
Nav2 — AMCL, Costmap, BT Navigator
License
MIT License
Diff Robot — differential-drive robot for ROS2 mapping & navigation — Atlas Robotics