Shop OBEX P1 Docs P2 Docs Learn Events
Problems encountered when trying to control servos with accelerometer — Parallax Forums

Problems encountered when trying to control servos with accelerometer

ldemonldemon Posts: 5
edited 2009-10-01 07:47 in BASIC Stamp
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

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-09-29 11:46
    Welcome to the forums.

    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
    ·
  • ldemonldemon Posts: 5
    edited 2009-09-29 12:50
    Thx stamptrol.
    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 ?
  • stamptrolstamptrol Posts: 1,731
    edited 2009-09-29 13:05
    From the spec sheet for your servo, neutral position is with a pulse of 1500 uSec. On a BS2 that would be a pulsout value of 750.

    To speed up the refresh, decrease or eliminate the PAUSE 20 after each pulsout.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • ldemonldemon Posts: 5
    edited 2009-09-29 13:28
    Ok everything changed, the pulses are correct too, but my servos only rotates in counterclockwise. I tried doing the tutorial "What's a Microcontroller?" Chpt 4 Activity 1, i encounter the same problem, the servos does not move to the position as supposed.

    Post Edited (ldemon) : 9/29/2009 2:26:54 PM GMT
  • stamptrolstamptrol Posts: 1,731
    edited 2009-09-29 14:46
    I'd take one servo and write a simple loop program to prove what the real number required to position it is.

    Try it with a pulsout of 650, then 750, then 1000.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • ldemonldemon Posts: 5
    edited 2009-09-30 16:56
    this is the current wiring of the circuit. note that the battery pack has 4x1.5V batteries. is it a power issue?
    2592 x 1944 - 1007K
  • ldemonldemon Posts: 5
    edited 2009-10-01 07:47
    Problems solved for the servos problem. But a new problem arised, I need to create a pulse to control a rotor, the ideal way to control this pulse through a trigger ( something similar to a xbox console, to increase the rotor speed, the user have to press harder ). Is there any electronic around that i can use to achieve this?
Sign In or Register to comment.