Go Down

Topic: Servo motor speed adjust (Read 4203 times) previous topic - next topic

luisandrade

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);
...




oric_dan

#1
Nov 14, 2012, 03:07 am Last Edit: Nov 14, 2012, 03:10 am by oric_dan(333) Reason: 1
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.

luisandrade

I understood, I will make some tests, thanks for now.

zoomkat


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.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

luisandrade

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

oric_dan

Quote
I made a test, really didn't work like I want.


So, what happened?

luisandrade

The motor went until the position called but in high speed.

rgallant

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  It is titled Servo timer so it may have the functionality you need.

oric_dan

#8
Nov 15, 2012, 03:11 am Last Edit: Nov 15, 2012, 03:13 am by oric_dan(333) Reason: 1
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.


luisandrade

I'm using a normal servo motor 0-180 degrees, I'm building a arm robot, the control is made directly without servo controller.

zoomkat

Try the "sweep" servo code example to see how it makes the servo move slower than usual.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

retrolefty

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

oric_dan

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.

retrolefty

#13
Nov 15, 2012, 07:12 pm Last Edit: Nov 15, 2012, 07:16 pm by retrolefty Reason: 1

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

oric_dan

luis, what Arduino board are you using?

Go Up