Project 4: joint PD and gravity compensation on the 7-DOF arm

Level 8 (after Lessons 8.1 and 8.2) · Time 3 hours · Difficulty 2 of 5

Objective

Implement joint-space PD and PD with gravity compensation for models/arm7.xml (torque motors on all seven joints), design the gains from the arm’s own inertia, and characterize the step response. Then predict, without simulating, how far the arm sags when the compensation is switched off.

Prerequisites

Starter code

starter.py asks for two constants and three functions:

Expected behaviour

All results below are from the reference solution ($\omega$ = 18 rad/s, $\zeta$ = 1) starting at the home keyframe with a 0.3 rad step on every joint.

Tests

MJC_IMPL=starter pytest projects/p04_joint_pd
pytest projects/p04_joint_pd

Four tests: gains of the right shape and sign; the compensated step (overshoot under 5%, within 1% after 0.5 s, every command inside ctrlrange); the steady error without compensation within 10% of your prediction on every loaded joint; and the compensated steady error under $10^{-4}$ rad. The common failures are mutants in mutants.json. python tools/mutate_project.py p04_joint_pd checks that each one fails: the first-order prediction fails the third test, and $\omega$ = 12, unclipped torques and ignored armature fail the second.

Common failures

Extension challenges

  1. Gain scheduling: recompute the gains from mj_fullM every step, and show the zero-pose step now meets the same criteria.
  2. Replace the diagonal design with $\tau = M(q)(\omega^2 e - 2\zeta\omega \dot q) + \text{bias}$ (computed torque) and compare overshoot and peak torque.
  3. Add 20 ms of actuator delay and find the largest $\omega$ that still settles without ringing.

Solution

solution.py, about 35 lines.