← Projects · Real-time MPC › Robot arm
Real-time MPC for a 7-joint robot arm
A nonlinear predictive controller that commands the seven joint torques of a Franka Emika Panda directly and moves its tool around a fast circle with sub-millimetre accuracy, within every joint's velocity and torque limits. It plans 0.35 s ahead on the full arm dynamics in a few milliseconds. Its joint-friction model is learned from a 6-second calibration motion, with a certified error bound.

NoteHow much grip can a controller count on? →

15 cm circle at 1.35 m/s, shown at quarter speed: the NMPC keeps every joint within its velocity limit; operational-space control drives a joint to 135 % of its limit, where a real Panda stops.
What it does
A fast tool motion asks a lot of the joints, and a torque-controlled arm such as the Panda stops itself the moment a joint exceeds its velocity limit. A controller that only looks one step ahead finds out when the limit is already hit. This one plans ahead:
- ModelThe Panda's full rigid-body dynamics, written in CasADi and checked against Pinocchio.
- Optimise in real timeA 0.35-second plan of the seven joint torques, re-solved 100 times a second with acados, warm-started from the previous plan shifted forward in time.
- Learn the frictionddma certifies a band around each joint's friction curve from a short calibration motion; a smooth model inside it goes into the controller.
- DeployGenerated C code (solver and dynamics) inside a ROS 2 C++ node, with a simulator node and tests against the Python version.
The controller tracks the tool reference, resolves the arm’s redundancy with a posture term, and respects the joint torque, velocity and position limits. Because it plans ahead, it slows the joints before they reach their limits and spreads the motion over the redundant joints.
Demo: a fast circle
The tool follows a vertical circle of radius 15 cm in front of the robot.
| Peak tool speed | Nonlinear MPC | Task-space QP | Operational-space control |
|---|---|---|---|
| 0.47 m/s | 0.02 mm · 47 % | 0.08 mm · 46 % | 0.08 mm · 46 % |
| 0.94 m/s | 0.04 mm · 100 % | 0.29 mm · 93 % | 0.38 mm · 93 % |
| 1.35 m/s | 0.04 mm · 100 % | 0.86 mm · 100 % | 0.99 mm · 135 % |
| 1.57 m/s | 0.64 mm · 100 % | 2.2 mm · 102 % | 1.5 mm · 160 % |
Each cell: RMS tool error, then the fastest joint as a share of its velocity limit (above 100 % a real Panda triggers its safety stop). Operational-space control is the textbook task-space inverse dynamics with a null-space posture task; the task-space QP adds torque and one-step velocity limits (OSQP), as in whole-body control frameworks. Both know the exact model.
Demo: joint friction, learned with a guarantee
The simulated arm has viscous and Coulomb friction in every joint, which no controller models. Before the task, the arm runs a 6-second joint sweep; for each sample, friction is the applied torque minus the torque the rigid body needs (with noise). Assuming only that friction does not decrease with speed and has a bounded slope, ddma returns a band that contains the true friction curve; a smooth model is fitted inside it, with a certified worst-case error of 0.3 to 0.7 N m per joint.
| Tool error with joint friction | 0.47 m/s | 0.94 m/s | 1.35 m/s |
|---|---|---|---|
| Operational-space control | 4.1 mm | 5.7 mm | 6.5 mm |
| Task-space QP | 4.2 mm | 6.7 mm | 9.0 mm |
| Nonlinear MPC, no friction model | 0.27 mm | 0.32 mm | 0.46 mm |
| Nonlinear MPC, ddma friction model | 0.06 mm | 0.05 mm | 0.05 mm |
| Nonlinear MPC, true friction (oracle) | 0.07 mm | 0.05 mm | 0.05 mm |

Algorithms and performance
- Solver: acados, multiple shooting, Gauss-Newton SQP with one real-time iteration per step, HPIPM; 14 states, 7 torques; the friction model is a run-time parameter.
- The detail that made it work: shifting the previous solution forward in time before each step. Without it, the iteration linearises around a stale plan and the joints overshoot their velocity limits by up to 25 % between samples, although every plan respects them.
| Controller (two laps at 1.35 m/s) | Median | 99th percentile | Tool error | Fastest joint |
|---|---|---|---|---|
| Nonlinear MPC, 15 intervals | about 3.5 ms | 8 ms | 0.04 mm | 100 % |
| Nonlinear MPC, 10 intervals (ROS 2 node) | about 2.6 ms | 5 ms | 0.11 mm | 100 % |
| Task-space QP | about 1 ms | 1.7 ms | 0.86 mm | 100 % |
| Operational-space control | about 0.6 ms | 0.9 ms | 0.99 mm | 135 % |
Engineering specific to this project
- Dynamics written once: forward kinematics, inverse dynamics, mass matrix and articulated-body algorithm in CasADi, matching Pinocchio to 10⁻⁹ or better; the same expressions go into acados and, through code generation, into C for ROS 2.
- Free-running real-time loop: as on a real torque-controlled arm, the robot runs its own 1 kHz loop between solver steps. The NMPC sends it the next 40 ms of its plan and its own feedback gain, so between steps the arm is stiff where the task needs it and soft in its redundant directions; the controller compensates its own latency by predicting through that loop. 12 of 13 repeated runs kept every joint within its velocity limit, at 0.16–0.50 mm; the README gives the full spread. With fixed joint-impedance gains instead, two joints swung to twice their limits.
- Synchronised mode (used by the tests): the ROS 2 loop tracks at 0.09 mm with the learned friction model.
Next
Deadline handling when the solver overruns for longer than the plan it sent; obstacle and self-collision constraints; a payload with certified mass bounds; a hardware run on a Panda through franka_ros2.