PDA

View Full Version : Getting my servos to stop



noobmuncher
12-26-2009, 03:47 PM
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 http://forums.parallax.com/images/smilies/confused.gif ) and I haven't had really any luck.

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[SERVO_COUNT] ' Array of servo I/O pins
long servo[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[index] specifies the pulse duration for
'' the servo connected to pin[index].
repeat index from 0 to (SERVO_COUNT - 1)
pin[index] := lookupz(index: 13,12)
servo[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[0], @servo[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[0] := 400
servo := -400
waitcnt(clkfreq*2 + cnt)
servo[0] := -400
servo := 400
waitcnt(clkfreq*2 + cnt)
'' Robot continues at full speed ahead.
repeat


***As a quick note, please ignore any of the descriptions, I haven't changed these yet from the program I was modifying***

Thanks

Leon
12-26-2009, 07:10 PM
You need to make the pulse duration 1.5 ms. It seems to be done by the initialisation code:





'' Initialize all servos to center pulse duration. Notice that the
'' duration stored in serov[index] specifies the pulse duration for
'' the servo connected to pin[index].
repeat index from 0 to (SERVO_COUNT - 1)
pin[index] := lookupz(index: 13,12)
servo[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[0], @servo[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)





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

StefanL38
12-26-2009, 07:17 PM
Hi Noobmuncher,

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