Society of Robots - Robot Forum

Software => Software => Topic started by: superwhitewish on February 24, 2010, 01:33:06 AM

Title: Controlling large number of servo with Axon
Post by: superwhitewish on February 24, 2010, 01:33:06 AM
Hi, I'm new to this forum, just ordered my axon board and first time in robotics. While waiting
for my axon to arrive, I just look into the source files included for the axon.

This is an idea that i got while learning the axon source file and the webbot library.
Both of them are controlling the servos one at a time by sending a high signal, wait for
1ms - 2ms, send low signal and go to  the next servo. This seems to limit the amount of servo that
can be controlled. EG. to contol 10 servo, it already waited for 10ms-20ms for the high
pulse. Already there's no time to wait for the low pulse. If you have 20++ servos then
maybe the duration of low pulse to each servo will pass the 20ms-40ms required by the servos.

This is only an idea that i just got, i post it here just to get opinions for it. maybe
some of you have already tried it and found that it's no good.

this is my code in theory. Please ignore any syntax error since the last time i wrote a program
was in 2002.

lets say we define a SERVO struct with 'Position' as it's element.


#define numservo = 20; //number of servos

struct {int Position}SERVO;

Then we define a group of servo our robot has:
SERVO servo[numservo];

in our robot controlling function, we modify the position of the servos:  

void control(void){

servo[0].position = 1500; //1.5ms
servo[1].position = 1200; //1.2ms
servo[2].position = 1700; //1.7ms
etc.... up to 20 servos.

move_servos(); ---> then we call this function to move all the servos
}


move_servos();//this is the function that move all the servos at once
{

//get the position of servo with the highest 'Position' value.
max_servo_position = GetMaxServoPosition(servo);

//set pulse to all servo to HIGH

for(i1=0; i1<numservo;i1++){
SetServoPulseHigh(servo[i1]);
next i1;
}

//now its just a matter of setting the individual servo pulse to low to move it to a specific position.


reset_timer(timer1); --> set timer1 to begin at 0
t=0; //for timer1


while(t <= max_servo_position){ //repeat until the last servo has been moved

//get the current time
t = get_timer(timer1);

for(i1=0; i1<numservo; i1++){ //repeat for each servo

//if the servo high pulse is already passed the servo[i1].Position, turn the pulse to LOW

if (t>servo[i1].position){
   SetServoPulseLow(servo[i1])}

next i1;
}

}

while(t<20000){t=get_timer(timer1);}//wait for the remaining of 20ms to end - even better if we can track how
               many ms our main function uses.
}

So in this code you can see that it only take in theory max 2ms to signal all the servo and wait for the remaining
18ms to complete the 20ms cycle. I dont know how ms it takes for the uC to do the logics,while & for,  but i belive it's
neglitible.

I've never tried this code since I just ordered my AXON last week and it's still in transit to Malaysia.
This is the first time I will do prgramming for robot so my idea could be just a crap.
I'm planning to build a 20servos hexapod robot. That's why I'm concern about max servo controlling capability.
Title: Re: Controlling large number of servo with Axon
Post by: Webbot on February 24, 2010, 04:32:10 AM
Thats exactly the kind of algorithm used by dedicated servo controllers. Largely coz they don't have anything else to do. Here's why.

1. Set all outputs high.

2. Wait for around 1ms before I need to do something.

3. Suddenly have to deal with 20+ servos all turning off at around the same time give or take +-0.5ms

4. Wait for 18ms or so before repeating.

If you want to use your Axon for other stuff (since a servo controller is a fraction of the price!) - then you've got two problems. The easiest one is making sure that the above happens every 20ms no matter what your main code is doing. Ahah - interrupts or scheduler you think. So the next problem, using interrupts, is how do you do step 3 above which could take 1ms without killing off everything else eg uarts, i2c, sensors, gps etc etc.

Title: Re: Controlling large number of servo with Axon
Post by: superwhitewish on February 28, 2010, 09:07:23 PM
Ok, after learning about interrupts and I found a source court from robotrealm site that make an axon as a 29channel servo controller I can understand what you are saying. I have a very little experience programming a MCU. Before this I make 3d game using c++ & openGL API and never used interrupt directly. Thanks for your reply.