# Math is Hard! Let's go Shopping!

A project log for Stubby the (Teaching) Hexapod

100% open source robot platform with accessability and affordability in mind: teaching children of all ages about robots & programming

The Big One 06/17/2014 at 19:270 Comments

So it has taken a while to get to where I am at now... trig is hard when you have not used it for 15+ years.  It is very fun to be re-learning all the stuff which I had forgotten long ago (Law of Cosines is pure beauty!  How could I have forgotten about something like that!)

Since the last log entry, there have been a few changes:

• Extend the Femurs from 30mm to 50mm; this allows a much more full range of motion for each leg (I hope it still allows the robot to stand... that discovery will hopefully take place tonight).
• A full inverse kinematics implementation, plus extra trig code to account for the indirect drive system used in the servos for better mechanical advantage.
• The addition of a 'simulation' folder with associated makefile, which prints out the desired angles, servo angles, and PWM values for each leg as it is set.  This simulation can be run on the command line and gives values which can then be plugged into the CAD software for a drawing of how the legs look.

To help myself fully understand what is happening, I drew everything up in QCad, with labeled angles and lengths, and refer to each of these figures in the source code.  (I could not imagine writing this code without such a reference: 100% required IMHO).  These diagrams are included here (see source/Leg.h for explanations and references to these figures):

Below is the output of the simulation, given the actual numbers obtained from the IK for various values.  In this example, Y and Z are both 0, and the X value varies as indicated.  (Keep in mind that the co-ordinate system has 0,0,0 on the ground directly underneath the center of the robot; this gives a 45mm offset for each leg.  So, for instance when the 140mm diagram shows a coxa joint to foot measurement of 95.3mm, the 45mm offset from center shifts it to be correct (95 + 45 = 140).

The updated frame plans (to include 50mm femurs), to be cut from 1/4" MDF, are here (and it still fits on a single 8.5x11" sheet of paper!):

Now that everything is working in simulation, the next step is to verify that it also works in real life.  Assuming I can move every leg to an arbitrary position in x,y,z co-ordinate space, I can then start the animation (gait, movements, etc).

And once that happens, I will post some more videos. :-)