Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ project already defines those targets. Includes are namespaced by domain, e.g.
| [Trajectory](doc/trajectory/README.md) | Cubic Spline Trajectory, Cartesian Path with SLERP Orientation, Time-Optimal Path Parameterization (TOPP-RA) |
| [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 |
| [Localization & Mapping](doc/localization/README.md) | Occupancy-Grid Mapping, Odometry Fusion, EKF Landmark Localization, 2-D Scan Matching (ICP), Monte Carlo Localization |
| [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 |
| [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 |

Each category page lists its algorithms with a brief description and links to the detailed
documentation.
Expand Down
77 changes: 77 additions & 0 deletions doc/controllers/manipulator/CoupledDamping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Coupled Damping Design

## Overview & Motivation

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.

A diagonal damper sized from each joint's own inertia ignores that coupling.
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.
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.

## Mathematical Theory

### Design

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

$$\omega_i = \sqrt{\frac{K_i}{M_{ii}}}$$

The damping matrix is the mass matrix scaled on both sides by the square roots of those frequencies:

$$D = 2\zeta\, W M W, \qquad W = \operatorname{diag}\left(\sqrt{\omega_i}\right)$$

### Properties

- **Diagonal**: $D_{ii} = 2\zeta\, \omega_i M_{ii} = 2\zeta \sqrt{K_i M_{ii}}$, the single-mass damper for joint $i$.
- **Coupling**: $D_{ij} = 2\zeta \sqrt{\omega_i \omega_j}\, M_{ij}$, so the damper couples the joints exactly where the arm does.
- **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$.
- **Symmetry and definiteness**: $D$ is symmetric, and positive definite whenever $M$ is and every $K_i > 0$, because $W$ is a positive diagonal congruence.

A joint with no inertia on its diagonal has no defined frequency; it gets no damping, and neither do its coupling terms.

## Complexity Analysis

| Step | Time | Space | Notes |
|-------------|----------|----------|----------------------------------------------------------|
| Frequencies | $O(n)$ | $O(n)$ | Two square roots per joint |
| Scaling | $O(n^2)$ | $O(n^2)$ | Each entry scaled by two weights, no product of matrices |

## Step-by-Step Walkthrough

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)$.

1. Frequencies: $\omega_1 = \sqrt{18 / 2} = 3$ and $\omega_2 = \sqrt{4.5 / 0.5} = 3$.
2. Weights: $W = \operatorname{diag}(\sqrt{3}, \sqrt{3})$.
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}$.

The frequencies are equal, so the damper is the scaled mass matrix and every mode is damped at $\zeta = 0.7$.

## Pitfalls & Edge Cases

- **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.
- **Rotor inertia**: the reflected rotor inertia of geared joints belongs on the diagonal of $M$ first, or the proximal joints are under-damped.
- **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$.
- **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.

## Variants & Generalizations

- **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.
- **Per-joint damping ratios**: $D = W' M W'$ with $W' = \operatorname{diag}(\sqrt{2\zeta_i \omega_i})$ when the joints need different ratios.
- **Constant design**: evaluate $M$ at a nominal pose once when the arm moves little.

## Applications

- Joint-space impedance control with stiffnesses chosen per joint.
- Cartesian impedance control, with the stiffness the tool spring puts on each joint, $K_i = (J^T K_x J)_{ii}$.
- PD gains from a bandwidth: equal frequencies give $K_p = \omega^2 M$ and $K_d = 2\zeta\omega M$.

## Connections to Other Algorithms

- [Impedance Control](ImpedanceControl.md): the task-space spring and damper this damper complements in joint space.
- [PD Control with Gravity Compensation](PdGravityCompensation.md): the equal-frequency case gives its mass-scaled gains.
- [Composite Rigid Body Algorithm](../../dynamics/CompositeRigidBodyAlgorithm.md): computes the mass matrix.

## References & Further Reading

- 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.
- N. Hogan, "Impedance Control: An Approach to Manipulation," *ASME Journal of Dynamic Systems, Measurement, and Control*, 107(1), 1985.
1 change: 1 addition & 0 deletions doc/controllers/manipulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Joint- and task-space controllers for robot manipulators.
| [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 |
| [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$ |
| [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 |
| [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 |
| [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 |
| [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 |
| [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$ |
Expand Down
2 changes: 2 additions & 0 deletions robotics/controllers/manipulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target_link_libraries(robotics.controllers.manipulator ${ROBOTICS_VISIBILITY}
target_sources(robotics.controllers.manipulator PRIVATE
CableTensionDistribution.hpp
ComputedTorqueControl.hpp
CoupledDamping.hpp
HybridPositionForceControl.hpp
ImpedanceControl.hpp
OperationalSpaceControl.hpp
Expand All @@ -27,6 +28,7 @@ target_sources(robotics.controllers.manipulator PRIVATE
robotics_add_coverage_sources(robotics.controllers.manipulator
CableTensionDistribution.cpp
ComputedTorqueControl.cpp
CoupledDamping.cpp
HybridPositionForceControl.cpp
ImpedanceControl.cpp
OperationalSpaceControl.cpp
Expand Down
4 changes: 4 additions & 0 deletions robotics/controllers/manipulator/CoupledDamping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "robotics/controllers/manipulator/CoupledDamping.hpp"

template math::SquareMatrix<float, 2> controllers::CoupledDamping<float, 2>(const math::SquareMatrix<float, 2>&, const math::Vector<float, 2>&, float);
template math::SquareMatrix<float, 6> controllers::CoupledDamping<float, 6>(const math::SquareMatrix<float, 6>&, const math::Vector<float, 6>&, float);
31 changes: 31 additions & 0 deletions robotics/controllers/manipulator/CoupledDamping.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "numerical/math/Math.hpp"
#include "numerical/math/Matrix.hpp"
#include <array>
#include <cstddef>
#include <type_traits>

namespace controllers
{
template<typename T, std::size_t N>
math::SquareMatrix<T, N> CoupledDamping(const math::SquareMatrix<T, N>& inertia, const math::Vector<T, N>& stiffness, T dampingRatio)
{
static_assert(std::is_floating_point_v<T>, "CoupledDamping supports floating-point types");

std::array<T, N> weight{};
for (std::size_t joint = 0; joint < N; ++joint)
weight[joint] = inertia.at(joint, joint) > T{} ? math::Sqrt(math::Sqrt(stiffness[joint] / inertia.at(joint, joint))) : T{};

math::SquareMatrix<T, N> damping{};
for (std::size_t row = 0; row < N; ++row)
for (std::size_t column = 0; column < N; ++column)
damping.at(row, column) = T{ 2 } * dampingRatio * weight[row] * inertia.at(row, column) * weight[column];
return damping;
}

#ifdef ROBOTICS_TOOLBOX_COVERAGE_BUILD
extern template math::SquareMatrix<float, 2> CoupledDamping<float, 2>(const math::SquareMatrix<float, 2>&, const math::Vector<float, 2>&, float);
extern template math::SquareMatrix<float, 6> CoupledDamping<float, 6>(const math::SquareMatrix<float, 6>&, const math::Vector<float, 6>&, float);
#endif
}
1 change: 1 addition & 0 deletions robotics/controllers/manipulator/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_link_libraries(robotics.controllers.manipulator_test PUBLIC
target_sources(robotics.controllers.manipulator_test PRIVATE
TestCableTensionDistribution.cpp
TestComputedTorqueControl.cpp
TestCoupledDamping.cpp
TestHybridPositionForceControl.cpp
TestImpedanceControl.cpp
TestOperationalSpaceControl.cpp
Expand Down
50 changes: 50 additions & 0 deletions robotics/controllers/manipulator/test/TestCoupledDamping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "numerical/math/Tolerance.hpp"
#include "robotics/controllers/manipulator/CoupledDamping.hpp"
#include <cmath>
#include <gtest/gtest.h>

namespace
{
using Matrix2 = math::SquareMatrix<float, 2>;
using Vector2 = math::Vector<float, 2>;

class TestCoupledDamping
: public ::testing::Test
{
protected:
static void ExpectNear(const Matrix2& actual, const Matrix2& expected)
{
for (std::size_t row = 0; row < 2; ++row)
for (std::size_t column = 0; column < 2; ++column)
EXPECT_NEAR(actual.at(row, column), expected.at(row, column), math::Tolerance<float>());
}

float dampingRatio{ 0.7f };
};
}

TEST_F(TestCoupledDamping, uncoupled_joints_get_the_damping_of_a_single_spring_and_mass)
{
const auto damping{ controllers::CoupledDamping(Matrix2{ { 2.0f, 0.0f }, { 0.0f, 0.5f } }, Vector2{ 8.0f, 2.0f }, dampingRatio) };

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) } });
}

TEST_F(TestCoupledDamping, equal_natural_frequencies_scale_the_coupled_mass_matrix)
{
const Matrix2 inertia{ { 2.0f, 0.6f }, { 0.6f, 0.5f } };
const float omega{ 3.0f };

const auto damping{ controllers::CoupledDamping(inertia, Vector2{ omega * omega * 2.0f, omega * omega * 0.5f }, dampingRatio) };

ExpectNear(damping, inertia * (2.0f * dampingRatio * omega));
}

TEST_F(TestCoupledDamping, a_joint_without_inertia_gets_no_damping)
{
const auto damping{ controllers::CoupledDamping(Matrix2{ { 2.0f, 0.0f }, { 0.0f, 0.0f } }, Vector2{ 8.0f, 2.0f }, dampingRatio) };

EXPECT_NEAR(damping.at(1, 1), 0.0f, math::Tolerance<float>());
EXPECT_NEAR(damping.at(0, 1), 0.0f, math::Tolerance<float>());
EXPECT_NEAR(damping.at(1, 0), 0.0f, math::Tolerance<float>());
}
Loading