Step 4
Feedback: P and PD control
Close the loop: measure the error and push against it. Then add damping so the base stops where you want.
Open loop can't react
Step 3's timed torques worked because nothing got in the way. If something bumps the arm, a timed plan carries on regardless. Feedback (a closed loop) measures what actually happened and corrects it, hundreds of times a second.
Proportional control
The error is how far the joint angle is from where you want it: . A P controller pushes in proportion to it:
, the proportional gain (N·m per rad), acts like a spring pulling the joint to its target. A spring with nothing to slow it bounces for ever, and this base has no friction at all: it swings past the target, back, and past again.
Add damping
A PD controller adds a push against the angular velocity :
, the derivative gain (N·m·s/rad), works like a shock absorber. Too little and the joint still overshoots; too much and it creeps. The sweet spot, critical damping, is
where kg·m² is the base's moment of inertia in this pose (you measured it in step 3).
Saturation
The base motor gives at most 10 N·m. With , a 1 rad error asks for 40 N·m, so at first the motor is flat out (saturated), and the PD law only takes over near the target. Bigger gains react harder, but they can't make the motor any stronger.
Pick & Place's position servos run this same PD law for you: see Pick & Place, step 1.
Your task
- Write
pd_torque(q, qd, target, kp, kd): the PD torque for one joint, withqfor andqdfor . - The program runs P only (
kd = 0) for 3 s: watch it swing in Plots. Then it steps the base from 0 to 1 rad with yourKPandKD, and pushes the hand sideways 1.5 s in. - Choose
KD. The step must settle within ±1° in 1 s and overshoot (go past the target) by under 5 % of the step, and after the push the base must be back within ±1° in under 0.8 s.