Project · Engineering
TurtleBot Digit Navigation
TurtleBot that reads a handwritten digit on a die, then crosses a mapped arena, avoiding obstacles, to the goal that digit points to.
- Ref.
- 02.02
- Period
- Jun 2024
- Status
- Completed
- Organization
- Master — IMERIR
- Contributors
- Axel COLMANT, Adel HANIFI, Joana INIESTA, Jules DUTILLEUX and Leonardo CAMP
- Stack
- ROS 2
- Nav2
- TurtleBot3
- LiDAR
- Python
- OpenCV
- PyTorch
- PyQt
Key points
- Handwritten digit (1 to 3) on a die read by a CNN trained on MNIST with PyTorch: 98% on the MNIST test set.
- Map of the arena built with the robot's LiDAR, with three goals placed on it.
- Autonomous navigation to the goal matching the digit, around the obstacles.
- Built the whole AI side, from image capture to detecting the die and recognising the handwritten digit.
The challenge
Three pieces: a die with a handwritten digit from 1 to 3 (Model 1), a TurtleBot (Model 2) and a robotic arm (Model 3). The die is shown to the PC camera, the app reads it, and the robot drives across an arena built with whatever we had at hand (table panels, bins, bottles and boxes) to the matching goal, A, B or C (1 to A, 2 to B, 3 to C), without hitting anything. The arm was there to pick up and move small cubes, but we only ever had it in simulation.
Built in a team of five during my Master. I handled the whole AI side: capturing the images, detecting the die in them and recognising the handwritten digit.
The system
Everything runs from a PyQt app on a PC (Fig. 1). A run goes in four steps:
- Map once. Before any run, the robot maps the arena and the three goals are placed on that map.
- Read the die. The PC camera takes ten pictures of the die and the app reads the digit.
- Send the goal. The app turns the digit into goal A, B or C and sends it to Nav2, the navigation stack of ROS 2.
- Drive. Nav2 plans a path and drives the TurtleBot there, around the obstacles.
Reading the die
From the camera image to the digit, with OpenCV and PyTorch (Fig. 2).
Finding the die. Each face is a white square with a dark outline. The image is turned into black and white many times over (an edge detector, then a threshold every 10 levels of brightness), so the face stands out whatever the lighting. Outlines become polygons, and a polygon counts as a face if it has 4 corners, right angles, and is about as wide as tall.
Making it look like MNIST. The 4 corners straighten the face as if seen from the front. It is then shrunk to 28×28, thresholded, and inverted: MNIST digits are white on black, ours were black on white.
Voting over ten pictures. One picture can be blurred, so the app takes ten, 200 ms apart. Only the scores of 1, 2 and 3 count, and the digit with the highest total confidence wins.
The model and the dataset
The dataset. MNIST: 70,000 handwritten digits in 28×28 greyscale, 60,000 for training and 10,000 for testing. The training digits come from about 250 writers and the test digits from different ones, so the score shows how the model reads a new hand, like ours on the dice.
The model. A small CNN in PyTorch, 21,840 parameters (Fig. 3):
- Conv 1: 10 filters of 5×5 pick up strokes, then pooling: 10 maps of 12×12.
- Conv 2: 20 filters combine them into curves and loops, then pooling: 20 maps of 4×4.
- Fully connected: 320 values to 50, then to 10 scores, one per digit.
Dropout switches off random parts of the network during training, so it cannot lean on a few features.
Training and result. 10 passes over the training set, batches of 100, cross-entropy loss, Adam optimiser, on a CPU. It reads 98.15% of the MNIST test set right, and 99.4% of the 1, 2 and 3 the robot uses.
Navigation
Built by my teammates on ROS 2 with Nav2, set up for the TurtleBot3.
Mapping. The robot is first driven around the arena while SLAM (Simultaneous Localization And Mapping) builds a map from the LiDAR, the spinning distance sensor on top (Model 2), and the wheel odometry. The result is a grid of 5 cm cells, free or occupied, about 3.5 m across (Fig. 4). The three goals are saved as coordinates on it.
Localising. AMCL (Adaptive Monte Carlo Localization) keeps a cloud of guesses of the robot's position. Each LiDAR scan scores them on how well they explain what the robot sees; bad guesses are dropped, good ones copied, and the cloud gathers on the real position, correcting the drift of the wheels.
Navigating. The app sends the goal to Nav2. A planner draws the shortest path on the map, with obstacles inflated by the robot's radius. A controller follows it, many times per second, avoiding obstacles that appear on the live LiDAR scan. The robot stops within 5 cm of the goal (Video 1).
Pick and place
The project also planned a robotic arm to move small cubes: a WidowX 250 6DOF (wx250s), a 6-axis arm from Interbotix (Model 3), programmed by my teammates in Python on ROS 2. We only had it in simulation, so in the final demo it runs as a separate step, started from its own button in the app: it grabs a cube on one side, turns, and sets it down on the other (Video 2).
Challenges and limits
From MNIST to a real die. MNIST digits are scanned, centred and high-contrast; a die seen by a webcam has shadows, perspective and paper texture. That is why most of the pipeline is about making the camera image look like MNIST before the model sees it.
Lighting. The last threshold, which turns the face into black and white, is fixed (180 out of 255), so the result depends on the light in the room. Voting over ten pictures smooths out a bad shot, not a badly lit room.
What was measured. The 98.15% is on the MNIST test set. No accuracy figure was kept for the real dice.
The arm. It stayed in simulation, with a fixed movement, and is not linked to the digit or to the robot's position.