This repository provides a modular framework for simulating and controlling robotic systems (e.g., cartpole, pendulum, manipulators) using Model Predictive Control (MPC) with MuJoCo as the simulator and acados as the controller. Below are some example simulations.
Block diagram overview of the framework. Two distinct blocks for the simulator and controller where each is independent of the other, allowing the simulator to be replaced by an actual robot. The simulator uses MuJoCo while the controller uses acados. Additionally, Pinocchio provides efficient rigid body dynamics algorithms which is then converted to CasADi symbolic expressions to integrate with acados. PyTorch is used as the deep learning framework which is also converted into CasADi symbolic expressions through the use of L4CasADi. Finally, if inverse kinematics is required, PINK is utilized. Dotted lines signify optional connections.
System architecture diagram showing module interactions, configuration inputs, and data flow between the simulator, controller, neural-network components, and robot model utilities. Dotted lines signify optional connections.
The codebase uses pixi to manage the environmant and run all the tasks. I assume that pixi has already been installed. If not visit pixi installation.
-
Clone the repository
git clone git@github.com:Nicosoh/mpc_MuJoCo.git -
Enter the project directory and install dependencies
cd mpc_mujoco pixi install -
Build and install ACADOS from source
pixi run acados_full -
Verify ACADOS installation
pixi run minimal_example -
Run the Cartpole model
pixi run main_cartpoleor
pixi shell python main.py cartpole
Results are saved in the data folder. A video, config and also graph. If render is set to false, the video will not be recorded.
To collect data for a robot model:
pixi run data_collector [robot_model]
And to visualize the data:
pixi run data_viz [robot_model] [folder_name]
For example with the pendulum:
pixi run data_collector pendulum
pixi run data_viz pendulum 2025-12-02_17-59-3e5_pendulum_data_collection
Plots will be saved in the [folder_name]/plots
To train a model, the dataset and DL model needs to be defined in the train config.
pixi run train_model [train_config]
To evaluate the model, the test dataset and model weights needs to be defiend in the test config.
pixi run evaluate_model [test_config]
Each module has its own configuration file:
- main.py →
config.yaml - Goal States(yrefs) →
yrefs - Collisions/Obstacles →
two_dof_arm_collision_config.py- Obstacles are only used for the manipulators.
- Data Collector →
data_config.yaml - Neural Network Training →
PendulumModelTrainConfig.ini - Neural Network Evaluation →
PendulumModelTestConfig.ini
-
MuJoCo — A fast, physics-based simulation engine for robotics and control
https://mujoco.org/ -
acados — A high-performance optimization framework for embedded optimal control
https://github.com/acados/acados -
Pinocchio — A fast and efficient library for rigid body dynamics and kinematics
https://github.com/stack-of-tasks/pinocchio -
PINK — Inverse kinematics solver built on top of Pinocchio
https://github.com/stephane-caron/pink -
CasADi — Symbolic framework and numerical optimization library for nonlinear control
https://web.casadi.org/ -
PyTorch — Deep learning framework for tensor computation and neural networks
https://pytorch.org/ -
l4casadi — Lightweight tools for integrating neural networks with CasADi
https://github.com/Tim-Salzmann/l4casadi






