Tutorials

AI-generated illustration of a compact wheeled robot with two glowing planner trajectories, rectangular obstacles, a spherical moving obstacle, and a goal marker. Simulation only.
Tutorial

How I built a TEB-style versus OSQP MPC local planner comparison for a differential-drive robot

A portfolio, simulation-only walkthrough of teb-mpc-local-planner: a differential-drive kinematic teaching model that compares a TEB-style single-band optimizer with a linearized kinematic MPC solved by OSQP 1.0.0. How to build the C++17 core, run the tests, and what the WASM browser demo actually shows, including the honest gaps.

Arpan Bom9 min read
ShareXLinkedIn

This is a simulation only

This is a portfolio demo, not a production Nav2 controller and not a test on a real robot. The plant is a differential-drive kinematic teaching model. It has never been run on hardware, it is not certified, and it is not a drop-in replacement for teb_local_planner or a nav2_core::Controller plugin. I built it to compare two local planners, a TEB-style single-band optimizer and a linearized kinematic MPC solved with OSQP, on locked simulation fixtures, with deterministic tests behind the numbers I quote below.

Try the live demo

The fastest way to see it working is the browser demo: https://applycoding.github.io/teb-mpc-local-planner/

The page title and heading both include the words "simulation only," and a short honesty line under the heading says the results come from a 2D kinematic simulation, not a recorded robot or a Nav2 plugin. The page loads the same C++ planners through a WASM module, not a TypeScript rewrite of TEB or MPC. You get a scenario menu for S1 to S4, Reset, Play, and Step x20 buttons, a Canvas view of the fitted map, and a metrics readout with a separate clock for each planner (teb_time and mpc_time). The canvas draws the map bounds, occupied rectangles, moving obstacles, the goal, both traces, and the two robot poses. TypeScript is UI only.

The GitHub Pages demo of teb-mpc-local-planner after a completed S4 run, showing the fitted map, both traces, the goal, and metrics with teb_time 5.65 s success 1 and mpc_time 20.29 s success 1. Simulation only.

Image: the GitHub Pages demo after a completed S4 run, with both planners succeeding. Simulation only. applycoding.com.

What the project is

teb-mpc-local-planner (repo: applycoding/teb-mpc-local-planner, commit 5280388) is a simulation-only local planner comparison. The stack, from the README and CMake graph, is:

Layer Role
tml_core C++17 kinematics, geometry, TEB-style solver, reference rollout, and metrics. No OSQP and no heap in the plan/step functions, as checked by tools/check_no_heap.py.
tml_osqp The only translation unit that includes OSQP. This is where osqp_setup runs for the linearized kinematic MPC.
tml_sim Host and WASM plant loop. It links both planners and steps them on the same fixtures.
web/ TypeScript UI and Canvas 2D, running the same C++ through WASM.

This is an original implementation of well-known methods: a timed-elastic pose band, a receding-horizon kinematic MPC, and a QP solved by OSQP. Those ideas are inspired by the projects credited in REFERENCES.md and NOTICE. I did not invent the algorithms, and I did not vendor teb_local_planner, Nav2 controllers, g2o, or the GPL project mpc_local_planner.

TML_BUILD_TESTS defaults on. TML_BUILD_ROS and TML_BUILD_PYTHON default off and are unsupported in this tree: turning TML_BUILD_PYTHON on is a CMake fatal error, and turning TML_BUILD_ROS on would look for a ros2/tml_planner adapter that is not in the repository. There is no ROS 2 Humble smoke job.

The two planners

Both planners see the same pose, goal, simplified costmap, and optional movers. Horizon and band length follow the plan: MPC uses a fixed horizon N = 25 with OSQP 1.0.0 (builtin algebra, OSQP_USE_LONG=OFF). A setup-once solver updates matrix values each tick and only counts OSQP_SOLVED as a product success. OSQP_SOLVED_INACCURATE is not accepted.

The MPC cost intended to couple successive controls through off-diagonal Rd terms in the quadratic P. That form made OSQP report OSQP_NONCVX, so this tree puts Rd into the linear term q only, and the diagonal P blocks use R + Rd on each stage. Tracking still penalizes changes in the command, but it is not the planned off-diagonal P. Mover half-planes also add an extra 0.08 m on the bound, beyond the plan's extra_margin_m only, so the QP stayed feasible against the nonlinear plant check.

The TEB-style solver is teaching code for a single timed pose band. It is not the distinctive-topologies planner and it does not use g2o.

On S3, the shared reference briefly commands v = 0 when x < 4.15 and the descending mover is still high, so both planners get time to cross. Without that short hold, the linearized MPC rollout grazed the circle before the half-plane constraints caught up in the plant substeps. I did not widen S2 or slow the S3 mover to pass the gates.

Scenarios S1 to S4

Locked JSON fixtures live in fixtures/scenarios/. Time starts at zero and the initial command is (0, 0).

  • S1 is an empty map, start (0, 0, 0), goal (8, 0, 0).
  • S2 is the same start and goal with two static occupancy rectangles that form a corridor.
  • S3 is an empty static map plus one circular mover.
  • S4 is a sparse, obstacle-free map, start (0, 0, 0), goal (-2.0, 0.5, pi), with reverse allowed. The S4 costmap origin is (-6, -4), not the (-2, -4) origin used by S1 to S3.

The browser camera fits each scenario's map into the 640x360 canvas, so the S4 goal stays inside the frame instead of sitting on the left edge.

Build the C++ core and run the tests

cmake -S . -B build -DCMAKE_CXX_COMPILER=g++-13
cmake --build build
ctest --test-dir build
python3 tools/check_no_heap.py

That is the same path the core GitHub Actions job runs on ubuntu-24.04 with g++-13. Core ctest does not need Node, ROS, or a Python module.

Run the browser demo locally

bash scripts/build_wasm.sh
cd web
npm ci
npm run test:unit
npm run build
npm run test:e2e

Vite base is /teb-mpc-local-planner/. The Playwright jobs use the production preview at that Pages prefix. One call to Step x20 is capped in the UI at 20 control ticks, which is 1.0 s of plant time at dt_ctl = 0.05 s, and each planner has its own clock.

Results from the tests and the live demo

On commit 5280388, core GitHub Actions run 42943244304 reported 100% tests passed, 0 tests failed out of 34, then ok: no malloc/new in tml_core. That suite includes unicycle hand cases, frozen-QP cost decrease, TEB objective decrease, OSQP 1.0.0 and OSQPInt size pins, invalid-input zero commands, S1 to S4 success gates, an S3 mutant that must collide, a brake-only controller that must fail S1, and WASM-export tests that require a separate sim time per planner and a successful S4 run for both planners. The asserted bounds in cpp/test/test_scenarios.cpp are: both default planners succeed on S1 and S4 with time_to_goal < 25 s, both succeed on S2 with clearance greater than 0, both succeed on S3 with time_to_goal < 30 s and a lateral peak greater than 0.3 m, the S3 mutant reports collision, and brake-only S1 reports timeout.

Web GitHub Actions run 42943244349 reported 3 Vitest tests passed (map framing for S1 and S4, plus the Pages base path) and 2 Playwright tests passed, including an S4 case that stays in frame and lets MPC succeed.

I also drove the live Pages demo with Playwright at this SHA. After one Step x20 on S1, both clocks read 1.00 s (not a shared clock counting twice). A full S4 run ended with both planners succeeding: TEB measured teb_time=5.65 s and path length 2.353 m, and MPC measured mpc_time=20.29 s and path length 4.063 m. Those are live demo measurements, not the test bounds. MPC's S4 path is slower and longer than TEB's. S4 still has no obstacles.

License and references

Apache-2.0. Copyright 2026 Arpan Bom. See LICENSE and NOTICE.

NOTICE lists the fetched dependencies with versions and licenses: OSQP 1.0.0 and QDLDL 0.1.8 (Apache-2.0), SuiteSparse AMD (BSD-3-Clause) bundled under the OSQP tree, GoogleTest 1.18.0 (BSD-3-Clause), nlohmann/json 3.12.0 (MIT), Node.js 26.13.0 (MIT), Vite 8.3.7 (MIT), TypeScript 7.0.2 (Apache-2.0), Vitest 5.1.0 (MIT), Playwright Test 1.65.0 (Apache-2.0), and Emscripten SDK 7.0.0. The Pages bundle is not exclusively Apache-2.0 when OSQP, AMD, nlohmann/json, or Emscripten glue is included.

NOTICE also points at REFERENCES.md for idea-only references. The permissive idea references are rst-tu-dortmund/teb_local_planner (BSD-3-Clause), OSQP and QDLDL (also dependencies), nav2_costmap_2d (BSD-3-Clause and Apache-2.0), nav2_core (Apache-2.0), nav2_mppi_controller (MIT; this demo does not implement MPPI), and AtsushiSakai/PythonRobotics (MIT). GPL and LGPL projects named there, including mpc_local_planner, CasADi, qpOASES, ECOS, and LGPL-licensed Nav2 packages, are excluded as code sources and are not dependencies.

How this was verified

I ran the standard portfolio-tutorial checks against commit 5280388270e285c681fa9878ff8aad6abc6f943c on main.

  • The GitHub repo is not a fork. gh api repos/applycoding/teb-mpc-local-planner reports "fork": false.
  • All 3 commits on main have author and committer Arpan Bom (applycoding@gmail.com). git log --format=%B main has no Co-authored-by trailers. The only remote branch at this SHA is main; the earlier cursor/teb-mpc-local-planner-build-6fa4 topic branch is gone.
  • A search of the tree found no third_party, vendor, or external directories, and no "ported from", "adapted from", or "copied from" markers in the authored source. GPL and LGPL names appear only as idea-only exclusions in REFERENCES.md and PLAN.md.
  • This is an original implementation of well-known methods (a TEB-style single-band optimizer and a linearized kinematic MPC solved with OSQP), inspired by the projects credited above. I did not invent these algorithms.
  • At 5280388, NOTICE names the direct CMake and npm pins with licenses, and it points at REFERENCES.md for idea-only references and the GPL or LGPL exclusions.
  • The repo license is Apache-2.0. The LICENSE file is byte-identical to the official Apache-2.0 text from apache.org.
  • Commands, paths, APIs, and the numbers in this tutorial were checked against the repo at 5280388. The 34/34 figure is from core GitHub Actions run 42943244304 on that commit. The web figures are from run 42943244349 (3 Vitest passed, 2 Playwright passed). Final Pages deploy 42943700763 on this SHA returned HTTP 200 for the live demo. An earlier Pages gate on the same SHA, run 42943472672, failed with "Missing successful core+web push runs" because the pages.yml workflow_run gate can fire before both push workflows are visible, then a later gate run deploys. All of those runs have actor and triggering_actor applycoding. There are no cursor[bot] workflow runs.
  • This project is simulation only. It has not been tested on a real robot. There is no ROS 2 Humble smoke job.

Limits

This is simulation only, on a kinematic teaching model, not a dynamic vehicle and not a nav2_core::Controller. It is not teb_local_planner. There is no ROS 2 Humble smoke job, and TML_BUILD_ROS and TML_BUILD_PYTHON are unsupported. The MPC P matrix does not carry the planned off-diagonal Rd terms; Rd enters through q only. S3 uses a brief reference hold when x < 4.15 and the mover is still high. Mover half-planes add 0.08 m on the bound. The S4 fixture is sparse, with no obstacles. On the live demo at this SHA, MPC's S4 path was slower and longer than TEB's (20.29 s and 4.063 m versus 5.65 s and 2.353 m). The Pages workflow can race on its gate, and a failed gate run precedes the successful deploy.