Source code for Context-Aware Deep Lagrangian Networks for Model Predictive Control (CaDeLaC).
If you find this work useful, please consider citing:
@misc{schulze2025_cadelac,
title={Context-Aware Deep Lagrangian Networks for Model Predictive Control},
author={Lucas Schulze and Jan Peters and Oleg Arenz},
year={2025},
eprint={2506.15249},
archivePrefix={arXiv},
primaryClass={cs.RO},
url={https://arxiv.org/abs/2506.15249},
}
For experiments videos, check the project website.
-
Clone the Repository
git clone [email protected]:Schulze18/cadelac.git cd cadelac git submodule update --recursive --init
-
Set Up Conda Environment
conda env create -f cadelac_env.yml conda activate cadelac
-
Install CaDeLaC as a Python pkg and additional Dependencies
pip install -e . pip install l4casadi==1.4.1 --no-build-isolation -
Install Acados (v0.4.3) Follow the official installation guide:
cd acados mkdir -p build && cd build cmake -DACADOS_WITH_QPOASES=ON .. make install -j4
Install the Python interface:
pip install -e acados/interfaces/acados_template
Add the following lines to your
.bashrcfile:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<acados_root>/lib" export ACADOS_SOURCE_DIR="<acados_root>"
-
Create a ROS Workspace
mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone [email protected]:Schulze18/cadelac.git cd cadelac git submodule update --recursive --init
-
Set Up Conda with ROS
conda env create -f cadelac_ros_env.yml conda activate cadelac_ros
To ensure Acados and Libfranka use the same compiler, add the installed compiler (
gcc-12) to yourPATH(recommended in.bashrc):export CC=$HOME/miniconda3/envs/cadelac_ros/bin/x86_64-conda-linux-gnu-gcc export CXX=$HOME/miniconda3/envs/cadelac_ros/bin/x86_64-conda-linux-gnu-g++
-
Install CaDeLaC and dependencies
pip install -e . pip install l4casadi==1.4.1 --no-build-isolation -
Install Acados (v0.4.3)
Follow the step 4 from Training and Simulation Setup. -
Install Libfranka (v0.13.3)
Libfranka provides low-level control for Franka Emika research robots.git clone --recurse-submodules https://github.com/frankarobotics/libfranka.git cd libfranka git checkout 0.13.3 git submodule update mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/opt/openrobots/lib/cmake -DBUILD_TESTS=OFF .. make
-
Build the ROS workspace
cd ~/catkin_ws catkin_make -DPYTHON_EXECUTABLE=$(which python) -DCMAKE_BUILD_TYPE=Release -DFranka_DIR:PATH={PATH_TO_LIBFRANKA}/libfranka/build -j2 source devel/setup.bash
The datasets used for training are available on Hugging Face:
git clone https://huggingface.co/datasets/schulze18/cadelac cadelac/learning/datasets/All scripts related to training the proposed models are located in the learning folder.
The training pipeline is adapted from Deep Lagrangian Networks and implemented in PyTorch.
python -m cadelac.learning.train_panda -l 2python -m cadelac.learning.train_panda -l 0Note:
Due to the dataset size, data loading may take a few minutes. During training, each epoch took around 30s on an NVIDIA GeForce RTX 4080. In the paper, we trained for 3000 epochs, but 1000 epochs already achieve similar performance.
python -m cadelac.learning.train_panda -l 1python -m cadelac.learning.train_panda -l 0 -f 1python -m cadelac.learning.train_panda -l 1 -f 1To evaluate joint tracking under random loads:
python -m cadelac.control.eval_controllers_multiple_envs -c 2Controller options:
-c 0: Nominal MPC-c 1: MPC + EKF-c 2: CaDeLaC (Context-Aware MPC)
Terminal 1: Launch hardware interface
conda activate cadelac_ros
source catkin_ws/devel/setup.bas
roslaunch franka_example_controllers effort_joint_controller.launch robot_ip:={ROBOT_IP} load_gripper:=true robot:=pandaTerminal 2: Run CaDeLaC controller
conda activate cadelac_ros
source catkin_ws/devel/setup.bash
cd catkin_ws/src/cadelac/
python -m cadelac.ros.cadelac_node -c 2Note:
As Acados needs to compile the controller in the first run, which will take several minutes for CaDeLaC, the safety flag compilation_run prevents the controller to be executed and holds the robot in place. Once the compilation is done, you can stop the script, set the flag toFalseand run again the script which will load the compiled controller. If you run a new controller for the first time, set the flag toTrueagain.
- Additional implementation details
- Dataset collection scripts