Shop OBEX P1 Docs P2 Docs Learn Events
L3G4200D 3 axis gyroscope — Parallax Forums

L3G4200D 3 axis gyroscope

botninjabotninja Posts: 6
edited 2014-05-31 01:05 in Accessories
I just bought a L3G4200D 3 axis gyroscope module. I plan to use this module to determine the rotation of my robot. However I need help. I do not know how to turn the output from the sensor into degrees or radians.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-20 17:56
    What microcontroller are you using with the gyro?

    I'm pretty sure what you need to do is integrate the measurements from the sensor.

    There will be maximum rotation speed for the gyro and maximum output. You can use these values to figure out how to convert the reading to angular speed.

    You need to multiply the angular speed by the time between each measurement to compute the total angle turned. You'll have a hard time coming up with a precise angle measurement just from the gyro since this sort of integration is prone to an accumulation of errors.

    A gyro can be combined with a magnetometer to help correct for these accumulated errors.
  • botninjabotninja Posts: 6
    edited 2014-05-22 06:23
    I'm am using an arduino uno. I would like to know what type of data the module outputs as well("I check the documentation thoroughly and did not find it.> I think that could help me understand how to create a rotation from the sensor.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-22 07:31
    On page 12 this application note it shows the values of the registers holding the rate data at various rotation speeds.

    There's lot of other documentation available on the product page.(under "Downloads & Documentation")

    Sensors like these generally use a set of registers which need to be set to put the sensor in the desired mode and then then the data registers are read. The registers can be written to and read from using either I2C or SPI.

    The sample Spin code used I2C so that's what I used when I experimented with the L3G4200D. I just used the default settings.

    I notice there isn't code for the Arduino available on the product page but Google returned a bunch of results when I did a search there.

    I know you already have the L3G4200D sensor (as do I) but you might want to think about getting one of these inexpensive MPU6050 chips. It does the angular integration for you. I tried one with an Arduino and I was amazed at how well it combined the sensor readings. There are some links to Arduino code for the MPU6050 in this thread.
  • botninjabotninja Posts: 6
    edited 2014-05-24 12:00
    Actual there is example code on learn.parallax.com, I am using that code for my robot. I have include a link: http://learn.parallax.com/KickStart/27911
    A
    lso I am a little confused by the explanation you gave in your first post Duane Degn(It's been a while since I took a calculus course if the integrating you reefer to is of the calculus type). Do you mind sending some form of detail instructions or psuedocode
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-24 12:38
    It's not really the calculus type of integration. Integrating in this context basically means "adding up". Since the gyro doesn't output an angle but a rate, you need to use the rate times time to come up with the angle moved. You keep adding up these bits of movement over time to compute the total angle moved. This process is very prone to error.

    I uploaded a video the other day (really poor quality). I was trying to use feedback from the L3G4200D with my omni bot. The video is unlisted but here's a link. I was comparing the L3G4200D to a helicopter gyro with heading lock. The heading lock gyro worked pretty well.

    I didn't have good enough low speed control of the omni wheels to be able to make good use of either gyro. I'm planning on changing the motors on my omni bot to ones with encoders. Hopefully motors with encoders will allow me to make better use of these gyros.

    Here's what I think some integration code would look like.
      repeat
        newAngle = newRateFromGyro * timeSinceLastReading
        totalAngle = totalAngle + newAngle
    
    

    Again, this sort of calculation is very prone to errors.
  • botninjabotninja Posts: 6
    edited 2014-05-25 13:16
    thank you this is a big help. I will try this on my robot.
  • rholtrholt Posts: 1
    edited 2014-05-30 18:14
    while this is a bit off topic, it's still about the gyro board. i just got mine today & i've been working on it for HOURS - seriously like over 5 hours and i have not gotten one bit of data from it. i'm using a Digix board (arduino due) and i've run at least 10 sketches against it and i have yet to get any data from the serial monitor. i've checked the baud and that is fine. now a lot of the sketches try and do some big things, but all i'm looking for is "proof of life" from this board! please send me out a link or code or the simplest way i can detect that this board is not defective.
    thanks in advance for your help!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-30 21:22
    rholt wrote: »
    i'm using a Digix board (arduino due) and i've run at least 10 sketches against it and i have yet to get any data from the serial monitor. . . .please send me out a link or code or the simplest way i can detect that this board is not defective.
    thanks in advance for your help!

    Do we need a Due board to test the code? I have an Uno and I'm willing to try out some code but I don't know if that will prove anything unless you also have a Uno compatible board.

    I don't use Arduino boards a lot so I'm not sure what the best way to help.

    Do you have an Uno?

    Do you have links to these sketches you've tried?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2014-05-31 01:05
    This example is with a different Gyro, but the principle is still the same .... I know from testing the other Gyro with this code I could turn a complete 360 and back and return to Zero if I was very careful with my motions. Keep in mind though to complicate things further, because of the rotation of the Earth there is a natural drift of 15 Degrees per hour that may "appear" to be an accumulative drift error at first.

    Here is the link:
    http://forums.parallax.com/showthread.php/127868-Gyro-lisy300
Sign In or Register to comment.