21 Jan 2012

Hexapod Robot with 3 DOF legs (degree of freedom)

This is an upgrade of the Hexapod Robot with 2DOF leg here:

So far we have:





I have ordered parts from Lynxmotion, but they don't have them in stock, so I will have to wait for another 1 or 2 months. Before that, I will build a smaller version hexapod robot to implement the algorithms.

Most of the parts in this project would be inherited from the 2DOF version robot, except the base.

I wanted to make a servo interface with the shield I bought off ebay, which would making it so easy to install the servos without making a mess. In theory i could use 48 servos on a Mega board, but I only soldered 20 servo ports, just to keep wires tidy and compact. I need only 18 servos for the legs and possibly 2 for the sensors anyway.

I am leaving some space on the right hand side of the board to put a adjustable voltage regulator in, as I am planning to use 8xAA batteries, or 3 lipo 11V batteries in the future.


Redesigned and made another base, with smaller diameter and larger thickness. the Previous one was too thin that it actually bends a little when it's standing.

found that when casting float to int, numbers are floor rounded e.g 4.4 = 4, 4.8 also = 4. which would introduce round-off error. need to implement number casting function to resolve this.

int FloatToInt(float input){
                // this is an alternative to cast number directly, to avoid floor rounding

                int temp = (int)input; // floor-rounded input
                float dif = input - (float)temp;             //
                if (dif < 0.5)            return temp;
                else                          return temp+1;

Also there is another problem with responding speed. I check the resulted in the C++ code against the simulation excel spreadsheet, found the error margin is quite big, because I was using int for all the calculations. I then change all of them into float. Although it works on the robot, but the responding time increased quite obviously, also the robot movement become unstable. I think it's because of the computational power of the Arduino just isn't good enough to do pure floating point IK cacluation. I will need to think of a way to balance between accuracy and computational load.

I have also place 2 4xAA battery holders in parallel to supply more current, because i found it could draw up to 1.5A when the servos are loaded which causes voltage to drop and fail to supply enough current and lead to legs paralysis.


Found a coupld of bugs in the algorithm, thanks to my Excel spread sheet simulation! Now the pitch and roll movements finally work properly, although the legs are still quite unstable. I still don't know why that is, maybe the dimension is still not correct, or maybe there are still bugs in the algorithms.


I have now adapted rotation matrix in Body IK algorithm, instead of estimating coordinate changes, i will be using formula derive from rotation matrix to calculate these changes (detail could be found in my last post, IK implementation).

I have also started to use micro seconds instead of degrees to write servos.

I have also had a major modification on the legs. It's now doubled the length of the original.

Found a problem with pin22 and pin32 when using them as servo pins. These two pins interference with each other, ie, control one of them would control the other one too. Luckily I made 20 pins, so I can just easily move up all the pins by 1, ie, now using 23 - 41.

We had a water tank overflow on the roof tonight, was a bit scary and we spent hours looking at the problem, so didn't do much testing on the new setup. will try tomorrow.

The main problem with it at the moment remains to be leg-end position accuracy. I don't know whether it's the hardware or the software. But since I have move all the calculation into floating point, it should give relatively good numerical results.

I have started looking at Gait, might implement 6 step ripple gait first.


Last night, I implemented a simple 6 step ripple gait, which I will explain in a minute. Let me explain what's the problem I discovered first with the IK algorithm.

When the legs are meant to move along Z axis, the front and rear legs are actually moving toward Z-X direction, which is not right. So I wrote a test program to test the leg IK algorithm by checking the actually physical change of the leg position, versus the coordinate I entered manually. Again the legs won't move solely along one particular axis (X or Z), but tend to go somewhere in between.

Spent an evening thinking about it, realize the original idea of calculation IK isn't perfect for my type of hexapod robot, which each leg are in a different frame (frame - Axis system), but I have always been assuming they are in the same frame as the center of body. for example, the frame of the front right leg is rotated -30 degree from  the frame of the center of body (see below picture), so before we calculate the change of angles from leg IK algorithm, we need to do coordinate transformation first, to convert it from body frame to the coxa frame.

A common way would be using rotation matrix. detail please go to my IK implementation post.

after the modification, the robot can finally walk like one. ; )


Good news from Robotshop! My parts have finally arrived their warehouse and has been already shipped to me. So I got to hurry up finishing body balance algorithm this week (probably my last implementation on IK)

This weekend I:
1. tidied up the code a lot!
2. implemented fast SIN, COS, ACOS functions (about 10 times faster than standard C trig functions! body rotation is so much smoother now)
3. implemented 7 more gaits (thanks to Jeroen Janssen's source code, I copied most of the stuff over)
    (1) Ripple 12 steps
    (2) Quadripple 9 steps
    (3) Tripod 4 steps

    (4) Tripod 6 steps
    (5) Tripod 8 steps
    (6) Wave 12 steps
    (7) Wave 18 steps

4. modified code to avoid using 'delay()', but to get the time using 'millis()', so processor can do other stuff while waiting rather than just freezes there. Also brings a bit more smooth movement there.

All looking great! however because I am getting so many functions and gaits now, I am having trouble with controls... nun-chuck is simple and handy, but it's very limited in terms of control options. I might need to come up with a menu system that I can switch between modes (body rotation, walking mode), and under walking mode i can also switch between gait types... I just love the nunchuck and don't want to replace it!


Took me 2 weeks to assemble the new body from Lynxmotion... (13 days of watching TV and 1 day of actually working :p ). The new body is great, although a bit too heavy than i thought it would be. The servos and the battery works very well together, max current supply is now up to 30A !!

Haven't been doing too much, so couldn't update. Just posted another video showing all the gaits, with or without Balance mode. also wrote a menu system for the Wii remote, so it's easier to switch between body rotation and walking modes, also different gaits... Here it is:

Each box represents a state, and I have 3 LEDs to indicate the different states I am in...

I have also tidied up the code a lot!!! reduced about 50% of the lines... although there are more functions.

I am still thinking should I use an extra Arduino to load the sensors for my next goal... maybe i should try it without first...

that's it....


I started learning writing Android Apps in Java recently, and I always wanted to go 'cordless', so I decided to write one for controlling the robot via bluetooth.

It was quite tough at the first few days, had no clue what to do since I had no at all experience on android app development, especially the bluetooth part, I can get it to be switched, that's about it!

Luckily I bumped into a couple great source code showing how to use bluetooth and simple graphics design (I used surface layout):

I wrote my first android app that controls LEDs on the arduino.


The Hexapod Robot Controller App is finally looking promising.

Here is the communication design:

Command format:
4 bytes
[type]    [x]     [y]    [extra]

type - is the type of action, or type of command
x      - first input, could be the input of X axis
y      - second input, could be the input of Y axis
extra - third input, e.g. speed of the movement, or just 0 if not needed

1. arduino will wait for a start-up command from the phone
2. arduino sends a signal back to the phone when it's available to process another command
3. the phone sends command whenever the 'acknowledge signal' is received from arduino, even input is 0.


need to do:

1. to adjust speed, add extra packet
     when adjusting speed, delay of driving each servo would also change
     cap min and max speed, probably 1 to 30
     delay = (int)20/resol;

2. i can't adjust speed while controlling the robot walking, so i need to add a toggle switch,   to lock down the movement input, so i can adjust speed.
     add code and radio button for translating around Y axis
     add code, so when using Acce for Z, X rotation, the joystick can do Y rotation


Because I didn't setup the servo constrain properly, tragedy happened! The teeth of the gear (the top copper one) are broken... probably happened because it was forcing it while the servo can't move anymore... i could see how this happened! Luckily ( should i say that?) they have gear on ebay, although it's not cheap but still better than buying a new one which is nearly 30!

Now I just have to wait!!! Hate!!!


Fantastic! The part finally arrived! What's even better is, the ebayer sent me the whole servo instead of the gear... haha, one's mistake is the other's gain! sometimes.. :-)

so let's fix it and make a video about my new android control app!


To Do:
1. Implement Fast trig functions

2. Convert Angles in degree/radian to MicroSeconds and use micro seconds to drive servos.

3. implement first Gait Sequence Generator

4. implement different Gaits

5. Body balancing algorithm

6. Automation, Sensor (IR or ultra sonic), basic AI (object following, avoiding)

7. control remotely (maybe bluetooth, or XBee)

8. Intermediate AI - Responses to outside world environment, possibly movement, or human gesture

9. Terrain Adaption - more sensors on the legs - highly linked with 5, and 8.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.