Go Down

Topic: perhaps a little help with servo control?? (Read 842 times) previous topic - next topic

daidalos

Sep 02, 2007, 11:06 pm Last Edit: Sep 02, 2007, 11:07 pm by daidalos Reason: 1
Hello everyone,

Here's my goal, its pretty simple - just a little prototype for a larger project....

I need to be able to control 9 servo's from one board (Decimilia) independently.  I'm a bit new at writing code however, so my approach was to write separate functions for each servo, and then call those functions in a main loop in whatever order was necessary to achieve the desired effect.  

I have some code that simply runs all of them at once, (just a test to see if my power supply was sufficient) -
how could I modify this or re-write the code to get independent control and get to a choreographed sequence of actuations?

Code: [Select]


#define SERVOa 13
#define SERVOb 12
#define SERVOc 11
#define SERVOd 10
#define SERVOe 9
#define SERVOf 8
#define SERVOg 7
#define SERVOh 6
#define SERVOi 5


#define MIN_PULSE 600
#define MAX_PULSE 2400
#define DELTA 1800


int lastPulse = 0;
int refreshTime = 20;

long randNumber;

void setup()
{
 int i;
 pinMode(SERVOa, OUTPUT);
 pinMode(SERVOb, OUTPUT);
 pinMode(SERVOc, OUTPUT);
 pinMode(SERVOd, OUTPUT);
 pinMode(SERVOe, OUTPUT);
 pinMode(SERVOf, OUTPUT);
 pinMode(SERVOg, OUTPUT);
 pinMode(SERVOh, OUTPUT);
 pinMode(SERVOi, OUTPUT);
 
 digitalWrite(SERVOa, LOW);
 digitalWrite(SERVOb, LOW);
 digitalWrite(SERVOc, LOW);
 digitalWrite(SERVOd, LOW);
 digitalWrite(SERVOe, LOW);
 digitalWrite(SERVOf, LOW);
 digitalWrite(SERVOg, LOW);
 digitalWrite(SERVOh, LOW);
 digitalWrite(SERVOi, LOW);

 
 Serial.begin(9600);
 for (i=0; i<10; i++)
 {
   digitalWrite(SERVOa, HIGH);
   digitalWrite(SERVOb, HIGH);
   digitalWrite(SERVOc, HIGH);
   digitalWrite(SERVOd, HIGH);
   digitalWrite(SERVOe, HIGH);
   digitalWrite(SERVOf, HIGH);
   digitalWrite(SERVOg, HIGH);
   digitalWrite(SERVOh, HIGH);
   digitalWrite(SERVOi, HIGH);
   
   delayMicroseconds((MIN_PULSE + MAX_PULSE)/2);
   
   digitalWrite(SERVOa, LOW);
   digitalWrite(SERVOb, LOW);
   digitalWrite(SERVOc, LOW);
   digitalWrite(SERVOd, LOW);
   digitalWrite(SERVOe, LOW);
   digitalWrite(SERVOf, LOW);
   digitalWrite(SERVOg, LOW);
   digitalWrite(SERVOh, LOW);
   digitalWrite(SERVOi, LOW);
   
   delay(20);
 }
 Serial.println("servo should be at center");

 delay(20);
}

void loop()

{
 int i;
 static int pulse_width;
 
 randNumber = random(600, 2400);
 delay(3000);
 
 pulse_width = randNumber;
 Serial.println(pulse_width, DEC);
 
/*
 if (millis() - lastPulse >= refreshTime) {
   digitalWrite(SERVOa, HIGH);
   digitalWrite(SERVOb, HIGH);
   digitalWrite(SERVOc, HIGH);
   digitalWrite(SERVOd, HIGH);
   digitalWrite(SERVOe, HIGH);
   digitalWrite(SERVOf, HIGH);
   digitalWrite(SERVOg, HIGH);
   digitalWrite(SERVOh, HIGH);
   digitalWrite(SERVOi, HIGH);
   
   delayMicroseconds(pulse_width);
   
   digitalWrite(SERVOa, LOW);
   digitalWrite(SERVOb, LOW);
   digitalWrite(SERVOc, LOW);
   digitalWrite(SERVOd, LOW);
   digitalWrite(SERVOe, LOW);
   digitalWrite(SERVOf, LOW);
   digitalWrite(SERVOg, LOW);
   digitalWrite(SERVOh, LOW);
   digitalWrite(SERVOi, LOW);
   
   delay(20);
   
   lastPulse = millis();
 }
}
*/
 
   for (i=0; i<100; i++)
{
     digitalWrite(SERVOa, HIGH);
     digitalWrite(SERVOb, HIGH);
     digitalWrite(SERVOc, HIGH);
     digitalWrite(SERVOd, HIGH);
     digitalWrite(SERVOe, HIGH);
     digitalWrite(SERVOf, HIGH);
     digitalWrite(SERVOg, HIGH);
       digitalWrite(SERVOh, HIGH);
       digitalWrite(SERVOi, HIGH);

     delayMicroseconds(pulse_width);

     digitalWrite(SERVOa, LOW);
     digitalWrite(SERVOb, LOW);
     digitalWrite(SERVOc, LOW);
     digitalWrite(SERVOd, LOW);
     digitalWrite(SERVOe, LOW);
     digitalWrite(SERVOf, LOW);
     digitalWrite(SERVOg, LOW);
       digitalWrite(SERVOh, LOW);
       digitalWrite(SERVOi, LOW);

     delay(20);
 }
}




thanks in advance !!

John_Ryan

Q. Was the supply adequate to power all 9 servo's ?

daidalos

Quote
Q. Was the supply adequate to power all 9 servo's ?



well .. somewhat ... ;)

I'm running a 9v 500Ma power supply - it pushes them all at once, however there is a slight lag time on some of them, and I could see that they're not running at full speed or power.

Leads me to believe that it could be two things - the refresh time in the code is too long for this amount of motors, or I need more amperage.

Daniel

running that many servos on so little current is goign to spell trouble.
You need at least a couple amps to power 9 servos properly.... they draw 1/4A easy.
They should be on a separate power supply too-- not on the Arduino supply.

daidalos

Quote
running that many servos on so little current is goign to spell trouble.
You need at least a couple amps to power 9 servos properly.... they draw 1/4A easy.  
They should be on a separate power supply too-- not on the Arduino supply.  


ok thanks, I'll look for another power supply

Daniel

yes try and run them separately... feeding the servos with a 6V battery would be perfect.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy