Skip to content

Schulze18/cadelac

Repository files navigation

CaDeLaC

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.

Installation - Training and Simulation

Training and Simulation Setup

  1. Clone the Repository

    git clone [email protected]:Schulze18/cadelac.git
    cd cadelac
    git submodule update --recursive --init
  2. Set Up Conda Environment

    conda env create -f cadelac_env.yml
    conda activate cadelac
  3. Install CaDeLaC as a Python pkg and additional Dependencies

    pip install -e .
    pip install l4casadi==1.4.1 --no-build-isolation
  4. 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 .bashrc file:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<acados_root>/lib"
    export ACADOS_SOURCE_DIR="<acados_root>"

Real Robot Setup

  1. 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
  2. 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 your PATH (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++
  3. Install CaDeLaC and dependencies

    pip install -e .
    pip install l4casadi==1.4.1 --no-build-isolation
  4. Install Acados (v0.4.3)
    Follow the step 4 from Training and Simulation Setup.

  5. 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
  6. 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

Datasets

The datasets used for training are available on Hugging Face:

git clone https://huggingface.co/datasets/schulze18/cadelac cadelac/learning/datasets/

Training and Evaluation

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.

Evaluate Pretrained Model (IROS 2025)

python -m cadelac.learning.train_panda -l 2

Learn Residual Dynamics

python -m cadelac.learning.train_panda -l 0

Note:
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.

Evaluate Trained Model

python -m cadelac.learning.train_panda -l 1

Learn Robot Model with DeLaN

python -m cadelac.learning.train_panda -l 0 -f 1

Evaluate DeLaN

python -m cadelac.learning.train_panda -l 1 -f 1

Control Experiments

Mujoco Simulation

To evaluate joint tracking under random loads:

python -m cadelac.control.eval_controllers_multiple_envs -c 2

Controller options:

  • -c 0: Nominal MPC
  • -c 1: MPC + EKF
  • -c 2: CaDeLaC (Context-Aware MPC)

Real Franka Robot

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:=panda

Terminal 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 2

Note:
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 to False and run again the script which will load the compiled controller. If you run a new controller for the first time, set the flag to True again.


TODO

  • Additional implementation details
  • Dataset collection scripts

About

Context-Aware Deep Lagrangian Networks for Model Predictive Control (CaDeLaC)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published