Skip to content

ChenDavidTimothy/casmu-mpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CasMuMPC - MPC with CasADi and MuJoCo

CasMuMPC is a small reference repo for building model predictive controllers in CasADi and running them against MuJoCo as the controlled plant.

High-level closed-loop relationship between CasADi MPC and MuJoCo in this repo

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.

Quick Start

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.

Run The Examples

python examples/pendulum_tracking/run.py
python examples/cartpole/run.py
python examples/acrobot/run.py
python examples/double_inverted_pendulum/run.py

Each example builds the controller, runs closed-loop simulation in MuJoCo, plots the result, and tries to render a replay video.

Example Gallery

Pendulum Tracking
Track a drifting upright reference.

Pendulum tracking rollout preview
Cart-Pole
Stabilize the upright cart-pole equilibrium.

Cart-pole rollout preview
Acrobot
Swing up from hanging and hold the target with a terminal capture set.

Acrobot rollout preview
Double Inverted Pendulum
Swing up a harder underactuated system with an energy-based objective.

Double inverted pendulum rollout preview

Notes

  • 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.

Author

ChenDavidTimothy
chendavidtimothy@gmail.com

License

MIT

Releases

No releases published

Packages

 
 
 

Contributors

Languages