slowing down a servo

Is it possible to control the speed of a servo by programming the chip?
I know that the 21 Channel Servo Driver AXE031 can do it, but I am trying not to use one of these.
 

papaof2

Senior Member
If the load on the servo isn't an issue, you could reduce the voltage applied or use PWM (ground side logic FET with adequate current capability).

Caution - untested code follows:

You could try stepping the servo from the current position to the next position in a loop. Not pretty; probably noisier and draws more current than a servo that runs steadily from one position to the next.

servo 3, 90

for b5 = 91 to 110 'might need steps larger than one
servopos 3, b5
'pause here if needed
next

John
 

goom

Senior Member
The following code is tested and working. Essentially the servo is incremented one small step at a time, with a pause in between each increment. The length of pause, and hence the speed, is programmed by a pot on an ADC input. It does get a little jerky, especially as very slow speeds, due to the limited resolution of the steps.
Code:
'Radio control servo slowdown
'PICAXE-08M connections are:
' Leg 1                   +5V
' Leg 2 (Serial in)       Tie to Ground through 10K resistor
' Leg 3 (In4/Out4)     Wiper of 10K potentiometer connected to +5V and ground
' Leg 4 (In3)             Pulse input from radio receiver
' Leg 5 (In2/Out2)     Pulse output to servo
' Leg 6 (In1/Out1)     Mode indicator output
      '1/2 second flash = no valid signal
      'Steady on = pass-through (no servo slowdown)
      'Flicker = servo slowdown mode
' Leg 7 (Out0/Serial Out) NC
' Leg 8                   Ground
symbol Delay=b8                                'Name the delay factor
symbol PWin=w0                                 'Name the input pulse length
symbol PWout=b2                               'Name the output pulse length
symbol PWinPrev=b3                            'Name the length of the prior input pulse length
symbol PWinErr=b6                              'Name the difference between input and output pulse lengths
symbol skip=b4                                   'Name the counter for skipping "Delay" times
restart:
   Skip=0
   high 1
   servo 2,135                                'Center the servo initially and on input pulse loss
   Pause 500                                  'Wait 1/2 second initially
   toggle 1
   readadc 4,Delay                          'Read the voltage from the delay potentiometer
   pulsin 3,1,PWin                            'Measure the input pulse width initially
   if PWin<75 or PWin>225 then restart        'Go back if no valid input detected
   high 1
   low 2                                   'Stop the sevo command if valid input detected
   PWinPrev=PWin                      'Initially set the prior pulse width to current pulse width
   if Delay<5 then StraightThru    'If delay pot set near zero skip slowdown routines
   Delay=Delay/21                     'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
   PWout=PWin                         'Set output pulse to input pulse initially
loop_:
   toggle 1
   PWinPrev=PWin                     'Reset the prior pulse width
   pulsin 3,1,PWin                     'Measure the input pulse
   if PWin<75 or PWin>225 then restart        'Go back if no valid input detected
   PwinErr=PWin-PWOut
   if PWinErr<2 or PWinErr>254 then StayPut   'Add 2 units of hysteresis
   if PWout<PWin then MoveUp
   if PWout>PWin then MoveDown
MoveDown:                                     'Routine to decrease the output pulse width
   if skip>=Delay then Skip1                'Loop to delay change to Delay x 20ms input periods
      Skip=Skip+1
      goto Skip2
  Skip1:
     Skip=0
     PWout=PWout-1
  Skip2:
     pulsout 2,PWout                       'Send the output pulse to the servo
     goto loop_                               'Return to re-measure the input pulse
MoveUp:                                      'Routine to increase the output pulse width
   if skip>=Delay then Skip3             'Loop to delay change to Delay x 20ms input periods
      Skip=Skip+1
      goto Skip4
  Skip3:
     Skip=0
     PWout=PWout+1
  Skip4:
     pulsout 2,PWout                       'Send the output pulse to the servo
     goto loop_                               'Return to re-measure the input pulse
StayPut:                                      'Routine to send the same output pulse
   pulsout 2,PWout
   goto loop_                                 'Return to re-measure the input pulse
StraightThru:
   pulsin 3,1,PWin
   if PWin<75 or PWin>225 then restart        'Go back if no valid input detected
   PwinErr=PWin-PWinPrev
   if PWinErr<2 or PWinErr>254 then Stay      'Add 2 units of hysteresis
   pulsout 2,PWin
   PWinPrev=PWin
   goto StraightThru             'Return to re-measure the input pulse
   Stay:
   pulsout 2,PWinPrev          'Set output pulse to input pulse
   goto StraightThru            'Return to re-measure the input pulse
 

westaust55

Moderator
Some further background to the hows and whys of the program code that goom has supplied.

The software is breaking the travel down into smaller increments with a delay between the "steps" so that the overall travel from commencement point A to destination point B is slower.
That is a given. (tick)


Additionally, at least for the servo motors I have experimented with,
the speed of travel is proportional to the remaining distance to be travelled.

Based upon this approach, if you have to travel through say 180 degrees, the servo electronics applies a higher/maximum voltage to the internal motor to start with. Then as the servo motor moves toweards the destination point, the voltage is gradually reduced so that the servo actually creeps in for the last part.

Thus with the software as given by goom, there is (or maybe depending on a given servo as I have only tested a few) a two fold speed control.
1. by using small increments even without a software delay in the program a reduction is speed is achieved since the servo electronics always sets the motor speed for a small remaining distance.
2. by adding program delays (pause command), further reduction in the average speed is achieved - but the servo motor will likely be getting a bit "jerky" in its movement.
 

Janne

Senior Member
If you need both slow and smooth movement, then i'd suggest dropping the servo input voltage down, or limiting it's current. At least with digital servos, that seems to be the only good working solution.
 

BeanieBots

Moderator
A higher range digital servo can itself have the speed programmed into it.

Fitting back-to-back diodes in series with the motor will give reduced speed with very little reduction in torque.

Finer / smoother speed control can be realised by adopting the pulsout method with a combination of varying the pulse width and the frame rate.
Slightly more complex to code but it's the method used here.

http://www.picaxeforum.co.uk/showthread.php?t=7760
 

Wrenow

Senior Member
And, let us not forget that there are commercial modules in existence to do kist this job in the R/C hobby marked, like this one http://www.hobby-lobby.com/servo_slow_down_module_2157_prd1.htm USD$19.99
of this one: http://www.rcdude.com/servlet/the-18/Dionysus-Servo-rate-reducer/Detail USD$9.99 (yes, under $10) - incredibly tiny, but not as adjustable.
So, it is a case of if you need to slow a servo, easy to do with off-the shelf parts (i.e, your goal is to slow a servo and you are wondering how to do it, and, incidentally, can you do it with a Picaxe).

But, if you are just using slowing a servo as a means of learning more about programming your Picaxe to increase your programming acumen. then Goom, Westie and BB have steered you in the right directions. I can't think of anything in particular to add.

By the way, Dionysus has lots of interesting bits for servos - reversers, mixers, rate slowers, range stretchers, glitch reducers, etc. at: http://www.dionysusdesign.com/index.php/cPath/29?osCsid=48b72a3c1ab35bdb4feff4b95c46b88e

Cheers,

Wreno
 

demonicpicaxeguy

Senior Member
Is it possible to control the speed of a servo by programming the chip?
I know that the 21 Channel Servo Driver AXE031 can do it, but I am trying not to use one of these.
can i ask why exactly you would want to slow down a servo?, i most of the things i've used them for i've usually wanted to speed them up or increase the travel
 

Wrenow

Senior Member
can i ask why exactly you would want to slow down a servo?, i most of the things i've used them for i've usually wanted to speed them up or increase the travel
In RC aircraft, irt is common to want to slow down servos on retractable landing gear and/or gear/bomb bay doors to make it more realistic looking (i.e., to more closely mimic a hydraulic system).

In RC Warships, it is occasionally used to slow turret rotation or gun elevation/depression to a more realistic speed depending on the mechanical drivetrain. In R/C Warship Combat, however, it is rarely used.

By the way, you did notice that Dionysis sells a "servo stretcher" to increase the range (there are other vendors of similar products, of course)?

Cheers,

Wreno
 

goom

Senior Member
Of course, a servo stretcher is very easy to implement with even the lowest level PICAXE. Just needs PULSIN, a bit of code to scale the pulse width, then PULSOUT. The timing of the output pulse stream is taken care of automatically by the timing of the input pulses.
 

profbill

New Member
Hi Westaust55,
I was fortunate enough to find your above post and your introduction to Digital Pots!
Most informative and very valuable indeed.
I have a simple circuit where I am using a 10k/100k pot as input to an 18M2 running a slightly modified version of GOOM's code driving an MCP4101 100k digital pot (many thanks for your code to drive the MCP4101)
The delay pot is 10k
I chose to quickly use the provided servo code modded sufficiently to get an experimental result.
The experiment is to slow down a joystick response in a very twitchy control enviornment and am pleased to say the results are very encouraging indeed. The Pot Delay picaxe /MCP4101 is placed between the joystick and the platform being controlled!
My only problem is that by dividing the delay by "21" or whatever I end up with +/- 11-12 steps of control. I have found that useful (usable) Delays are 1 and 2!
Before I sit down and write some code that will give me "continous control" rather than a couple of "step control" positions I wondered if you or has anybody you may know of may have attempted to do something similar e.g. using a manually driven potentiometer
that can be slowed down and the result presented on a digital potentiometer!
Any advice on the matter would be most welcome!

Bill.
 
Top