Society of Robots - Robot Forum

Software => Software => Topic started by: bilals on March 08, 2010, 01:37:59 AM

Title: How to generate the tripod gait ?
Post by: bilals on March 08, 2010, 01:37:59 AM
This is just a solid works design for my hexapod. Its not yet complete. However i am trying to write the program for this hexapod. Let me first explain this figure:

(http://i48.tinypic.com/11jq540.jpg)

The fig shows the six legs of the hexapod (named 1-6) with 3 servos in each leg (named 1-3) for each leg. Servo one in each leg rotates about a vertical axis (normal to the ground). Servos 2 & 3 rotate about an axis into the page. To make it clearer, servo 1 moves the leg move either forwards or backwards. Servos 2& 3 move the legs upwards or downwards. This is the way i think the servos should work for a tripod gait.

First lets name Legs 1,4&5------>T1
                     Legs 2,3&6------>T2

To move forward:
1)Initially all legs are on the ground.
2)Servo2 of T1 rotates, moving the legs of T1 upward.
3)Servo1 of T1 rotates, moving the legs of T1 forward.
4)Servo1 of T2 rotates, moving the legs of T2 backward, therefore pushing the body forward.
5)Servo2 of T1 rotates, moving the legs of T1 downward.
6)Servo2 of T2 rotates, moving the legs of T2 upward.
7)Servo1 of T2 rotates, moving the legs of T2 forward.
8)Servo1 of T1 rotates, moving the legs of T1 backward (push the body forward).
9)Servo2 of T2 rotates, moving the legs of T2 downward.

I am not sure but i think this is the way.

Now, when it comes to programming how can i do that. I need to know first what are the &bank used for (In AVR studio) what are the timers for. What does TIMER1COMPAREA mean.

Can i just do it this way i.e. Servo2 of T1 rotates, moving the legs of T1 upward:

act_setSpeed(&Leg1_servo_2,150)
act_setSpeed(&Leg4_servo_2,150)
act_setSpeed(&Leg5_servo_2,150)
delay

and then do the other steps (3-9).

I know there is a better way to do it. But this is my first time programming and i am lost. Please guide me.
Title: Re: How to generate the tripod gait ?
Post by: Hasan999 on March 08, 2010, 10:53:33 AM
For the theory, I think you can find a lot of info on the WebbotLib's pdf file and/or societyofrobots.com itself, otherwise search for it elsewhere, or wait for someone to explain... but I can help you with the programming... (assuming that you've already started using Webbot Library, and it compiles successfully)

Just copy paste this code (replacing the existing webbitlib code you have)... and read all my //comments and change things accordingly:

Code: [Select]
#include "sys/axon.h"
#include "uart.h"
#include "rprintf.h"
#include "servos.h"
#include "a2d.h"

//Change the ports according to your servo connections:
SERVO &Leg1_servo_1 = MAKE_SERVO(FALSE, C7,1500, 500);
SERVO &Leg1_servo_2 = MAKE_SERVO(FALSE, A6,1500, 500);
SERVO &Leg1_servo_3 = MAKE_SERVO(FALSE, E7,1500, 500);
SERVO &Leg2_servo_1 = MAKE_SERVO(FALSE, H2,1500, 500);
SERVO &Leg2_servo_2 = MAKE_SERVO(FALSE, C1,1500, 500);
SERVO &Leg2_servo_3 = MAKE_SERVO(FALSE, A5,1500, 500);
SERVO &Leg3_servo_1 = MAKE_SERVO(FALSE, E2,1500, 500);
SERVO &Leg3_servo_2 = MAKE_SERVO(FALSE, H6,1500, 500);
SERVO &Leg3_servo_3 = MAKE_SERVO(FALSE, C0,1500, 500);
SERVO &Leg4_servo_1 =MAKE_SERVO(FALSE, A4,1500, 500);
SERVO &Leg4_servo_2 =MAKE_SERVO(FALSE, E3,1500, 500);
SERVO &Leg4_servo_3 =MAKE_SERVO(FALSE, H5,1500, 500);
SERVO &Leg5_servo_1 =MAKE_SERVO(FALSE, C3,1500, 500);
SERVO &Leg5_servo_2 =MAKE_SERVO(FALSE, J6,1500, 500);
SERVO &Leg5_servo_3 =MAKE_SERVO(FALSE, E6,1500, 500);
SERVO &Leg6_servo_1 =MAKE_SERVO(FALSE, H4,1500, 500);
SERVO &Leg6_servo_2 =MAKE_SERVO(FALSE, C4,1500, 500);
SERVO &Leg6_servo_3 =MAKE_SERVO(FALSE, A1,1500, 500);

//make sure you know which servos are in which bank (better not change this arrangement)
SERVO_LIST servo1[] = {&Leg1_servo_1};
SERVO_LIST servo2[] = {&Leg2_servo_1};
SERVO_LIST servo3[] = {&Leg3_servo_1};
SERVO_LIST servo4[] = {&Leg4_servo_1};
SERVO_LIST servo5[] = {&Leg5_servo_1};
SERVO_LIST servo6[] = {&Leg6_servo_1};
SERVO_LIST servo7[] = {&Leg1_servo_2,&Leg1_servo_3};
SERVO_LIST servo8[] = {&Leg2_servo_2,&Leg1_servo_3};
SERVO_LIST servo9[] = {&Leg3_servo_2,&Leg1_servo_3};
SERVO_LIST servo10[]= {&Leg4_servo_2,&Leg1_servo_3};
SERVO_LIST servo11[]= {&Leg5_servo_2,&Leg1_servo_3};
SERVO_LIST servo12[]= {&Leg6_servo_2,&Leg1_servo_3};

//Corresponding banks:
SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servo1);
SERVO_DRIVER bank2 = MAKE_SERVO_DRIVER(servo2);
SERVO_DRIVER bank3 = MAKE_SERVO_DRIVER(servo3);
SERVO_DRIVER bank4 = MAKE_SERVO_DRIVER(servo4);
SERVO_DRIVER bank5 = MAKE_SERVO_DRIVER(servo5);
SERVO_DRIVER bank6 = MAKE_SERVO_DRIVER(servo6);
SERVO_DRIVER bank7 = MAKE_SERVO_DRIVER(servo7);
SERVO_DRIVER bank8 = MAKE_SERVO_DRIVER(servo8);
SERVO_DRIVER bank9 = MAKE_SERVO_DRIVER(servo9);
SERVO_DRIVER bank10 = MAKE_SERVO_DRIVER(servo10);
SERVO_DRIVER bank11 = MAKE_SERVO_DRIVER(servo11);
SERVO_DRIVER bank12 = MAKE_SERVO_DRIVER(servo12);

#define threshold 8

void appInitHardware(void){
uartInit(UART1, 115200);
rprintfInit(&uart1SendByte);

// Initialising the servo controller
servosInit(&bank1, TIMER1_COMPAREA);
servosInit(&bank2, TIMER3_COMPAREB);
servosInit(&bank3, TIMER1_COMPAREB);
servosInit(&bank4, TIMER1_COMPAREC);
servosInit(&bank5, TIMER5_COMPAREB);
servosInit(&bank6, TIMER3_COMPAREC);
servosInit(&bank7, TIMER5_COMPAREA);
servosInit(&bank8, TIMER3_COMPAREA);
servosInit(&bank9, TIMER4_COMPAREA);
servosInit(&bank10, TIMER4_COMPAREB);
servosInit(&bank11, TIMER4_COMPAREC);
servosInit(&bank12, TIMER5_COMPAREC);

}
// The loopStart parameter has the current clock value in uS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

//now instead of 'values' (currently: 0) you can use variables later on...
act_setSpeed{&Leg1_servo_1,0};
act_setSpeed{&Leg2_servo_1,0};
act_setSpeed{&Leg3_servo_1,0};
act_setSpeed{&Leg4_servo_1,0};
act_setSpeed{&Leg5_servo_1,0};
act_setSpeed{&Leg6_servo_1,0};

act_setSpeed{&Leg1_servo_2,0};
act_setSpeed{&Leg2_servo_2,0};
act_setSpeed{&Leg3_servo_2,0};
act_setSpeed{&Leg4_servo_2,0};
act_setSpeed{&Leg5_servo_2,0};
act_setSpeed{&Leg6_servo_2,0};

act_setSpeed{&Leg1_servo_3,0};
act_setSpeed{&Leg2_servo_3,0};
act_setSpeed{&Leg3_servo_3,0};
act_setSpeed{&Leg4_servo_3,0};
act_setSpeed{&Leg5_servo_3,0};
act_setSpeed{&Leg6_servo_3,0};

return 0;
}

Once compiled and uploaded, this program should make all your servos hold their centre positions...

Hope this helps...
Title: Re: How to generate the tripod gait ?
Post by: bilals on March 08, 2010, 10:06:52 PM
Thank you Hasan999, but where do you paste this code. In the hardware.h or program-name.c ? Hasan999, did the program work fine for you, no power issues ?
Because I am having a problems with Axon II. Its resetting repeatedly and rapidly. I am not sure if the problem is due to software (program i wrote) or due to hardware.
Can you please tell me what can cause resetting of AxonII ?
Title: Re: How to generate the tripod gait ?
Post by: little-c on March 09, 2010, 02:56:19 AM
not enough voltage.

too low a voltage and the chip resets.

Title: Re: How to generate the tripod gait ?
Post by: Hasan999 on March 09, 2010, 03:23:51 AM
The program should be pasted on your main program's .c file.

But seriously, first try the 'default' program to see if it compiles sucessully. If it does, when it is 'ON', does the Axon reset then as well?

If it doesn't, copy paste my program (Im assuming you've already changed the ports according to your connections), and compile, run, and see what happens?, if the Axon resets, try including this code 'before' the actSpeed commands:

Code: [Select]
servosDisconnect(&bank2);
servosDisconnect(&bank3);
servosDisconnect(&bank4);
servosDisconnect(&bank5);
servosDisconnect(&bank6);
servosDisconnect(&bank7);
servosDisconnect(&bank8);
servosDisconnect(&bank9);
servosDisconnect(&bank10);
servosDisconnect(&bank11);
servosDisconnect(&bank12);

So basically, you'll be disconnecting all the servos except for the one is bank1. So now compile again, run, and check if servo: 'Leg1_servo_1' is running. If so, then try removing the disconnect command for more banks and see how many servos work, until Axon resets.

Which battery do you use, 6V? _____mAh? .. and is your robot too heavy?


Title: Re: How to generate the tripod gait ?
Post by: bilals on March 09, 2010, 03:42:25 AM
So basically, you'll be disconnecting all the servos except for the one is bank1. So now compile again, run, and check if servo: 'Leg1_servo_1' is running. If so, then try removing the disconnect command for more banks and see how many servos work, until Axon resets.

Which battery do you use, 6V? _____mAh? .. and is your robot too heavy?

I am using a 6V battery with 2300mAh, i am in the process of building the robot. So, what i am doing is just trying to make the program with all servos connected to axon but no body and legs yet (No load on the servos).

So are you saying that maintaining all servos center position might be drawing a lot of current. How can i solve this problem ? If i cant run all servos at one time, then the robot might not be able to hold its position. After that, when i try to make the robot move forward, many servos will be running at the same time, what to do ?

Thanks in advance
Title: Re: How to generate the tripod gait ?
Post by: Hasan999 on March 09, 2010, 06:00:51 AM
2300mAh is actually not so good for 18 servos... BUT... that is something that you should worry about later...

If you've not built the robot yet, then the servos have no external torque, and your battery can easily handle all at a time, especially when fully charged.

Later on, when you'd build the robot, you might notice, that due to the weight of the robot the servos get extra torque and the battery can't take it [btw, it still might take it when 'fully' charged]...

But, you can simply buy another battery pack, and attach it in parallel, so that you have 6V and (2300+2300) 3600mAh [good enough]...However, do that only when you've built the robot, and you really require more Power.

The other problem you would face is the Servos that would not hold extremely tight...but if your robot is not heavy enough (let me estimate and guess, up to 2kg) would work !...otherwise, if you can imagine, the legs/arm servos will slip due to weight.

Good Luck.
Title: Re: How to generate the tripod gait ?
Post by: bilals on March 09, 2010, 06:34:16 AM
2300mAh is actually not so good for 18 servos... BUT... that is something that you should worry about later...

If you've not built the robot yet, then the servos have no external torque, and your battery can easily handle all at a time, especially when fully charged.

Later on, when you'd build the robot, you might notice, that due to the weight of the robot the servos get extra torque and the battery can't take it [btw, it still might take it when 'fully' charged]...

But, you can simply buy another battery pack, and attach it in parallel, so that you have 6V and (2300+2300) 3600mAh [good enough]...However, do that only when you've built the robot, and you really require more Power.

The other problem you would face is the Servos that would not hold extremely tight...but if your robot is not heavy enough (let me estimate and guess, up to 2kg) would work !...otherwise, if you can imagine, the legs/arm servos will slip due to weight.

Good Luck.

Thanks.

My estimate for the robot weight is about 2.5kg. I'd like to know how heavy is your robot and what are the battery specs that you use. How many servos operate at the same time in your hexapod ?

why do you use &bankX command along with the TIMERYCOMPAREZ ? What are they used for ?

#define threshold 8


}
// The loopStart parameter has the current clock value in uS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

//now instead of 'values' (currently: 0) you can use variables later on...
act_setSpeed{&Leg1_servo_1,0};
act_setSpeed{&Leg2_servo_1,0};
act_setSpeed{&Leg3_servo_1,0};
act_setSpeed{&Leg4_servo_1,0};
act_setSpeed{&Leg5_servo_1,0};
act_setSpeed{&Leg6_servo_1,0};

act_setSpeed{&Leg1_servo_2,0};
act_setSpeed{&Leg2_servo_2,0};
act_setSpeed{&Leg3_servo_2,0};
act_setSpeed{&Leg4_servo_2,0};
act_setSpeed{&Leg5_servo_2,0};
act_setSpeed{&Leg6_servo_2,0};

act_setSpeed{&Leg1_servo_3,0};
act_setSpeed{&Leg2_servo_3,0};
act_setSpeed{&Leg3_servo_3,0};
act_setSpeed{&Leg4_servo_3,0};
act_setSpeed{&Leg5_servo_3,0};
act_setSpeed{&Leg6_servo_3,0};

return 0;
}

One more thing regarding the code in quotation above in BOLD:

1) What is this threshold? Why is it 8?
2) Why is it return 0? From what i previously read, is that its better if you give 20ms between pulses (correct me if i am worng)?
Title: Re: How to generate the tripod gait ?
Post by: Hasan999 on March 09, 2010, 07:21:05 AM
My robot is a 4 legged robot having 5 servos in each leg... it weighs the same, around 2.5kg, and after combining 3 different battery packs, I have a combined power of (1600+1600+1400) = 4600mAh  ;D

It can actually hold the load/weight and run all the 21 servos "when is it fully charged" for a few seconds (or minutes) depending on the load etc....

Now again, for the software theories, I am  :-\ lol... but you can search for PWM Timers and threshold etc, to learn more about these stuff.

However, the return 0; means it will delay 0ms before looping. You are correct, servos need to have 20ms between pulses, but that is already taken care of in 'servo.h' file, that has a SERVO DELAY of 20, that means, THAT loop will keep on looping without delay, but will give signals to each servo once their '20ms' is passed.

Nevertheless, I observe a different case when I use more than 1 servo in 1 bank, as I said, 'servos wont be tight' for you: servos in bank 6 to 12. (again, don't change that, I have put those servos there for a good reason). But, maximum number of 16-bit Timers possible are 12, and that's why you can't add more banks. That is the reason, I have been requesting Webbot to update the library to include the feature to use 8-bit Timers as well - that will solve a lot of problems.

Anyway, Good Luck...
Title: Re: How to generate the tripod gait ?
Post by: bilals on March 09, 2010, 07:28:22 AM
It can actually hold the load/weight and run all the 21 servos "when is it fully charged" for a few seconds (or minutes) depending on the load etc....

Really !? So, your robot only works for few seconds or minutes before running out of charge.

Can i connect the axon to a power source ? Transformer connected to home supplied electricity.
Title: Re: How to generate the tripod gait ?
Post by: Hasan999 on March 09, 2010, 08:17:15 AM
Not running out of charge... but losing its power (axon resets) as it cannot take the load/torque for some particular configurations of my robot.

I tried with a DC Supply Unit, that could supply upto 10A... it was worse than the battery :p...

But, if you can get one, try with a DC Supply Unit that could supply upto 20A...but do it at your own risk :p

As per Admin, a servo would require a load of 0.5A to 1A ...so maximum load needed by your robot would be around 18A.