Atlas Robotics
ROS2 Foxy / Humble

Autonomous Mecanum-Wheel Robot

Autonomous Mecanum-Wheel Robot

A four-wheel Mecanum mobile robot that can move in any direction (including sideways and turning in place), well suited to workshops and tight spaces. An ESP32 handles motor control and encoder reading at the low level, while a Raspberry Pi 4 runs ROS2 for SLAM, localization and navigation at the high level. The robot can build a map on its own, localize itself, avoid obstacles and plan its own paths.

View source on GitHub

Project gallery

Autonomous Mecanum-Wheel Robot
Autonomous Mecanum-Wheel Robot
Autonomous Mecanum-Wheel Robot
Autonomous Mecanum-Wheel Robot

Demo videos

Mapping — scanning and building a map with Cartographer SLAM

Navigation — autonomous navigation and obstacle avoidance with Nav2

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 Mecanum wheels work

A Mecanum wheel differs from a regular wheel in one small but important detail: its rim carries many free rollers, mounted at 45° to the wheel's axis of rotation. The rollers are not driven by the motor; they just spin freely on their own axes.

How a Mecanum wheel works

When the motor turns the wheel, the force at the contact point with the floor is "filtered" by the roller: the component of force along the roller's axis is not transmitted to the floor (since the roller spins freely in that direction), and only the component perpendicular to the roller's axis produces real thrust. Because the roller axis is tilted 45°, the real thrust on the floor is also tilted 45° from the wheel's direction of rotation, instead of pointing straight along it as with a regular wheel.

Why four wheels together can move in any direction

The robot's four wheels are mounted with two mirror-image roller orientations (forming an "X" when seen from above): the front-left/rear-right wheels one way, the front-right/rear-left wheels the other way. By changing the speed and direction of each wheel independently, the individual 45° thrusts of the 4 wheels add up as vectors, letting the robot:

  • Move straight forward/backward: all 4 wheels turn in the same direction at the same speed
  • Move sideways (strafe): the two diagonal pairs turn in opposite directions
  • Turn in place: the left and right wheels turn in opposite directions
  • Move diagonally in any direction: by mixing different ratios between the wheels

In short: a Mecanum wheel does not move omnidirectionally "by itself"; that ability comes from adding up the 45° thrust vectors of 4 independent wheels. This is also why all 4 motors must be controlled simultaneously and precisely, unlike a differential-drive vehicle that only controls 2 wheels.

Building the kinematic model of a 4-wheel Mecanum robot

An accurate kinematic model is essential to convert between "which way the robot needs to move" (the control command) and "how fast each wheel needs to turn" (the actual motor command). These two conversions are called inverse kinematics and forward kinematics.

Kinematic model of a 4-wheel Mecanum robot

Defining the coordinate frame

The robot's desired velocity is expressed in a frame attached to the robot body (base_link), with 3 independent components, the characteristic degrees of freedom of an omnidirectional system:

  • vx: forward/backward velocity (along the robot body)
  • vy: left/right velocity (across the robot body; only Mecanum/omni robots have this)
  • ω: angular velocity around the vertical axis

plus two fixed geometric parameters: l_x (half the distance between the front and rear wheel axles) and l_y (half the left–right track width), and r, the wheel radius.

Inverse kinematics: from the control command to each wheel's speed

v1 = vx − vy − (lx+ly)ω     (front-left wheel)
v2 = vx + vy + (lx+ly)ω     (front-right wheel)
v3 = vx + vy − (lx+ly)ω     (rear-left wheel)
v4 = vx − vy + (lx+ly)ω     (rear-right wheel)

The actual angular velocity to set for each motor is ωᵢ = vᵢ / r. This is exactly what the kinematic.launch.py node in the project's motor_control package computes whenever it receives a Twist command (from the keyboard, a joystick or Nav2), converting it into 4 wheel speeds sent to the ESP32.

Forward kinematics: from each wheel's speed to the robot's velocity (used for odometry)

vx = (v1 + v2 + v3 + v4) / 4
vy = (−v1 + v2 + v3 − v4) / 4
ω  = (−v1 + v2 − v3 + v4) / (4·(lx+ly))

This reverse calculation uses data from the encoders on the 4 motors to estimate how the robot is actually moving; the result is integrated over time to get odometry (the estimated position), one of the localization data sources fed into SLAM.

Limitation to keep in mind: the kinematic model above is idealized and assumes no wheel slip. In practice a Mecanum wheel touches the floor through many small rollers with intermittent contact and slips more than a regular wheel, so the accumulated drift of encoder-only odometry is usually larger than on a differential-drive robot and needs extra sensors (IMU, LiDAR) to compensate.

The LiDAR sensor and how it works

The robot uses a YDLIDAR X3 Pro, a low-cost 2D LiDAR that measures distance by optical triangulation, unlike high-end LiDARs that use Time-of-Flight.

The triangulation principle of a triangulation LiDAR

The triangulation principle

A laser diode shines a beam onto an object; the reflected light is focused through a lens onto a linear image sensor (PSD/CMOS) placed a fixed distance from the laser diode, called the baseline (b). Where the light spot lands on the image sensor depends on the reflection angle, which in turn depends on the distance to the object. From the triangle formed by (diode – object – image sensor), the distance D follows the approximate formula:

D = f · b / x

where f is the lens focal length, b is the baseline and x is the measured position of the light spot on the image sensor.

Spinning 360° to build environment data

The whole emitter–receiver assembly is mounted on a motor that spins continuously through 360°. Each revolution produces hundreds or thousands of (angle, distance) pairs, packed into a sensor_msgs/LaserScan message on the /scan topic (by the ydlidar_ros2_driver package in the project). This is the main input for both SLAM (building the map) and Nav2 (real-time obstacle detection).

In short: the YDLIDAR X3 Pro measures distance with optical triangle geometry rather than time of flight. It is much cheaper than a ToF LiDAR, at the cost of a shorter range (suited to indoor spaces of a few metres) and accuracy that drops at longer distances.

SLAM fundamentals

SLAM (Simultaneous Localization and Mapping) solves two problems that depend on each other: to know exactly where the robot is you need a reliable map, but to build a reliable map you need to know exactly where the robot was when each measurement was taken. This is the classic "chicken and egg" problem of autonomous mobile robots.

In probabilistic terms, SLAM jointly estimates the robot's trajectory and the map from the sequence of sensor measurements and control commands; the more observations agree with each other, the more confident both the trajectory and the map become.

Two common families of SLAM

  • Filter-based SLAM, e.g. EKF-SLAM and FastSLAM (particle filter): updates the estimate sequentially with each new measurement; lightweight, but struggles with large maps or many loops.
  • Graph-based SLAM (pose-graph optimization): represents the poses the robot has visited as "vertices" in a graph and the constraints between them (from scan matching and loop closure) as "edges", then optimizes the whole graph to reduce accumulated error. Cartographer (used in this project) belongs to this family.

Front-end and back-end

Every modern SLAM system is split into two processing layers:

  • Front-end: processes raw sensor data (scan matching, aligning the current LiDAR scan with the existing local map to estimate the current position)
  • Back-end: periodically re-optimizes the whole trajectory from the collected constraints, especially loop closure: when the robot returns to a place it has already visited, the system recognizes it and uses it to "pull" the whole trajectory back to the true position, removing the drift accumulated along the way between the two visits.

In short: without loop closure, SLAM is just "integrating error" and the map gradually distorts over time. Recognizing previously visited places is what really sets SLAM apart from drawing a map from odometry alone.

Cartographer SLAM (building the map)

Cartographer is an open-source 2D/3D SLAM system developed by Google, used in the project's robot_mapping package (started with cartographer.launch.py). Cartographer is graph-based and splits the work into two layers: Local SLAM and Global SLAM.

Local SLAM: building submaps

Instead of matching every scan against the whole map (very expensive as the map grows), Cartographer groups a sequence of consecutive scans into a small submap. Each new scan is matched against the current submap with non-linear optimization (based on the Ceres Solver library), using odometry/IMU data as the initial guess so the matching converges faster and more reliably. Once enough scans have accumulated, the submap is "finished" and a new one starts.

Global SLAM: pose graph optimization and loop closure

In parallel, Cartographer keeps checking whether the current position matches any older submap, using the efficient branch-and-bound scan matching search. When it finds a confident enough match (a loop closure), a new constraint is added to the pose graph, and the pose graph of all submaps is periodically re-optimized, slightly adjusting the relative positions between submaps so the overall map is consistent and no longer "broken" where the robot looped back.

New LiDAR scan
     │
     ▼
Scan matching against the current submap (Local SLAM, Ceres)
     │
     ▼
Insert the scan into the submap  ──►  Enough scans? → finish the submap, start a new one
     │
     ▼
Check for loop closure against older submaps (branch-and-bound)
     │
     ▼
Optimize the global pose graph (periodically) → consistent map

Cartographer's output is an occupancy grid map, described in the next section.

The occupancy grid algorithm (map representation)

An occupancy grid represents the environment as a discrete grid of square cells, each holding a probability value p ∈ [0, 1] that the cell is occupied by an obstacle.

Occupancy grid — a probabilistic grid map

Ray casting: updating the grid from one LiDAR scan

For each laser beam in a scan, the cells along the beam's path (from the robot to where the beam hits an obstacle) are treated as free, lowering their occupied probability; the cell at the final hit point of the beam is treated as occupied, raising its occupied probability. Cells that no beam has ever passed through stay unknown (p = 0.5).

Log-odds: efficient Bayesian updates

Instead of storing the probability p directly (which requires repeated multiplication and loses numerical precision), occupancy grids usually store log-odds:

l = log( p / (1 − p) )

The advantage of log-odds is that each Bayesian update only needs an addition instead of multiplying probabilities:

l_new = l_old + l_measurement − l_prior

To get the probability p back for display or processing, just invert it: p = 1 − 1/(1 + eˡ). This representation makes updating thousands of grid cells per scan very fast, which matters when running in real time on limited hardware such as the Raspberry Pi 4.

Navigation2 fundamentals

Nav2 (Navigation2) is the official ROS2 navigation framework, responsible for safely taking the robot from its current position to a desired goal. It is used in the project's robot_navigation package (navigation.launch.py).

The two-layer costmap architecture

Nav2 represents the space the robot must avoid with a costmap, an extension of the occupancy grid made of two layers working in parallel:

  • Global costmap: built on the whole static map created by SLAM (plus an inflation layer that "inflates" the area around obstacles by the robot's safety radius), used for overall path planning.
  • Local costmap: a small window that moves with the robot, continuously updated from live sensor data (LiDAR), used to detect and avoid sudden obstacles that are not on the static map.

Planner, controller and Behavior Tree

Nav2 splits navigation into two separate computation layers:

  • Global planner: computes the optimal path (e.g. with the NavFn or Smac Planner algorithms) on the global costmap, ignoring instantaneous dynamics.
  • Local controller: follows that path in real time, constantly adjusting velocity to stay on the trajectory and avoid obstacles that suddenly appear on the local costmap.

The whole process (compute the path → follow the path → handle failures) is coordinated by a Behavior Tree (BT), which lets you define decision-tree logic (retry, switch to recovery behaviors such as turning in place or backing up when stuck) clearly and much more extensibly than a hand-written state machine.

BT: ComputePathToPose → FollowPath
         │                  │
         ▼                  ▼
     (failed?)       (new obstacle?)
         │                  │
         ▼                  ▼
   Recovery behavior (spin, back up, wait) → retry

System block diagram

Block diagram of the Mecanum robot system

The system is divided into 4 independent functional blocks:

  • Power block: a 3S2P lithium battery (11.1V–12.6V) through a main switch, distributed along two paths: raw voltage (~12V) straight to the 2 motor drivers (where high current is needed), and through 2 buck DC-DC step-down modules (XL4005 5V-5A for the Raspberry Pi 4, LM2596 5V-3A for the ESP32) to give the processing block a stable 5V supply.
  • Central processing block: the Raspberry Pi 4 (running ROS2: SLAM, Nav2, high-level processing) talks both ways with the ESP32 (real-time motor control loop, encoder reading) over UART, the usual layered architecture for ROS2 robots: the MCU handles real-time work, the embedded computer handles heavy computation.
  • Drive block (x2, left/right): each side has 1 L298N driver controlling 2 GA25 motors (4 motors in total, in a Mecanum layout), taking PWM/DIR control signals directly from the ESP32.
  • Sensor block: the YDLIDAR X3 Pro connects to the Raspberry Pi 4 over USB (LiDAR scan data for SLAM/Nav2), and the encoders on the motor shafts connect to the ESP32 through GPIO (rotation speed data for the speed control loop and odometry).

Power lines (red) and control/data signal lines (black) are drawn separately in the diagram to make it clear that the motor drivers receive raw power straight from the battery (not through the step-down modules, since they need much more current than the processing block) while their control signals still come from the ESP32.

Basic calculations for the robot design

Below is a worked example illustrating how to choose the motors and estimate the top speed, using the specs of the 60 RPM GA25 gear motor chosen for the project and some typical geometric assumptions for this class of small robot (mass, wheel radius).

Theoretical top speed

With a motor output speed after the gearbox of N = 60 rpm and Mecanum wheels with an assumed diameter of 60mm (radius r = 0.03m):

ω = 2π × N / 60 = 2π × 60 / 60 ≈ 6.28 rad/s
v_max = ω × r ≈ 6.28 × 0.03 ≈ 0.19 m/s  (≈ 0.68 km/h)

This is the theoretical speed with no load and no slip; in practice friction, load and the battery voltage dropping over time make the real speed lower than this.

Estimating the required torque

The minimum torque each motor must produce for the robot to move steadily on a flat surface, with an assumed robot mass m ≈ 3.5kg (frame, battery and control boards) and a rolling friction coefficient μ ≈ 0.6 (rubber wheels on tile/vinyl floors):

T_required = (m × g × μ × r) / n_driven_wheels
           = (3.5 × 9.8 × 0.6 × 0.03) / 4
           ≈ 0.154 N·m ≈ 1.57 kgf·cm per wheel

A 60RPM GA25-370 motor at 12V typically has a rated torque of around 2–3 kgf·cm depending on the manufacturer, higher than the required value above, which leaves the margin needed when the robot crosses small bumps or rugs, or accelerates suddenly.

Methodology note: this is a reference calculation with reasonable assumed parameters for this class of robot, not measurements from a specific design. Its purpose is to illustrate how to approach motor selection from the load, not to publish exact technical specifications.

Power consumption and battery selection

Estimated average current draw

ComponentEstimated current draw
Raspberry Pi 4 (running ROS2 + SLAM)~1.2 – 2.5 A @ 5V
ESP32~0.15 – 0.25 A @ 5V
YDLIDAR X3 Pro~0.3 – 0.4 A @ 5V
4× GA25 motors (light load, average)~0.3 – 0.5 A per motor @ 12V

Converting everything to average power (ignoring the buck modules' conversion efficiency to keep this first estimate simple):

P_compute ≈ (2.5 + 0.25 + 0.4) × 5V ≈ 15.75 W
P_motors ≈ 4 × 0.4 × 12V ≈ 19.2 W
P_total ≈ 35 W (average, not counting acceleration peaks)

Choosing the battery capacity: a 3S2P configuration

The project uses a 3S2P lithium battery: 3 cells in series (3S, giving a nominal 11.1V and 12.6V when full, matching the figure in the power block) and 2 groups in parallel (2P, doubling the capacity). With 18650 cells of a reference 2600mAh capacity:

Battery capacity = 2 × 2600mAh = 5200mAh
Energy           = 11.1V × 5.2Ah ≈ 57.7 Wh

Estimated runtime (with safety factors: using only ~80% of the capacity to protect the lithium battery's lifespan, and ~85% buck conversion efficiency):

T_runtime ≈ (57.7 Wh × 0.8 × 0.85) / 35 W ≈ 1.12 hours

In short: with an estimated average power draw of ~35W, the 3S2P 5200mAh battery gives about a little over 1 hour of continuous operation: enough for mapping/navigation tests in the lab, but an area to improve if the robot were developed into a product that runs a full work shift (see Next steps).

Testing and evaluation

The robot was tested in two main scenarios, matching the two videos at the top of the page:

Test 1: Mapping (SLAM)

The robot was driven manually (teleop) to scan the whole test area with Cartographer, with the occupancy grid map built in real time in RViz2. Main observations:

  • Cartographer follows the shape of walls and static obstacles quite well in a small-to-medium test space
  • When the robot passes back over the same area (loop closure), the map adjusts smoothly without obvious "breaks"
  • On slippery floor sections or when driving too fast, the odometry sometimes drifts temporarily before scan matching corrects it

Test 2: Navigation (Nav2)

With the map ready, goal poses were set directly in RViz2 to test autonomous navigation. Main observations:

  • The robot plans sensible paths on the global costmap and follows them in most cases
  • When obstacles that are not on the static map appear (people walking past, newly placed objects), the local costmap updates in time and the robot adjusts its trajectory to avoid them
  • The Mecanum wheels' ability to move sideways (strafe) lets the robot handle obstacle avoidance in tight spaces well, without having to turn like a differential-drive vehicle

Observed limitations

  • Mecanum wheel slip makes encoder-only odometry less accurate than on a differential-drive robot, so SLAM has to compensate for more of this error
  • The 2D LiDAR only scans one fixed plane and cannot detect obstacles below or above that plane (e.g. table edges, low objects on the floor)
  • Battery runtime is limited (a little over 1 hour per the calculation above), only suitable for short test sessions

Summary and next steps

Summary

The project successfully built a complete 4-wheel Mecanum mobile robot research prototype following the layered architecture common in real ROS2 robots: an ESP32 runs the real-time motor control loop at the low level, and a Raspberry Pi 4 runs ROS2 for SLAM (Cartographer) and navigation (Nav2) at the high level, connected over UART. Test results show the robot can map its environment, localize, plan paths and avoid obstacles, demonstrating that the chosen hardware/software architecture works with mainstream, affordable components (ESP32, Raspberry Pi 4, YDLIDAR X3 Pro, GA25 motors).

Next steps

  • Compensate for Mecanum wheel slip: add an IMU and an extended Kalman filter (EKF, the robot_localization package) to fuse wheel odometry with inertial data, reducing accumulated error before it reaches SLAM
  • Closed-loop motor speed control (PID): the encoders are already in place, so a PID loop can be closed on the ESP32 to keep speed steadier as the load changes and improve the input odometry
  • Add sensors at other heights: a depth camera (RGB-D) or a 3D LiDAR to detect obstacles outside the current 2D LiDAR's scan plane
  • Optimize power: re-evaluate the step-down modules' efficiency, and consider a larger battery or a battery management system (BMS) for longer operation
  • Upgrade the compute: move to a more powerful platform (e.g. NVIDIA Jetson) to add object detection/computer vision running alongside SLAM and Nav2
  • Quantitative testing: add quantitative benchmarks (map error, path-tracking error, time to reach the goal) instead of only qualitative observation, for objective comparison between improved versions

Specifications

Drive type
4 Mecanum wheels (omnidirectional)
Microcontroller
ESP32 — motor control, encoder reading
Onboard computer
Raspberry Pi 4 (4GB/8GB RAM)
LiDAR sensor
YDLIDAR X3 Pro
Motors
4x GA25 DC motors with encoders
Motor driver
L298N (4 channels)
Power
3S2P 12V lithium battery
Operating system
Ubuntu 20.04 / 22.04
Framework
ROS2 Foxy / Humble
SLAM
Cartographer
Navigation
Nav2 (Navigation2)
Autonomous Mecanum-Wheel Robot — Atlas Robotics