Time to work out the actual inverse kinematics for the arm. The skeleton design for the arm looks like this:
The arm is made of four bones and four hinges. The bone and hinge on the farthest left cannot be rotated independently; the arm was designed so this will rotate as the arm moves to keep the bone pointing directly down. This leaves three bones and hinges we need to model.
Using the 8BitModule visual editor, the arm IK looks as follows:
Here we have three bones with their given lengths (in mm, although units don't matter as long as they're all the same). The first hinge rotates around the z-axis, the remaining two around their relative y-axes. The relative direction of each bone is along the +ve z-axis (the arm is a straight line).
With this IK configuration we can now set the end of the arm (the effector) to the desired location and read back the generated angles for the hinges.
On the right-to-left stroke the tip of the arm (effector) attempts to stay on a straight line (it moves between five points). The code for this looks like this:
The arm consists of two "bones" hinged on the same axis. This code moves it on a path every 8 seconds, with each movement taking a second (so 5 seconds of movement, with a 3 second pause). The IK part is given the point to place the effector, and generates the angles for the two arm servos.
The mechanical design of this robot arm was extensively cribbed from the MeArm Classic design (see here https://shop.mime.co.uk/collections/mearm). While the physical arm looks very different - I wanted something a little less skeletal - the way the outer beams and internal rods interact to keep the effector (that's the end bit of the arm) parallel to the ground at all times, was based on the MeArm. My goal is to add different effector attachments to the arm, and this design makes that super simple.
Three servos move the arm; one servo rotates the arm around the base, while the other two move the arm up and down, forward and back. When the servos move together, the upper arm moves forward and back; if one servo moves independently, the lower arm moves up and down.
The above shows the section of the arm: three main pieces for the arm and three arm rods to coordinate the movement (plus a few other bits to hold it all together). The rods are connected to the main arm pieces using pins to allow them to move as the arm moves, so keeping the effector parallel.