Problems encountered when trying to control servos with accelerometer
ldemon
Posts: 5
I tried using the accelerometer to control the pulse supplied to the servos. However the servos only turned anti-clockwise regardless of the pulse value.
It powered by 4xAA batteries. Servo is a Hitec HS-55.
' Controlling servos with accelerometer
'{$STAMP BS2}
'{$PBASIC 2.5}
accelx VAR Word 'accelerometer x value
accely VAR Word 'accelerometer y value
pulsex VAR Word 'pulse to control pitching
pulsey VAR Word 'pulse to control lateral movement
DO
PULSIN 6, 1, accelX
PULSIN 7, 1, accelY
PAUSE 20
pulsex = accelx * 3 / 4 - 1400
pulsey = accely * 3 / 4 - 1400
DEBUG HOME, DEC4 ? pulsex, DEC4 ? pulsey
PULSOUT 0, pulsex 'control elevator
PAUSE 20
PULSOUT 1, pulsey 'control rudder
PAUSE 20
PULSOUT 2 , pulsey 'control aileron
PAUSE 20
RETURN
LOOP
i m new in Basic stamp. Feel free to point out the mistakes that i made so i can learn from it. Thanks.
Post Edited (ldemon) : 9/29/2009 8:50:11 AM GMT
It powered by 4xAA batteries. Servo is a Hitec HS-55.
' Controlling servos with accelerometer
'{$STAMP BS2}
'{$PBASIC 2.5}
accelx VAR Word 'accelerometer x value
accely VAR Word 'accelerometer y value
pulsex VAR Word 'pulse to control pitching
pulsey VAR Word 'pulse to control lateral movement
DO
PULSIN 6, 1, accelX
PULSIN 7, 1, accelY
PAUSE 20
pulsex = accelx * 3 / 4 - 1400
pulsey = accely * 3 / 4 - 1400
DEBUG HOME, DEC4 ? pulsex, DEC4 ? pulsey
PULSOUT 0, pulsex 'control elevator
PAUSE 20
PULSOUT 1, pulsey 'control rudder
PAUSE 20
PULSOUT 2 , pulsey 'control aileron
PAUSE 20
RETURN
LOOP
i m new in Basic stamp. Feel free to point out the mistakes that i made so i can learn from it. Thanks.
Post Edited (ldemon) : 9/29/2009 8:50:11 AM GMT
Comments
When DEBUG shows the values for pulsex and pulsey, are they within the valid values for the servo? Should be 750 to 1500 on the BS2, I think.
Secondly, the servos expect to be updated within 20 mSec or so. Your loop is at least 80 mSec and probably longer due to the DEBUG.
RETURN is only used to get back from a subroutine, which is non-existent in your program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
The pulsex and pulsey are within the valid values of the servos i used (Hitec Hs-55).
The pulse required is 600-2400ms, so i m right to say that the pulsex n pulsey that is to be supplied shd be 300-1200 ?
Is there anyway that i could modify my program so that is will take 20msec to control 3 servo ?
To speed up the refresh, decrease or eliminate the PAUSE 20 after each pulsout.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Post Edited (ldemon) : 9/29/2009 2:26:54 PM GMT
Try it with a pulsout of 650, then 750, then 1000.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·