ansonantony_
  • Home
  • Projects
  • Blog
  • CV
  • Guestbook
  • Newsletter
  • Contact

// stay updated

new posts and project updates, by email

© 2026 Anson Antony

githubinstagramcoffeerss

built with next.js + supabase · privacy

← all projects

// project · 20 commits · March 2025, rebuilt November 2026

Robot Navigation

Drives a small robot to its goals in simulation, steering around the obstacles its laser scanner sees.

8 of 8waypoints reached in Gazebo, with every planner

C++ node on a simulated TurtleBot3, no collisions, never closer than 0.15 m to an obstacle

Watch the replay ↓View code on GitHub ↗

●Replays of recorded Gazebo runs and benchmark results. Simulation only, never run on a real robot.

  • C++17
  • ROS 2
  • Gazebo
  • Python
  • pybind11
12345678

8 / 8

waypoints

0.17 m

closest pass

10 to 12x

C++ vs Python

The path the robot actually drove in Gazebo, from its odometry, with the C++ node and the potential-field planner. Circles are pillars, numbers are the waypoints in order.

01 Replay

What this robot does, and what it does not

The robot reacts to what its laser scanner sees right now. It has no map and plans no route, so it can drive around pillars and out of small dead ends but could not solve a maze. The same navigation code exists twice: in C++, the version the robot runs, and in Python, the reference the C++ version is checked against. Everything here ran in simulation, in Gazebo and in a lightweight 2D simulator, never on a physical robot.

The Gazebo tour, recorded

Eight waypoints weaving between the pillars and around the arena. The line is the robot's own odometry. Switch planner or node to see each recorded run.

// node
// planner
12345678
sim time
84.2 s
driven
17.1 m
waypoints
8 / 8
closest pass
0.17 m

Finished: 8 of 8 waypoints in 84.2 s of simulated time, 17.1 m driven. Closest pass is the gap between the robot's edge and any pillar or wall over the whole run.

Gazebo 3D view of the walled arena with seven red pillars and the TurtleBot3 sweeping blue laser rays across it
Gazebo 11: the arena and the TurtleBot3 Burger, its laser rays drawn in blue.
RViz top-down view: laser hits as red dots, the travelled path in blue, coloured wedges showing free space in five directions, and the next waypoint
RViz2 with the C++ node: free space per direction (red near, green open), heading arrow, path so far and the next waypoint.

50 random scenarios, none used for tuning

The arena plus four random extra pillars, a random start and a goal at least 2.5 m away, 90 seconds allowed. Every planner gets the same 50 scenarios, chosen after all the fixes were done. The C++ and Python planners give the same result in every single run. Path efficiency is the straight-line distance divided by the distance driven.

Benchmark on 50 unseen scenarios
PlannerGoals reachedCollisionsTime to goalPath efficiencyClosest pass
Sector100%0%24.7 s0.920.16 m
Potential field100%0%25.2 s0.960.17 m
Follow the gap100%0%34.4 s0.850.13 m
Development scenarios, used while fixing the planners
Benchmark on the 50 development scenarios
PlannerGoals reachedCollisionsTime to goalPath efficiencyClosest pass
Sector100%0%25.7 s0.890.17 m
Potential field100%0%23.3 s0.980.18 m
Follow the gap96%0%30.8 s0.880.14 m

Three bugs the benchmark found

Goals reached on the development scenarios before and after each fix.

  1. Potential field

    54% → 80%

    Problem. Never reached a goal next to a wall: the wall pushed as hard as the goal pulled, so the robot circled about 0.4 m away.

    Fix. Fade the push near the goal (Ge and Cui, 2000) and ignore obstacles farther away than the goal.

  2. Potential field

    80% → 100%

    Problem. One push per laser beam, so a wall that filled more beams pushed harder; the total often pointed backwards.

    Fix. Weight each beam by its angle, so the push no longer depends on the scanner resolution.

  3. Follow the gap

    46% → 96%

    Problem. Always took the widest opening, even when it led away from the goal, so the robot wandered.

    Fix. Take the opening closest to the goal direction and aim at its point nearest the goal.

C++ against the Python reference

Microseconds per laser scan (1,000 µs = 1 ms), median. Lower is better.

Text summary: Sector: Python 1,127 µs, C++ 112 µs (p99 2,120 and 292 µs). Potential field: Python 1,347 µs, C++ 130 µs (p99 2,472 and 274 µs). Follow the gap: Python 2,042 µs, C++ 166 µs (p99 3,738 and 387 µs). 1,152 identical 360-beam scans, three times each. The C++ time includes passing the scan in from Python, so the C++ code alone is a little faster. Both are far inside the 200 ms between scans; the C++ node leaves room for denser scanners or a slower on-board computer.

02 How it works

  1. step 1

    Look around

    Five times a second the robot gets a 360-beam laser scan. Missing or out-of-range readings are cleaned up, and the free space is measured in five directions from right to left.

  2. step 2

    Know where the goal is

    Odometry gives the robot its position, so it knows the distance and direction to the next waypoint. Goals come from a list or from a click in RViz.

  3. step 3

    Choose a direction

    One of three planners turns the scan and the goal into a speed and a turn rate: free-space sectors, a potential field where the goal pulls and obstacles push, or steering into the opening closest to the goal.

  4. step 4

    Drive, and get unstuck

    The robot slows down near obstacles. If it stays blocked it backs out, but only if nothing is behind it, and if it makes no progress toward the goal it follows the wall out of the trap.

// tap a step to see what it does

  1. ↓→
  2. ↓→
  3. ↓→
  4. ↓→

3/6 PlannerThe core step. Sector: speed falls with clearance and the robot turns to the more open side, with a dead band so it does not flip left and right. Potential field: the goal pulls, obstacles push. Follow the gap: steer into the opening closest to the goal.

One control cycle per laser scan. The planner core is plain C++ with no ROS code, shared by the ROS node, the unit tests and the Python benchmark.

03 Summary

WhatResultCompared with
Waypoints reached on the 8-point Gazebo tour, C++ node8 of 8, every planner84 to 87 s of simulated time and 17.1 to 17.4 m driven per tour
Closest the robot's edge came to a pillar or wall0.15 to 0.17 mSame Gazebo tours. No collisions in Gazebo or in any benchmark run
Goals reached in 50 random scenarios the planners were never tuned on100%All three planners, with the C++ and the Python planner alike
C++ planner time per laser scan, median0.11 to 0.17 msPython reference 1.1 to 2.0 ms, so 10 to 12 times faster. A new scan arrives every 200 ms
C++ against Python decisionsidenticalWithin 1e-9 on every step of 30 closed-loop runs, and trial for trial on the 50-scenario benchmark
Potential-field planner after two fixes found by the benchmark54% to 100%Goals reached on the development scenarios, the ones used while fixing it, so not a held-out number

Sources: the project README and its results folder: the recorded Gazebo runs (results/web/gazebo_tour.json), the benchmark tables and the timing table. Gazebo runs were recorded headless in Docker on a laptop under WSL2.

04 Technical details, for engineers›

Stack. ROS 2 Humble, C++17 (rclcpp, ament_cmake) and Python 3.10 (rclpy, ament_python), Gazebo 11 with the TurtleBot3 Burger model, RViz2, pybind11, GoogleTest, pytest, Docker, GitHub Actions.

Two implementations. The planner is a ROS-free C++ library linked into the rclcpp node, the GoogleTest suite and a pybind11 module. The rclpy node and its planner are the reference. A parity test drives 30 runs in the 2D simulator and feeds every scan to both planners: speed, turn rate, state and all sector distances must agree within 1e-9 on every step, including the stateful recovery and trap logic. The port keeps Python's tie-breaking and rounding so this holds.

Potential field. Repulsion follows Khatib's (1/d - 1/d0)/d², with 15% of it turned sideways so an obstacle dead ahead cannot cancel the goal. Near the goal it is scaled by (d_goal/d0)², and obstacles farther away than the goal are skipped. Each beam is weighted by the angle between beams, so the force is an integral over the field of view and does not grow with scanner resolution.

Node. Goals from RViz's 2D Goal Pose or a waypoint list, holds position after the last one. Parameters are validated on every change (unknown planners and inverted thresholds are rejected; topic names are read-only). A scan watchdog stops the robot, and the C++ node sends a zero velocity from a pre-shutdown callback on Ctrl-C, while ROS can still publish. RViz markers show free space per direction, heading, safety ring, goals and the travelled path.

Evaluation. A 2D simulator reads the obstacles from the Gazebo world file, so the benchmark and Gazebo share one arena. Scenarios are seeded and identical for every planner. The fixes were made on one set of scenarios (seed 7) and checked once on a new set (seed 2026).

CI. colcon builds and tests both packages in a ros:humble-ros-base container: 26 Python unit tests, 16 GoogleTest cases, the parity test, and the ROS linters (flake8, pep257, cpplint, uncrustify, lint_cmake, xmllint). The C++ code builds with -Wall -Wextra -Wpedantic -Werror. Every run posts benchmark tables for both implementations.

Limits. Purely reactive, with no map or global planner. Simulation only. The 2D simulator has no inertia, wheel slip or sensor noise, so it compares planners with each other and Gazebo is the physics check. The nodes' ROS wiring is tested in Gazebo rather than by node-level tests.

// other projects

FabEye →Classifies defect patterns on semiconductor wafer maps and flags the uncertain ones for human review.WaferLens →Spots when a chip factory's yield starts dropping and points to the machine that caused it.WaferEdge →Watches wafer results at the machine in real time and stops a bad lot before more wafers are processed.