Getting my servos to stop
noobmuncher
Posts: 124
Hello,
So I am experimenting with servos with the propeller for the first time and I finally understand how to control them, however I am running into a small issue... I can't figure out what the code is to get them to stop. I have tried changing the speed down to zero (I am not really even sure what that is though ) and I haven't had really any luck.
Thanks
So I am experimenting with servos with the propeller for the first time and I finally understand how to control them, however I am running into a small issue... I can't figure out what the code is to get them to stop. I have tried changing the speed down to zero (I am not really even sure what that is though ) and I haven't had really any luck.
***As a quick note, please ignore any of the descriptions, I haven't changed these yet from the program I was modifying***my code said...
''Control Two Servos.spin
''Demonstrate how to send signals to 2 servos with the Servos object.
''This example assumes continuous rotation servos on a differential
''drive robot.
''
''IMPORTANT: If you are using the Spin Stamp 1:
'' - Set _xinfreq to 10_000_000
'' - Set PLL multiplier to 8x
CON
_clkmode = xtal1 + pll16x ' Crystal feedback & PLL multiplier
_xinfreq = 5_000_000 ' 5 MHz crystal
SERVO_COUNT = 2 ' Number of servos to control
VAR
byte pin[noparse][[/noparse]SERVO_COUNT] ' Array of servo I/O pins
long servo[noparse][[/noparse]SERVO_COUNT] ' Array of servo pulse duraitons
long pulseCountAddr, pulseCount ' The servo pulse count
OBJ
Servos : "Servos for PE Kit" ' Declare Servos object
PUB testServos | index, speed
'' Initialize all servos to center pulse duration. Notice that the
'' duration stored in serov[noparse][[/noparse]index] specifies the pulse duration for
'' the servo connected to pin[noparse][[/noparse]index].
repeat index from 0 to (SERVO_COUNT - 1)
pin[noparse][[/noparse]index] := lookupz(index: 13,12)
servo[noparse][[/noparse]index] := lookupz(index: 0, 0)
'' Start the servos object, and pass it the addresses of the pin and
'' pulse duration arrays along with the number of servos the object
'' will control. The object returns the address of the variable it
'' updates when it has completed sending a current pulse cycle.
pulseCountAddr := servos.start(@pin[noparse][[/noparse]0], @servo[noparse][[/noparse]0], SERVO_COUNT)
'' Uncomment repeat loop for centering servos.
'repeat
'' Wait for a 3 s, letting the object deliver center pulses to the servos.
waitcnt(clkfreq * 3 + cnt)
'' Loop sweeps the servos connected to P13..P12. To ensure ramping,
'' the loop does not update the servo positions until the pulsecount has
'' increased. This ensures that both servos will update at the same
'' time, which is important when getting a differential drive mobile
'' robot started going straight ahead.
servo[noparse][[/noparse]0] := 400
servo := -400
waitcnt(clkfreq*2 + cnt)
servo[noparse][[/noparse]0] := -400
servo := 400
waitcnt(clkfreq*2 + cnt)
'' Robot continues at full speed ahead.
repeat
Thanks
Comments
If you uncommment 'repeat it should centre the servos and stop them.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Post Edited (Leon) : 12/26/2009 12:59:37 PM GMT
for analysing your problem the forum needs your COMPLETE code.
Look at the atteched picture to learn how to upload an archived project
best regards
Stefan