Let's Make Robots!

How to contol servo speed from serial

Hello all

I have  renbotics ServoShield and I have made a code on arduino where from serialport I can send commads to servos and it happens with that way... S01P1200,S14P2300etc..I mean that  Servo 1 to 1200 posion and servo 14 to 2300 posion

NowI have one problem.How can I control the servo's  speed from serial port? For example S01P1200F.... 1 SERVO, 1200 POSION, F = SPEED...Is  there any code for controlling  servos speed so that I  can take it and include it into my code? As I know  servoshield 1.5 library I use , can't support any speed control.

My code that moves servo is this , but how can I contol the speed?o you have any clue?

 

....

case 's':  
                        {
     char servoid[extractedCommand.substring(1,3).length() + 1];
     char servopos[extractedCommand.substring(4,8).length() + 1];
     extractedCommand.substring(1,3).toCharArray(servoid, sizeof(servoid));
     extractedCommand.substring(4,8).toCharArray(servopos, sizeof(servopos));
  
     // Convert extracted strings to integers
     int sid = atoi(servoid);
     int spos = atoi(servopos);
  
     //Print some debug info
     char debugMsg[256];
     sprintf(debugMsg,"command string: %s   Servo Id: %d   Servo Position: %d", command, sid, spos);
     Serial.println(debugMsg);
  
     // Move the
     shieldServos.setposition(sid , spos);
     delay(1);
     break;

....

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Below is your code to sweep the servos from 700 to 2400. In this sketch, you have a variable called "incrementDelay". If this variable is 0, it is full speed, if it is a bigger number, it is slower. That is your speed control.

void loop()
{
const int angleIncrement =10;
const int incrementDelay = 10;
for (int angle = 700; angle < 2400; angle += angleIncrement)

for (int i = 0; i < 16; i++)
servos.setposition (i,angle);
delay (incrementDelay); <------  Make this bigger to go slower
}

Yes my friend, but i have 2 problems.. ths first problem is ,to angleIncrement! if i can 1 step, and delay 1  have the half posion in the right speed.. but, i change the incrementDelay to 5 sec, i have full posion but is slow..!

the second problem, if i can to angleIncrement 10 an delay 1 sec, i have speed but 1/4 posion, and if i can change to 10 i have normal speed, full posion, but if i can the incrementDelay  50 , is slow but the speed no smooth, is step step step...

I would like to know  how to control speed the VarSpeedServo library... the method... this library is very good..I have slow and smooth speed.. and fast and foul posion!!!!! but this is for arduino pin

I send from serial port, posion for example : #00P1831... this code with 10 angleIncrement for normal speed the problem is how can it  goes to servo 1831 -->"1" ms

i dont know much about the serial port, but i did find a servo library someone had made, in which you can define the speed for each servo movement.

http://arduino.cc/forum/index.php?topic=61586.0

you just write the servo position, as normal, but there is a second function, after the position, which defines the speed (0 to 255)

you can obviosuly read that speed off an integer as you would anything else. maybe this would help? It works perfectly in my experience

yes I have this library, but I have the servoshield from http://www.renbotics.com/ , and this library does not play with my shield!

 

My shiled has a library but it does not have any speed control and I have to make it!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
void controlledServoMove(int srvNum, int startPos, int endPos, int spd) {
    if (startPos < endPos) {
        for (int move = startPos; move = endPos; ++move) {
            servo.setposition(srvNum, move);
            delay (spd);
        }
    else {
        for (int move = startPos; move = endPos; --move) {
            servo.setposition(srvNum, move);
            delay (spd);
        }
    }
}

My code will move a single servo at a given speed. I have not put much thought into moving multiple servos at once.

Put all the servos and servo positions in an array?

hello

Sorry for the  delay

I have made a library according to this example , but finally it isn't the right way.In order to have speed, we must make step , so we don't have accuracy.Does somebody knows a right method , so that then I can fix it? If you do give us please an example.Old Posion 1100 new pos 2200 ,how can we fix it to do it slow and how fast ?...

P.S. I want it for many servos' 10 or 16 for example

No good method,no good accuracy

 

void loop()
{
const int angleIncrement =10;
const int incrementDelay = 10;
for (int angle = 700; angle < 2400; angle += angleIncrement)
{
for (int i = 0; i < 16; i++)
servos.setposition (i,angle);
delay (incrementDelay); // so we'll take 10 * 180 milliseconds = 1.8 seconds for the traverse.
}

goodmorning my friend
Yes but I have this code and I can contol the speed for all 16 servos...But in this case I give first position and the next where it should be moved.....In my case I am sending you from serial port ,how do you think I could write this code(I will have many first and last positions for servos) with first command S00P1200,S09P1350,S10P0960,S15P1800 and the last goes to S00P2350,S09P0600,S10P2400,S15P0960
for example Servo 0 first pos 1200us and last pos 2350us</p><p>Servo 9 first pos 1350us and last pos 600us Servo 10 first pos 960us and last pos 2400us servo 15 first pos 1800us and last post 960us

i have this code

 

void loop()
{
  const int angleIncrement =10;
const int incrementDelay = 10;
  for (int angle = 700; angle < 2400; angle += angleIncrement)
 {
  for (int i = 0; i < 16; i++)
  servos.setposition (i,angle);
  delay (incrementDelay); // so we'll take 10 * 180 milliseconds = 1.8 seconds for the traverse.
 }
}

goodmorning my friend
Yes but I have this code and I can contol the speed for all 16 servos...But in this case I give first position and the next where it should be moved.....In my case I am sending you from serial port ,how do you think I could write this code(I will have many first and last positions for servos) with first command S00P1200,S09P1350,S10P0960,S15P1800 and the last goes to S00P2350,S09P0600,S10P2400,S15P0960
for example Servo 0 first pos 1200us and last pos 2350us</p><p>Servo 9 first pos 1350us and last pos 600us Servo 10 first pos 960us and last pos 2400us servo 15 first pos 1800us and last post 960us

i have this code

 

void loop()
{
  const int angleIncrement =10;
const int incrementDelay = 10;
  for (int angle = 700; angle < 2400; angle += angleIncrement)
 {
  for (int i = 0; i < 16; i++)
  servos.setposition (i,angle);
  delay (incrementDelay); // so we'll take 10 * 180 milliseconds = 1.8 seconds for the traverse.
 }
}

I went to renbotics.com, and, looked at both of their shields. The manuals for both shields tell exactly what the libraries that come with the shields can do.

You can:

  void setposition(int servo, int position);
  int setbounds(int servo, int minposition, int maxposition);
  int getposition(int servo);
  int invertservo(int servo); 

As Bajdi said, the only way to control the speed would be to control how far you tell the servo to move each time, and, how quickly it should change its position.