Part III · The Robotics Side

13.The Robot as an Environment: Kinematics, Dynamics & Control

Kober §1.3Spong 2006Siciliano 2009ReacherPendle
A reinforcement learning practitioner who does not understand the plant is not doing control — they are doing curve fitting and hoping.
Adapted from the classical-control tradition · The premise of Part III
Siciliano & Khatib, Springer Handbook of Robotics

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 qRnq \in \mathbb{R}^n lists its joint variables — for Reacher, two angles q=(q1,q2)q = (q_1, q_2). Its pose is where the end-effector actually is, an element of SE(2)SE(2) in the plane (position plus orientation) or SE(3)SE(3) 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 1,2\ell_1, \ell_2:

x=1cosq1+2cos(q1+q2),y=1sinq1+2sin(q1+q2).x = \ell_1 \cos q_1 + \ell_2 \cos(q_1 + q_2), \qquad y = \ell_1 \sin q_1 + \ell_2 \sin(q_1 + q_2).

This is always well defined, cheap, and unique. Inverse kinematics goes the other way and is where the difficulties live. Squaring and adding:

x2+y2=12+22+212cosq2cosq2=x2+y21222212,x^2 + y^2 = \ell_1^2 + \ell_2^2 + 2\ell_1\ell_2 \cos q_2 \quad\Longrightarrow\quad \cos q_2 = \frac{x^2+y^2-\ell_1^2-\ell_2^2}{2\ell_1\ell_2},

so

q2=±arccos(x2+y21222212),q1=atan2(y,x)atan2(2sinq2,  1+2cosq2).q_2 = \pm\arccos\left(\frac{x^2+y^2-\ell_1^2-\ell_2^2}{2\ell_1\ell_2}\right), \qquad q_1 = \operatorname{atan2}(y,x) - \operatorname{atan2}\big(\ell_2 \sin q_2,\; \ell_1 + \ell_2\cos q_2\big).

13.2 The Jacobian: velocities, forces, and singularities

Differentiating forward kinematics gives the Jacobian J(q)J(q), mapping joint velocities to end-effector velocity, p˙=J(q)q˙\dot{p} = J(q)\,\dot q. For Reacher:

J(q)=[1s12s122s121c1+2c122c12],J(q) = \begin{bmatrix} -\ell_1 s_1 - \ell_2 s_{12} & -\ell_2 s_{12} \\ \ell_1 c_1 + \ell_2 c_{12} & \ell_2 c_{12} \end{bmatrix},

with s1=sinq1s_1 = \sin q_1, s12=sin(q1+q2)s_{12} = \sin(q_1+q_2) and so on.

The Jacobian does three jobs at once. It maps velocities forward. It maps forces backward — the static force relation τ=JF\tau = J^\top F says the joint torques needed to exert an end-effector force FF are the Jacobian transpose applied to it, which is how force control is implemented. And it diagnoses singularities.

For Reacher, detJ=12sinq2\det J = \ell_1 \ell_2 \sin q_2, which vanishes at q2=0q_2 = 0 (arm fully extended) and q2=πq_2 = \pi (fully folded). At those configurations the arm loses the ability to move in one direction entirely, and any controller that inverts JJ demands infinite joint velocity.

The manipulability ellipsoid — the image of the unit joint-velocity ball under JJ — 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-sandbox

Drag the end-effector to solve inverse kinematics, or move the joints directly. The ellipse is the manipulability ellipsoid.

Control
drag the orange tip

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.

Switching elbow solutions holds the end-effector perfectly still while the arm folds through an entirely different configuration — that is redundancy, and Chapter 19 spends it on obstacle avoidance. Now straighten the arm until q₂ approaches zero: the ellipse flattens to a line, meaning there is a direction the tip simply cannot move, and any controller inverting J would demand infinite joint velocity to try.

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 L=TV\mathcal{L} = T - V (kinetic minus potential energy) and apply the Euler–Lagrange equation:

ddtLq˙iLqi=τi.\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot q_i} - \frac{\partial \mathcal{L}}{\partial q_i} = \tau_i.

For any serial manipulator this always produces the same structure — the manipulator equation:

M(q)q¨+C(q,q˙)q˙+g(q)=τ.M(q)\,\ddot q + C(q,\dot q)\,\dot q + g(q) = \tau.

Each term has a clean physical reading. M(q)M(q) 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. C(q,q˙)q˙C(q,\dot q)\dot q collects Coriolis and centrifugal effects, the velocity-dependent coupling that makes fast motion qualitatively harder than slow motion. g(q)g(q) is gravity, the term that is usually largest and, helpfully, the easiest to cancel exactly.

For Reacher, writing α=m1c12+m2(12+c22)+I1+I2\alpha = m_1 \ell_{c1}^2 + m_2(\ell_1^2 + \ell_{c2}^2) + I_1 + I_2, β=m21c2\beta = m_2 \ell_1 \ell_{c2}, δ=m2c22+I2\delta = m_2 \ell_{c2}^2 + I_2:

M(q)=[α+2βcosq2δ+βcosq2δ+βcosq2δ],C(q,q˙)=[βq˙2sinq2β(q˙1+q˙2)sinq2βq˙1sinq20].M(q) = \begin{bmatrix} \alpha + 2\beta \cos q_2 & \delta + \beta\cos q_2 \\ \delta + \beta \cos q_2 & \delta \end{bmatrix}, \qquad C(q,\dot q) = \begin{bmatrix} -\beta \dot q_2 \sin q_2 & -\beta(\dot q_1 + \dot q_2)\sin q_2 \\ \beta \dot q_1 \sin q_2 & 0 \end{bmatrix}.

A useful structural fact: M˙2C\dot M - 2C 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:

τ=Kpe+Kiedt+Kde˙.\tau = K_p e + K_i \int e\, dt + K_d \dot e.

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

τ=M(q)(q¨d+Kde˙+Kpe)+C(q,q˙)q˙+g(q)\tau = M(q)\big(\ddot q_d + K_d \dot e + K_p e\big) + C(q,\dot q)\dot q + g(q)

makes the closed-loop error dynamics exactly linear: e¨+Kde˙+Kpe=0\ddot e + K_d \dot e + K_p e = 0. 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 xk+1=Axk+Bukx_{k+1} = A x_k + B u_k and cost k(xkQxk+ukRuk)\sum_k (x_k^\top Q x_k + u_k^\top R u_k), the optimal policy is linear state feedback u=Kxu = -Kx with K=(R+BPB)1BPAK = (R + B^\top P B)^{-1} B^\top P A, where PP solves the discrete algebraic Riccati equation

P=Q+APAAPB(R+BPB)1BPA.P = Q + A^\top P A - A^\top P B\,(R + B^\top P B)^{-1} B^\top P A.

Rustrl-sim/src/reacher/dynamics.rs
rust
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
}
Reacher's analytic dynamics and a discrete LQR solver in nalgebra. These are the baselines Chapters 14–20 must beat — and it is worth knowing that on reaching tasks, they often do not lose.

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, τ=τclassical+τlearned\tau = \tau_{\text{classical}} + \tau_{\text{learned}}. 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 qq and q˙\dot q. 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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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 edition
    Chapter 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. Springer
    The 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. Wiley
    The 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 Hall
    LQR and the Riccati equation, with the convergence analysis.
  • Thrun, S., Burgard, W. & Fox, D. (2005). Probabilistic Robotics. MIT Press
    The EKF and the belief-state machinery of §13.6, developed in full.