Dynamics & Torque Control, step 2
Gravity compensation
Cancel gravity with the arm's own model: it floats wherever you leave it, and PD stops sagging.
Builds on Force, torque & gravity and Feedback: P and PD control, from the free Foundations.
Write and run this step in the simulator with ProFloating
At rest (, ) step 1's equation leaves : the torques that exactly cancel gravity. Command at every instant and the arm floats. It stays wherever it is, and nothing pulls it anywhere else. Add a little damping, , and a push makes it glide and stop where you leave it. Collaborative robots use this mode so that a person can guide the arm by hand.
PD alone sags
The PD controller (Foundations: P and PD control),
pulls each joint towards its target like a spring with stiffness (N·m per rad) and a damper (N·m·s per rad). At rest it only makes torque when there is an error , so the arm sinks until the spring holds it up, :
This is the steady-state error. A stiffer spring sags less, never zero, and stiff gains make a harsh arm that is dangerous to stand next to.
Add the model
Now the model supplies the holding torque (feed-forward), and PD only corrects what the model gets wrong (feedback). At rest , so , with the same gentle gains.
The program
It floats the arm with pd_gravity(q, qd, q, True) (the target is wherever the arm is), and at t = 0.5 s the hand gets a push. Then it glides to three poses with PD alone, holding each for a second, and does the same with PD + g. Plots shows the shoulder and elbow errors.
Your task
- In
pd_gravity(q, qd, q_des, gravity), add (arm.gravity_torques(q)) whengravityis True. - Write
predicted_error(q_des): PD alone's steady-state error for each joint.
The arm must float still and come to rest after the push, PD alone must end within 15 % of your prediction, and PD + g within 0.2° of every target.