go away spammer

Author Topic: Running multiple servos simultaneously... [HELP]  (Read 2074 times)

0 Members and 1 Guest are viewing this topic.

Offline Hasan999Topic starter

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Running multiple servos simultaneously... [HELP]
« on: December 22, 2009, 01:39:43 PM »
[Axon Microcontroller - HS-422 Servos] - Im a beginner !

Lets say I have to turn Servos at pins C4 and E4 both by 90ยบ Simultaneously...

This is my program for 1 servo:

for(uint16_t i=0;i<15;i++) {
servo(PORTC,4,1115);
delay_ms(20); }


Now if I modify it to:

for(uint16_t i=0;i<15;i++) {
servo(PORTC,4,1115);
servo(PORTE,4,1115);
delay_ms(20); }


Then both servos run simultaneously and equally.

BUT my question is, how to program servo's at different intervals (and different speeds) BUT also simultaneously?

For example: (assuming C4 and E4 are initially at center 700)

Rotate Servo C4 to position 1115 (with speed delay 80ms)
Rotate Servo E4 to position 1115 (with speed delay 20ms) Starting 1 Second after the C4 Started.

Imagine this in a timeline:

C4--------------------------------(speed 80ms delay)------------------------------END
                                          E4--------(speed 20ms delay)--------END
0s-------------------------------1s-------------------------------2s----------------------------TIME-->


If not exact, please try to provide a sample code of such programming.

Thanks a lot in advance !
« Last Edit: December 22, 2009, 01:41:27 PM by Hasan999 »

Offline weighates

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Running multiple servos simultaneously... [HELP]
« Reply #1 on: December 22, 2009, 03:23:02 PM »
I am not familiar with the axon but I would just send a aquare wave manually.  For this your going to need to look up the PWM on your servos to be exact as they are different for every servo. 
Here is some pseudo code, your going to need to change ports and speeds

DDRD = 0xff;
DDRE = 0xff;
for (int i = 0; i < 100; i==)
{
      PORTD = 0xff;
      _delay_ms(2);  //makes port D servo's go fast
      PORTE = 0xff;
      _delay_ms(1.6);  //makes port E servo's go slow
      PORTD = 0x00;
      PORTE = 0x00;
}

This isn't actually simultaniously but there is only a 3.6 ms delay which isnt noticable at all.  Google square waves to servo's  for more info.
Chris

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Running multiple servos simultaneously... [HELP]
« Reply #2 on: December 22, 2009, 03:55:15 PM »
Servo's have there own PID controllers. You can google the term but i will give you the info you need to know.

Basically, the are two values the servo cares about.

1. where it is now
2. where it is told to be

the further away these two values are from each-other, the faster the servo will move. (up to a certain speed).

So for what you are asking, if you wanted a servo to move more slowly, only tell it to be little off what it is now. Think of it as a carrot in front of a horse. The further away you hold the carrot, the faster it will go to try to get it.

So here is some psedu-code that should help.

while (position < goal)
{
position = position + 2;
servo(PORTC,4,position);
delay(100)
}

You play with the value added to position every time (in my example, 2) and with how long the delay is to change how fast the servo will move.

To synchronize the servos like you ask, i would add an IF to the loop that checks if the first servo has gotten to a certian poition, then sends the second servo it's new position.

Hope this helps, and you understand servos a little more.
 

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Running multiple servos simultaneously... [HELP]
« Reply #3 on: December 22, 2009, 04:00:08 PM »
Also, figured i should mention.

When tweaking these values, you might find the servo jitters. This means it got to the goal and stopped before you sent it the next position. This means your delay is too long. You will find that to get a nice smooth slow movement you will have to experiment until you find a good pairing of values (delay, and notches moved each time).

Offline weighates

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Running multiple servos simultaneously... [HELP]
« Reply #4 on: December 22, 2009, 04:05:13 PM »
My code was for a modified servo with 360 rotation.   If your servo is unmoded it wont work but madsci code will.

 


Get Your Ad Here