The general coordinate transformation structure for controlling the robot arm is as shown below.
Converting from pixel position to 2D image coordinates either involved using the AR tags to determine the width and height of the canvas or manually presetting the width and height of the canvas in mm, and then finding the distance of the pixel position to the center of the image and scaling that value appropriately. Converting from 2D image coordinates to 3D robot coordinates either involved using the AR tags to determine the center of the canvas or manually presetting the center of the canvas in mm, and then translating the coordinates as appropriate. It also relied on the assumption that the canvas would be completely flat and had a premeasured height. Converting from 3D robot coordinates (Cartesian coordinates) to modified spherical coordinates used the measurements from the Sawyer arm found below.
For our implementation, the equivalents for the spherical coordinates we computed were the horizontal rotation angle (φ), vertical rotation angle (ϴ), and compression length (r).
The horizontal rotation angle is directly controlled by the first joint, where joints are ordered from the base to the end effeector. In contrast to how φ is computed from Cartesian to spherical coordinates, the horizontal rotation angle has an offset due to the fact that the end effector isn't directly aligned to the base of the robot.
The vertical rotation angle is directly controlled by the second joint and sixth joint, where the purpose of the sixth joint is to invert the rotation of the second joint to keep the end effector vertical. In contrast to how ϴ is computed from Cartesian to spherical coordinates, the vertical rotation angle is computed as the angle below the xy plane to the axis orthogonal to the robot arm.
The compression length is directly controlled by the fourth joint, which compresses the elbow of the robot arm, and the second and sixth joint are adjusted in order to avoid affecting the vertical rotation angle and keep the end effector vertical. The desired radius is subtracted from the maximum radius of the arm in order to compute the compression length, and this length is used with the 400 mm arm lengths to determine the second, fourth, and sixth joint angles with standard trigonometric formulas.
The video on the left demonstrates the motions along the modified spherical coordinates. The exact details for the formulas and calculations can be found in the code in controller.py.