Algorithmresearch
SIMBICON
Also called simple biped locomotion control.
Control a simulated biped with a finite state machine of target poses tracked by PD controllers, with balance feedback on the swing hip.
- Time
- O(n) controlO(n^3) simulation_step
- Space
- O(n^2) extra
- Where
- n = the number of links of the character
- Model
- Real RAM
- Properties
- deterministicnot exactonlineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- KangKang Yin, Kevin Loken, Michiel van de Panne, 2007
SIMBICON is a simple controller that makes a simulated two legged character walk, run or skip in a physics simulation. It has three parts. A finite state machine with a few states per step holds target poses: for each joint, a target angle. Each joint tracks its target with a proportional derivative (PD) torque, except that the torso and the swing hip track angles in the world frame, and the stance hip takes the torque that makes this possible. A balance feedback law moves the target of the swing hip with the horizontal distance from the stance foot to the center of mass and with the velocity : , so the character steps farther forward when it falls forward. Yin, Loken and van de Panne (2007) showed that this small set of rules gives robust gaits in 2D and 3D; the gait parameters are found by hand or by optimization, and no stability property is proved.
In plain words
To walk, you do not plan every muscle. You repeat a few poses: swing a leg forward, plant it, swing the other leg. SIMBICON does the same: it holds a short list of poses and moves each joint toward the pose of the moment with a spring and a damper. When the character tips forward, it places the next foot a bit farther ahead to catch itself, and when it tips back, a bit closer. It also keeps the upper body upright as seen from the world, not as seen from the leg. That is enough for the simulated character to keep walking, also when something pushes it.
The problem
The input is a simulated articulated character with joint motors, its state (the positions and velocities of all links), contact with the ground, and a gait: for each state of the machine, a duration or an end condition, the target angles, and the feedback gains and . The task is to compute the joint torques at every simulation step so that the character walks without falling.
The simulation is a model: a rigid body system with joint torques, gravity and a ground contact model. Its laws are classical mechanics, and its contact force is a penalty model or a constraint solver. The controller is a heuristic on top of it, and the gains and target poses are tuning.
The algorithm
SIMBICON-STEP(s, q, q̇, gait) ▷ state, positions, velocities- 1
if (s is timed and its clock ≥ T) or (s waits for contact and the swing foot touches) s ← (s + 1) mod 4; clock ← 0 ▷ two states per step, the legs alternate- 2
d ← x_com - x_stance foot; v ← ẋ_com ▷ the code uses the hip in place of the com - 3
θ_swh ← θ_d0 + c_d d + c_v v ▷ the balance feedback - 4
τ_torso ← k_p (θ_torso - φ_torso) - k_d φ̇_torso ▷ PD in the world frame - 5
τ_B ← k_p (θ_swh - φ_swing thigh) - k_d φ̇_swing thigh ▷ swing hip, world frame - 6
τ_A ← -τ_torso - τ_B ▷ stance hip - 7
knee torques ← PD on the relative knee angles - 8
return the hip and knee torques, clamped to the torque limit
Each state has the targets: the torso angle and the swing hip angle in the world frame, and the knee angles relative to the thigh. For a walk the paper uses four states: state 0 lasts a fixed time and lifts and swings the leg; state 1 ends when the swing foot touches the ground; states 2 and 3 are the same with the legs swapped.
The stance hip rule. The torso and the swing thigh have no motor that connects them to the world. The torque at the swing hip acts on the swing thigh and, as a reaction, on the torso. Setting the stance hip torque to makes the total torque of the two hips on the torso exactly , so the torso behaves as if a PD motor tied it to the world; the stance leg, which pushes on the ground, takes the reaction.
The feedback. If the center of mass is ahead of the stance foot () or moves forward fast ( large), the swing target moves forward and the next step is longer, which slows the body. The paper applies the same law in the sagittal and in the coronal plane in 3D.
Example
The code simulates a planar toy with five links: a torso (70 kg, 0.48 m), two thighs (5 kg, 0.45 m) and two shins with point feet (4 kg, 0.50 m). The ground is a penalty spring and damper with a tangential spring and a Coulomb limit ; the step is symplectic Euler with ms, and the torques are limited to 400 N m. The gains are the paper's and for all joints. The gait has two states per step:
| state | duration | torso | swing hip | swing knee | stance knee | ||
|---|---|---|---|---|---|---|---|
| 0, 2 | 0.30 s | 0 | 0.20 | 0 | 0.40 | -1.10 | -0.05 |
| 1, 3 | until contact | 2.20 | 0 | 0 | -0.70 | -0.05 | -0.10 |
These values are tuning for the toy, not the table of the paper.
Started at 0.8 m/s, the toy walks for 5 s without a fall, with 14 foot strikes and 5.94 m covered. The step settles at about 0.42 m and 0.34 s, about 1.2 m/s. Over 10 s it makes 29 strikes and covers about 12.1 m. Started at any speed from 0.3 to 1.2 m/s, it also walks. With and the same targets, it falls after 0.81 s and 2 strikes. All these numbers are measurements of this toy, and they show only that the feedback matters here.
Correctness
The proof file proves the exact parts of the controller.
- A joint torque is a generalized force on the child angle and on the parent angle.
- So the stance hip rule of line L6 gives the torso exactly the generalized force of line L4, as long as no hip torque is clamped (Theorem 1).
- The swing target of line L3 is affine in and , and for positive gains it moves forward when the body is ahead or moves faster.
- The state machine visits the states in the order ; the timed states last their duration rounded up to a simulation step, and each end of a contact state is one foot strike (Theorem 2).
What is not proved is that the character walks. The paper does not prove stability or a limit cycle; it shows robustness by experiments, such as pushes and slopes. The code shows only a measurement on one toy.
Proof: The SIMBICON stance hip rule gives the torso exactly its world frame PD torque, and the state machine cycles in orderfull
We use the notation of the page. The arithmetic is exact. The biped is planar, with the generalized coordinates : the hip position and the world angles of the torso, the two thighs and the two shins. A joint between a parent link with angle and a child link with angle has the relative angle .
This file proves only the exact parts of the controller. That the toy walks without a fall is a measurement in the test, and the gains and the target poses are tuning. No property of the gait (stability, a limit cycle, robustness to pushes) is proved here or in the paper.
Joint torques as generalized forces
Lemma 1. A torque at a joint between the links and , acting on and with the reaction on , has the generalized forces and , and no part on the other coordinates.
Proof. The virtual work of the joint torque is . The generalized force is the coefficient of each virtual displacement.
The stance hip rule
Theorem 1. Let be any torque and any swing hip torque, and set the stance hip torque to (line L6). If neither hip torque is clamped by the torque limit, the total generalized force on the torso angle from the joint torques is .
Proof. The torso is the parent of both hips and of no knee. By Lemma 1, .
So the torso feels the PD torque of line L4 on its world angle, as if a motor tied it to the world, and the swing thigh feels (plus the knee reaction), which is also a PD on its world angle (line L5). This is the reason for the rule: neither link has a motor to the world, and the stance leg, which touches the ground, takes the reaction. When the torque limit is active, the identity fails by the clamped amount; the test checks the identity without the limit.
Lemma 2. The swing thigh target of line L3, , is affine in the horizontal distance from the stance foot to the hip and in the hip velocity . For , a hip that is farther in front of the stance foot or moves faster forward gives a swing target that is farther forward.
Proof. The partial derivatives are and .
In the angle convention of the code, a positive thigh angle swings the foot forward, so a larger target places the next foot farther ahead; this is the balance feedback of the paper, and the gains are tuning.
The state machine
Theorem 2. The controller visits the states in the order . States 0 and 2 last exactly their duration, rounded up to the next simulation step. States 1 and 3 end at the first step at which the swing foot is below the ground. Every end of state 1 or state 3 is counted as one foot strike.
Proof. Line L1 tests the end condition once per step, and the only change of state is with the clock reset to 0. A timed state with duration ends at the first step with clock , and the clock grows by the step . A contact state has no duration, so it ends exactly when the swing foot height is below 0, and the code records one strike there.
The swing side changes from state 1 to state 2 and from state 3 to state 0, so the legs alternate. Whether a contact state ever ends is not proved: if the character falls with the swing foot in the air, the state can last to the end of the run, and the test reports the fall.
Complexity
The controller costs per joint, for links. The simulation is the expensive part: the code builds the mass matrix of the coordinates and solves it by Gaussian elimination, per step, and space. A recursive method such as the articulated body algorithm costs per step. With 1 ms steps, one second of motion is 1000 steps.
Properties
- Simple. Each state has a few angles and two gains; a gait is a small table.
- Robust in practice. The feedback places the feet to catch the body; the paper reports gaits that survive pushes and changes of the ground.
- Not exact. The character follows the targets only roughly, and the walk is a measured behavior, not a guarantee.
- Online. Each torque uses only the current state.
- No reference motion. Unlike DeepMimic, SIMBICON needs no motion capture; but its gaits look less like a person unless the targets come from data.
Variants and improvements
- Optimized gaits. Search the target angles, durations and gains with an optimizer for speed, style or robustness.
- Generalized controllers. Later work by Coros, Beaudoin and van de Panne made the gait parameters depend on the speed and the terrain, with virtual forces and gravity compensation.
- Tracking data. Use target poses from motion capture and keep the feedback, to get a more human style.
- Learned policies. DeepMimic replaces the state machine by a neural network policy that outputs PD targets, trained by reinforcement learning to track a clip.
- Model based balance. Robotics controllers use the zero moment point, the linear inverted pendulum model or the capture point to choose the steps with a model, where SIMBICON uses a linear law with tuned gains.
When to use it
Use SIMBICON as a first controller for a simulated character in a game or a study of locomotion: it is short, easy to tune by hand, and reacts to pushes. It is not a model of human walking and not a robot controller with guarantees; for a real robot, the zero moment point and hybrid zero dynamics methods have a theory. For a character that must move like captured motion, use a tracking controller such as DeepMimic.
Pitfalls
- The frame of the torso. A torso PD in the frame of the stance thigh does not keep the torso upright; the world frame rule of line L6 is the core of the method.
- The center of mass. The feedback uses the center of mass; the code uses the hip, which is close for this toy with a heavy torso but not in general.
- Torque limits. When a hip torque is clamped, the torso no longer gets its PD torque, and a fall can follow.
- Stiff contact. A stiff penalty ground needs small time steps; with a large step the feet bounce or sink.
- Tuning. Small changes in the table can make a gait fail. Change one value at a time and test from several start speeds.
- Contact detection. If the swing foot touches early, for example by scuffing, the state machine switches early, and the step is short.
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/simbicon/. The authors are listed in prov/FMSJGE.jsonl.
"""SIMBICON control of a planar biped: a toy.
The controller is the one of Yin, Loken and van de Panne (2007): a finite
state machine of target poses, PD control of every joint, the torso and the
swing hip controlled in the world frame, the stance hip torque
tau_A = -tau_torso - tau_B, and the balance feedback
theta_d = theta_d0 + c_d d + c_v v on the swing hip.
The simulated character is a toy, not the model of the paper. It has five
links (torso, two thighs, two shins), point feet, no ankles, a penalty
spring and damper for the ground and a tangential spring with a Coulomb
limit for friction. The world is the xy plane with y up and gravity
(0, -9.81) m/s^2; the character walks toward +x.
Coordinates q = (x, y, phi_0, ..., phi_4): (x, y) is the hip, phi_0 is the
world angle of the torso measured from straight up, and phi_1 ... phi_4
are the world angles of the left thigh, left shin, right thigh and right
shin measured from straight down. All angles are counterclockwise, so a
positive thigh angle puts the leg forward and a bent knee has a negative
relative angle phi_shin - phi_thigh, as in the paper.
The step is symplectic Euler: M(q) qdd = Q, then qd += dt qdd, q += dt qd.
All gains and the gait table are tuning; the number of steps without a fall
is a measurement of this toy only.
"""
import math
G = 9.81
# Links: (mass kg, length m). The shin includes the foot.
M_TORSO, L_TORSO = 70.0, 0.48
M_THIGH, L_THIGH = 5.0, 0.45
M_SHIN, L_SHIN = 4.0, 0.50
KP_JOINT, KD_JOINT = 300.0, 30.0 # Nm/rad and Nms/rad (paper, Section 7)
KP_GROUND, KD_GROUND = 1.0e5, 1.0e3 # N/m and Ns/m (toy values)
KT_GROUND, DT_GROUND = 5.0e4, 5.0e2 # tangential spring and damper (toy)
MU = 0.8 # Coulomb friction (toy)
TORQUE_LIMIT = 400.0 # Nm
# Index of each link angle in q.
TORSO, THIGH_L, SHIN_L, THIGH_R, SHIN_R = 2, 3, 4, 5, 6
LEGS = {"L": (THIGH_L, SHIN_L), "R": (THIGH_R, SHIN_R)}
# A gait is four states. Each has a duration (None means "until the swing
# foot touches"), c_d, c_v, and the targets: torso (world), swing hip
# (world), swing knee and stance knee (relative). States 0 and 1 swing the
# left leg, states 2 and 3 the right leg.
WALK_TABLE_1 = (
# dt, cd, cv, torso, swing hip, swing knee, stance knee
(0.30, 0.0, 0.20, 0.0, 0.40, -1.10, -0.05),
(None, 2.20, 0.0, 0.0, -0.70, -0.05, -0.10),
)
def make_gait(table=WALK_TABLE_1):
a, b = table
return [a, b, a, b]
def swing_side(state):
return "L" if state in (0, 1) else "R"
def stance_side(state):
return "R" if state in (0, 1) else "L"
def _dirs(q):
"""Unit direction d_k and its derivative d'_k for every link angle."""
d, dp = {}, {}
s, c = math.sin(q[TORSO]), math.cos(q[TORSO])
d[TORSO], dp[TORSO] = (-s, c), (-c, -s)
for k in (THIGH_L, SHIN_L, THIGH_R, SHIN_R):
s, c = math.sin(q[k]), math.cos(q[k])
d[k], dp[k] = (s, -c), (c, s)
return d, dp
# Each point is the hip plus a sum of a * d_k over its terms (k, a).
BODIES = (
(M_TORSO, M_TORSO * L_TORSO ** 2 / 12.0, TORSO, ((TORSO, L_TORSO / 2),)),
(M_THIGH, M_THIGH * L_THIGH ** 2 / 12.0, THIGH_L, ((THIGH_L, L_THIGH / 2),)),
(M_SHIN, M_SHIN * L_SHIN ** 2 / 12.0, SHIN_L, ((THIGH_L, L_THIGH), (SHIN_L, L_SHIN / 2))),
(M_THIGH, M_THIGH * L_THIGH ** 2 / 12.0, THIGH_R, ((THIGH_R, L_THIGH / 2),)),
(M_SHIN, M_SHIN * L_SHIN ** 2 / 12.0, SHIN_R, ((THIGH_R, L_THIGH), (SHIN_R, L_SHIN / 2))),
)
FEET = {"L": ((THIGH_L, L_THIGH), (SHIN_L, L_SHIN)), "R": ((THIGH_R, L_THIGH), (SHIN_R, L_SHIN))}
TOTAL_MASS = sum(b[0] for b in BODIES)
def point(q, terms, d=None):
if d is None:
d, _ = _dirs(q)
x, y = q[0], q[1]
for k, a in terms:
x += a * d[k][0]
y += a * d[k][1]
return x, y
def point_vel(q, qd, terms, dp=None):
if dp is None:
_, dp = _dirs(q)
vx, vy = qd[0], qd[1]
for k, a in terms:
vx += a * dp[k][0] * qd[k]
vy += a * dp[k][1] * qd[k]
return vx, vy
def foot(q, side):
return point(q, FEET[side])
def center_of_mass(q):
d, _ = _dirs(q)
sx = sy = 0.0
for m, _, _, terms in BODIES:
x, y = point(q, terms, d)
sx += m * x
sy += m * y
return sx / TOTAL_MASS, sy / TOTAL_MASS
def dynamics(q, qd, gen_force):
"""Return qdd from M(q) qdd = gravity and velocity terms + gen_force."""
n = 7
d, dp = _dirs(q)
M = [[0.0] * n for _ in range(n)]
Q = list(gen_force)
for m, inertia, own, terms in BODIES:
M[0][0] += m
M[1][1] += m
M[own][own] += inertia
# bias acceleration of the COM: -sum a d_k phi_k'^2
bx = by = 0.0
for k, a in terms:
w2 = qd[k] * qd[k]
bx -= a * d[k][0] * w2
by -= a * d[k][1] * w2
fx, fy = -m * bx, -m * (G + by)
Q[0] += fx
Q[1] += fy
for k, a in terms:
jx, jy = a * dp[k][0], a * dp[k][1]
M[0][k] += m * jx
M[1][k] += m * jy
M[k][0] += m * jx
M[k][1] += m * jy
Q[k] += jx * fx + jy * fy
for k2, a2 in terms:
M[k][k2] += m * (jx * a2 * dp[k2][0] + jy * a2 * dp[k2][1])
return solve(M, Q)
def solve(A, b):
"""Gaussian elimination with partial pivoting on copies of A and b."""
n = len(b)
A = [row[:] for row in A]
b = list(b)
for c in range(n):
p = max(range(c, n), key=lambda r: abs(A[r][c]))
A[c], A[p] = A[p], A[c]
b[c], b[p] = b[p], b[c]
piv = A[c][c]
for r in range(c + 1, n):
f = A[r][c] / piv
if f != 0.0:
Ar, Ac = A[r], A[c]
for k in range(c, n):
Ar[k] -= f * Ac[k]
b[r] -= f * b[c]
x = [0.0] * n
for r in range(n - 1, -1, -1):
s = b[r] - sum(A[r][k] * x[k] for k in range(r + 1, n))
x[r] = s / A[r][r]
return x
def joint_torques_to_generalized(tau):
"""tau = (hip_L, knee_L, hip_R, knee_R). A joint torque acts +tau on the
child link angle and -tau on the parent link angle."""
Q = [0.0] * 7
pairs = ((TORSO, THIGH_L), (THIGH_L, SHIN_L), (TORSO, THIGH_R), (THIGH_R, SHIN_R))
for t, (parent, child) in zip(tau, pairs):
Q[child] += t
Q[parent] -= t
return Q
def pd(kp, kd, target, angle, rate):
return kp * (target - angle) - kd * rate
def clampt(t):
return max(-TORQUE_LIMIT, min(TORQUE_LIMIT, t))
def balance_target(theta0, cd, cv, d, v):
"""The SIMBICON feedback law theta_d = theta_d0 + c_d d + c_v v."""
return theta0 + cd * d + cv * v
def control(state, q, qd, gait, kp=KP_JOINT, kd=KD_JOINT):
"""Return the joint torques (hip_L, knee_L, hip_R, knee_R) for one step."""
_, cd, cv, tor, swh, swk, stk = gait[state]
sw_th, sw_sh = LEGS[swing_side(state)]
st_th, st_sh = LEGS[stance_side(state)]
fx, _ = foot(q, stance_side(state))
d = q[0] - fx # @line L2
v = qd[0]
theta_swh = balance_target(swh, cd, cv, d, v) # @line L3
tau_torso = pd(kp, kd, tor, q[TORSO], qd[TORSO]) # @line L4
tau_b = pd(kp, kd, theta_swh, q[sw_th], qd[sw_th]) # @line L5
tau_a = -tau_torso - tau_b # @line L6
tau_swk = pd(kp, kd, swk, q[sw_sh] - q[sw_th], qd[sw_sh] - qd[sw_th]) # @line L7
tau_stk = pd(kp, kd, stk, q[st_sh] - q[st_th], qd[st_sh] - qd[st_th])
tau = {}
tau[(swing_side(state), "hip")] = clampt(tau_b)
tau[(swing_side(state), "knee")] = clampt(tau_swk)
tau[(stance_side(state), "hip")] = clampt(tau_a)
tau[(stance_side(state), "knee")] = clampt(tau_stk)
return (tau[("L", "hip")], tau[("L", "knee")], tau[("R", "hip")], tau[("R", "knee")]) # @line L8
class Ground:
"""Penalty contact for one point foot, with a tangential anchor spring."""
def __init__(self):
self.anchor = {"L": None, "R": None}
def force(self, side, p, v):
x, y = p
vx, vy = v
if y >= 0.0:
self.anchor[side] = None
return 0.0, 0.0
fn = max(0.0, -KP_GROUND * y - KD_GROUND * vy)
if self.anchor[side] is None:
self.anchor[side] = x
ft = -KT_GROUND * (x - self.anchor[side]) - DT_GROUND * vx
lim = MU * fn
if abs(ft) > lim:
ft = math.copysign(lim, ft)
# slide: move the anchor so that the spring holds the limit
self.anchor[side] = x + (ft + DT_GROUND * vx) / KT_GROUND
return ft, fn
def foot_force_generalized(q, side, f):
_, dp = _dirs(q)
Q = [0.0] * 7
Q[0] += f[0]
Q[1] += f[1]
for k, a in FEET[side]:
Q[k] += a * (dp[k][0] * f[0] + dp[k][1] * f[1])
return Q
def initial_state(speed=0.8):
"""Right foot under the hip, left leg behind and off the ground."""
q = [0.0, L_THIGH + L_SHIN - 0.003, 0.0, -0.30, -0.45, 0.0, 0.0]
qd = [speed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
return q, qd
def fallen(q):
return q[1] < 0.6 or abs(q[TORSO]) > 0.8
def simulate(gait=None, steps=5000, dt=0.001, speed=0.8):
"""Run the toy and return a dict with the measured quantities.
Each line is one simulation step; the controller runs at every step.
"""
if gait is None:
gait = make_gait()
q, qd = initial_state(speed)
ground = Ground()
state, clock = 0, 0.0
strikes, fell_at, transitions = [], None, []
for i in range(steps):
sw = swing_side(state)
fy_sw = foot(q, sw)[1]
dur = gait[state][0]
if (dur is not None and clock >= dur) or (dur is None and fy_sw < 0.0): # @line L1
if dur is None:
strikes.append((i * dt, foot(q, sw)[0]))
transitions.append((i * dt, state))
state, clock = (state + 1) % 4, 0.0
tau = control(state, q, qd, gait)
Q = joint_torques_to_generalized(tau)
_, dp = _dirs(q)
for side in ("L", "R"):
p = foot(q, side)
v = point_vel(q, qd, FEET[side], dp)
f = ground.force(side, p, v)
if f != (0.0, 0.0):
Qf = foot_force_generalized(q, side, f)
Q = [a + b for a, b in zip(Q, Qf)]
qdd = dynamics(q, qd, Q)
qd = [a + dt * b for a, b in zip(qd, qdd)]
q = [a + dt * b for a, b in zip(q, qd)]
clock += dt
if fallen(q):
fell_at = i * dt
break
return {
"strikes": strikes,
"fell_at": fell_at,
"transitions": transitions,
"distance": q[0],
"time": (i + 1) * dt,
"q": q,
"qd": qd,
}
test_simbicon.py 112 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/simbicon/. The authors are listed in prov/FMSJGE.jsonl.
"""Tests of the SIMBICON toy.
Exact checks: the stance hip rule makes the net hip torque on the torso equal
to the torso PD torque, the feedback law, and the order and timing of the
state machine. The dynamics are checked by energy in free flight. The walk
itself is measured: the number of foot strikes without a fall in this toy,
with and without the balance feedback.
"""
import math
import random
import simbicon as s
def energy(q, qd):
d, dp = s._dirs(q)
e = 0.0
for m, inertia, own, terms in s.BODIES:
x, y = s.point(q, terms, d)
vx, vy = s.point_vel(q, qd, terms, dp)
e += 0.5 * m * (vx * vx + vy * vy) + 0.5 * inertia * qd[own] ** 2 + m * s.G * y
return e
def test_stance_hip_rule_gives_torso_torque():
rng = random.Random(1)
gait = s.make_gait()
for _ in range(200):
q = [rng.uniform(-1, 1), 0.9] + [rng.uniform(-0.3, 0.3) for _ in range(5)]
qd = [rng.uniform(-0.5, 0.5) for _ in range(7)]
state = rng.randrange(4)
tau = s.control(state, q, qd, gait)
if max(abs(t) for t in tau) >= s.TORQUE_LIMIT:
continue
Q = s.joint_torques_to_generalized(tau)
want = s.pd(s.KP_JOINT, s.KD_JOINT, gait[state][3], q[s.TORSO], qd[s.TORSO])
assert abs(Q[s.TORSO] - want) < 1e-9
# the swing thigh gets the world frame PD torque
th = s.LEGS[s.swing_side(state)][0]
sh = s.LEGS[s.swing_side(state)][1]
_, cd, cv, _, swh, _, _ = gait[state]
d = q[0] - s.foot(q, s.stance_side(state))[0]
target = swh + cd * d + cv * qd[0]
tb = s.pd(s.KP_JOINT, s.KD_JOINT, target, q[th], qd[th])
tk = tau[1] if s.swing_side(state) == "L" else tau[3]
assert abs(Q[th] - (tb - tk)) < 1e-9
assert abs(Q[sh] - tk) < 1e-9
def test_feedback_law():
assert abs(s.balance_target(-0.70, 2.20, 0.0, 0.1, 1.0) - (-0.48)) < 1e-15
assert abs(s.balance_target(0.40, 0.0, 0.20, 0.3, 1.5) - 0.70) < 1e-15
def test_free_flight_energy():
q = [0.0, 3.0, 0.2, 0.3, -0.4, -0.2, 0.5]
qd = [0.5, 1.0, 1.0, -2.0, 3.0, 1.5, -1.0]
e0 = energy(q, qd)
dt = 1e-4
worst = 0.0
for _ in range(3000):
qdd = s.dynamics(q, qd, [0.0] * 7)
qd = [a + dt * b for a, b in zip(qd, qdd)]
q = [a + dt * b for a, b in zip(q, qd)]
worst = max(worst, abs(energy(q, qd) - e0))
assert worst / abs(e0) < 2e-4
def test_state_machine_order_and_timing():
r = s.simulate(steps=2000)
tr = r["transitions"]
states = [st for _, st in tr]
assert states[:8] == [0, 1, 2, 3, 0, 1, 2, 3]
starts = [0.0] + [t for t, _ in tr]
for (t, st), t0 in zip(tr, starts):
if st in (0, 2):
assert abs((t - t0) - 0.30) < 1.5e-3
# contact states end at a foot strike
assert len(r["strikes"]) == sum(1 for st in states if st in (1, 3))
def test_measured_walk_with_feedback():
r = s.simulate(steps=5000)
assert r["fell_at"] is None
assert len(r["strikes"]) >= 12
xs = [x for _, x in r["strikes"]]
assert all(b > a for a, b in zip(xs, xs[1:]))
assert 3.0 < r["distance"] < 9.0
def test_measured_fall_without_feedback():
table = (
(0.30, 0.0, 0.0, 0.0, 0.40, -1.10, -0.05),
(None, 0.0, 0.0, 0.0, -0.70, -0.05, -0.10),
)
r = s.simulate(gait=s.make_gait(table), steps=5000)
assert r["fell_at"] is not None
assert len(r["strikes"]) < 5
def test_solver():
rng = random.Random(3)
A = [[rng.uniform(-1, 1) for _ in range(5)] for _ in range(5)]
for i in range(5):
A[i][i] += 3.0
x = [rng.uniform(-1, 1) for _ in range(5)]
b = [sum(A[i][k] * x[k] for k in range(5)) for i in range(5)]
y = s.solve(A, b)
assert all(math.isclose(a, c, abs_tol=1e-12) for a, c in zip(x, y))
History
KangKang Yin, Kevin Loken and Michiel van de Panne presented SIMBICON at SIGGRAPH 2007. It built on earlier work on hand designed controllers for simulated figures, such as the controllers of Hodgins and coworkers for running and athletics in the 1990s, and on foot placement rules like those of the Raibert hopping controller. The simple rules made it a common base for later work on simulated locomotion, which moved to optimization of the gaits and then to learned policies such as DeepMimic in 2018.
References
- KangKang Yin, Kevin Loken and Michiel van de Panne, SIMBICON, simple biped locomotion control, ACM Transactions on Graphics 26(3) (SIGGRAPH 2007), article 105, the finite state machine of target poses, the PD control with the torso and swing hip in the world frame, the stance hip rule, the balance feedback law, and the gains kp 300 and kd 30
- Xue Bin Peng, Pieter Abbeel, Sergey Levine and Michiel van de Panne, DeepMimic, example-guided deep reinforcement learning of physics-based character skills, ACM Transactions on Graphics 37(4) (SIGGRAPH 2018), the later learned controllers that track motion clips with PD targets
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 FMSJGE Edit this page History Report an error Markdown