LiDAR SLAM mecanum rover
I drove my mecanum rover forward, sideways and on the spot while it tracked its own position and built a LiDAR map, which I saved.

Diagram in words
System diagram: RPLIDAR C1 sends scans to a Raspberry Pi 5 running ROS 2 and slam_toolbox. Serial micro-ROS links the Pi to an RP2040 controlling four motors. Four wheel encoders and an IMU provide odometry. Arrows show data flow, not physical wiring or sensor bus connections.
Explore the rover in 3D
Try it
Choose Start mapping, then Auto-explore. Watch the blank parts of the map fill in as the laser scans each room.

A simulation of how my rover maps a room. The real one runs ROS 2 and slam_toolbox on a Raspberry Pi 5.
3D model rebuilt from the parts list; sizes estimated. This demo does not run ROS 2 or slam_toolbox. No hardware is connected.
- Role
- Personal projectElectricalSoftware
- Timeline
- Jul - Aug 2026
- Tools
- C/C++, ROS 2, micro-ROS, slam_toolbox
- Sensors
- Four wheel encoders, a BNO055 inertial sensor and a 360° RPLIDAR C1 scanner
- Status
- I saved the occupancy grid and tracked the rover’s position and heading during the drive.
Main components
- RP2040Wheel commands and quadrature decoding
- Raspberry Pi 5ROS 2 and slam_toolbox
- Mecanum wheelsIndependent drive at each corner
- Wheel encodersRotation of each drive motor
- RPLIDAR C1Ranges around the chassis
- BNO055Inertial heading for odometry
How it's built
I split the work between two boards. The Pico runs my motor firmware. The Raspberry Pi 5 builds the map with slam_toolbox.
The rover could slide alongside a wall with its scanner facing the same direction, then turn on the spot to look into a doorway. I wanted the map to keep up with both movements. A command to strafe tells me where I intended to go. To place a laser return on the map I also need an estimate of where the chassis was when the scanner saw it.
I wrote the drive firmware, connected the boards and configured the mapping stack. The hardware test ended with two things I could inspect separately. I could watch the rover's position and heading change on the live map, and I could save an occupancy grid of the room after the drive. The interactive version above exposes the drive and grid updates so you can follow a return from a wheel command to a cell on the screen.
- C1 typical scan rate (datasheet)
- 10 Hz
Mecanum drive kinematics
What the four wheel signs mean
Each mecanum wheel carries rollers at 45° to the wheel. A driven wheel can generate a sideways component of motion as well as a forward one. The roller orientation changes across the chassis. When the four wheels turn together for forward travel, the sideways contributions cancel. A different combination makes the rover slide left with its nose still pointing forward.
The diagram runs three commands through the inverse kinematics of the website demo. Read across one row. A plus means rotation in that wheel’s forward direction. In a left strafe, the front left and rear right reverse together. In a left turn, the wheels on the same side agree. Comparing the last two rows explains how the machine can move sideways or turn even though both commands reverse two motors.
On the real rover those labels have to agree in three places. The motor output has to drive the intended corner, positive wheel speed has to mean forward at that corner, and the encoder count has to increase in the corresponding direction. Swapping the front and rear connections on one side can leave a forward command looking plausible. A strafe asks those same two wheels to disagree and exposes the mistake.
Motor feedback and the serial bridge
Counting wheel motion on the Pico
I put motor control and interrupt-driven quadrature decoding on the RP2040. Each encoder has two signals that change as the motor turns. The order of their transitions distinguishes forward rotation from reverse. Keeping a separate signed count for each wheel preserves information that would disappear if I only recorded a single distance for the chassis.
Encoders measure rotation at the wheels. They cannot see a roller slipping against the floor. The BNO055 inertial sensor supplies heading information to the odometry estimate. Heading matters even on a straight pass because a small change in orientation changes where every range measurement lands on the map. The scanner provides another observation of the room that wheel motion alone cannot supply.
Crossing the serial bridge
The Raspberry Pi 5 runs ROS 2 and the mapping software. Its serial micro-ROS connection carries wheel commands toward the Pico and encoder feedback in the other direction. A requested wheel speed is an instruction. A returned count describes movement at the motor. Keeping these as separate parts of the interface lets the mapping side use measured rotation even when the wheels do something different from the requested motion.
For a forward command, each wheel should report forward rotation. A sideways command changes the expected signs at two corners. Comparing the four feedback channels separately makes a reversed encoder easier to spot than looking at a single chassis speed. I checked the direction and count at each wheel before the mapping run.
| Signal | Origin | Use |
|---|---|---|
| Wheel speeds | Pi → Pico | Drive the four corners |
| Signed counts | Pico → Pi | Estimate chassis motion |
| Heading | BNO055 | Orient the motion estimate |
| Laser returns | RPLIDAR C1 | Locate surfaces around the rover |
LiDAR SLAM pipeline
Placing a scan on a moving map
The laser reports a distance and a direction relative to the rover. The occupancy grid lives in the room’s coordinate frame. A return from a wall in front of the sensor must land in a different place after the rover has turned. Position and heading connect the two frames. That is why displaying a plausible scan on its own would only have tested part of the system.
On the physical rover, wheel and inertial odometry supplied a motion estimate and slam_toolbox matched laser scans as I drove. A wall seen during the next pass gives the mapper a constraint on the change in pose. The live display then has two outputs to inspect together: the map of the surroundings and the changing pose of the chassis inside it. The saved grid records the surroundings after the run.
SLAMTEC specifies a typical scan rate of 10 Hz for the C1M1. For the same scanner, the specified maximum range is 12 m at 70% reflectivity and 6 m at 10%.
- Read the wheel encoders and inertial heading to estimate chassis motion.
- Collect a scan around the rover with the RPLIDAR C1.
- Use odometry and scan matching in slam_toolbox to update the pose and map.
- Inspect the moving pose, then save the completed occupancy grid.
Reading free space in the demo
In the browser version, the scanner traces rays through a known simulated room. The grid shown here was generated by driving forward, strafing left and then turning. Cells traversed by a ray accumulate evidence of free space. A return adds occupied evidence at its endpoint. Beyond that endpoint the ray says nothing, even if the simulator already knows where the other walls are. The dark region behind a wall is a good place to see the distinction.
The excerpt is from the grid code used by this demo. The first observation marks a cell as seen. Later observations add or subtract evidence in the same cell while keeping the total inside configured limits. That lets repeated views reinforce a wall and keeps an unseen cell distinguishable from a cell that the laser has actually looked through. The exported diagram is a sample of this process. The separate hardware test used slam_toolbox and a real laser.
const index = y * grid.width + x;
if (!grid.seen[index]) { grid.seen[index] = 1; grid.knownCells++; }
const evidence = occupied ? settings.hit_log_odds : settings.miss_log_odds;
grid.logOdds[index] = Math.max(settings.min_log_odds, Math.min(settings.max_log_odds,
grid.logOdds[index] + evidence));Testing the wheels and the saved map
Before driving I checked each wheel’s direction, motor mapping and encoder count. Those checks gave each corner a known identity before I tried movements that depended on all four. I then drove the assembled rover forward, sideways and around its own centre under manual control. The sideways pass was particularly informative because it used the rollers to change position while keeping the nose pointed in the same direction.
During the mapping run I watched the rover’s position and heading update as I drove. I saved an occupancy grid of the physical environment at the end of the run.
Links
- RepositoryArchived rover build notes
ProjectESP32 quadcopter- Build notesHardware test record
- Mapping libraryslam_toolbox