Doorgaan naar hoofdcontent

No Cutting Corners: what the AI agent did not find

This summer I built a motion planner for robot vehicles in just over a week: about three thousand lines of C, 243 tests, and four kinds of vehicle. I did not type a single line of it myself. All of it was written in sessions with an AI agent (Claude Code), and I steered: specifying, reviewing, breaking things, redirecting.

The most instructive thing about that project is not in the code. It is in this one fact: every behavioural bug was found by a human driving the GUI, not by the agent. Every single one, while all the tests were green.

But first: what is it?

What it is: a path follower that knows motors are slow

For the Omnibot project at Fontys ICT we have an electric quad: rear-wheel drive, car-style steering on the front wheels, an NVIDIA Orin for planning and an ESP32-P4 for real-time control. It has to follow a path neatly.

The standard solutions, such as pure pursuit and Stanley, assume the vehicle does what you ask, at the moment you ask it. But our steering servo turns at most about 86 degrees per second, and the speed control has a lag of about 0.8 seconds. Ask for a steering angle and you get it a quarter of a second later. At 3 m/s that is 75 centimetres further on. By then you are already in the kerb.

The answer is model predictive control (MPC): simulate a number of possible futures with a model of how the vehicle really responds, and pick the best one. The usual MPC reaches for a heavy optimisation library for that. I set a hard requirement:

No external maths libraries, no solver, no matrix inversion. Only sin, cos and tan.

Not out of purism, but because the same code has to run on the planning computer and later on the microcontroller, and because a student has to be able to understand it at two in the morning.

That works if you only generate movements the vehicle can physically make. Then optimising comes down to little more than "simulate lots of futures and take the cheapest". There are two variants in the code: a fixed grid of candidates (predictable, ideal for tests) and MPPI, which simulates 256 random variations around the previous solution and averages them cleverly. MPPI drives best.

Why it is fun: the vehicle brakes by itself

This is where the beauty is for me. Nobody programmed a rule that says: slow down before a corner. The model knows the steering servo can only turn so fast. Drive too fast and every simulated future misses the corner, so the cheapest one is automatically the future in which the vehicle slowed down earlier. The behaviour follows from the physics.

A second surprise is geometric. In a corner, the inner rear wheel always runs inside the line the front wheel draws. On our vehicle, at full steering lock, that is 25 centimetres. For a vehicle driving next to a kerb, those 25 centimetres are the whole problem. That is why the planner checks all four wheels, not just the centre of the vehicle. Hence the name: no cutting corners.

The inner rear wheel cuts the corner by 25 cm

Off-tracking, simulated with the real C model: the rear wheel (orange) runs 25 cm inside the track of the front wheel. The figure labels are in Dutch.

A few numbers from the paper:

  • One MPPI computation with 256 variations takes 3.2 ms on a single core of a 2017 laptop. So the Orin has plenty of headroom.
  • Docking (stopping neatly at a target pose) is accurate to 0.9 to 4.6 cm, for all four vehicle types.
  • Ackermann, skid-steer, differential drive and a three-wheeled omni robot sit behind one interface. Adding a new vehicle requires no change at all to the solvers or the GUI.

And there is a playground: a GUI with sliders where you drag walls and waypoints around and immediately see what the planner does. That GUI runs exactly the same C library as the tests. Nothing was rebuilt in Python, and every figure in the paper comes from the real solver.

The playground: sliders, candidate trajectories and an editor for walls and waypoints

Why it matters: six bugs the agent did not see

Back to that one fact. Six behavioural bugs were found, and all of them were found by a human playing with the GUI:

  • a crash when switching to the omni robot;
  • a vehicle that kept circling the goal, because circling was cheaper than stopping;
  • a vehicle that kept creeping forward a tiny bit forever after reaching the goal;
  • getting stuck in corners sharper than 90 degrees;
  • freezing next to a wall that had been dragged into a bend;
  • a dangerous back-and-forth shuffle when a differential drive docked.

Every time, the test suite was green. They share the same shape: it is behaviour that only exists in the closed loop, over many seconds, in a situation nobody had thought of writing a test for.

The seventh is perhaps the best one, because it was not a bug at all. After a fix, a screenshot seemed to show the problem was still there. But the GUI had been running since before the rebuild and still had the old library in memory. An afternoon gone. Since then the Help → About menu shows which file is actually loaded. When a human and an agent debug together, make the tool say what it is really running.

What did work well, and is worth copying?

  • A plan document before every phase, with references and an explicit list of what is out of scope. You then have the architecture discussion in prose, where being wrong is cheap.
  • Test-driven development on the PC. Pure C modules without hardware, so every claim about behaviour can be checked in under a second.
  • Measure first, then encode. Test limits were set by measuring first and then freezing that value. Numbers you invent to make a test pass are worse than no test at all.

What this means for education

I work with students at Fontys ICT, and this project is also a data point in a question that keeps me busy: what does good education in embedded software look like when there is an AI agent in the room?

The agent delivers structure, tests, documentation and consistency across a C codebase of many files, at a pace no student can match. What it does not deliver is the suspicion that makes someone drag a wall into a bend just to see what happens. If that is the skill that remains, our assignments should be built around it. Less "write this function", more "try to break this system and explain why it failed".

Where are we now?

The planner works in simulation and has been tested thoroughly there. Two things are still open, and they are written up rather than waved away:

  • Robustness. In simulation, the vehicle is the model. In reality, grip changes with the surface and response time changes with battery voltage. The plan is to measure first, then add a simple correction, and only then consider heavier methods.
  • Real hardware. Every actuator value is still an estimate until we have measured the step response on the real vehicles.

The code is open source (AGPL-3.0), and the documentation and figures are free to use in teaching material (CC BY-SA 4.0). The full paper, dead ends included, is in the repository: chat-l18l/no_cutting_corners_with_AI.

This article is part of the series Building with AI agents: projects I build together with AI agents. That link takes you to every part of the series, including new ones.

Lees dit artikel in het Nederlands: No Cutting Corners: wat de AI-agent níet vond

Reacties

Populaire posts van deze blog

Denon DHT T100 DESIGNED TO FAIL : bad caps (ceramic caps this time)

A friend gave me a Denon DHT-T100 to look at. Do not spend much time on it.. ok. It had a problem, it started clicking and ticking after power on, and after some time. (a so called intermittent problem) Sometimes it did not tick or click, but it was basically not usable. The clicking had a sharp click in one channel and repeated after about a second, then sound recovered and it would click and drop out again. He told me, do not spend any time on it, yeah, right. ;-) like I would give up after 15 minutes. I wanted to know what was going on with this thing, I found some schematic online and started measuring the usual things. The power supply, 24V did it drop down when a tick occurred ? Difficult to find out because sometimes the thing would play for hours without a glitch. I eventually found out the 24 V PSU, the step down SMPS on board and the LDO's were all ok, all power rails remained within spec, but it still glitched sometimes. (while power was ok) I inves...

Fixed voltage on cheap buck converter (MP1584) conversion with single 0805 resistor

Everywhere I look on the Ali and Ebays I see these step down converters based on MP1584. I bought a couple and actually they are not bad at all. The output voltage is set by the trimming-resistor in the left top corner of the picture. This works OK, but.. it is dangerous because it is rather sensitive to the touch. I decided that I wanted fixed output, so I had to figure out how this thing worked. The datasheet looks like this : R1 in the datasheet is what I call "R feedback" in my image. The value of R2 is mostly 8.2K Ohm in the boards I have seen.  So to set some common values for output voltage: change R1 to 27K for 3V3 output (actually 3.4 volt, but 27K is a standard value) or change R1 to 43K0 for 5.0 Volt output. (43 K is a standard value) A standard 0805 size resistor fits precisely, how convenient ;-). Make sure the other resistor is really 8.2K because that determines the feedback ratio. This way you can not burn up your circ...

Raspberry Pi, PyFace Digital, the lost documentation, I found it finally

The Raspberry PI or R-pi from  http://www.raspberrypi.org/  is well known these days. It is not an accident that I have one, I have been doing Linux stuff since 1991, and professionally since 1996 I can not skip over these developments, have to keep up with the new kids. :-) Times have changed, hardware has become very affordable, everybody knows the Arduino , Raspberry Pi and Beagle-Bone-Black (BBB). Not everybody knows the stuff that  http://www.acmesystems.it/  aka Acme-Systems and  https://github.com/OLIMEX/OLINUXINO  aka  Olimex make, so I will endorse them here. Since I am an engineer I expect to connect switches and relays to the boards and some documentation with products, not so with the " PiFace Digital " board, it comes without serious documentation, not a even the schematic. All links on their blog point nowhere. People asked them many times, yet nowhere is the schematic to be found. I finally found some info after hours of googl...