← All posts

Control

From NMPC to the ECU: what changes when the controller leaves the simulator

Ali Emre Akçakoca27 October 20263 min readTürkçe oku

In simulation, a nonlinear MPC has all the time in the world. If the solver takes a little longer on a hard turn, the simulator simply waits. On a vehicle, nothing waits. The control period is fixed, and the controller either answers inside it or does not answer at all.

That one difference reshapes almost every design decision. After three years of working on planning and control for autonomous vehicles, these are the three lessons I would give to anyone taking their first NMPC from a simulator to an embedded target.

1. The time budget is the specification

Average solve time is the wrong number to look at. What matters is the worst case, because the worst case arrives exactly when the vehicle is doing something difficult: a tight curve, an evasive manoeuvre, a constraint that suddenly becomes active.

So measure the tail of the distribution, on the target hardware, with realistic scenarios, and design for that. A controller that solves in 4 ms on average and 40 ms once a minute does not meet a 20 ms budget. It meets it most of the time, which on a vehicle means it does not.

Practical consequences:

  • Profile on the real processor early. A desktop CPU flatters every solver.
  • Keep the horizon and the model as small as the task allows. Every extra state and every extra step costs time in the worst case, not just on average.
  • Prefer formulations whose solve time is predictable over formulations that are elegant.

2. Warm starts are not optional

Consecutive MPC problems are nearly identical: the vehicle has moved one step, the reference has shifted one step, and everything else is the same. Taking the previous solution, shifting it by one step and using it as the starting point turns a cold solve into a few corrective iterations.

Without warm starting, real-time performance is mostly luck. With it, the solver usually starts within a few iterations of the answer, and the iteration cap you set in lesson 1 becomes a safety net rather than the normal case.

3. Always have a fallback

Even a well-tuned solver will occasionally fail to converge: bad initial guess, an infeasible moment caused by sensor noise, a numerical edge case nobody saw in simulation. The question is not whether this happens but what the vehicle does in that control period.

A layered answer works well:

  1. Return the best feasible iterate if the solver ran out of iterations but found something feasible.
  2. Otherwise reuse the shifted previous plan for a step or two. It was valid a moment ago and is usually still close.
  3. If failures persist, hand over to a simple, well-understood controller and degrade gracefully.

Sending nothing, or sending whatever the solver had when it gave up, is never the right answer.

Before the first test drive

  • Worst-case solve time measured on the target hardware
  • Iteration cap and best-feasible return in place
  • Warm start from the shifted previous solution
  • Fallback behaviour defined and tested for solver failure
  • Logging of solve time, iterations and status every cycle

The pattern behind all three

Each lesson is the same idea seen from a different side: on a vehicle, the controller is part of a real-time system, and real-time systems are judged by their worst moment. Simulation is where you prove the controller is right. The step to the ECU is where you prove it is always on time.

If you are new to MPC, the notes on MPC in practice start from the beginning, with code you can run.

NMPCReal-timeAutonomous vehicles
Ali Emre AkçakocaIndustrial and mechatronics engineer working on planning and control for autonomous vehicles, and on optimization in research.About meWork with me

Keep reading

Discussion

Questions or corrections? Send me an email.

Send an email