Arduino Forum

Topics => Robotics => Topic started by: luisandrade on Nov 14, 2012, 02:21 am

Title: Servo motor speed adjust
Post by: luisandrade on Nov 14, 2012, 02:21 am
Hi all, I would like to know if is possible adjust the rc servo motor speed without use loop for?

With loop for I can control the speed adjusting the time.

for(int i=0; i<180; i++){
servo.Write(i);
delay(15);

And this way, how do I control the speed rotation?
servo.Write(150);
Servo.Write(30);
...



Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 14, 2012, 03:07 am
servo.Write(150);  // should go one direction
servo.Write(30);   // should go the other direction.

servo.Write(90);    // should stop.
servo.Write(80);    // should go one direction slowly.
servo.Write(100);   // should go the other direction slowly.
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 14, 2012, 03:53 am
I understood, I will make some tests, thanks for now.
Title: Re: Servo motor speed adjust
Post by: zoomkat on Nov 14, 2012, 04:11 am

servo.Write(150);  // should go one direction
servo.Write(30);   // should go the other direction.

servo.Write(90);    // should stop.
servo.Write(80);    // should go one direction slowly.
servo.Write(100);   // should go the other direction slowly.



That is for a servo modified for continous rotation and not an unmodified servo.
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 14, 2012, 11:43 am
I made a test, really didn't work like I want. I looking for a way to make that control, some idea let me know.
att
luis andrade
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 14, 2012, 06:36 pm
Quote
I made a test, really didn't work like I want.


So, what happened?
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 14, 2012, 09:21 pm
The motor went until the position called but in high speed.
Title: Re: Servo motor speed adjust
Post by: rgallant on Nov 14, 2012, 09:34 pm
I am assuming you are controlling the servos directly and not using a separate servo controller ?

An SD21 servo controller gives you an option to set a speed register but that is over kill if you are using 2 or 3 servos.

The example used in the SD 21 documentation to explain the speed is shown below, but this handled by the servo controller

Quote

The servo pulses are automatically refreshed every 20mS. If the Speed register is zero (0x00) then the servo is simply set to the requested position. On power up the Speed registers are set to zero to give full speed, so unless you need to slow them down the Speed registers can be ignored. If the Speed register is set to something other than zero then that value is added to the current position every 20mS until the target position is reached. If you wish to move from 1000 to 2000 and the Speed register is set to 10, then it will take 2 seconds to reach the set position. The formula for the time it will take to make the move is:

((Target position-Start position)/Speed Reg)*20mS

Here are some examples:

Start Position     Target Position     Speed Reg     Time for Move
2000   1000   10   2000mS (2Sec)
1000   2000   10   2000mS (2Sec)
1000   2000   1      20000mS (20Sec)
1000   2000   100   200mS (0.2Sec)
1234   1987   69   220mS (0.22Sec)



Basically doing what your loop does but the load is moved to the servo controller.

This post may help http://arduino.cc/forum/index.php/topic,21975.0.html (http://arduino.cc/forum/index.php/topic,21975.0.html)  It is titled Servo timer so it may have the functionality you need.
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 15, 2012, 03:11 am
Quote
That is for a servo modified for continous rotation and not an unmodified servo.


Yeah, I think I made a big mistake. My first comment should have been "is it a regular or modified servo?"
Apparently, it's regular, which is why the for-loop works.

The only way to control the movement speed of an unmodified servo is to keep updating the position values
every 20-msec or so. IE, interpolation, (start_pos - end_pos)/velocity = pos_increment per unit time.
That's probably what the long thread pointed to talks about. Either code this into the Arduino, or as indicated,
use a servo controller with this feature built-in.

Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 15, 2012, 04:14 am
I'm using a normal servo motor 0-180 degrees, I'm building a arm robot, the control is made directly without servo controller.
Title: Re: Servo motor speed adjust
Post by: zoomkat on Nov 15, 2012, 04:31 am
Try the "sweep" servo code example to see how it makes the servo move slower than usual.
Title: Re: Servo motor speed adjust
Post by: retrolefty on Nov 15, 2012, 05:19 pm
The maximum speed a servo can move is strictly a function of the servo's design and what mechanical load it is attached to. However in your software you can make the servo move slower by issuing smaller step changes in position commands from start to ending desired position, and by waiting the appropriate amount of time between those issued incremental position commands. It would be pretty simple to write a user general purpose function such as:

void moveServo(int finalPosition, int stepTime);


Lefty
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 15, 2012, 06:27 pm
Quote
void moveServo(int finalPosition, int stepTime);


The hard part is integrating this thing into the rest of the program, so the updates are made on
nice even 20-msec time intervals, but it doesn't impact operation of other routines. Probably need
a timer interrupt to call the update code.
Title: Re: Servo motor speed adjust
Post by: retrolefty on Nov 15, 2012, 07:12 pm

Quote
void moveServo(int finalPosition, int stepTime);


The hard part is integrating this thing into the rest of the program, so the updates are made on
nice even 20-msec time intervals, but it doesn't impact operation of other routines. Probably need
a timer interrupt to call the update code.


The best solution is if the servo library (class) had such a function built into it so that it might be made non-blocking and closely synced up with the automatic servo framing rate being generated so that step change timing could be a even number of frame rates, 1 to 'very slow' . But alas I'm not up to the task as I just play being a programmer on this site, as solder is my real programming language.  ;)

Lefty
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 15, 2012, 08:24 pm
luis, what Arduino board are you using?
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 15, 2012, 09:01 pm
I'm using a arduino mega 2560.
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 16, 2012, 04:20 am
I've been playing with the Arduino Servo library code today. Maybe I will be able to add velocity
control, but no guarantees as yet.
Title: Re: Servo motor speed adjust
Post by: zoomkat on Nov 16, 2012, 05:31 am
previous servo speed discussions that might be of interest.

http://arduino.cc/forum/index.php?topic=61586.0
http://arduino.cc/forum/index.php?topic=108073.0
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 16, 2012, 07:31 am
Where were you about 8-hours ago? LOL.
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 16, 2012, 07:36 am
What?
I didn't understand what you mean.
Title: Re: Servo motor speed adjust
Post by: oric_dan on Nov 16, 2012, 07:37 am
Sorry, I was speaking to zoomkat.
Title: Re: Servo motor speed adjust
Post by: luisandrade on Nov 16, 2012, 08:08 am
No problem.