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
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.
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.
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:
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 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.