Feedforward and Computed-Torque Control
Feedforward from the inverse dynamics model reduces tracking error by orders of magnitude — but only if your model is good, and it never is.
🎯 By the end you'll understand
How inverse dynamics produces a feedforward torque command from a desired trajectory. Why computed-torque control achieves exact linearization of the arm equation of motion — and why that exactness is its greatest liability on hardware. How model error propagates into tracking error under computed-torque vs. pure PD. Why partial feedforward (gravity compensation only) is often the most robust practical choice. And how the feedforward-feedback separation principle lets you tune each path independently.
KEY INSIGHTYour model is wrong — the question is how wrong
Feedforward control is not about having a perfect model. It is about trading sensitivity to disturbances for sensitivity to model error. Knowing which you have more of determines whether feedforward helps or hurts.
A PD controller reacts to error after it happens. It is inherently late — the arm has already deviated before the controller does anything about it. Feedforward control predicts the torque the arm will need and applies it before the error builds. At its limit, if you have a perfect model, feedforward alone tracks the trajectory with zero error and feedback is not needed at all. The catch: no model is perfect, and perfect is the only thing that makes pure feedforward stable. In practice, the question is not "should I use feedforward" but "how much of the model should I trust, and what happens when I am wrong."
Feedback is robust to model error but late. Feedforward is fast but fragile to model error. Computed-torque control achieves full model linearization — it turns the nonlinear arm dynamics into a double integrator, which you can then control with simple PD gains. But the linearization is exact only if the model is exact. When inertia differs by 30% (typical for a real arm with cable routing, connector mass, and thermal effects not captured in the CAD), the computed-torque controller is feeding wrong torques and the feedback gains are tuned for the wrong plant. The coupling that was canceled analytically re-emerges as an unmodeled disturbance.
CORE CONCEPTInverse dynamics: from desired motion to required torque
The equation of motion for an n-DOF robot arm derived in Lesson 3.2 is:
Forward dynamics solves for acceleration given torque: given τ, compute q̈. Inverse dynamics solves the other direction: given a desired acceleration q̈d, what torque τ is required? Simply rearrange the equation of motion:
This is the feedforward signal. Applied alone with no feedback, it is an open-loop trajectory player — the arm executes whatever motion the model predicts. In practice you combine it with a feedback term that corrects the inevitable model error:
Compute the desired trajectory: qd(t), q̇d(t), q̈d(t)
A trajectory planner generates joint-space position, velocity, and acceleration profiles, typically via minimum-jerk or polynomial interpolation between waypoints. The acceleration profile is what the inverse dynamics model needs.
Compute the feedforward torque via inverse dynamics
Evaluate M(qd), C(qd, q̇d), and g(qd) from the model. Multiply as above. This is an O(n²) to O(n³) computation depending on which algorithm you use — for a 6-DOF arm it runs comfortably at 1 kHz on a microcontroller.
Add the feedback term
The feedback term corrects error that accumulated because the model is wrong, disturbances acted, or the initial condition was off. Typically PD on position and velocity error: τfb = Kpe + Kdė where e = qd − q.
Send the total command: τ = τff + τfb
The total torque command sums the predictive feedforward and the reactive feedback. The ratio of how much work each term does is determined by model quality: better model → feedforward dominates. Worse model → feedback must compensate more.
In a well-designed feedforward + feedback architecture, you can tune the two paths independently. The feedforward gains (the model itself) are identified from system identification experiments — they are not tunable parameters in the control-theory sense. The feedback gains (Kp, Kd) are tuned for disturbance rejection and robustness around the linearized error dynamics. This separation is what makes the architecture tractable: you are not trying to tune one set of gains to do two fundamentally different jobs.
HOW IT WORKSComputed-torque control: exact linearization and its price
Computed-torque control (also called inverse dynamics control) takes feedforward to its logical extreme: set the feedforward term to cancel the entire nonlinear dynamics, leaving a perfectly linear error system that you can control with simple gains.
Define the desired closed-loop error dynamics. You want the position error e = qd − q to obey:
To achieve this, substitute τ = M(q)[q̈d + Kdė + Kpe] + C(q, q̇)q̇ + g(q) into the equation of motion. If the model is exact, the M(q) terms cancel, the C and g terms cancel, and you are left with exactly ë + Kdė + Kpe = 0 — a decoupled, linear, second-order system for each joint.
The arm's equation of motion is nonlinear — M, C, and g are all nonlinear functions of q and q̇. A standard PD controller designed around a linearized model will have varying performance across the workspace because the plant changes. Computed-torque control uses the model to cancel the nonlinearity before the linear controller sees anything. The feedback gains now govern a linear, time-invariant system (locally) regardless of the arm's configuration. This is conceptually different from linearizing around an operating point — it works everywhere, simultaneously, if the model is exact.
Here is the computed-torque controller in minimal Python, using a toy 1-DOF revolute joint to make the structure clear:
import numpy as np # Robot model parameters (from URDF / system identification) m = 1.8 # kg·m² — effective inertia at joint (link + load) b = 0.05 # N·m·s/rad — viscous friction g_c = 9.81 * 0.35 # N·m — gravity coefficient for this joint # Computed-torque controller gains (tuned for the linearized error system) Kp = 120.0 # rad/s² per rad — bandwidth squared roughly Kd = 22.0 # rad/s² per rad/s — 2*sqrt(Kp) for critical damping def computed_torque(q, qdot, q_des, qdot_des, qddot_des): """ q, qdot : current joint pos, vel (measured) q_des, qdot_des : desired joint pos, vel (from trajectory) qddot_des : desired joint acc (from trajectory) Returns τ in N·m. """ e = q_des - q # position error edot = qdot_des - qdot # velocity error # Gravity compensation: g(q) for revolute joint gq = g_c * np.cos(q) # Inertia and friction (the full "model") # For multi-DOF arm: replace m with M(q), add C(q,qdot)*qdot Mq = m # Computed-torque law: cancel dynamics + enforce desired error ODE tau = Mq * (qddot_des + Kd * edot + Kp * e) + b * qdot + gq return tau
The highlighted line is the heart of the controller. The term in parentheses is the desired acceleration (feedforward) plus the linear feedback (PD on error). Multiplying by M(q) converts from desired joint-space acceleration to torque units. Adding b*qdot and g(q) cancels the model's friction and gravity. If the actual robot has those exact values, the error dynamics are a perfect double integrator with poles at the roots of s² + Kds + Kp = 0.
Now for the bad news. The actual arm has cable mass the URDF does not model, thermal expansion that shifts the friction coefficient, link inertia estimates that are ±15% even from a good CAD model, and joint flexibility not captured in the rigid-body model. Computed-torque divides everything by the model inertia — so errors in M are amplified. A 30% inertia error does not cause 30% worse tracking. It causes the feedback gains to be tuned for the wrong plant, and the un-canceled nonlinear coupling re-emerges as a persistent disturbance the feedback gains were never designed to reject.
SEE ITComputed-torque vs. PD — injecting model error
Three controller configurations track a sinusoidal joint trajectory. You control two model errors: inertia error (how wrong M is) and gravity error (how wrong g is). A 20% inertia error and 15% gravity error are representative of a real arm with cable routing and mounting hardware not in the URDF. Watch how each controller degrades — and which one survives.
The chart tells the real story. At zero model error, computed-torque wins decisively — the linearization works and the PD gains can be small. As inertia error grows, computed-torque degrades faster than pure PD in many configurations, because the feedback gains were designed for the (wrong) linearized plant — they are no longer appropriate for the actual plant. PD+gravity compensation is the pragmatic middle: gravity is the largest static nonlinearity (it does not require knowing inertia), and compensating it accurately reduces the steady-state bias that forces PD gains high, while exposing only the gravity model to error (not the inertia model).
IN PRACTICEPartial feedforward: the robust compromise
The spectrum from "pure PD" to "full computed-torque" has more interesting points in the middle than the literature typically emphasizes. Here is how practitioners actually deploy these controllers:
| Feedforward strategy | What gets cancelled | Model dependency | Practical use case |
|---|---|---|---|
| Pure PD | Nothing | None (gains only) | Slow motion, light arms, stiff joints. Baseline to beat. |
| PD + gravity comp | Gravity vector g(q) | Joint angles + mass distribution | Most industrial arms at low speed. Robust workhorse. |
| PD + gravity + inertia (diagonal) | g(q) + diagonal M(q) | Link masses + CoM (ignore coupling) | Medium speed. Avoids inertia coupling errors. |
| Full computed-torque | M(q), C(q,q̇), g(q) — everything | Complete dynamic model | Only when model is exceptionally well identified. Sim-first validation required. |
| Adaptive computed-torque | Everything (estimated online) | Model structure only (params learned) | Research systems; adds complexity, convergence guarantees are narrow. |
Gravity compensation deserves its position as the default first upgrade from pure PD. Why? Because gravity is the one term in the equation of motion that does not depend on velocity or acceleration — it is a pure function of joint configuration. This means:
Gravity error does not amplify with speed
The Coriolis and inertia terms scale with velocity and acceleration. Gravity does not. This means you can identify gravity compensation parameters at low speed, apply them at high speed, and the error stays bounded — unlike inertia errors, which grow with q̈.
Gravity parameters are the easiest to identify
Hold the arm at static equilibrium at multiple configurations, measure the torque required to hold position — that is directly the gravity term. No trajectory execution required, no velocity measurements, no acceleration estimation. The inertia matrix requires dynamic experiments with known accelerations, which introduces its own errors.
Gravity compensation does not destabilize the feedback loop
Adding feedforward that is wrong can destabilize the system if it introduces frequency-domain phase shifts. Gravity compensation is quasi-static — it does not affect the frequency-domain behavior of the feedback loop. You can add it to a working PD controller without re-tuning the gains, and the worst that happens with a wrong gravity model is a steady-state bias (which the PD integrator, if present, removes anyway).
In a controller of the form τ = τff(qd, q̇d, q̈d) + τfb(e, ė), the feedforward path is open-loop with respect to the tracking error. It does not affect the stability of the closed-loop feedback system. You can therefore add, remove, or adjust the feedforward term without changing the closed-loop poles — the Bode margins from Lesson 3.6 remain unchanged. This is the formal justification for the "add gravity comp without re-tuning" recommendation above: the separation principle guarantees stability is not affected.
The caveat: this separation holds exactly only when the feedforward does not feed back into the error loop. If your computed-torque controller uses the actual q (not qd) to evaluate M(q), C(q,q̇), g(q), you have introduced a coupling — errors in q affect the feedforward, which affects the torque, which affects q. This coupling is usually benign but breaks the clean separation, and it is the source of most of the subtle instabilities seen in computed-torque implementations on hardware with significant model error.
FOLLOWBOTFeeding FollowBot's arm with inverse dynamics
FollowBot's 6-DOF arm is at the Stage 3 milestone: full dynamics model derived, PID velocity controller tuned to a quantitative settling-time spec via Ziegler-Nichols then refined via root locus (Lessons 3.4 and 3.6). Now we close the loop on tracking performance for trajectory execution — specifically the figure-eight end-effector trajectory used to verify the arm's workspace.
The arm's URDF defines link masses and inertia tensors from the CAD model. After mounting the arm on FollowBot's mobile base, three additional mass sources are not in the URDF:
Cable routing: approximately 180 g distributed over 6 joints
Power and signal cables run along the arm links and through the joints. Their mass distribution changes with configuration — a cable bundle at joint 4 shifts the effective CoM of link 4 by 8–12 mm depending on the joint angle. The URDF does not model this because cable routing is not a rigid body.
Joint connectors and fasteners: approximately 60 g across all joints
Servo motors, strain wave gear assemblies, and encoder discs are modeled as point masses at the joint axes in the URDF. The actual fastener mass distribution is eccentric — it contributes a small but non-zero off-diagonal term to the inertia matrix that the diagonal approximation misses.
Gripper payload variation: 0–200 g depending on task
The gripper carries payloads of unknown mass during operation. A 200 g payload at 450 mm from joint 6 changes the gravity term at joint 6 by roughly 0.88 N·m — significant relative to the motor's 3 N·m continuous torque rating. The inertia contribution is smaller but non-negligible during fast motions.
Given these realities, FollowBot's arm controller uses PD + gravity compensation as the deployment architecture, with computed-torque reserved for lab testing with a known payload in a controlled environment. Here is the gravity compensation node for FollowBot's arm, publishing a torque overlay on top of the PD controller's output:
import rclpy from rclpy.node import Node from sensor_msgs.msg import JointState from std_msgs.msg import Float64MultiArray import numpy as np # Gravity compensation torques per joint (N·m), calibrated statically at 8 configs # g_c[i] = torque needed to hold joint i at q=0 against gravity # sign: positive = torque resisting gravity pull-down at neutral config G_C = np.array([0.0, 3.62, 1.85, 0.44, 0.21, 0.06]) # 6-DOF arm G_AX = np.array([0, 1, 1, 1, 0, 1]) # which joints fight gravity (1) vs not (0) class GravityComp(Node): def __init__(self): super().__init__('gravity_comp') self.create_subscription(JointState, '/arm/joint_states', self.js_cb, 10) self.pub = self.create_publisher(Float64MultiArray, '/arm/gravity_torque', 10) def js_cb(self, msg): q = np.array(msg.position[:6]) # first 6 joints # For revolute joints fighting gravity: tau_g = G_C * cos(q) # (valid for joints whose gravity torque is a cosine of their angle) tau_g = G_AX * G_C * np.cos(q) out = Float64MultiArray() out.data = tau_g.tolist() self.pub.publish(out) def main(): rclpy.init() rclpy.spin(GravityComp()) rclpy.shutdown()
The highlighted line is the gravity compensation formula. For a revolute joint rotating about a horizontal axis, the gravity torque is G_C * cos(q): maximum when the link is horizontal (q = 0), zero when it points straight down (q = π/2). The static calibration of G_C requires holding each joint at three to four angles and measuring the torque required for equilibrium — something FollowBot's current strain-wave gearboxes can report via motor current sensing.
With this node running, the PD controller's effective plant has gravity removed from the equation of motion. The feedback gains can now be tuned purely for inertia and disturbance rejection — which is easier, more linear, and more consistent across the workspace. Measured cross-track error on the figure-eight trajectory drops from 8.2 mm (pure PD) to 3.1 mm (PD + gravity comp), satisfying the Stage 3 milestone spec of <5 mm.
With this lesson, FollowBot's arm has: (1) full dynamics model from Lagrangian derivation (Lesson 3.2); (2) PID velocity controller tuned to settling-time spec via Ziegler-Nichols + root locus refinement (Lessons 3.4, 3.6); (3) feedforward from gravity compensation reducing figure-eight cross-track error from 8.2 mm to 3.1 mm, below the 5 mm milestone spec. The computed-torque controller is implemented and validated in simulation; hardware deployment awaits full dynamic system identification scheduled for Stage 6 (sim-to-real).
WEAKNESSWhere this bites
Simulation uses the same model that the computed-torque controller uses, so the controller looks perfect in sim. In simulation, the inertia error is zero by construction. On hardware, the actual arm has cable mass, fastener eccentricity, joint flexibility, and thermal drift that the model does not capture. A computed-torque controller tuned in simulation with correct model parameters will diverge on hardware where inertia differs by 30%. The feedback gains were chosen assuming M(q) is exact — they are not strong enough to reject the residual coupling that emerges when M̂ ≠ M. The fix is not better tuning; it is system identification on the actual hardware before choosing the feedforward architecture. Using computed-torque on an arm you have not dynamically identified is the fastest way to produce impressive simulation results that fail embarrassingly in a demo.
The separation principle holds when the feedforward path is computed from the desired trajectory (qd, q̇d, q̈d) only, not from the actual state. Many textbook implementations and ROS control packages compute the model terms M(q), C(q, q̇) using the measured joint state q, q̇. This is convenient and has better tracking when the model is correct, but it introduces a feedback path through the feedforward term: errors in q change the feedforward torque, which changes q. The closed-loop poles are no longer what the linear analysis predicts. At small model errors this is benign. At large model errors (30%+ inertia mismatch) you may observe oscillations that look like PD gain tuning problems but are actually feedforward instability caused by this hidden feedback coupling.
Gravity compensation is robust, but it is not free of failure modes. The most common: assuming the gravity model is separable across joints (gtotal = sum of per-joint terms), which holds only if links have no coupling through shared mass distributions. For compact designs where joint 3's motor housing hangs past joint 4's rotation axis, the gravity torque at joint 4 depends on the configuration of joint 3. A simplified per-joint gravity model will produce a position-dependent bias that looks like — and is often misdiagnosed as — a PD integrator tuning problem. The fix is to compute g(q) properly from the full kinematic tree, not per-joint approximations.
KEY INSIGHTHow this connects
- 3.2 · Lagrangian Dynamics: Energy Methods and the Equation of Motion — the M, C, g matrices used in this lesson are derived there from first principles using the Lagrangian. Computed-torque control is only possible if you have those terms in closed form.
- 3.4 · PID Control: Derivation, Tuning, and When It Fails — pure PD is the baseline this lesson improves on. The tuning methods and stability analysis from that lesson govern the feedback term in the feedforward+feedback architecture.
- 3.6 · Frequency-Domain Analysis: Bode Plots and Robustness Margins — the feedforward-feedback separation principle is why frequency-domain stability margins remain valid when feedforward is added. The Bode margins from that lesson still characterize the feedback loop's robustness, independently of the feedforward path.
- 3.8 · State-Space Representation and LQR → — LQR extends the linear quadratic framework to optimal state feedback. Computed-torque makes the arm a linear system; LQR is the natural next step for choosing feedback gains optimally within that linear framework, rather than by hand-tuning Kp and Kd.
Feedforward is not a replacement for feedback — it is a way to reduce the burden on feedback by canceling predictable nonlinearities. The right mental model: feedforward handles the physics you understand; feedback handles the physics you do not. Better models shift work from feedback to feedforward. Model uncertainty shifts it back. Stage 6 (sim-to-real) closes this loop by providing tools to measure model error quantitatively and decide how much feedforward you can safely trust.
GLOSSARYKey terms introduced
- Feedforward control
- A control signal computed from a model of the plant and the desired trajectory, applied before any error occurs. Reduces tracking error by predicting required inputs rather than reacting to deviations. Complementary to feedback control, not a replacement for it.
- Inverse dynamics
- The computation of the joint torques required to produce a specified joint acceleration, given the current configuration and velocity. The reverse of forward dynamics (given torques, compute acceleration). Produces the feedforward torque command τff = M(q)q̈d + C(q,q̇)q̇ + g(q).
- Computed-torque control
- A nonlinear control law that uses the full inverse dynamics model to cancel the arm's dynamics, reducing the closed-loop error system to a decoupled linear double integrator that can be controlled with simple PD gains. Also called inverse dynamics control. Exact linearization is achieved only when the model is exact.
- Exact linearization
- A nonlinear control technique that uses the known system dynamics to cancel nonlinearities analytically, leaving a linear plant that can be controlled with linear methods. Contrast with local linearization (Taylor expansion around an operating point), which is only valid in a neighborhood. Computed-torque achieves exact linearization for the arm EOM globally, given perfect model knowledge.
- Gravity compensation
- Partial feedforward that cancels only the gravity term g(q) from the equation of motion. The most robust feedforward addition because gravity is a static function of configuration (independent of velocity), is the largest nonlinearity at low speed, and can be identified without dynamic experiments. PD + gravity compensation is the standard industrial deployment strategy.
- Feedforward-feedback separation principle
- The property that a feedforward path computed from the reference signal only (not the actual state) does not affect the closed-loop poles of the feedback system. Stability margins analyzed for the pure feedback loop remain valid when feedforward is added. Allows independent tuning of the two paths.
- Model error amplification
- The phenomenon by which errors in the dynamic model used for computed-torque control produce tracking errors that are disproportionately large compared to the model error magnitude. Arises because computed-torque divides the motor command by the model inertia, amplifying inertia estimation errors. A 30% inertia error does not cause 30% worse tracking — it destabilizes the linearized plant assumption.
ACTIVE RECALLCheck your understanding
Answer in your own words first, then reveal.
1What is the feedforward torque computed by inverse dynamics, and what assumption makes it exact?›
The feedforward torque is τff = M(q)q̈d + C(q,q̇)q̇ + g(q) — evaluated at the desired trajectory state qd, q̇d, q̈d. This is the torque the arm would need to achieve exactly the desired acceleration if the arm dynamics were exactly as modeled. The assumption that makes it exact is that the dynamic model (M, C, g) is a perfect representation of the physical system. In practice, this assumption is always violated to some degree due to unmodeled mass, joint flexibility, and friction nonlinearities. The feedforward reduces but does not eliminate tracking error; the residual error is handled by the feedback term.
2Why does computed-torque control fail more severely than pure PD when the inertia model is wrong by 30%?›
Pure PD does not use the inertia model at all — its feedback gains are tuned empirically and do not depend on knowing M. When inertia changes by 30%, the PD controller's closed-loop bandwidth changes roughly proportionally — it is slower or faster than intended but remains stable. Computed-torque, by contrast, explicitly divides the motor command by the model inertia M̂ to cancel it. When M̂ ≠ M (the actual inertia), this cancellation is incomplete — the residual inertia (M − M̂) reappears as an unmodeled nonlinear coupling that acts as a disturbance. Worse, the PD feedback gains were tuned for the linearized plant that computed-torque was supposed to produce, not for the actual plant with the residual coupling. The gains are simultaneously wrong in a way PD gains cannot be, because PD gains are not premised on exact linearization.
3State the feedforward-feedback separation principle and give one concrete consequence for how you should tune a computed-torque controller.›
The separation principle: if the feedforward term is computed from the reference trajectory only (not the measured state), it does not appear in the closed-loop characteristic polynomial of the feedback system. Stability and bandwidth of the feedback loop are determined solely by the PD gains and the plant, independent of the feedforward path. Concrete consequence: you can add, remove, or modify gravity compensation without re-tuning Kp and Kd. Conversely, you should tune the PD feedback gains with feedforward disabled (or in the absence of any feedforward), verify the stability margins, and then add feedforward — the margins will be unchanged. If the margins change when you add feedforward, the feedforward is feeding back through the actual state measurement, violating the separation principle's premise.
4Why is gravity compensation the most robust first upgrade from pure PD, and what is its characteristic failure mode?›
Gravity compensation is robust for three reasons: (1) the gravity term g(q) depends only on joint position, not velocity or acceleration — it does not amplify with speed, so errors stay bounded at all motion rates; (2) gravity parameters are identifiable from static experiments (hold at equilibrium, measure torque) — no dynamic trajectory execution is required, minimizing identification error; (3) it does not affect the feedback loop's frequency-domain behavior (separation principle), so it cannot destabilize a working PD controller. Its characteristic failure mode is assuming per-joint separability of the gravity model. When one link's mass center is close to another joint's axis, the gravity torque at that second joint depends on the configuration of both joints. A per-joint approximation produces a configuration-dependent steady-state bias that is often misdiagnosed as PD integrator saturation. The fix is to compute g(q) from the full kinematic chain.