Algorithmcore
Impedance control
Also called Hogan impedance control.
Makes the end effector behave as a chosen mass, spring and damper around a goal motion, so contact forces stay moderate and predictable.
- Time
- O(n^3) per_step
- Space
- O(n^2) extra
- Where
- n = the number of joints, equal to the task dimension (a nonredundant arm); the bounds are for one control step
- Model
- Real RAM
- Properties
- deterministicnot exactonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Neville Hogan, 1985
Impedance control is a way to control a robot that touches its environment. It does not command a position or a force. It commands a relation between the two: the end effector should move as if it were a chosen mass on a chosen spring and damper, attached to a goal motion . In free space the end effector then follows ; against an obstacle it pushes with a force that the spring sets, and the force stays bounded even when the position of the obstacle is not known exactly. Hogan introduced the idea in 1985. The dual scheme, which measures the force and commands a motion, is admittance control.
In plain words
A position-controlled robot that meets a wall it did not expect pushes as hard as its motors allow, because it tries to reach a point inside the wall. A person in the same case gives way. Impedance control makes the robot give way in a chosen manner.
The designer picks three numbers per direction: a mass, a stiffness and a damping. The robot then reacts to a push as a weight on a spring and a shock absorber would. A soft spring gives gentle contact but poor accuracy in free space, and a stiff spring gives the reverse. If the goal point is a little inside a surface, the robot presses on the surface with a force equal to the spring stiffness times that depth, or less if the surface is soft.
The problem
The arm has joints and its end effector has a task position with Jacobian , square and nonsingular in the region of interest. The environment applies a force to the end effector, so the arm obeys
by the duality of the Jacobian and statics. A goal motion and target matrices , , (symmetric positive definite) are given. With , the task is to choose so that
The algorithm
This is the form with a force sensor at the wrist and a full dynamic model. Diagonal target matrices are the usual choice.
IMPEDANCE(q, q', x_0, x_0', x_0'', F_ext, M_d, D_d, K_d)- 1
x ← f(q); x' ← J(q) q' - 2
x̃ ← x - x_0; x̃' ← x' - x_0' - 3
a_x ← x_0'' + M_d⁻¹ (F_ext - D_d x̃' - K_d x̃) ▷ wanted task acceleration - 4
a_q ← J(q)⁻¹ (a_x - J'(q, q') q') - 5
τ ← M(q) a_q + C(q, q') q' + g(q) - J(q)ᵀ F_ext - 6
return τ
Lines L4 and L5 are computed-torque control toward the acceleration . The term in line L5 cancels the measured contact force, and line L3 puts it back, scaled by . If the target mass is not changed ( equal to the task-space inertia of the arm), the force sensor is not needed, and the law reduces to
for a fixed goal. This simple form is the one most often used on torque-controlled arms. It is PD control with gravity compensation with the spring and damper placed in task space.
Example
Take the planar 2R arm with m and point masses of 1 kg at the link ends, in a vertical plane with gravity along . A frictionless wall fills m and acts as a stiff spring, for with N/m. The targets are kg, N/m and N s/m, which is critical damping. The arm starts at rest with its end point at m, and the goal is fixed at , 5 cm inside the wall.
At the start, , so line L3 gives m/s and lines L4 and L5 give N m. The table shows a simulation with RK4 and a step of 1 ms.
| time (s) | end point (m) | wall force (N) |
|---|---|---|
| 0.100 | 0.98910 | 0 |
| 0.115 | first contact | 0 |
| 0.131 | peak | 67.5 |
| 0.200 | 1.00321 | 32.1 |
| 0.500 | 1.00192 | 19.24 |
| 1.500 | 1.0019231 | 19.231 |
At rest the target equation gives . Together with the wall law this gives the rest position m and the contact force
The force is that of the target spring and the wall spring in series. The impact peak of 67.5 N is set by the target mass and the speed at contact, not by the spring alone. The coordinate stays at 0.5 m within m during the whole motion, because the target matrices are diagonal and the law cancels the arm's own inertia. The simple law without a force sensor reaches the same rest force, but its coordinate moves by up to 1.8 mm during the impact, because the arm's inertia couples the two directions.
Correctness
The claim is: with an exact model, a nonsingular and an exact force measurement, the closed loop satisfies for every force . Putting line L5 into the arm equation, the , and terms cancel, so . Then by line L4, and line L3 rearranges to the target equation. For a passive environment and a fixed goal, the energy plus the energy stored in the environment does not grow, which bounds the motion and the contact force. The full proof, including the rest force against a spring wall, is in the proof file.
Proof: Impedance control gives the target impedancefull
The arm obeys , where and . We assume that the model in line L5 is exact, that is nonsingular along the motion, and that the value passed to IMPEDANCE is the true contact force. , and are symmetric positive definite.
Theorem 1 (target dynamics). Under these assumptions, at every time, where .
Proof. Put the torque of line L5 into the arm equation:
The terms , and cancel, so , and because is invertible. Differentiating gives . By line L4, , so . By line L3, . With this is the target equation.
Theorem 2 (bounded energy with a passive environment). Let the goal be fixed (). Let the environment be a spring with energy and force . Then satisfies .
Proof. With a fixed goal, . By Theorem 1 and the symmetry of and ,
The first and last terms cancel because .
So and stay bounded by , and the contact force stays bounded on the bounded set of positions that the motion can reach.
Theorem 3 (rest force against a spring wall). Let the task directions be decoupled (, , diagonal), and let the wall act along the first coordinate with for and otherwise, with and . If the closed loop is at rest, then and the force on the wall is , where is the first diagonal entry of .
Proof. At rest, , so Theorem 1 gives . If , the right side is , so , which is a contradiction. So and . Solving gives the stated . The force on the wall is .
Law without a force sensor. For with a fixed goal, the function satisfies . The computation is the one of PD control with gravity compensation: , the skew symmetry removes the and terms, and removes the rest except . At rest, , and since is nonsingular, , so Theorem 3 holds for this law too.
Complexity
In the real-RAM model, with joints and a task of dimension :
- Lines L1 and L2 need the forward kinematics and the geometric Jacobian. For a serial chain, the joint frames take operations and the Jacobian then takes .
- Line L4 solves a linear system with , which takes operations by Gaussian elimination.
- Line L5 is one inverse dynamics call, with the recursive Newton-Euler algorithm, plus in .
So one step costs time and memory. For a 6-joint arm this is a fixed small number of operations. The law without a force sensor needs only times a vector and the gravity torque, which is .
Properties
- Bounded contact force. At rest against a spring-like surface, the force is times the depth of the goal inside the surface, so it is at most times that depth, whatever the stiffness of the surface.
- One law for free motion and contact. No switching is needed when contact starts or ends. This is the main practical advantage over hybrid position/force control.
- Passivity. The simple law makes the arm a passive system seen from the contact point. Coupled to any passive environment, the system stays stable, which is not true for most position or force controllers.
- No force tracking. The force is not controlled directly. It follows from the depth of the goal and the stiffness of the environment, and it changes if the surface is not where the model says.
Variants and improvements
- Without inertia shaping. If is the natural task-space inertia , no force sensor is needed. This is the simple law above, also called compliance control or Cartesian stiffness control when the target mass is ignored.
- Admittance control. On an arm with stiff position servos and no torque control, measure the force, integrate the target dynamics to get a reference motion, and send it to the position loop. See admittance control.
- Orientation. For rotations the spring needs care: a spring on Euler angles depends on the chosen angles. Springs on the axis-angle error, or on the rotation matrix, give a stiffness that does not depend on the coordinates.
- Redundant arms. With more joints than task directions, the operational space formulation gives the task impedance and leaves a null space for a second task.
- Variable impedance. The stiffness and damping can change with time or with the task phase, but a changing stiffness can inject energy and needs its own stability check.
When to use it
Use it whenever the robot touches its environment and the position of the contact surface is uncertain: assembly such as peg-in-hole insertion, polishing, opening doors, and physical work with people. It needs a torque-controlled arm or at least a joint torque interface. For an arm with only position control, use admittance control. When a precise contact force must be held, combine it with an explicit force loop or use hybrid position/force control.
Pitfalls
- Stiff environments and impact. The impact force depends on the target mass and the approach speed. A small target mass needs a fast inner loop and accurate force measurement; with a slow loop or noisy sensors, a small against a stiff wall can make the contact unstable.
- Model errors. The full law cancels the inertia of the arm. Errors in the model or in the force measurement leave the target equation only approximately true, and friction in the joints hides small forces.
- Singularities. Line L4 needs , which does not exist at a kinematic singularity. Near one, the joint torques grow large for a small task force.
- Coordinates of the spring. A diagonal stiffness in one frame is not diagonal in another. Choose the frame in which the task has natural directions, such as the normal of the surface.
- Goal inside the obstacle. The contact force is set by how far the goal lies inside the surface. A goal far inside a stiff surface gives a large force; plan the goal with the surface position in mind.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/impedance-control/. The authors are listed in prov/TVY2W5.jsonl.
"""Impedance control of the end point of a planar 2R arm.
The arm obeys M(q) q'' + C(q, q') q' + g(q) = tau + J(q)^T F_ext, where
F_ext is the force of the environment on the end point. The law with a
force sensor makes the end point error x~ = x - x0 obey
Md x~'' + Dd x~' + Kd x~ = F_ext.
The law without a force sensor, tau = J^T (Kd (x0 - x) - Dd x') + g(q), gives
the same spring and damper at rest but not the chosen mass.
Matrices are lists of rows and vectors are lists. Only the standard library.
"""
import math
GRAVITY = 9.81
class TwoLinkArm:
"""Planar 2R arm in a vertical plane, with point masses at the link ends.
q1 is measured from the horizontal x axis, q2 from link 1. The y axis
points up, and gravity acts along -y.
"""
def __init__(self, m1=1.0, m2=1.0, l1=1.0, l2=1.0, grav=GRAVITY):
self.m1, self.m2, self.l1, self.l2, self.grav = m1, m2, l1, l2, grav
def mass(self, q):
m1, m2, l1, l2 = self.m1, self.m2, self.l1, self.l2
c2 = math.cos(q[1])
a = (m1 + m2) * l1 * l1 + m2 * l2 * l2 + 2.0 * m2 * l1 * l2 * c2
b = m2 * l2 * l2 + m2 * l1 * l2 * c2
return [[a, b], [b, m2 * l2 * l2]]
def coriolis(self, q, qd):
h = self.m2 * self.l1 * self.l2 * math.sin(q[1])
return [[-h * qd[1], -h * (qd[0] + qd[1])], [h * qd[0], 0.0]]
def gravity(self, q):
m1, m2, l1, l2, gr = self.m1, self.m2, self.l1, self.l2, self.grav
c1, c12 = math.cos(q[0]), math.cos(q[0] + q[1])
return [(m1 + m2) * gr * l1 * c1 + m2 * gr * l2 * c12, m2 * gr * l2 * c12]
def fk(self, q):
"""Position of the end point."""
q12 = q[0] + q[1]
return [
self.l1 * math.cos(q[0]) + self.l2 * math.cos(q12),
self.l1 * math.sin(q[0]) + self.l2 * math.sin(q12),
]
def jacobian(self, q):
s1, c1 = math.sin(q[0]), math.cos(q[0])
s12, c12 = math.sin(q[0] + q[1]), math.cos(q[0] + q[1])
l1, l2 = self.l1, self.l2
return [[-l1 * s1 - l2 * s12, -l2 * s12], [l1 * c1 + l2 * c12, l2 * c12]]
def jdot_qdot(self, q, qd):
"""The term J'(q, q') q' of the end point acceleration."""
w1, w12 = qd[0], qd[0] + qd[1]
s1, c1 = math.sin(q[0]), math.cos(q[0])
s12, c12 = math.sin(q[0] + q[1]), math.cos(q[0] + q[1])
l1, l2 = self.l1, self.l2
return [
-l1 * c1 * w1 * w1 - l2 * c12 * w12 * w12,
-l1 * s1 * w1 * w1 - l2 * s12 * w12 * w12,
]
def ik(self, x, elbow=1.0):
"""Joint angles that put the end point at x (elbow = +1 or -1)."""
l1, l2 = self.l1, self.l2
c2 = (x[0] ** 2 + x[1] ** 2 - l1 * l1 - l2 * l2) / (2 * l1 * l2)
if abs(c2) > 1.0:
raise ValueError("point out of reach")
q2 = elbow * math.acos(c2)
q1 = math.atan2(x[1], x[0]) - math.atan2(l2 * math.sin(q2), l1 + l2 * math.cos(q2))
return [q1, q2]
def accel(self, q, qd, tau, f_ext):
"""Solve M q'' = tau + J^T F_ext - C q' - g for q''."""
m = self.mass(q)
c = self.coriolis(q, qd)
g = self.gravity(q)
j = self.jacobian(q)
r = [
tau[i] + j[0][i] * f_ext[0] + j[1][i] * f_ext[1] - c[i][0] * qd[0] - c[i][1] * qd[1] - g[i]
for i in range(2)
]
return solve2(m, r)
def solve2(a, b):
"""Solve the 2 by 2 system a x = b by Cramer's rule."""
det = a[0][0] * a[1][1] - a[0][1] * a[1][0]
if det == 0.0:
raise ValueError("singular 2 by 2 matrix")
return [(b[0] * a[1][1] - a[0][1] * b[1]) / det, (a[0][0] * b[1] - b[0] * a[1][0]) / det]
def matvec2(a, v):
return [a[0][0] * v[0] + a[0][1] * v[1], a[1][0] * v[0] + a[1][1] * v[1]]
def impedance_control(arm, q, qd, x0, x0d, x0dd, f_ext, md, dd, kd):
"""Impedance law with a force sensor and a full dynamic model.
f_ext is the measured force of the environment on the end point.
md, dd and kd are lists of diagonal task-space gains.
"""
j = arm.jacobian(q)
x, xd = arm.fk(q), matvec2(j, qd) # @line L1
xt = [x[i] - x0[i] for i in range(2)] # @line L2
xtd = [xd[i] - x0d[i] for i in range(2)]
ax = [x0dd[i] + (f_ext[i] - dd[i] * xtd[i] - kd[i] * xt[i]) / md[i] for i in range(2)] # @line L3
jq = arm.jdot_qdot(q, qd)
aq = solve2(j, [ax[i] - jq[i] for i in range(2)]) # @line L4
m, c, g = arm.mass(q), arm.coriolis(q, qd), arm.gravity(q) # @line L5
tau = [
sum(m[i][k] * aq[k] + c[i][k] * qd[k] for k in range(2)) + g[i] - (j[0][i] * f_ext[0] + j[1][i] * f_ext[1])
for i in range(2)
]
return tau # @line L6
def simple_impedance(arm, q, qd, x0, dd, kd):
"""Impedance law without a force sensor: tau = J^T (Kd (x0 - x) - Dd x') + g(q)."""
j = arm.jacobian(q)
x, xd = arm.fk(q), matvec2(j, qd)
f = [kd[i] * (x0[i] - x[i]) - dd[i] * xd[i] for i in range(2)]
g = arm.gravity(q)
return [j[0][i] * f[0] + j[1][i] * f[1] + g[i] for i in range(2)]
def wall(x_wall, k_env):
"""A frictionless wall x <= x_wall with stiffness k_env, as F_ext(x, x')."""
def force(x, xd):
pen = x[0] - x_wall
return [-k_env * pen, 0.0] if pen > 0.0 else [0.0, 0.0]
return force
def free_space(x, xd):
return [0.0, 0.0]
def rk4_step(f, t, x, dt):
"""One classical Runge-Kutta step for x' = f(t, x)."""
k1 = f(t, x)
k2 = f(t + dt / 2, [x[i] + dt / 2 * k1[i] for i in range(len(x))])
k3 = f(t + dt / 2, [x[i] + dt / 2 * k2[i] for i in range(len(x))])
k4 = f(t + dt, [x[i] + dt * k3[i] for i in range(len(x))])
return [x[i] + dt / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) for i in range(len(x))]
def simulate(arm, law, env, q0, qd0, dt, steps):
"""Simulate the arm with law(t, q, qd, f_ext) and the environment env.
The sensor reads the true contact force. Return the list of (t, q, qd).
"""
def f(t, s):
q, qd = s[:2], s[2:]
x, xd = arm.fk(q), matvec2(arm.jacobian(q), qd)
fe = env(x, xd)
tau = law(t, q, qd, fe)
return qd + arm.accel(q, qd, tau, fe)
s = list(q0) + list(qd0)
out = [(0.0, s[:2], s[2:])]
for k in range(steps):
s = rk4_step(f, k * dt, s, dt)
out.append(((k + 1) * dt, s[:2], s[2:]))
return out
test_impedance_control.py 120 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/impedance-control/. The authors are listed in prov/TVY2W5.jsonl.
import math
import random
from impedance_control import (
TwoLinkArm,
free_space,
impedance_control,
matvec2,
simple_impedance,
simulate,
wall,
)
MD = [1.0, 1.0]
KD = [400.0, 400.0]
DD = [40.0, 40.0] # critical damping: Dd = 2 sqrt(Kd Md)
K_ENV = 1e4
X_WALL = 1.0
X0 = [1.05, 0.5]
def test_kinematics_against_finite_differences():
arm = TwoLinkArm(l1=0.9, l2=0.7)
rng = random.Random(1)
for _ in range(10):
q = [rng.uniform(-3, 3) for _ in range(2)]
qd = [rng.uniform(-2, 2) for _ in range(2)]
h = 1e-6
xp = arm.fk([q[i] + h * qd[i] for i in range(2)])
xm = arm.fk([q[i] - h * qd[i] for i in range(2)])
v = matvec2(arm.jacobian(q), qd)
jp = matvec2(arm.jacobian([q[i] + h * qd[i] for i in range(2)]), qd)
jm = matvec2(arm.jacobian([q[i] - h * qd[i] for i in range(2)]), qd)
jq = arm.jdot_qdot(q, qd)
for i in range(2):
assert abs((xp[i] - xm[i]) / (2 * h) - v[i]) < 1e-7
assert abs((jp[i] - jm[i]) / (2 * h) - jq[i]) < 1e-6
x = arm.fk(arm.ik(arm.fk(q), 1.0 if math.sin(q[1]) > 0 else -1.0))
assert max(abs(x[i] - arm.fk(q)[i]) for i in range(2)) < 1e-12
def test_closed_loop_is_the_target_impedance():
# For any state and any contact force, Md x~'' + Dd x~' + Kd x~ = F_ext.
arm = TwoLinkArm()
rng = random.Random(4)
for _ in range(20):
q = [rng.uniform(-2, 2), rng.uniform(0.3, 2.8)]
qd = [rng.uniform(-2, 2) for _ in range(2)]
x0, x0d, x0dd, fe = ([rng.uniform(-1, 1) for _ in range(2)] for _ in range(4))
tau = impedance_control(arm, q, qd, x0, x0d, x0dd, fe, MD, DD, KD)
qdd = arm.accel(q, qd, tau, fe)
j = arm.jacobian(q)
x, xd = arm.fk(q), matvec2(j, qd)
jq = arm.jdot_qdot(q, qd)
xdd = [matvec2(j, qdd)[i] + jq[i] for i in range(2)]
for i in range(2):
lhs = MD[i] * (xdd[i] - x0dd[i]) + DD[i] * (xd[i] - x0d[i]) + KD[i] * (x[i] - x0[i])
assert abs(lhs - fe[i]) < 1e-9
def test_free_space_error_matches_closed_form():
arm = TwoLinkArm()
w = 20.0
def goal(t):
return (
[0.9 + 0.1 * math.sin(t), 0.5 + 0.1 * math.cos(t)],
[0.1 * math.cos(t), -0.1 * math.sin(t)],
[-0.1 * math.sin(t), -0.1 * math.cos(t)],
)
def law(t, q, qd, fe):
x0, x0d, x0dd = goal(t)
return impedance_control(arm, q, qd, x0, x0d, x0dd, fe, MD, DD, KD)
q0 = arm.ik([0.85, 0.65])
out = simulate(arm, law, free_space, q0, [0.0, 0.0], 1e-3, 1000)
e0 = [arm.fk(q0)[i] - goal(0.0)[0][i] for i in range(2)]
ed0 = [-goal(0.0)[1][i] for i in range(2)]
for t, q, _ in out[::50]:
x = arm.fk(q)
for i in range(2):
want = (e0[i] + (ed0[i] + w * e0[i]) * t) * math.exp(-w * t)
assert abs((x[i] - goal(t)[0][i]) - want) < 1e-7
def test_contact_force_at_rest():
arm = TwoLinkArm()
env = wall(X_WALL, K_ENV)
def law(t, q, qd, fe):
return impedance_control(arm, q, qd, X0, [0.0, 0.0], [0.0, 0.0], fe, MD, DD, KD)
out = simulate(arm, law, env, arm.ik([0.9, 0.5]), [0.0, 0.0], 1e-3, 1500)
x = arm.fk(out[-1][1])
force = env(x, None)
want = K_ENV * KD[0] / (K_ENV + KD[0]) * (X0[0] - X_WALL)
assert abs(-force[0] - want) < 1e-6
assert abs(x[0] - (KD[0] * X0[0] + K_ENV * X_WALL) / (KD[0] + K_ENV)) < 1e-9
# The impedances are decoupled: the y motion never sees the contact.
assert max(abs(arm.fk(q)[1] - X0[1]) for _, q, _ in out) < 1e-9
def test_law_without_force_sensor():
arm = TwoLinkArm()
env = wall(X_WALL, K_ENV)
def law(t, q, qd, fe):
return simple_impedance(arm, q, qd, X0, DD, KD)
out = simulate(arm, law, env, arm.ik([0.9, 0.5]), [0.0, 0.0], 1e-3, 2500)
x = arm.fk(out[-1][1])
want = K_ENV * KD[0] / (K_ENV + KD[0]) * (X0[0] - X_WALL)
assert abs(-env(x, None)[0] - want) < 1e-4
assert abs(x[1] - X0[1]) < 1e-6
# Without inertia shaping the arm's own mass couples x and y on the way.
assert max(abs(arm.fk(q)[1] - X0[1]) for _, q, _ in out) > 1e-4
History
Robot force control had several schemes by the early 1980s, such as stiffness control, damping control and the hybrid scheme of Raibert and Craig, and Mason described compliant motion with natural and artificial constraints in 1981. Neville Hogan published "Impedance control: an approach to manipulation" in three parts in the Journal of Dynamic Systems, Measurement, and Control in March 1985. He argued that a manipulator interacts with its environment as a physical system, so the controller should set its impedance, and that the robot should look like an impedance because the environment usually looks like an admittance. The idea became the base of most later interaction control, including the control of collaborative robots.
References
- Neville Hogan, Impedance control: an approach to manipulation: Part I, Theory, Journal of Dynamic Systems, Measurement, and Control 107(1), 1985, pages 1 to 7; Parts II (implementation) and III (applications) follow in the same issue
- Kevin M. Lynch and Frank C. Park, Modern Robotics, Mechanics, Planning, and Control, Cambridge University Press, 2017, Chapter 11, Section 11.7 (impedance control) and Section 11.7.1 (impedance-control algorithm)
- Bruno Siciliano, Lorenzo Sciavicco, Luigi Villani and Giuseppe Oriolo, Robotics, Modelling, Planning and Control, Springer, 2009, Chapter 9 (force control, compliance and impedance control)
- Bruno Siciliano and Oussama Khatib (editors), Springer Handbook of Robotics, second edition, Springer, 2016, Chapter 9 (Force Control, by Luigi Villani and Joris De Schutter)
- Mark W. Spong, Seth Hutchinson and M. Vidyasagar, Robot Modeling and Control, second edition, Wiley, 2020, Chapter 10 (force control)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag TVY2W5 Edit this page History Report an error Markdown