Part III · The Robotics Side
13.The Robot as an Environment: Kinematics, Dynamics & Control
“A reinforcement learning practitioner who does not understand the plant is not doing control — they are doing curve fitting and hoping.”
Twelve chapters have treated the environment as a black box returning s′ and r. Part III opens it. When the environment is a physical machine, it has structure: rigid bodies with known geometry, dynamics that follow from Lagrangian mechanics, and decades of control theory that already solves large parts of the problem. This chapter derives that structure for Reacher from first principles, builds the classical controllers RL must be measured against, and identifies exactly where learning has something to add — which is a narrower and more interesting set of places than enthusiasm suggests.
Foundation
SE(2)/SE(3), forward and inverse kinematics worked completely, the Jacobian and manipulability, the Lagrangian derivation of M(q)q̈ + C(q,q̇)q̇ + g(q) = τ, LQR via the Riccati recursion, and the EKF.
Conceptual
Reacher as a mechanism you can drag: watch joint space and task space respond to each other, and see the manipulability ellipsoid collapse at a singularity.
Practical
The rl-sim crate: URDF chains via urdf-rs and k, Reacher in rapier2d, and PID/LQR baselines with a benchmark suite that later chapters must beat.
After this chapter you can
- Compute forward and inverse kinematics for a two-link arm, including both elbow solutions
- Derive the Jacobian, use it to map velocities and forces, and identify singularities
- Derive the manipulator equation from the Lagrangian and interpret each term physically
- Derive the LQR controller from the Riccati equation and recognize it as Chapter 5’s value iteration
- Explain what PID, LQR and operational-space control each do well, and what defeats them
- Identify the four distinct places learning can enter a robot control stack
13.1 Configuration, pose, and the two spaces
A robot's configuration lists its joint variables — for Reacher, two angles . Its pose is where the end-effector actually is, an element of in the plane (position plus orientation) or in space.
Everything in robot control lives in the tension between these two descriptions. You command joint space, because that is where the motors are. You care about task space, because that is where the mug is.
Forward kinematics maps one to the other. For Reacher with link lengths :
This is always well defined, cheap, and unique. Inverse kinematics goes the other way and is where the difficulties live. Squaring and adding:
so
13.2 The Jacobian: velocities, forces, and singularities
Differentiating forward kinematics gives the Jacobian , mapping joint velocities to end-effector velocity, . For Reacher:
with , and so on.
The Jacobian does three jobs at once. It maps velocities forward. It maps forces backward — the static force relation says the joint torques needed to exert an end-effector force are the Jacobian transpose applied to it, which is how force control is implemented. And it diagnoses singularities.
For Reacher, , which vanishes at (arm fully extended) and (fully folded). At those configurations the arm loses the ability to move in one direction entirely, and any controller that inverts demands infinite joint velocity.
The manipulability ellipsoid — the image of the unit joint-velocity ball under — visualizes this: it is round where the arm is dexterous and flattens to a line at a singularity.
Reacher: joint space and task space
ch13-kinematics-sandboxDrag the end-effector to solve inverse kinematics, or move the joints directly. The ellipse is the manipulability ellipsoid.
q₁
34.4°
q₂
63.0°
tip x
0.717
in units of ℓ₁
tip y
-1.40
in units of ℓ₁
det J = ℓ₁ℓ₂ sin q₂
0.891
invertible
Condition number
3.99
1 = isotropic, ∞ = singular
Reading the ellipse
The ellipse is the set of end-effector velocities reachable from a unit ball of joint velocities. A round ellipse means the arm moves equally well in every direction; an elongated one means it is fast along the major axis and sluggish across it.
Current reach: 0.85 of maximum. The dashed circles bound the reachable annulus — inverse kinematics has no solution outside them, which is a constraint any task-space action must respect.
13.3 Dynamics: the manipulator equation
Kinematics ignores mass. To command torques we need dynamics, and the systematic route is Lagrangian mechanics.
Form the Lagrangian (kinetic minus potential energy) and apply the Euler–Lagrange equation:
For any serial manipulator this always produces the same structure — the manipulator equation:
Each term has a clean physical reading. is the mass matrix: symmetric, positive definite, and configuration-dependent — an extended arm has more rotational inertia than a folded one, which is why a controller tuned in one configuration misbehaves in another. collects Coriolis and centrifugal effects, the velocity-dependent coupling that makes fast motion qualitatively harder than slow motion. is gravity, the term that is usually largest and, helpfully, the easiest to cancel exactly.
For Reacher, writing , , :
A useful structural fact: is skew-symmetric, which encodes energy conservation and underpins the stability proofs of most classical robot controllers.
13.4 Classical control: the baselines RL must beat
Three controllers, in increasing order of how much they know about the robot.
PID knows nothing. It drives the error to zero using proportional, integral and derivative terms:
It is model-free, ubiquitous, and remarkably effective for slow, well-geared, fully actuated systems. It struggles with coupling, gravity that varies with configuration, and anything fast.
Computed torque knows the model and cancels it. Choosing
makes the closed-loop error dynamics exactly linear: . This is feedback linearization, and it is beautiful when the model is right. Its weakness is precisely its strength — it depends entirely on model accuracy, and Chapter 15 is about how wrong models actually are.
LQR is optimal control for a linearized system, and it deserves special attention here because it is exactly the machinery of Chapter 5 in continuous form. For dynamics and cost , the optimal policy is linear state feedback with , where solves the discrete algebraic Riccati equation
use nalgebra::{Matrix2, Vector2};
pub struct ReacherParams {
pub m1: f64, pub m2: f64,
pub l1: f64, pub l2: f64,
pub lc1: f64, pub lc2: f64,
pub i1: f64, pub i2: f64,
pub g: f64,
}
impl ReacherParams {
/// Configuration-dependent mass matrix M(q) — symmetric, positive definite.
pub fn mass_matrix(&self, q: &Vector2<f64>) -> Matrix2<f64> {
let alpha = self.m1 * self.lc1.powi(2)
+ self.m2 * (self.l1.powi(2) + self.lc2.powi(2))
+ self.i1 + self.i2;
let beta = self.m2 * self.l1 * self.lc2;
let delta = self.m2 * self.lc2.powi(2) + self.i2;
let c2 = q[1].cos();
Matrix2::new(
alpha + 2.0 * beta * c2, delta + beta * c2,
delta + beta * c2, delta,
)
}
/// Coriolis/centrifugal matrix C(q, q̇).
pub fn coriolis(&self, q: &Vector2<f64>, dq: &Vector2<f64>) -> Matrix2<f64> {
let beta = self.m2 * self.l1 * self.lc2;
let s2 = q[1].sin();
Matrix2::new(
-beta * dq[1] * s2, -beta * (dq[0] + dq[1]) * s2,
beta * dq[0] * s2, 0.0,
)
}
/// Forward dynamics: q̈ = M⁻¹(τ − C q̇ − g).
pub fn accel(&self, q: &Vector2<f64>, dq: &Vector2<f64>, tau: &Vector2<f64>) -> Vector2<f64> {
let m = self.mass_matrix(q);
let c = self.coriolis(q, dq);
let grav = self.gravity(q);
m.try_inverse().expect("M(q) is positive definite") * (tau - c * dq - grav)
}
}
/// Discrete LQR by iterating the Riccati recursion to its fixed point.
/// This is Chapter 5's value iteration, specialized to quadratic value functions.
pub fn dlqr(a: &Matrix2<f64>, b: &Matrix2<f64>, q: &Matrix2<f64>, r: &Matrix2<f64>)
-> Matrix2<f64>
{
let mut p = *q;
for _ in 0..500 {
let s = r + b.transpose() * p * b;
let k = s.try_inverse().unwrap() * b.transpose() * p * a;
let p_next = q + a.transpose() * p * (a - b * k);
if (p_next - p).norm() < 1e-12 { p = p_next; break; }
p = p_next;
}
(r + b.transpose() * p * b).try_inverse().unwrap() * b.transpose() * p * a
}13.5 Where learning actually enters
Given all this machinery, what is left for reinforcement learning? Four distinct entry points, and confusing them is a common source of wasted effort.
Learning the policy — replace the controller entirely. Correct when the dynamics are too complex or contact-rich to model, as in legged locomotion over rough terrain. Usually wasteful when a classical controller already works.
Learning the model — keep classical control, learn the dynamics it needs. This is Chapter 12's territory and Chapter 15's system identification. Often the highest-value option, because a small correction to a mostly-right model goes a long way.
Learning a residual — run a hand-designed controller and let a policy learn a correction on top, . The classical part guarantees baseline competence and safety; the learned part handles what the model missed. Chapter 17 builds this properly, and it is frequently the pragmatic answer for real deployments.
Learning to tune — treat controller gains as the action space and let RL adapt them online. Modest, low-risk, and underused.
13.6 State estimation, and Chapter 4's confession revisited
One more piece of reality. The controllers above assume you know and . You measure encoder counts and integrate noisy signals.
The extended Kalman filter is the standard answer: maintain a Gaussian belief over the state, propagate it through linearized dynamics (predict), and correct it with each measurement (update). It is Chapter 4's belief update, specialized to Gaussians and linearized dynamics.
This is where Chapter 4's confession becomes concrete. The observation is not the state; a filter produces an estimate with real error; and a policy trained on ground-truth simulator state will encounter estimation error it has never seen. Chapter 15's teacher–student method exists precisely to handle this, and Chapter 19's recurrent policies learn to do the filtering themselves.
13.7 Chapter bridge
The black box is open. Reacher is a mechanism with derivable kinematics, a Jacobian that says what it can and cannot do, dynamics that follow from the Lagrangian, and classical controllers that already solve a respectable fraction of the problem. We know where learning belongs — and, equally useful, where it does not.
Chapter 14 asks what makes robot RL hard in ways that have nothing to do with algorithms. Kober's four curses: the dimensionality we quantified in Chapter 5, the sample cost that shaped Chapter 11, the under-modelling that Chapter 12 fought, and the one we have so far avoided entirely — goal specification. Reward functions are the interface between human intent and an optimizer that will exploit any gap in your phrasing, and the results are a catalogue of instructive disasters.
- 01Foundation●●●Both elbows
Derive Reacher’s inverse kinematics completely, including both elbow solutions and the reachability conditions. Then determine which solution a continuous IK-following controller should choose, and what happens at the boundary between them.
- 02Foundation●●●Jacobian and singularities
Compute det J for Reacher and identify all singular configurations. At q₂ = 0, determine the direction in which end-effector motion becomes impossible, and verify it against the manipulability ellipsoid.
- 03Foundation●●●The full Lagrangian derivation
Derive M(q), C(q,q̇) and g(q) for Reacher from the Lagrangian, showing every step. Verify that M is symmetric positive definite and that Ṁ − 2C is skew-symmetric.
- 04Foundation●●●LQR is value iteration
Starting from the Bellman optimality equation with a quadratic value function V(x) = xᵀPx and linear dynamics, derive the Riccati recursion. Identify precisely which step corresponds to Chapter 5’s max over actions.
- 05Conceptual●●●Feel the redundancy
In the kinematics sandbox, hold the end-effector at a fixed point and move through both elbow solutions. Then move to the workspace boundary and describe what happens to the manipulability ellipsoid.
- 06Conceptual●●●PID versus LQR under disturbance
Compare PID and LQR on Pendle’s stabilization with an impulse disturbance. Tune PID as well as you can. Then increase the disturbance until each fails, and report the margin between them.
- 07Practical●●●Computed torque
Implement computed-torque control for Reacher and verify the error dynamics are linear when the model is exact. Then perturb the mass parameters by 10%, 25% and 50%, and measure how tracking degrades. This is a preview of Chapter 15.
- 08Practical●●●The baseline suite
Build a benchmark harness that evaluates any controller on Reacher reaching and Pendle swing-up with pinned seeds, reporting success rate, settling time and energy. Every later chapter’s learned policy will be measured against it.
References
Baseline references
- Kober, J., Bagnell, J. A. & Peters, J. (2013). Reinforcement Learning in Robotics: A Survey. International Journal of Robotics Research 32(11)§1.2 RL in the context of optimal control, and §1.3 on the physical structure that distinguishes robot problems from generic MDPs.
- Sutton, R. S. & Barto, A. G. (2018). Reinforcement Learning: An Introduction. MIT Press, 2nd editionChapter 4 — the value iteration that §13.4 shows LQR to be a closed-form instance of.
Further reading & modern sources
- Siciliano, B., Sciavicco, L., Villani, L. & Oriolo, G. (2009). Robotics: Modelling, Planning and Control. SpringerThe standard reference for everything in §13.1–13.4: kinematics, Jacobians, dynamics, and control.
- Spong, M. W., Hutchinson, S. & Vidyasagar, M. (2006). Robot Modeling and Control. WileyThe Lagrangian derivation of the manipulator equation, and the skew-symmetry property used in stability proofs.
- Yoshikawa, T. (1985). Manipulability of Robotic Mechanisms. International Journal of Robotics Research 4(2)The manipulability ellipsoid, in the original.
- Khatib, O. (1987). A unified approach for motion and force control of robot manipulators: The operational space formulation. IEEE Journal on Robotics and Automation 3(1)Operational-space control — the task-space formulation that Chapter 20’s impedance action spaces build on.
- Anderson, B. D. O. & Moore, J. B. (1990). Optimal Control: Linear Quadratic Methods. Prentice HallLQR and the Riccati equation, with the convergence analysis.
- Thrun, S., Burgard, W. & Fox, D. (2005). Probabilistic Robotics. MIT PressThe EKF and the belief-state machinery of §13.6, developed in full.
