Jacobians & Velocity Control, step 4
Newton's method for IK
Solve inverse kinematics for any target by repeating small Jacobian steps until the error vanishes.
Builds on Optimisation: gradient descent and Least squares: fitting noisy data, from the free Foundations.
Write and run this step in the simulator with ProIK without a formula
The closed-form IK from Pick & Place only works because this arm is simple and the gripper points straight down. Most arms have no neat formula, so general-purpose solvers work numerically: start from a guess and keep improving it.
Near , the Jacobian is a linear model of FK: . To close the error , solve that model for , take the step, and repeat:
This is Newton's method. Close to a solution the error roughly squares each iteration: 1 cm, then 0.1 mm, then far below anything you can measure.
Making it robust
- Redundancy. Four joints for a 3-D goal gives infinitely many solutions. takes the smallest step, so you land on a solution near your starting guess.
- Cap the step. Far from the goal the linear model is poor, and a full step can fling the arm somewhere useless or pin it against a joint limit. If rad, scale down to that length.
- Respect the joint limits. Clip to
arm.limitsafter every step. - Know when to give up. If the error isn't below 0.1 mm after 100 iterations, the target is probably out of reach. Raise
ValueError.
Your task
- Implement
numerical_ik(p, q0). It returns 4 joint angles that put the grasp point atp, starting the search fromq0. - The program then touches the three yellow targets in order with
arm.move_joints.
arm.ik() and arm.move_to() are switched off. The grader runs your solver from the home pose on 20 random targets (within 2 mm), and checks that it reports two targets that are out of reach.