Feedforward and Compliant Control
If you ask a stiff position controller to wipe a whiteboard, you're asking for trouble. Misjudge the wall's distance by two millimeters, and a stiff controller treats the wall like an error to crush — slamming motor current to maximum until either the marker snaps or the wrist faults out. Humans don't wipe tables by locking their joints like concrete; we keep our arm springy and let the surface guide our hand.
Core ideas covered in this module
- Gravity compensation feedforward
- Computed torque control
- Virtual spring-damper impedance control
Feedforward: paying gravity before the error happens
The cleanest upgrade you can give any feedback controller is feedforward: instead of waiting for gravity to pull the arm down so PID can notice the error, you compute g(q) ahead of time and add it directly to the motor command.
Take that idea one step further and you get computed torque control: compute the full model τ_ff = M(q)q̈_des + C(q,q̇)q̇ + g(q) in feedforward, and let a gentle PD loop clean up whatever small friction or modeling errors remain. Because feedforward handles the heavy lifting, your feedback gains don't have to be brutally stiff anymore.
Impedance control: programming a virtual spring and damper
Once gravity compensation holds the arm weightless in mid-air, what should happen if someone bumps the wrist or a table blocks the gripper? With impedance control, we stop commanding rigid positions and instead make the end-effector behave like a tunable virtual spring and shock absorber attached to the target:
- When the path is clear, the virtual spring pulls the hand cleanly to the target.
- When a rigid surface or human hand pushes in, the arm yields smoothly along the virtual spring instead of fighting at max torque.
- Tuning stiffness K sets how firm the touch feels; tuning damping B keeps rebounds smooth and calm.
Interactive lab
Interactive Impedance Control Sandbox
MuJoCo WASM· LiveChoosing stiffness for the task
Compliance doesn't mean floppy everywhere. When carrying a heavy tray across a room, you might dial K up high along vertical Z so the tray stays level, while keeping K soft along X and Y so bumping a doorframe doesn't spill anything. That directional stiffness — plus gravity compensation underneath — is what turns a rigid industrial robot into a safe collaborator.
Gravity-compensated impedance control
τ = g(q) + J(q)ᵀ [ K (x_target − x) − B · ẋ ]
Gravity compensation g(q) cancels weight ahead of time, while the virtual spring K and damper B translate end-effector deflection into safe, bounded joint torques via Jᵀ.
A robot is trying to insert a snug peg into a chamfered hole that might be offset by 3 mm. Why does compliant impedance control beat stiff high-gain PID here?
Virtually every modern contact-rich manipulation stack — from surgical arms to diffusion policies inserting USB plugs — runs an underlying impedance or operational-space controller with gravity compensation so learned trajectories stay safe during real physical contact.
Hands-On Python Notebook
05 · Gravity Compensation & Impedance Control
Combine feedforward gravity compensation with Cartesian virtual spring-damper impedance control against a stiff contact wall.
Try this on your own inside the notebook
- Compute contact force vs. stiffness K when pressing into a wall
- Tune damping B to eliminate bounce after wall impact
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-4/05_feedforward_impedance_control.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.