matthias-mayr/Cartesian-Impedance-Controller

A C++ implementation of Cartesian impedance control for torque-controlled manipulators with ROS 2 & 1 bindings.

📦 Cartesian Impedance Controller

What it is – A C++ library and ROS 2 controller that lets a robot arm behave like a virtual spring‑damper in Cartesian (world‑space) coordinates. By specifying stiffness, damping and optional external wrenches, the controller translates a desired end‑effector pose into joint torques while keeping a null‑space behaviour for the arm’s joints.

Why it matters – Cartesian impedance control is a common way to make collaborative manipulators safe and compliant: the robot can gently follow a trajectory, react to contact forces, or be guided by a human without hard stops. This repo bundles a lightweight, reusable base library (usable outside ROS) and a full ROS 2 ros2_control integration that works with popular arms such as the Franka Emika Panda/Research 3 and KUKA iiwa 7.


Key Features (as listed in the README)

  • Runtime‑tunable stiffness & damping for each Cartesian axis (translation + rotation).
  • Dynamic pose updates and the ability to apply arbitrary Cartesian forces/torques (wrenches) on the fly.
  • Optional filtering of stiffness, pose and wrench signals for smoother behaviour.
  • Joint‑space null‑space control so the arm can follow a joint configuration (e.g., from MoveIt) without interfering with the end‑effector task.
  • Jerk limitation to avoid sudden torque spikes.
  • Separate base library that can be linked into non‑ROS simulators (e.g., DART).
  • ROS‑2 integration with dynamic_reconfigure/rqt_reconfigure and plain ROS topics for setting stiffness, damping, and wrenches.
  • Support for trajectory execution via the standard follow_joint_trajectory action and a fire‑and‑forget joint‑trajectory topic.

How to get it running

1. Clone & build (local workspace)

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
git clone https://github.com/matthias-mayr/Cartesian-Impedance-Controller src/Cartesian-Impedance-Controller
bash src/Cartesian-Impedance-Controller/scripts/install_dependencies.sh   # pulls Eigen, RBDyn, etc.
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
colcon build
source install/setup.bash

2. Docker alternative

# Build image
docker build -t cartesian_impedance_controller:latest .
# Run (exposes host display for RViz2, uses host network)
docker run -it --rm \
  --net=host -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  cartesian_impedance_controller:latest

Add --build-arg BUILD_FRANKA_ROS=true to the docker build command if you need the Franka ROS 2 stack inside the container.


Using the controller in a ROS 2 robot description

  1. Add a controller entry to your ros2_control YAML (example shown in the README). The type is cartesian_impedance_controller/CartesianImpedanceController.
  2. Provide a parameter file (see the README template) that defines:
    • Joint list and end‑effector frame
    • Update frequency (e.g., 500 Hz)
    • Stiffness & damping values for translation & rotation
    • Optional null‑space stiffness/damping, filtering constants, and a default wrench.
  3. Launch the robot’s ros2_control manager as usual; the controller will appear as a ROS 2 node.
  4. Tune at runtime:
    • Via rqt_reconfigure (or the CLI) for stiffness, damping, and wrench toggles.
    • By publishing geometry_msgs/WrenchStamped to /set_cartesian_stiffness, /set_damping_factors, or /set_cartesian_wrench.
    • Trajectories can be sent to /follow_joint_trajectory (action) or /joint_trajectory (topic) – MoveIt integration works out of the box.

Limitations & Gotchas (from the README)

  • No joint‑friction model – friction is ignored, which may affect very low‑speed tasks.
  • Stiffness/damping are uncoupled across Cartesian axes; you cannot specify cross‑coupling terms.
  • No built‑in gravity compensation for tools; you must supply an appropriate wrench if needed.
  • Requires RBDyn, SpaceVecAlg, mc_rbdyn_urdf – missing these will cause CMake errors (the repo provides a helper script).
  • Potential SIMD mismatches – all parts of the stack must be compiled with the same SIMD settings, otherwise the controller may crash.

Testing & Validation

The repository ships three test suites:

Test Needs simulation? What it checks
base_tests No Pure C++ library (stiffness, damping, filtering) unit tests
ros_tests Yes ROS‑2 topic/parameter plumbing
ros_func_tests Yes End‑to‑end controller behaviour (force application, motion tracking)
Run them with colcon test (unit tests) or launch the minimal mock simulation and execute the ROS test binaries as described in the README.

Citation

If you use this controller in research or a product, cite the JOSS paper:

Mayr et al., (2024). A C++ Implementation of a Cartesian Impedance Controller for Robotic Manipulators. Journal of Open Source Software, 9(93), 5194. https://doi.org/10.21105/joss.05194

Bottom line – The Cartesian Impedance Controller is a ready‑to‑use, well‑documented ROS 2 component for compliant robot arm control, with a clean C++ core that can also be embedded in custom simulators.

Related

  • Project
  • Project
  • Project
  • Project