CrackRobotics

Step 1

Joints, targets & PD control

Command joint angles, let physics run, and meet the PD controller behind every industrial arm.

Meet your robot

The arm in the viewer has four joints:

#JointMovesAxis
0basespins the whole armvertical (z)
1shouldertilts the upper armhorizontal (y)
2elbowbends the forearmhorizontal (y)
3wristtilts the gripperhorizontal (y)

A list of angles like [base, shoulder, elbow, wrist] is called a configuration, written qq. Angles are in radians, and the pitch joints are measured from straight up.

You command targets, not motion

Real robot arms almost never take motor torques straight from your program. Each joint runs its own PD position controller hundreds of times per second:

τ=kp (qtarget−q)−kd q˙\tau = k_p\,(q_{\text{target}} - q) - k_d\,\dot q

Your job is to send target angles. The controller pushes the joint towards the target (the kpk_p term) and damps the motion so it doesn't overshoot (the kdk_d term).

The second big idea is that nothing moves until simulated time passes. arm.set_joint_targets(q) only changes the target. sim.wait(seconds) then runs the physics. Real robot code has the same shape: a command is sent and then the program waits for the motion to finish.

arm.set_joint_targets(q)   # jump: moves as fast as it can
arm.move_joints(q, 2.0)    # glide there over 2 s
sim.wait(0.5)              # run physics for 0.5 s

Your task

  1. Move the arm to the ready pose [0.0, 0.5, 1.5, 1.14] and hold it for at least half a second. Notice that 0.5+1.5+1.14≈π0.5 + 1.5 + 1.14 \approx \pi, which points the gripper straight down.
  2. Turn the base to face the cup. world.cup.position gives you (x,y,z)(x, y, z). The base angle is measured from the +x+x axis, so you need atan2⁡(y,x)\operatorname{atan2}(y, x).
  3. Close the gripper, then open it again.

Press Run and watch the result replay in the viewer. Try swapping move_joints for set_joint_targets to see the difference.

Goals

  • Program runs without errors
  • Reached the ready pose and held it for 0.5 s
  • Base faces the cup at the end (within 3°)
  • Gripper closed, then opened again
Loading physics…
Loading 3D view…
0.0 / 0.0 s

Python is loading. It takes a few seconds the first time.