Hexapod Robot for the P1/P2
There are several hexapod robots out there but none of them are for the P1 or P2.
I did see the quick bite that controlled 16 servos so this project will need to control 18 servos. This winter project will actually make use of those servos, not just make them turn.
All the part will be 3D printed and require minimal hardware to put it together. I am a little concerned about the small servos sold by parallax. They have a working voltage of 3v to 4.8v. Why did they stop before 5 volts which is a very common voltage to use? Anyway, the servos that I will be using for this first go around will be some generic servos so all the part will be fitted for that purpose. My next build I will try to use the Micro bit servos.
This project will require floating point math as well as some geometry functions to calculate the position of all six legs. Inverse kinemetric.
So far, I have designed and printed the Coxa (hip), Femur, and Tibia (claw). In addition, I also printed a top and bottom shell to attach the legs to.
One additional Item that I need is the servo controller. Either I use PCA9685 or I need to build a servo board to power the servos and run 18 wires for each servo.
Once the unit is assembled, I can set the servos to 90 degrees and start to calculate the x, y and z position of each leg.
I also plan to use an ESP8266 to send commands to the robot.
Mike
Comments
I have not worked with these servos before so I thought I should check to see what PWM I need to send to get to 0, 90, and 180 degrees. Then I can develop a formula to convert angles into PWM values.
Here is the program I used to run the servo through its paces:
So, the range looks like 1950 or 10.8 pulses per degree. I used 10 times that and then divided it back out so I could avoid using floating point.
It's nice to be able to plug all this in and have it work. It took a while to solder the servo driver board and its only half done at this point.
Here is a video of the servo and rig in action:
Servo Rig
Mike
It's been a while and I have been banging my head to see how to calculate the position of the leg knowing the angle of the coxa, femur and tibia. With the Scara I built before there were only two angles to consider and the Z axis was just the height you set. This is not the case with a Hexapod leg as it is moving in 3 dimensions at the same time.
The legs are attached along the body of the Hexapod at known points, so this is easy enough to figure out. This leave 6 calculations for each of the legs. The calculations are to determine from the center of the Hexapod where each leg will land in the X and Y plain. In addition, we want to know how high or low the leg is in the Y plain.
From the above drawing there are a few things we know to help us figure out the value of X and Z. One of the problems is that each leg is mounted at an angle from the center of the Hexapod so that 180 degrees can be made use of with moving the servos around. This later will become and offset value.
One more thing is that looking down at the servos they turn counterclockwise from 0 degrees to 180 degrees. Since the servos are mounted to the top plate of the Hexapod they turn backwards so the angle will have to be subtracted from 180 to reverse the movement of the servo. The other two servos on the right side turn in the correct direction but the servos on the left side need to be reversed as well.
The legs are numbered from 1 to 6 in a counter clockwise fashion. The first servo is in the upper right corner and the 6th servo in the upper left corner.
Now to calculate X and Z knowing that the servo at a is 23 degrees from the Z axis and the servo at b is 42 degrees. Now if the angle at b was 90 degrees the distance between a and c would be the square root of a squared plus b squared. That only happens once in 180 degrees so that can’t be used.
We can however use the two right triangles that make up the femur and the tibia to get the distance of X.
So the X distance is 44.28. Now we need the Z distance which is the difference between the a height and the c height using the other side of the two right triangles.
That would make the difference -15.56 plus the height of the unit which is 17, so the leg is almost touching the ground.
Now we need to put it all together to find the X, Y, and Z point of the leg. The coxa is at 45 degrees making the final values as follows:
If this was leg 1 then it would be located at X=76.21 (41.21 + 35) and Y=91.21 (41.21 + 50).
This is all good but now I need to make the hexapod move and this is done by giving each leg a new location from where it is now. To do this we need to be able to determine the three angles based on the given X, Y, and Z point.
Leg 1 is located at (76.21, 91.21, 1.44) what angles make up this position:
The coxa angle is 45 degrees and using the law of cosines I can determine the tibia angle:
I can use the same formula to get the femur angle:
From this angle we need to subtract 90 degrees to move it from the Y plain to the X plain. Now this angle is the angle of the femur-tibia and not associated with the X access. To get that angle we need to subtract the angle made by the X access and Z. We will use the arc tangent so that we get the proper sign of the angle so that we add or subtract that angle value to get the true femur angle.
So the femur angle is 23 degrees.
Using these two methods I can now determine where a leg is and how to place a leg.
Next step is write an interface program so that I can talk to the hexapod and tell it where to place the legs so that I can do calibrations. With attaching the servos to the legs the resulting angle is not correct and I will need to adjust those angles so that the leg will be at the point that is calculated. In addition the hexapod needs to have all the servos at the same angle so that when putting the leg together the legs are at the correct starting point. Having all the servos at 90 degrees, which is the mid point of the servos angle, it is easy enough to see if the joints are at that angle for assemble. In addition any servo can be used for any joint so assemble is straight forward.
After some snafu's I got the Hexapod assembled.
I decided to update my servo library to include the servo angle function as well as being able to set the servo range. This interduce a bug that required several iterations to find it. It led me down several roads before I backed up and found it.
Anyway I now have the Parallax ESP8266 working with my control program written in C#. I'm able to use a pull down and have it find the ESP8266 unit and then make a connection to it so I can send commands. Right now I only have 3 commands: Get current angle of a leg, Move a leg or legs to an angle, and Move a leg to an X/Y position.
So using visual code to write the program for the P2 and using visual studio to write the control program worked out nicely. I had to account for servos on the left moving counterclockwise and also account for errors in assembly that led to an adjustment value for all the angles.
To communicate with the Hexapod I connect up to the telnet port on the ESP8266 and send it JSON objects which are broken down and then a JSON object is return to the Hexapod control program. At first things were not working until I found out that the C# program was sorting the JSON object fields. This led to a dilemma of either interpreting the object that way or finding another way to encode the JSON object so the fields were in the correct order.
I was able to find another way to encode the data so that the fields were in the correct order and all is good. One of the nice things is that I can have the visual code connected to the Hexapod at the same time the visual studio control program is connected. That way I can see the raw JSON data coming back from the Hexapod.
As you will see from the video fitting all that wire into the cavity of the Hexapod was a little bit of a challenge. I still need to find room for the battery.
Here is a capture of the Hexapod control program screen:
The P2 Hexapod firmware:
Sample of the JSON data:
Video of the Hexapod in action:
YouTube Video
Next step is to make it walk.
Mike
Hexapod Parts
Success, The Hexapod is walking using Gate1.
Gate1 is where three legs are lifted while the other 3 hold up the hexapod. Then move the up legs forward and the down legs backwards. From there you put the three legs down and repeat the process. To move the exact distance, you would divide the distance by 2.
I had to update the code so that I could tell when a movement was complete before moving to the next. A new function was added call move hexapod.
Updated code with move hexapod added:
Mike