Skip to content

Commit eb60bca

Browse files
feat(controllers): coupled damping design for impedance control (#50)
* feat(controllers): coupled damping design for impedance control CoupledDamping(M, K, zeta) returns D = 2 zeta W M W with W = diag(sqrt(omega_i)) and omega_i = sqrt(K_i / M_ii): each joint gets the single-mass damper 2 zeta sqrt(K_i M_ii) on its diagonal, and the damper couples the joints where the mass matrix does. With equal frequencies it is 2 zeta omega M, so every mode is damped at zeta. A joint with no inertia gets no damping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU * docs(controllers): describe the coupled damper without calling it critical Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU * fix(controllers): drop the empty namespace around the explicit instantiations Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU * docs(controllers): keep the coupled damping overview within 400 columns Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7cb9827 commit eb60bca

8 files changed

Lines changed: 167 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ project already defines those targets. Includes are namespaced by domain, e.g.
4343
| [Trajectory](doc/trajectory/README.md) | Cubic Spline Trajectory, Cartesian Path with SLERP Orientation, Time-Optimal Path Parameterization (TOPP-RA) |
4444
| [Mobile Robots](doc/mobile/README.md) | Planar Odometry, Differential-Drive Kinematics, Car-Like Kinematics, Omnidirectional Kinematics, Skid-Steer Kinematics, Pure-Pursuit Path Tracking, Kanayama Trajectory Tracking, Stanley Path Tracking |
4545
| [Localization & Mapping](doc/localization/README.md) | Occupancy-Grid Mapping, Odometry Fusion, EKF Landmark Localization, 2-D Scan Matching (ICP), Monte Carlo Localization |
46-
| [Manipulator Control](doc/controllers/manipulator/README.md) | PD Control with Gravity Compensation, Computed-Torque Control, Impedance Control, Operational-Space Control, Hybrid Position/Force Control, Slotine–Li Adaptive Control, Cable Tension Distribution |
46+
| [Manipulator Control](doc/controllers/manipulator/README.md) | PD Control with Gravity Compensation, Computed-Torque Control, Impedance Control, Coupled Damping Design, Operational-Space Control, Hybrid Position/Force Control, Slotine–Li Adaptive Control, Cable Tension Distribution |
4747

4848
Each category page lists its algorithms with a brief description and links to the detailed
4949
documentation.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Coupled Damping Design
2+
3+
## Overview & Motivation
4+
5+
An impedance or PD controller makes each joint behave as a spring of stiffness $K_i$ and a damper. On a single mass the damper that gives damping ratio $\zeta$ is $2\zeta\sqrt{K m}$. A robot arm is not a set of independent masses: its mass matrix couples the joints, and the shoulder and elbow move each other.
6+
7+
A diagonal damper sized from each joint's own inertia ignores that coupling.
8+
The fast coupled mode of two strongly coupled joints, whose inertia is much smaller than either joint's own, is then damped far beyond what a sampled controller can deliver, and it oscillates; a light wrist next to heavy proximal joints suffers the same way.
9+
Shaping the damper with the mass matrix itself gives every mode of the arm a sensible damping ratio, while each joint keeps the damping its own spring and inertia call for.
10+
11+
## Mathematical Theory
12+
13+
### Design
14+
15+
With $M$ the joint-space mass matrix, $K = \operatorname{diag}(K_i)$ the joint stiffnesses and $\zeta$ the damping ratio, each joint's natural frequency on its own diagonal inertia is
16+
17+
$$\omega_i = \sqrt{\frac{K_i}{M_{ii}}}$$
18+
19+
The damping matrix is the mass matrix scaled on both sides by the square roots of those frequencies:
20+
21+
$$D = 2\zeta\, W M W, \qquad W = \operatorname{diag}\left(\sqrt{\omega_i}\right)$$
22+
23+
### Properties
24+
25+
- **Diagonal**: $D_{ii} = 2\zeta\, \omega_i M_{ii} = 2\zeta \sqrt{K_i M_{ii}}$, the single-mass damper for joint $i$.
26+
- **Coupling**: $D_{ij} = 2\zeta \sqrt{\omega_i \omega_j}\, M_{ij}$, so the damper couples the joints exactly where the arm does.
27+
- **Equal frequencies**: if every $\omega_i = \omega$, then $D = 2\zeta\omega M$. The closed loop $M\ddot{e} + D\dot{e} + Ke = 0$ with $K = \omega^2 M$ then gives every mode the natural frequency $\omega$ and damping ratio $\zeta$.
28+
- **Symmetry and definiteness**: $D$ is symmetric, and positive definite whenever $M$ is and every $K_i > 0$, because $W$ is a positive diagonal congruence.
29+
30+
A joint with no inertia on its diagonal has no defined frequency; it gets no damping, and neither do its coupling terms.
31+
32+
## Complexity Analysis
33+
34+
| Step | Time | Space | Notes |
35+
|-------------|----------|----------|----------------------------------------------------------|
36+
| Frequencies | $O(n)$ | $O(n)$ | Two square roots per joint |
37+
| Scaling | $O(n^2)$ | $O(n^2)$ | Each entry scaled by two weights, no product of matrices |
38+
39+
## Step-by-Step Walkthrough
40+
41+
Two joints with $M = \begin{bmatrix} 2 & 0.6 \\ 0.6 & 0.5 \end{bmatrix}$, $\zeta = 0.7$ and the stiffnesses $K = (18, 4.5)$.
42+
43+
1. Frequencies: $\omega_1 = \sqrt{18 / 2} = 3$ and $\omega_2 = \sqrt{4.5 / 0.5} = 3$.
44+
2. Weights: $W = \operatorname{diag}(\sqrt{3}, \sqrt{3})$.
45+
3. Damping: $D = 2 \cdot 0.7 \cdot 3 \cdot M = 4.2\, M = \begin{bmatrix} 8.4 & 2.52 \\ 2.52 & 2.1 \end{bmatrix}$.
46+
47+
The frequencies are equal, so the damper is the scaled mass matrix and every mode is damped at $\zeta = 0.7$.
48+
49+
## Pitfalls & Edge Cases
50+
51+
- **Configuration dependence**: $M$ changes with the pose. Recompute $D$ every control period for an arm that moves far, or the coupling terms describe the wrong pose.
52+
- **Rotor inertia**: the reflected rotor inertia of geared joints belongs on the diagonal of $M$ first, or the proximal joints are under-damped.
53+
- **Unequal frequencies**: the per-mode damping ratio is exactly $\zeta$ only when all $\omega_i$ are equal. With very different frequencies the modes are damped near, not at, $\zeta$.
54+
- **Sampling limits**: the damping per control period, $2\zeta\omega_i T$, must stay well below one. A stiff, light joint can ask for more damping than the loop can deliver at a given period.
55+
56+
## Variants & Generalizations
57+
58+
- **Task space**: the same design with the task inertia $\Lambda$ and a task stiffness damps a Cartesian impedance; near a singularity $\Lambda$ is unbounded, which is why a joint-space damper is often preferred there.
59+
- **Per-joint damping ratios**: $D = W' M W'$ with $W' = \operatorname{diag}(\sqrt{2\zeta_i \omega_i})$ when the joints need different ratios.
60+
- **Constant design**: evaluate $M$ at a nominal pose once when the arm moves little.
61+
62+
## Applications
63+
64+
- Joint-space impedance control with stiffnesses chosen per joint.
65+
- Cartesian impedance control, with the stiffness the tool spring puts on each joint, $K_i = (J^T K_x J)_{ii}$.
66+
- PD gains from a bandwidth: equal frequencies give $K_p = \omega^2 M$ and $K_d = 2\zeta\omega M$.
67+
68+
## Connections to Other Algorithms
69+
70+
- [Impedance Control](ImpedanceControl.md): the task-space spring and damper this damper complements in joint space.
71+
- [PD Control with Gravity Compensation](PdGravityCompensation.md): the equal-frequency case gives its mass-scaled gains.
72+
- [Composite Rigid Body Algorithm](../../dynamics/CompositeRigidBodyAlgorithm.md): computes the mass matrix.
73+
74+
## References & Further Reading
75+
76+
- A. Albu-Schäffer, C. Ott, U. Frese, G. Hirzinger, "Cartesian Impedance Control of Redundant Robots: Recent Results with the DLR-Light-Weight-Arms," *IEEE ICRA*, 2003.
77+
- N. Hogan, "Impedance Control: An Approach to Manipulation," *ASME Journal of Dynamic Systems, Measurement, and Control*, 107(1), 1985.

‎doc/controllers/manipulator/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Joint- and task-space controllers for robot manipulators.
99
| [PD Control with Gravity Compensation](PdGravityCompensation.md) | Globally stable set-point regulator $\tau = K_p e - K_d \dot{q} + g(q)$ — needs only the gravity torque |
1010
| [Computed-Torque Control](ComputedTorqueControl.md) | Feedback linearization: one inverse-dynamics pass at the commanded acceleration gives decoupled error dynamics $\ddot{e} + K_d\dot{e} + K_p e = 0$ |
1111
| [Impedance Control](ImpedanceControl.md) | Task-space mass–spring–damper behaviour: passive $J^T(Ke + D\dot{e}) + g$ without force sensing, or full inertia shaping through $\Lambda(q)$ and a measured wrench |
12+
| [Coupled Damping Design](CoupledDamping.md) | Mass-matrix-shaped damper $D = 2\zeta W M W$, $W = \operatorname{diag}(\sqrt{\omega_i})$: each joint's single-mass damping, coupled where the arm is |
1213
| [Operational-Space Control](OperationalSpaceControl.md) | Decoupled task-space tracking through $\Lambda(q)$, joint-space Coriolis/gravity compensation and a dynamically consistent null space for secondary torques |
1314
| [Hybrid Position/Force Control](HybridPositionForceControl.md) | Constraint-frame selection between a motion PD and a damped force PI with anti-windup, mapped through $J^T$ with gravity and Coriolis compensation |
1415
| [Slotine–Li Adaptive Control](SlotineLiAdaptiveControl.md) | Globally convergent tracking with unknown inertial parameters: regressor feedforward, sliding-variable damping and the passivity-based update $\dot{\hat{a}} = -\Gamma Y^T s$ |

‎robotics/controllers/manipulator/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_link_libraries(robotics.controllers.manipulator ${ROBOTICS_VISIBILITY}
1616
target_sources(robotics.controllers.manipulator PRIVATE
1717
CableTensionDistribution.hpp
1818
ComputedTorqueControl.hpp
19+
CoupledDamping.hpp
1920
HybridPositionForceControl.hpp
2021
ImpedanceControl.hpp
2122
OperationalSpaceControl.hpp
@@ -27,6 +28,7 @@ target_sources(robotics.controllers.manipulator PRIVATE
2728
robotics_add_coverage_sources(robotics.controllers.manipulator
2829
CableTensionDistribution.cpp
2930
ComputedTorqueControl.cpp
31+
CoupledDamping.cpp
3032
HybridPositionForceControl.cpp
3133
ImpedanceControl.cpp
3234
OperationalSpaceControl.cpp
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "robotics/controllers/manipulator/CoupledDamping.hpp"
2+
3+
template math::SquareMatrix<float, 2> controllers::CoupledDamping<float, 2>(const math::SquareMatrix<float, 2>&, const math::Vector<float, 2>&, float);
4+
template math::SquareMatrix<float, 6> controllers::CoupledDamping<float, 6>(const math::SquareMatrix<float, 6>&, const math::Vector<float, 6>&, float);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include "numerical/math/Math.hpp"
4+
#include "numerical/math/Matrix.hpp"
5+
#include <array>
6+
#include <cstddef>
7+
#include <type_traits>
8+
9+
namespace controllers
10+
{
11+
template<typename T, std::size_t N>
12+
math::SquareMatrix<T, N> CoupledDamping(const math::SquareMatrix<T, N>& inertia, const math::Vector<T, N>& stiffness, T dampingRatio)
13+
{
14+
static_assert(std::is_floating_point_v<T>, "CoupledDamping supports floating-point types");
15+
16+
std::array<T, N> weight{};
17+
for (std::size_t joint = 0; joint < N; ++joint)
18+
weight[joint] = inertia.at(joint, joint) > T{} ? math::Sqrt(math::Sqrt(stiffness[joint] / inertia.at(joint, joint))) : T{};
19+
20+
math::SquareMatrix<T, N> damping{};
21+
for (std::size_t row = 0; row < N; ++row)
22+
for (std::size_t column = 0; column < N; ++column)
23+
damping.at(row, column) = T{ 2 } * dampingRatio * weight[row] * inertia.at(row, column) * weight[column];
24+
return damping;
25+
}
26+
27+
#ifdef ROBOTICS_TOOLBOX_COVERAGE_BUILD
28+
extern template math::SquareMatrix<float, 2> CoupledDamping<float, 2>(const math::SquareMatrix<float, 2>&, const math::Vector<float, 2>&, float);
29+
extern template math::SquareMatrix<float, 6> CoupledDamping<float, 6>(const math::SquareMatrix<float, 6>&, const math::Vector<float, 6>&, float);
30+
#endif
31+
}

‎robotics/controllers/manipulator/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target_link_libraries(robotics.controllers.manipulator_test PUBLIC
1212
target_sources(robotics.controllers.manipulator_test PRIVATE
1313
TestCableTensionDistribution.cpp
1414
TestComputedTorqueControl.cpp
15+
TestCoupledDamping.cpp
1516
TestHybridPositionForceControl.cpp
1617
TestImpedanceControl.cpp
1718
TestOperationalSpaceControl.cpp
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "numerical/math/Tolerance.hpp"
2+
#include "robotics/controllers/manipulator/CoupledDamping.hpp"
3+
#include <cmath>
4+
#include <gtest/gtest.h>
5+
6+
namespace
7+
{
8+
using Matrix2 = math::SquareMatrix<float, 2>;
9+
using Vector2 = math::Vector<float, 2>;
10+
11+
class TestCoupledDamping
12+
: public ::testing::Test
13+
{
14+
protected:
15+
static void ExpectNear(const Matrix2& actual, const Matrix2& expected)
16+
{
17+
for (std::size_t row = 0; row < 2; ++row)
18+
for (std::size_t column = 0; column < 2; ++column)
19+
EXPECT_NEAR(actual.at(row, column), expected.at(row, column), math::Tolerance<float>());
20+
}
21+
22+
float dampingRatio{ 0.7f };
23+
};
24+
}
25+
26+
TEST_F(TestCoupledDamping, uncoupled_joints_get_the_damping_of_a_single_spring_and_mass)
27+
{
28+
const auto damping{ controllers::CoupledDamping(Matrix2{ { 2.0f, 0.0f }, { 0.0f, 0.5f } }, Vector2{ 8.0f, 2.0f }, dampingRatio) };
29+
30+
ExpectNear(damping, Matrix2{ { 2.0f * dampingRatio * std::sqrt(8.0f * 2.0f), 0.0f }, { 0.0f, 2.0f * dampingRatio * std::sqrt(2.0f * 0.5f) } });
31+
}
32+
33+
TEST_F(TestCoupledDamping, equal_natural_frequencies_scale_the_coupled_mass_matrix)
34+
{
35+
const Matrix2 inertia{ { 2.0f, 0.6f }, { 0.6f, 0.5f } };
36+
const float omega{ 3.0f };
37+
38+
const auto damping{ controllers::CoupledDamping(inertia, Vector2{ omega * omega * 2.0f, omega * omega * 0.5f }, dampingRatio) };
39+
40+
ExpectNear(damping, inertia * (2.0f * dampingRatio * omega));
41+
}
42+
43+
TEST_F(TestCoupledDamping, a_joint_without_inertia_gets_no_damping)
44+
{
45+
const auto damping{ controllers::CoupledDamping(Matrix2{ { 2.0f, 0.0f }, { 0.0f, 0.0f } }, Vector2{ 8.0f, 2.0f }, dampingRatio) };
46+
47+
EXPECT_NEAR(damping.at(1, 1), 0.0f, math::Tolerance<float>());
48+
EXPECT_NEAR(damping.at(0, 1), 0.0f, math::Tolerance<float>());
49+
EXPECT_NEAR(damping.at(1, 0), 0.0f, math::Tolerance<float>());
50+
}

0 commit comments

Comments
 (0)