Reactive Control

Track a moving goal pose in real time with model predictive control.

Model Predictive Control (MPC) re-optimizes a short trajectory at every control step, producing smooth actions that drive the robot toward the goal while respecting joint limits and avoiding collisions. By warm-starting each solve from the previous solution, cuRobo’s MPC achieves real-time rates suitable for closed-loop control and teleoperation.

Unlike single-shot motion planning (which computes one trajectory up front), MPC continuously adapts to changing goals and dynamic obstacles. This makes it the right choice when the target is not known in advance or when the environment changes during execution.

By the end of this tutorial you will have:

  • Configured and initialized cuRobo’s MPC solver

  • Set up a tracking problem from the robot’s retract configuration

  • Offset the end-effector goal by 20 cm and converged on it

  • Saved a trajectory plot as a PDF

Step 1: Run the tutorial

python -m curobo.examples.getting_started.reactive_control

To try MPC with a humanoid robot:

python -m curobo.examples.getting_started.reactive_control --visualize --robot unitree_g1.yml

Step 2: Check the output

When the tutorial finishes successfully you will see:

Target link: panda_hand
Running MPC for 100 steps...
  Step 25/100  position error: 0.XXXX
  Step 50/100  position error: 0.XXXX
  Step 75/100  position error: 0.XXXX
  Step 100/100 position error: 0.XXXX
Trajectory plot saved to: ~/.cache/curobo/examples/reactive_control/reactive_control.pdf

Step 3: Understand the pipeline

The example runs five stages:

  1. Configure MPC: Create an MPCSolverCfg with the robot config, scene model, optimization_dt (time resolution of the planned trajectory), and interpolation_steps (intermediate steps between optimization knots).

  2. Setup the problem: Initialize the MPC solver with the robot’s retract configuration and zero velocity/acceleration via setup.

  3. Set the goal: Compute the current end-effector pose with FK, offset it by 20 cm in Y, and pass it to update_goal_tool_poses.

  4. Control loop: At each step call optimize_action_sequence, extract the last action in the optimized horizon, and feed it back as the current state for the next iteration. The solver warm-starts from the previous solution.

  5. Save: Stack the collected joint positions into a trajectory and plot the joint positions over time with matplotlib.

Step 4: Interactive MPC with Viser

For an interactive version with a web-based 3D viewer, run:

python -m curobo.examples.getting_started.reactive_control --visualize

Open http://localhost:8080 in your browser. Drag the control frames to update the target pose and watch the robot track the goal in real time. Obstacles in the scene are also interactive. Use --robot to change the robot and --port to change the server port.