Algorithmadvanced
Raibert hopping controller
Also called Raibert three-part controller.
Controls a hopping robot by three separate heuristic laws: a fixed leg thrust for hop height, foot placement for forward speed, and hip torque in stance for body attitude.
- Time
- O(1) per_step
- Space
- O(1) extra
- Where
- s = the fixed number of state variables of the hopper; the bounds are for one control step
- Model
- Real RAM
- Properties
- deterministicnot exactonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Marc H. Raibert, H. Benjamin Brown, Michael Chepponis, 1984
The Raibert hopping controller balances a one-legged robot that runs by hopping. It splits the task into three parts that act at different times of the hop cycle: a fixed thrust of the leg in stance sets the hop height, the position of the foot at touchdown sets the forward speed, and the hip torque in stance keeps the body level. Each part is a simple feedback law, and the three are tuned as if they did not interact. The controller is a heuristic: it works well on real machines, but there is no proof that the closed loop converges, and the speed law has a known bias.
In plain words
A pogo stick rider stays up by doing three things. To hop higher, they push harder on the stick when it starts to spring back. To go faster or slower, they put the stick down behind or ahead of the body. To keep the body upright, they push the body against the stick while it is on the ground, because only then can the stick push back.
Raibert's controller does these three things with three small rules. The foot rule is the clever one. If the foot lands at a certain neutral spot, the body leaves the ground with the same speed it had when it landed. The rule estimates that spot from the speed and the time on the ground, and then moves the foot further ahead to slow down or further back to speed up.
The problem
The robot is a body with mass and pitch inertia , with the hip at its center of mass, and one telescoping leg. The leg is a spring of stiffness and rest length , with damping . An actuator can change in stance, and a hip actuator applies a torque between the body and the leg. The leg mass is small, so in flight the hip can swing the leg to any angle from the vertical without moving the body. The motion is in the vertical plane, with gravity m/s along and the body pitch .
The robot runs through a cycle of flight and stance, which makes it a hybrid system (see hybrid automata). In stance the foot is pinned and the body moves like a spring-loaded inverted pendulum with a hip torque. The task is to reach a wanted forward speed and a steady hop height, with the pitch near .
The algorithm
The controller reads the phase (flight or stance), the body state and the duration of the last stance.
RAIBERT-CONTROL(phase, ẋ, φ, φ̇, T_s)- 1
if phase = flight - 2
x_f ← ẋ T_s / 2 + k_ẋ (ẋ - ẋ_d) ▷ foot position ahead of the hip - 3
θ ← arcsin(x_f / ℓ_0) ; swing the leg to θ before touchdown - 4
else ▷ stance - 5
if the leg has started to lengthen - 6
ℓ_r ← ℓ_0 + δ ▷ thrust - 7
else ℓ_r ← ℓ_0 - 8
τ ← -k_p (φ - φ_d) - k_v φ̇ ▷ hip torque on the body - 9
at lift-off, T_s ← length of the stance that just ended
Height (lines L5 to L7). The leg actuator makes the leg longer by a fixed amount during the second half of stance. This puts the same energy into each hop, and friction and damping take energy out. The height settles where they balance. A feedback that changes from the error of the apex height is a common addition.
Speed (lines L2 and L3). In stance the hip moves forward by about . If the foot is in the middle of that path, the stance is symmetric and the body leaves with the speed it had at touchdown. So is an estimate of this neutral point. A foot ahead of it slows the body, and a foot behind it speeds the body up. The term moves the foot by an amount proportional to the speed error.
Attitude (line L8). In flight a hip torque would only swing the leg. In stance the foot is on the ground, so a hip torque turns the body. A PD law on the pitch keeps the body level.
Example
The model has kg, kg m, N/m, m and N s/m. The gains are m, s, N m/rad, N m s/rad and . The hopper starts at the apex m with m/s and rad. Stance is integrated with RK4 at s, and flight is solved exactly.
Before the first hop there is no measured stance time, so the controller uses s, half the period of the spring. Line L2 gives m, and line L3 gives rad. The hops then go as follows; the values are at the start of each flight, and is at touchdown.
| hop | (m/s) | (rad) | apex (m) | (rad) | stance time (s) |
|---|---|---|---|---|---|
| 1 | 0.5000 | 0.2000 | 0.7000 | 0.1088 | 0.1758 |
| 2 | 0.0107 | -0.0882 | 0.7283 | 0.0025 | 0.1752 |
| 3 | 0.1550 | 0.0417 | 0.7408 | 0.0365 | 0.1747 |
| 4 | -0.0468 | -0.0204 | 0.7537 | -0.0110 | 0.1743 |
| 8 | -0.0043 | -0.0015 | 0.7854 | -0.0010 | 0.1731 |
The first stance stops the robot almost at once. On the second hop the pitch is rad, and the hip torque that corrects it also pushes the body forward, so the speed jumps to 0.155 m/s. This is the coupling between the attitude and the speed loops. After that, speed and pitch shrink by about half each hop with alternating sign, and the apex rises toward the height where the thrust and the damper balance (about 0.81 m for this model).
Correctness
There is no convergence proof for the closed loop, and the controller is a heuristic. The proof file shows the facts that the three laws use, for the model above. The leg force of a massless leg is the spring force along the leg plus across it. Without damping and thrust the energy is conserved, so the thrust is the only source of energy. For a vertical bounce the stance time is with and ; for m/s (a drop from 0.7 m) this is 0.18135 s, longer than s because the leg leaves at its rest length, not at the spring's equilibrium. A conservative stance in which the hip passes over the foot at the lowest point is symmetric, so the speed out equals the speed in. That is the neutral point. The estimate is exact only if the forward speed is constant in stance.
Proof: What can be proved about Raibert's hopping controllerpartial
Raibert's three-part controller is a heuristic. There is no proof that the closed loop of the full hopper converges to the desired speed, height and attitude, and the tests show that on the model of the implementation the speed settles with an offset. This file proves the facts on which the three parts rest, for the model of the implementation: a body of mass and pitch inertia with the hip at the center of mass, a massless leg with spring stiffness , damping and rest length , and a foot that does not slip during stance.
Lemma 1 (the leg force). In stance, let be the vector from the foot to the hip, , and the unit vector that is turned by degrees. If the hip applies the torque to the body, the force of the leg on the body is with .
Proof. The leg has no mass, so the forces and the moments on it sum to zero. The forces on it are the ground force at the foot and at the hip, so the ground force is . The moments about the foot are the moment of at the hip, , and the hip torque on the leg, . So . The axial part of is the spring and damper force , and , . Hence the normal part is .
This is the force in stance_deriv. The body then obeys and .
Lemma 2 (energy). If , and is constant, then is constant in stance. In flight, without the spring term is constant. At touchdown and at lift-off the spring term is zero.
Proof. In stance, , because and the normal part is zero. Also , and is constant. The sum is zero. Flight is ballistic. Touchdown happens at , and lift-off happens when , that is at .
So with the only change of energy is at line L6, where the rest length grows by during stance. The spring energy grows at that instant by , where is the leg length at the switch. This is the thrust: it adds energy each hop, and the damper takes energy away. The hop height settles where the two are equal; that this balance is a stable fixed point is a measurement, not a proof.
Lemma 3 (vertical stance time). Let the leg be vertical, , , and let the hip touch down at the speed . Then the stance lasts with and , and the hip leaves at the speed upward.
Proof. With , the stance equation is . At touchdown and . Write , with and ; then . Lift-off is the first later time with , that is again, which is with , so . At that point .
Lemma 4 (the neutral point). Let , and constant. If at some instant of stance the hip is right above the foot and , then the stance is symmetric about : the lift-off state is the touchdown state with and negated. In particular the forward speed at lift-off equals the forward speed at touchdown.
Proof. Put . The stance equations for are and with and . Let be the solution and set and . The time reversal does not change the sign of a second derivative, so and . The length and the force depend only on and , so they are the same for both curves. Hence and , and is also a solution. At both solutions have , the same , the same (since ) and . By uniqueness they are equal. So the state at is the state at with and negated and unchanged. The lift-off condition is symmetric too, so lift-off is at .
In a symmetric stance the foot is at the middle of the horizontal path of the hip. The path has length over the stance, so the neutral foot position is ahead of the hip at touchdown. Line L2 uses , which equals only if the forward speed is constant during stance. With the foot ahead of the hip, the leg force slows the body in the first half and speeds it up in the second, so the forward speed dips during stance, and on the model of the implementation the result is : the estimate is too far forward. The term moves the foot from this estimate; with a fixed the speed settles where the two errors cancel, which is below on this model. The size of the offset is measured in the tests, not derived.
Decoupling. Raibert's argument for treating the three parts as separate loops is that, with the hip at the center of mass, the thrust changes mainly the vertical energy, the foot placement changes mainly the forward speed, and the hip torque changes mainly the pitch. Lemma 1 shows that the hip torque also gives the normal force , so the attitude loop does change the speed, and the coupling is small only when is small next to the spring force. This is a heuristic.
Complexity
Each control step evaluates one of the three laws, so it takes operations and memory in the real-RAM model. The cost of a simulation is the cost of the integrator: about RK4 steps per stance, about 175 here.
Properties
- Decoupled by design. Each law acts on one quantity and at one phase. The coupling that remains, mainly between attitude and speed, is treated as a disturbance.
- Speed offset. On the model above, with m/s the speed settles at 0.32 m/s for s and at 0.41 m/s for s. The offset comes from the bias of the neutral point estimate, and a larger gain makes it smaller. This is a measurement on this model.
- Steady hopping is a limit cycle. The steady gait is a limit cycle of the hybrid system, and its stability is found by simulation or by numerically linearizing the hop-to-hop map.
- Few parameters. There are five gains, and each has a direct physical meaning.
Variants and improvements
- Three dimensions. Raibert, Brown and Chepponis (1984) applied the same three laws to the forward and sideways directions of a 3D hopper, with the hip torque controlling pitch and roll.
- Several legs. Raibert's virtual leg idea makes legs that move together act as one leg, so the one-legged laws run a biped, a trotting or pacing quadruped, and a bounding quadruped (Raibert 1986).
- Integral or learned speed terms. An integral of the speed error, or a lookup table of the neutral point, removes the speed offset.
- Model-based successors. The capture point gives a foot placement law with the same structure for the linear inverted pendulum, and convex MPC replaces the three laws by an optimization over the ground forces.
When to use it
Use it for running robots with springy legs and short stances, for a first controller on a new hopping or bounding machine, or as a baseline. It needs no model beyond the rough stance time and works with poor state estimates. For walking with long stances and a large foot, ZMP or capture point methods fit better. When the speed must be exact, add an integral term or a model-based foot placement.
Pitfalls
- Wrong sign of the speed gain. A negative puts the foot behind the neutral point when the robot is too fast, and the speed grows each hop. In the model above, one hop at m/s with s gives m/s.
- Too large a speed gain. The speed then alternates in sign and grows. With s, , and m/s, the model above does not settle.
- Hip torque in flight. A torque in flight turns the leg, not the body; attitude control must wait for the stance.
- Foot slip. The attitude law and the foot placement assume the foot does not slip. A large hip torque with a short leg can exceed the friction at the foot.
- First hop. With no measured stance time the law uses a guess. A poor guess makes the first hops uneven.
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/raibert-hopping-controller/. The authors are listed in prov/V4NCCQ.jsonl.
"""Raibert's three-part controller on a planar one-legged hopper.
The model: a rigid body of mass m and pitch inertia I, with the hip at the
center of mass, and a massless telescoping leg with a spring of stiffness k,
a damper b and a rest length that the controller can change. Coordinates:
x forward, z up, gravity -g along z, pitch phi counterclockwise.
The body state is s = [x, z, phi, vx, vz, wphi]. In flight the body is
ballistic and the massless leg is moved at once to the touchdown angle, so
the flight is solved in closed form. In stance the foot is pinned at
(foot_x, 0) and the stance is integrated with RK4 at the fixed step dt.
Lift-off (the spring force falls to zero while the leg lengthens) is found
by bisection on the last step.
The controller (Raibert 1986, chapter 2):
thrust - the spring rest length grows from l0 to l0 + delta when the
leg starts to lengthen, which adds energy each hop;
placement - in flight, the foot goes to x_f = vx Ts / 2 + k_x (vx - vx_d)
ahead of the hip, where Ts is the last stance time;
attitude - in stance, the hip torque is -k_p (phi - phi_d) - k_v wphi.
"""
import math
G = 9.81
class Hopper:
def __init__(self, m=10.0, inertia=0.5, k=4000.0, b=0.0, l0=0.5, g=G):
self.m = m
self.inertia = inertia
self.k = k
self.b = b
self.l0 = l0
self.g = g
def energy(self, s, foot_x=None, rest=None):
"""Kinetic plus gravity energy, plus the spring energy in stance."""
e = 0.5 * self.m * (s[3] ** 2 + s[4] ** 2) + 0.5 * self.inertia * s[5] ** 2 + self.m * self.g * s[1]
if foot_x is not None:
l = math.hypot(s[0] - foot_x, s[1])
e += 0.5 * self.k * (rest - l) ** 2
return e
class Gains:
def __init__(self, delta=0.0, k_x=0.0, k_p=0.0, k_v=0.0, vx_d=0.0, phi_d=0.0):
self.delta = delta
self.k_x = k_x
self.k_p = k_p
self.k_v = k_v
self.vx_d = vx_d
self.phi_d = phi_d
def foot_placement(vx, vx_d, ts, k_x, l0):
"""Return the leg angle from the vertical; positive puts the foot ahead of the hip."""
xf = vx * ts / 2.0 + k_x * (vx - vx_d) # @line L2
xf = max(-0.9 * l0, min(0.9 * l0, xf))
return math.asin(xf / l0) # @line L3
def attitude_torque(phi, wphi, gains):
"""Hip torque on the body during stance."""
return -gains.k_p * (phi - gains.phi_d) - gains.k_v * wphi # @line L8
def leg(s, foot_x):
"""Return (l, ldot, ux, uz) of the leg vector from the foot to the hip."""
rx, rz = s[0] - foot_x, s[1]
l = math.hypot(rx, rz)
ux, uz = rx / l, rz / l
return l, ux * s[3] + uz * s[4], ux, uz
def spring_force(robot, rest, l, ldot):
return robot.k * (rest - l) - robot.b * ldot
def stance_deriv(robot, s, foot_x, rest, gains):
l, ldot, ux, uz = leg(s, foot_x)
fs = spring_force(robot, rest, l, ldot)
tau = attitude_torque(s[2], s[5], gains)
# Massless leg: the moment of the leg force about the foot cancels the hip
# torque on the leg, so the force part normal to the leg is -tau / l.
fn = -tau / l
fx = fs * ux - fn * uz
fz = fs * uz + fn * ux
return [s[3], s[4], s[5], fx / robot.m, fz / robot.m - robot.g, tau / robot.inertia]
def rk4_step(robot, s, foot_x, rest, gains, h):
def f(y):
return stance_deriv(robot, y, foot_x, rest, gains)
k1 = f(s)
k2 = f([a + h / 2 * b for a, b in zip(s, k1)])
k3 = f([a + h / 2 * b for a, b in zip(s, k2)])
k4 = f([a + h * b for a, b in zip(s, k3)])
return [a + h / 6 * (p + 2 * q + 2 * r + w) for a, p, q, r, w in zip(s, k1, k2, k3, k4)]
def flight(robot, s, theta):
"""Ballistic flight until the foot, held at leg angle theta, touches z = 0.
Return (state at touchdown, flight time, apex height of the hip).
"""
zc = robot.l0 * math.cos(theta)
z, vz, g = s[1], s[4], robot.g
apex = z + max(vz, 0.0) ** 2 / (2 * g)
if apex < zc:
raise ValueError("the hopper does not rise high enough to swing the leg")
t = (vz + math.sqrt(vz * vz + 2 * g * (z - zc))) / g
out = [s[0] + s[3] * t, zc, s[2] + s[5] * t, s[3], vz - g * t, s[5]]
return out, t, apex
def stance(robot, s, foot_x, gains, dt=1e-3, max_steps=5000):
"""Integrate one stance from touchdown to lift-off with RK4.
Return (state at lift-off, stance time, number of RK4 steps).
"""
t, steps = 0.0, 0
thrusting = False
rest = robot.l0 # @line L7
for _ in range(max_steps):
l, ldot, _, _ = leg(s, foot_x)
if not thrusting and ldot > 0.0: # @line L5
thrusting = True
rest = robot.l0 + gains.delta # @line L6
new = rk4_step(robot, s, foot_x, rest, gains, dt)
steps += 1
l, ldot, _, _ = leg(new, foot_x)
if thrusting and spring_force(robot, rest, l, ldot) <= 0.0:
lo, hi = 0.0, dt
for _ in range(40):
mid = (lo + hi) / 2
y = rk4_step(robot, s, foot_x, rest, gains, mid)
ly, ldy, _, _ = leg(y, foot_x)
if spring_force(robot, rest, ly, ldy) <= 0.0:
hi = mid
else:
lo = mid
steps += 40
return rk4_step(robot, s, foot_x, rest, gains, hi), t + hi, steps
s = new
t += dt
raise ValueError("no lift-off within max_steps")
def hop(robot, gains, s, ts, dt=1e-3):
"""One flight and one stance, starting in flight.
Return (state at the next lift-off, the new stance time Ts, a record dict).
"""
theta = foot_placement(s[3], gains.vx_d, ts, gains.k_x, robot.l0) # @line L1
td, t_fl, apex = flight(robot, s, theta)
foot_x = td[0] + robot.l0 * math.sin(theta)
lo, ts_new, steps = stance(robot, td, foot_x, gains, dt) # @line L4
record = {"apex": apex, "vx": s[3], "phi_td": td[2], "theta": theta, "ts": ts_new, "steps": steps}
return lo, ts_new, record # @line L9
def run(robot, gains, s, n_hops, ts=None, dt=1e-3):
"""Run n_hops hops from the flight state s; return the list of hop records."""
if ts is None:
ts = math.pi * math.sqrt(robot.m / robot.k)
out = []
for _ in range(n_hops):
s, ts, rec = hop(robot, gains, s, ts, dt)
out.append(rec)
return out, s
def vertical_stance_time(robot, v):
"""Closed form stance time of a vertical bounce at touchdown speed v, no damping, no thrust."""
w = math.sqrt(robot.k / robot.m)
alpha = math.atan2(v / w, robot.m * robot.g / robot.k)
return (2 * math.pi - 2 * alpha) / w
test_raibert_hopping_controller.py 88 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/raibert-hopping-controller/. The authors are listed in prov/V4NCCQ.jsonl.
# Stance: RK4 with dt = 1e-3 s, lift-off located by bisection. Flight: closed form.
import math
import random
from raibert_hopping_controller import Gains, Hopper, foot_placement, run, vertical_stance_time
MAX_STEPS = 10000
def test_vertical_stance_time_matches_closed_form():
# No thrust, no damping, leg vertical: the stance is a half-period of a
# shifted harmonic oscillator, t_s = (2 pi - 2 alpha) / w.
robot = Hopper()
recs, _ = run(robot, Gains(), [0.0, 0.7, 0.0, 0.0, 0.0, 0.0], 3)
v = math.sqrt(2 * robot.g * (0.7 - robot.l0))
want = vertical_stance_time(robot, v)
for rec in recs:
assert abs(rec["ts"] - want) < 1e-8
assert abs(rec["apex"] - 0.7) < 1e-8
assert sum(r["steps"] for r in recs) < MAX_STEPS
def test_energy_is_conserved_without_thrust_and_damping():
robot = Hopper()
rng = random.Random(5)
s = [0.0, 0.7, rng.uniform(-0.2, 0.2), rng.uniform(0.3, 0.8), 0.0, rng.uniform(-0.5, 0.5)]
e0 = robot.energy(s)
recs, s_end = run(robot, Gains(), s, 5)
assert abs(robot.energy(s_end) - e0) < 1e-6 * e0
assert sum(r["steps"] for r in recs) < MAX_STEPS
def test_thrust_and_damping_give_one_hop_height():
robot = Hopper(b=40.0)
gains = Gains(delta=0.03)
finals = []
total = 0
for z in (0.6, 0.9):
recs, _ = run(robot, gains, [0.0, z, 0.0, 0.0, 0.0, 0.0], 15)
apex = [r["apex"] for r in recs]
total += sum(r["steps"] for r in recs)
# The change per hop shrinks, as for a stable fixed point.
assert abs(apex[-1] - apex[-2]) < 0.5 * abs(apex[2] - apex[1])
finals.append(apex[-1])
assert abs(finals[0] - finals[1]) < 0.01
assert total < MAX_STEPS
def test_foot_placement_sign():
# A foot ahead of the neutral point slows the hopper; behind, it speeds up.
robot = Hopper(b=20.0)
out = []
for k_x in (0.05, -0.05):
gains = Gains(delta=0.02, k_x=k_x, k_p=800.0, k_v=60.0)
_, s = run(robot, gains, [0.0, 0.7, 0.0, 0.5, 0.0, 0.0], 1)
out.append(s[3])
assert out[0] < 0.1 < 0.5 < out[1]
assert foot_placement(0.5, 0.0, 0.17, 0.05, 0.5) > foot_placement(0.5, 0.0, 0.17, 0.0, 0.5) > 0
def test_stops_in_place_and_levels_the_body():
robot = Hopper(b=20.0)
gains = Gains(delta=0.02, k_x=0.03, k_p=800.0, k_v=60.0, vx_d=0.0)
recs, _ = run(robot, gains, [0.0, 0.7, 0.2, 0.5, 0.0, 0.0], 20)
assert abs(recs[-1]["vx"]) < 1e-3
assert abs(recs[-1]["phi_td"]) < 1e-3
assert abs(recs[1]["phi_td"]) < 0.1
assert sum(r["steps"] for r in recs) < MAX_STEPS
def test_speed_settles_below_the_target():
# The neutral point vx Ts / 2 is an estimate. On this model it is too far
# forward, so the speed settles below vx_d, closer for a larger k_x.
robot = Hopper(b=20.0)
finals = []
total = 0
for k_x in (0.02, 0.05):
gains = Gains(delta=0.02, k_x=k_x, k_p=800.0, k_v=60.0, vx_d=0.5)
recs, _ = run(robot, gains, [0.0, 0.7, 0.0, 0.0, 0.0, 0.0], 16)
total += sum(r["steps"] for r in recs)
v = [r["vx"] for r in recs]
assert abs(v[-1] - v[-2]) < 2e-3
finals.append(v[-1])
assert 0.25 < finals[0] < finals[1] < 0.5
assert total < MAX_STEPS
History
Marc Raibert built the planar one-legged hopper at Carnegie Mellon University in the early 1980s and reported its balance experiments with H. Benjamin Brown in 1984. The same year Raibert, Brown and Chepponis reported a 3D one-legged machine with the same three-part controller. Raibert's 1986 book Legged Robots That Balance extended the method to bipeds and quadrupeds through virtual legs. Later work explained the success of the controller with the spring-loaded inverted pendulum and with the symmetry of the stance phase.
References
- Marc H. Raibert, Legged Robots That Balance, MIT Press, 1986, Chapter 2 (hopping on one leg in the plane) and Chapter 3 (hopping in three dimensions)
- Marc H. Raibert and H. Benjamin Brown, Experiments in balance with a 2D one-legged hopping machine, Journal of Dynamic Systems, Measurement, and Control 106(1), 1984, pages 75 to 81
- Marc H. Raibert, H. Benjamin Brown and Michael Chepponis, Experiments in balance with a 3D one-legged hopping machine, The International Journal of Robotics Research 3(2), 1984, pages 75 to 92
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 V4NCCQ Edit this page History Report an error Markdown