CasMuMPC is a small reference repo for building model predictive controllers in CasADi and running them against MuJoCo as the controlled plant.
CasADi owns the prediction model, cost, and constraints. MuJoCo owns the plant. The repo keeps that controller-and-plant boundary explicit, including the state and coordinate mappings needed to connect the optimizer to the simulator, so the closed-loop relationship stays easy to read instead of disappearing behind a larger framework.
Warning
CasMuMPC is intentionally not a reusable MPC library.
The small casmu/ package exists only to keep the examples clean.
CasMuMPC is not a modular library and is not meant to be imported as a dependency in other projects.
Python 3.12+ is required. This repo is tested on Python 3.12 on Ubuntu 24.04.
git clone https://github.com/ChenDavidTimothy/casmu-mpc.git
cd casmu-mpc
pip install -e .ffmpeg is optional. If it is installed, the example scripts also export MP4 rollouts.
python examples/pendulum_tracking/run.py
python examples/cartpole/run.py
python examples/acrobot/run.py
python examples/double_inverted_pendulum/run.pyEach example builds the controller, runs closed-loop simulation in MuJoCo, plots the result, and tries to render a replay video.
|
Pendulum Tracking Track a drifting upright reference. |
Cart-Pole Stabilize the upright cart-pole equilibrium.
|
|
Acrobot Swing up from hanging and hold the target with a terminal capture set.
|
Double Inverted Pendulum Swing up a harder underactuated system with an energy-based objective.
|
- The controller model does not need to share MuJoCo coordinates exactly. Several examples make the coordinate conversion explicit on purpose.
- Warm starts matter for the harder swing-up problems. The acrobot and double inverted pendulum examples both seed the optimizer deliberately.
- This repo stays intentionally lean. The focus is on readable control code, not on packaging, plugin systems, or a highly abstract architecture.
ChenDavidTimothy
chendavidtimothy@gmail.com
MIT
