Algorithmcore
Hybrid position/force control
Also called Raibert-Craig hybrid control.
Splits the task space by selection matrices into directions that control force and directions that control position, and runs one controller in each.
- 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
- Marc H. Raibert, John J. Craig, 1981
Hybrid position/force control is a scheme for tasks in which a robot tool slides along a surface while it presses on it. The task space is split into directions in which the surface blocks motion, where the controller regulates the contact force, and the other directions, where the controller regulates the position. Diagonal selection matrices and in a task frame pick the two sets. Raibert and Craig introduced the scheme in 1981, using the natural and artificial constraints of Mason to choose the directions. Unlike impedance control, it controls the force explicitly, but it needs a model of where the constraints are.
In plain words
Think of wiping a table. Along the table you care about where the cloth goes. Down into the table you cannot move anyway, so you care about how hard you press. Hybrid control writes this down: in each direction of a frame fixed to the task, choose either "control the position" or "control the force", never both.
The table itself fixes the motion downward and the force sideways (if there is no friction). These are the natural constraints. The task adds the other half: a path along the table and a pressing force downward. These are the artificial constraints. The controller runs a position loop in the free directions and a force loop in the blocked ones.
The problem
The arm has joints and obeys , where is the wrench of the environment on the tool and is square and nonsingular. In a task frame aligned with the contact, a diagonal matrix with entries 0 or 1 marks the directions in which the environment blocks the motion, and marks the free ones. A desired motion is given in the free directions, and a desired force that the tool should apply in the blocked directions. The task is to choose so that and , where is the measured force that the tool applies.
The algorithm
This is the task-space form with a dynamic model. The integral of the force error is kept as a state.
HYBRID(q, q', x_d, x_d', x_d'', F_d, F, ∫(F_d - F), S_f)- 1
x ← f(q); x' ← J(q) q' - 2
a_p ← x_d'' + K_d (x_d' - x') + K_p (x_d - x) ▷ position loop - 3
F_f ← F_d + K_fi ∫(F_d - F) - K_v x' ▷ force loop with active damping - 4
Λ ← (J M⁻¹ Jᵀ)⁻¹; μ ← Λ (J M⁻¹ (C q' + g) - J' q') - 5
F_cmd ← Λ (I - S_f) a_p + S_f F_f + μ - 6
τ ← Jᵀ F_cmd - 7
return τ
Line L4 computes the task-space inertia and the bias force of the operational space formulation. Line L5 uses them so that the position loop sees a unit mass in the free directions, while the force command passes through directly. Line L6 maps the task force to joint torques by Jacobian-statics duality. The term in line L3 adds damping in the force directions; it is zero when the contact is rigid.
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 at m acts as a stiff spring with N/m. The force direction is the wall normal , so , with N. The position direction is , with m. The gains are , (critical damping at 20 rad/s), N s/m and . The arm starts at rest at , touching the wall with zero force.
At the start, rad, and line L4 gives kg and N. The position error is zero, but the speed error is m/s, so line L2 gives m/s. Line L5 gives N, and line L6 gives N m.
A simulation with RK4 and a step of 1 ms gives:
| time (s) | force on the wall (N) | error in (mm) |
|---|---|---|
| 0.01 | 8.48 | |
| 0.02 | 9.95 | |
| 0.05 | 10.000 | |
| 0.10 | 10.000 | |
| 0.50 | 10.000 |
The force settles in about 50 ms, with a peak of 10.0012 N. The error is m, the critically damped response to the initial speed error, as if the wall were not there. The tool presses 0.1 mm into the spring wall, which is .
With a gravity model in which the second mass is 0.8 kg instead of 1 kg, and a fixed goal , the force settles at 10.152 N with . With s it settles at 10.000 N. The position still ends 2.5 mm low, because the position loop has no integral term.
Correctness
The claim is: with an exact model, the closed loop in task coordinates is
If the contact is rigid and frictionless, the constraint keeps and . Because is positive definite, these two facts force . So the force on the environment equals , which is when , and the free directions obey exactly. Against a frictionless spring surface, the same argument applies at every rest point: the position error is zero and the force is . With , the force at rest is even when the model is wrong, because the integral state can stop only when the force error is zero. The full proof is in the proof file.
Proof: Hybrid control decouples the free directions and sets the contact forcefull
The arm obeys with positive definite and square and nonsingular, and , so and . The matrices and are diagonal with entries 0 or 1, so , and . The gains , , and are diagonal with positive entries ( may be zero). Write for the integral state, with and , and for the force that the tool applies. Parts 1 to 4 assume that the controller uses the exact model.
Lemma 1 (closed loop in task space). Under the torque of lines L1 to L7,
Proof. Let . Then , so
using and from line L4. The matrix is positive definite because is nonsingular, so exists. Putting in from line L5 gives the claim.
Lemma 2. Let be positive definite and let . If , then .
Proof. , and positive definiteness gives .
Theorem 1 (rigid frictionless contact). Let the environment be a rigid frictionless constraint along the force directions: for all time and . Then at all times the applied force is and the position error satisfies . With , . With , stays zero and too.
Proof. Let . Since , . Multiply Lemma 1 by : . By Lemma 2, , so . The last term is zero because for diagonal . Lemma 1 now reads , so , and with diagonal gains . Subtracting gives . For the integral, , and since , for all time.
With positive diagonal gains, each component of is a stable second-order linear system, so exponentially, and with it does not overshoot.
Theorem 2 (rest points against a spring surface). Let be constant and let the environment push only along the force directions, , with any law . At every rest point of the closed loop (, , ), and .
Proof. At rest, and , and . Let , so . Lemma 1 gives . Then , so , and then , which gives . From , . In each force direction, either and the force is that component of , or and gives the same.
Theorem 3 (stability of one force direction). Let there be one force direction , a spring surface with in contact, and constant . Hold fixed and put . Then the force subsystem is exponentially stable if and only if (for ); for , its motion part is exponentially stable for all .
Proof. The vector has only entry nonzero, equal to , and the entry of is zero. So the row of Lemma 1 is , which does not involve the position directions. With and ,
Differentiating the first equation and using the second gives . The characteristic polynomial is . For , the Routh-Hurwitz test for a cubic with positive coefficients says that all roots have negative real part if and only if , which is . For , the variable does not enter, and the motion obeys , which is exponentially stable for .
Remark (wrong model). If the controller uses a wrong model, Lemma 1 fails, and so does the conclusion of Theorem 2 for . The step " gives " does not use the model, so with every rest point still has the exact force . The position directions have no integral term, so their rest error remains.
Complexity
In the real-RAM model, with joints and task dimension , one step needs the Jacobian ( entries), the inertia matrix and its inverse (), the product and its inverse (), and a few matrix-vector products (). So it takes time and memory. For a 6-joint arm this is a fixed number of operations. The original joint-space form without costs too, because of .
Properties
- Explicit force regulation. Unlike impedance control, the force in the constrained directions follows directly and does not depend on the stiffness of the environment at rest.
- Orthogonal split. Position and force are never controlled in the same direction. This is consistent only when the selection matches the real constraints in a frame where they are axis-aligned.
- Needs the contact geometry. The task frame and come from a model of the contact. If the surface is tilted or curved and the frame is not updated, the position loop fights the surface and the force loop pushes into free space.
- Needs contact. In a force direction without contact, the force loop accelerates the tool until it hits something. Switching between free motion and contact needs care.
Variants and improvements
- Original joint-space form. Raibert and Craig mapped the position errors to joint space through and added a separate force term through , with gains in joint space. Later analyses found that this form can be unstable in some arm configurations; the task-space form with above avoids the problem.
- Constraint-based form. Lynch and Park write the constraints as and use a projection matrix that depends on the state instead of a constant . This handles constraints that are not aligned with fixed axes.
- Hybrid impedance control. Use an impedance law in the position directions, so that the tool stays compliant when it meets an unexpected obstacle there.
- Force control on a position-controlled arm. Realize the force loop as an outer loop that adjusts the position command, as in admittance control with in the force directions.
- Parallel force/position control. Let both loops act in all directions, with the force loop given priority by an integral term, which avoids the need for an exact selection matrix.
When to use it
Use it for contact tasks with known, simple geometry: pressing a tool on a flat surface while moving along it (grinding, polishing, deburring), turning a crank, or pushing a peg along the axis of a hole while keeping the side forces at zero. When the contact geometry is uncertain or contact starts and ends often, impedance control is usually more robust.
Pitfalls
- Wrong frame. The selection matrix is meaningful only in a task frame aligned with the contact. Using it in a fixed base frame when the surface is tilted leads to conflicts between the loops.
- Stiff contact and force gains. The force loop includes the environment stiffness. Against a stiff surface, high force gains or too little damping make the contact chatter. For one force direction against a spring wall, with the effective mass held fixed, the loop is stable if and only if .
- Friction. With friction, the surface also applies forces in the position directions, so and the position loop sees a disturbance. Friction also lets the surface hold the tool against forces inside the friction cone.
- Loss of contact. If the force command is negative or the surface ends, the tool leaves the surface and the force loop has no plant to act on. Clamp the force command and detect the loss of contact.
- Singularities. and fail near a kinematic singularity.
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/hybrid-position-force-control/. The authors are listed in prov/YQZW8R.jsonl.
"""Hybrid position/force control of a planar 2R arm against a wall.
The wall is the line x = x_w, and the tool slides on it without friction.
The x direction (the wall normal) is force controlled and the y direction
is position controlled, with the selection matrices S_f = diag(1, 0) and
S_p = I - S_f. The law works in task space with the task inertia
Lam = (J M^-1 J^T)^-1:
F_cmd = Lam S_p a_p + S_f F_f + mu, tau = J^T F_cmd.
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."""
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):
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):
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):
l1, l2 = self.l1, self.l2
c2 = (x[0] ** 2 + x[1] ** 2 - l1 * l1 - l2 * l2) / (2 * l1 * l2)
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, c, g, j = self.mass(q), self.coriolis(q, qd), self.gravity(q), 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 inv2(a):
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 [[a[1][1] / det, -a[0][1] / det], [-a[1][0] / det, a[0][0] / det]]
def mul2(a, b):
return [[sum(a[i][k] * b[k][j] for k in range(2)) for j in range(2)] for i in range(2)]
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 solve2(a, b):
return matvec2(inv2(a), b)
def transpose2(a):
return [[a[0][0], a[1][0]], [a[0][1], a[1][1]]]
def task_inertia(model, q, qd):
"""Return Lam = (J M^-1 J^T)^-1 and mu = Lam (J M^-1 (C q' + g) - J' q')."""
j = model.jacobian(q)
minv = inv2(model.mass(q))
lam = inv2(mul2(mul2(j, minv), transpose2(j)))
c, g = model.coriolis(q, qd), model.gravity(q)
h = [c[i][0] * qd[0] + c[i][1] * qd[1] + g[i] for i in range(2)]
jm = matvec2(mul2(j, minv), h)
jq = model.jdot_qdot(q, qd)
return lam, matvec2(lam, [jm[i] - jq[i] for i in range(2)])
def hybrid_control(model, q, qd, x_des, xd_des, xdd_des, f_des, f_meas, f_int, sf, gains):
"""Return the joint torques of hybrid position/force control.
sf is the diagonal of S_f (1 for a force direction, 0 for a position
direction). f_des and f_meas are the desired and measured forces that the
tool applies to the environment, and f_int is the integral of
f_des - f_meas. gains = (kp, kd, kfi, kv) are lists of diagonal gains.
"""
kp, kd, kfi, kv = gains
j = model.jacobian(q)
x, xd = model.fk(q), matvec2(j, qd) # @line L1
ap = [xdd_des[i] + kd[i] * (xd_des[i] - xd[i]) + kp[i] * (x_des[i] - x[i]) for i in range(2)] # @line L2
ff = [f_des[i] + kfi[i] * f_int[i] - kv[i] * xd[i] for i in range(2)] # @line L3
lam, mu = task_inertia(model, q, qd) # @line L4
pa = matvec2(lam, [(1.0 - sf[i]) * ap[i] for i in range(2)]) # @line L5
fcmd = [pa[i] + sf[i] * ff[i] + mu[i] for i in range(2)]
tau = matvec2(transpose2(j), fcmd) # @line L6
return tau # @line L7
def wall(x_wall, k_env):
"""Force of a frictionless spring wall x >= x_wall on the tool."""
def force(x):
pen = x[0] - x_wall
return [-k_env * pen, 0.0] if pen > 0.0 else [0.0, 0.0]
return force
def rk4_step(f, t, x, dt):
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, model, env, goal, f_des, sf, gains, q0, dt, steps):
"""Simulate the closed loop; the state is (q, q', integral of the force error).
goal(t) returns (x_des, xd_des, xdd_des). The sensor reads the true
force that the tool applies, -F_ext. Return a list of (t, q, qd, f_applied).
"""
def f(t, s):
q, qd, fi = s[:2], s[2:4], s[4:]
fe = env(arm.fk(q))
applied = [-fe[0], -fe[1]]
xs, xds, xdds = goal(t)
tau = hybrid_control(model, q, qd, xs, xds, xdds, f_des, applied, fi, sf, gains)
err = [sf[i] * (f_des[i] - applied[i]) for i in range(2)]
return qd + arm.accel(q, qd, tau, fe) + err
s = list(q0) + [0.0, 0.0, 0.0, 0.0]
out = []
for k in range(steps + 1):
fe = env(arm.fk(s[:2]))
out.append((k * dt, s[:2], s[2:4], [-fe[0], -fe[1]]))
if k < steps:
s = rk4_step(f, k * dt, s, dt)
return out
test_hybrid_position_force_control.py 79 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hybrid-position-force-control/. The authors are listed in prov/YQZW8R.jsonl.
import math
import random
from hybrid_position_force_control import (
TwoLinkArm,
hybrid_control,
inv2,
matvec2,
simulate,
task_inertia,
wall,
)
SF = [1.0, 0.0]
F_DES = [10.0, 0.0]
K_ENV = 1e5
def gains(kfi):
return ([400.0, 400.0], [40.0, 40.0], [kfi, kfi], [600.0, 600.0])
def slide(t):
return [0.0, 0.5 + 0.1 * math.sin(2 * t)], [0.0, 0.2 * math.cos(2 * t)], [0.0, -0.4 * math.sin(2 * t)]
def test_task_space_closed_loop():
# x'' = S_p a_p + Lam^-1 (S_f F_f + F_ext) for any state and contact force.
arm = TwoLinkArm()
rng = random.Random(2)
kp, kd, kfi, kv = gains(5.0)
for _ in range(20):
q = [rng.uniform(-2, 2), rng.uniform(0.3, 2.8)]
qd = [rng.uniform(-2, 2) for _ in range(2)]
xs, xds, xdds, fd, fm, fi, fe = ([rng.uniform(-1, 1) for _ in range(2)] for _ in range(7))
tau = hybrid_control(arm, q, qd, xs, xds, xdds, fd, fm, fi, SF, (kp, kd, kfi, kv))
qdd = arm.accel(q, qd, tau, fe)
j = arm.jacobian(q)
jq = arm.jdot_qdot(q, qd)
xdd = [matvec2(j, qdd)[i] + jq[i] for i in range(2)]
x, xd = arm.fk(q), matvec2(j, qd)
ap = [xdds[i] + kd[i] * (xds[i] - xd[i]) + kp[i] * (xs[i] - x[i]) for i in range(2)]
ff = [fd[i] + kfi[i] * fi[i] - kv[i] * xd[i] for i in range(2)]
lam, _ = task_inertia(arm, q, qd)
extra = matvec2(inv2(lam), [SF[i] * ff[i] + fe[i] for i in range(2)])
for i in range(2):
assert abs(xdd[i] - ((1 - SF[i]) * ap[i] + extra[i])) < 1e-9
def test_force_and_slide_with_exact_model():
arm = TwoLinkArm()
q0 = arm.ik([1.0, 0.5])
out = simulate(arm, arm, wall(1.0, K_ENV), slide, F_DES, SF, gains(0.0), q0, 1e-3, 1500)
for t, q, _, fa in out:
err = arm.fk(q)[1] - slide(t)[0][1]
# The y error is the critically damped response to the initial speed error 0.2.
assert abs(err + 0.2 * t * math.exp(-20.0 * t)) < 1e-5
if t >= 0.5:
assert abs(fa[0] - F_DES[0]) < 1e-4
assert abs(arm.fk(q)[0] - (1.0 + F_DES[0] / K_ENV)) < 1e-9
def test_integral_term_removes_force_offset_of_a_wrong_model():
arm = TwoLinkArm()
model = TwoLinkArm(m2=0.8)
q0 = arm.ik([1.0, 0.5])
def hold(t):
return [0.0, 0.5], [0.0, 0.0], [0.0, 0.0]
errs = []
for kfi in (0.0, 20.0):
out = simulate(arm, model, wall(1.0, K_ENV), hold, F_DES, SF, gains(kfi), q0, 2e-3, 1500)
errs.append(abs(out[-1][3][0] - F_DES[0]))
assert errs[0] > 0.05
assert errs[1] < 1e-6
History
In 1981, Mason published a formalism of natural and artificial constraints for compliant motion, and Raibert and Craig published the hybrid position/force controller in the Journal of Dynamic Systems, Measurement, and Control. Their controller used a selection matrix to choose force or position control in each direction of a constraint frame. Later work moved the scheme to task space with the dynamic model, as in Khatib's operational space formulation, and generalized the selection matrix to projections onto the constraint and motion subspaces.
References
- M. H. Raibert and J. J. Craig, Hybrid position/force control of manipulators, Journal of Dynamic Systems, Measurement, and Control 103(2), 126-133, 1981, the whole paper
- Matthew T. Mason, Compliance and force control for computer controlled manipulators, IEEE Transactions on Systems, Man, and Cybernetics 11(6), 1981, pages 418 to 432
- Kevin M. Lynch and Frank C. Park, Modern Robotics, Mechanics, Planning, and Control, Cambridge University Press, 2017, Chapter 11, Section 11.5 (force control) and Section 11.6 (hybrid motion-force control)
- Bruno Siciliano, Lorenzo Sciavicco, Luigi Villani and Giuseppe Oriolo, Robotics, Modelling, Planning and Control, Springer, 2009, Chapter 9 (force control, natural and artificial constraints, hybrid force/motion 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)
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 YQZW8R Edit this page History Report an error Markdown