Shop OBEX P1 Docs P2 Docs Learn Events
What am i doing wrong with my gyro? — Parallax Forums

What am i doing wrong with my gyro?

MagnusMagnus Posts: 18
edited 2005-11-29 03:00 in BASIC Stamp
I am trying to interface a GWS PG-03 gyro to my Stamp, but i can't get it to work.

* The Gyro woks fine connected to my RC receiver with a servo on the output.
* The gyro works fine with the input connected to the stamp and the output to a servo

When i try to measure the gyro puls with the PULSIN command i don't get any values at all. the code i'm using is attached below.

I have tried attaching the gyro with and without a 10Kohm pulldown resistor but without luck.

What am I missing???

/Magnus


Stamp code:


' {$STAMP BS2e}
' {$PBASIC 2.5}

servo PIN 15
gyro PIN 6
time VAR Word
i VAR Byte

i=0
Main:
i=i+1
PULSOUT servo,750 ' give gyro input
PULSIN gyro, 1, time ' read gyro pulse length
IF i=10 THEN GOSUB print ' print value to debug, only once every tenth time if there is a
' timing problem
GOTO main:


print:
DEBUG "gyro=", DEC time
i=0
RETURN

Comments

  • LarryLarry Posts: 212
    edited 2005-11-26 22:57
    you're not doing anything wrong, It's just that the gyro is triggering faster than the stamp can execute the pulsin command after the pulsout command. a dual trace scope will show the two pulses are very closely linked.

    Try triggering with another stamp or 555 timer, or at least measure the output of the receiver with the stamp and then using the stamp on the output side of the gyro to measure it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MagnusMagnus Posts: 18
    edited 2005-11-28 09:21
    Thank you,
    I connected the gyro to a servo controller and now everything works. Now it's just programming the stamp to do something useful with the input i get. Has anyone done any integrating of a gyro signal to keep track of current angle/heading?

    /Magnus
  • LarryLarry Posts: 212
    edited 2005-11-29 03:00
    Well, you can give it a try, but I have my doubts that a Stamp will be the way to go here. But a try won't cost you more that a couple of hours work. to do it, you need a loop with PULSIN , a little math to compute the angle change, itegrating (adding) it to the direction variable, drift correction, then back to start. a scaler constant for drift and for angle change makes tuning things easier.

    When you get an application going, have the gyro stay still at the start of the program so you can get the drift over time.

    The problem with using the Stamp is that integrating a gyro depends on taking readings at regular intervals . On a PIC (which is what a Stamp is), this is usually done by using one of the CCP (Capture and Compare) timer units to interrupt the program at regular intervals to take the readings. The Basic Stamp programming language has usurped all the timers for use with program commands like PULSIN, PULSOUT, RCTIME, COUNT, etc. You, as the user, have no direct access to the timers. (BS3?)

    Even the units with polled interrupts won't do you much good because they won't respond to an interrupt until the current command is done.

    To do the integrations properly, I think you need to dedicate a PIC or SX chip to the integrations, where you have control of the timers. I don't use SX basic, so I don't know if it gives you control of the timers, so you may need to code in assembler.

    ·Still, If you can do the calculations and get back to the PULSIN command· in less than the 20 or so microsecconds before the next time the gyro triggers, you might stand a chance. You will be depending on the regular timing of the servo controller to·establish ·the time iterval, and you won't be able to do much else.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (Larry) : 11/29/2005 3:25:06 AM GMT
Sign In or Register to comment.