curobo.examples.getting_started.reactive_control module¶
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:
Configure MPC: Create an
MPCSolverCfgwith the robot config, scene model,optimization_dt(time resolution of the planned trajectory), andinterpolation_steps(intermediate steps between optimization knots).Setup the problem: Initialize the MPC solver with the robot’s retract configuration and zero velocity/acceleration via
setup.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.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.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.
- reactive_control(num_steps=100)¶
Run a headless MPC control loop that tracks a target pose.
This function sets up an MPC solver for the Franka robot, offsets the end-effector goal by 20 cm in the Y direction, and runs a fixed number of MPC iterations to converge on the target. The resulting trajectory is saved as a USD animation.
- interactive_mpc_example(
- robot_file='franka.yml',
- port=8080,
Launch an interactive Viser viewer for real-time MPC tracking.
Sets up a web-based 3D viewer where you can drag control frames to update the target pose and watch the robot track the goal with MPC in real time. Obstacles in the scene are also interactive.
- Parameters:
robot_file – Robot config file name.
port – Viser server port.
- test()¶
Run reactive control example as a self-test.
- main()¶
Main entry point.