This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/chain

Rigid-body dynamics for a planar chain of links

A serial chain of rigid links in the plane, joined by revolute joints: a pendulum when it has one link, a double pendulum or an acrobot when it has two, a planar arm when it has more. This is the same object a robotics simulator works with, restricted to two dimensions so that the algebra stays readable.

A chain is one n by 4 matrix, a row per link:

body[i, 0]  mass
body[i, 1]  moment of inertia about the link's own center of mass
body[i, 2]  length, from this joint to the next
body[i, 3]  distance from this joint to the center of mass

q[i] is joint i measured against the link before it, and q[0] is measured against the x axis, so a single link hangs at rest at -pi/2. Gravity is -CHAIN_G in y.

chain_rnea is the recursive Newton-Euler algorithm: one pass out to the tip carrying accelerations, one pass back to the base carrying forces, and the torque at each joint falls out. The mass matrix comes from n calls to it with a unit acceleration at one joint and gravity off; the bias term from one call with no acceleration and gravity on; and forward dynamics from solving M qdd = tau - h with those two.

Used with import chain.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 31–375