How to read the angle from the gyro FXAS21002C

Discussion in 'UDOO NEO' started by Lingxiao Wang, Aug 18, 2016.

  1. Lingxiao Wang

    Lingxiao Wang New Member

    Joined:
    Aug 18, 2016
    Messages:
    3
    Likes Received:
    0
    Hi, guys. I am trying to read angle from the Gyro, and right now, by following the tutorial here, I can read the "gx"(gyroSensor.gyroData.x) from the M4 core.
    However, my problem is that how to transform the "gx" to the real angle, and does anyone can provide the sample code to read the angle from the Gyro.
    Thanks!
     
  2. Lingxiao Wang

    Lingxiao Wang New Member

    Joined:
    Aug 18, 2016
    Messages:
    3
    Likes Received:
    0
    In addition, what is the gyroSensor.gyroData.x? Is this the angular speed on X axis?
     
  3. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    You can't. A gyroscope measures the angular speed, i.e. the speed the sensor rotates over one of its axises. So if the sensor doesn't move, the sensor returns zero for all axises independent if it's perfectly horizontal or not relatively to the horizon. To get these angles you might consider using the accelerometer and use vector addition to get the vector representing the direction and length where the acceleration goes. If the sensor doesn't move this is equivalent to where the ground is. From there it's just a set of sinuses and cosines to get the angles ;-)

    As already said, gyroData.x doesn't represent a particular angle rather than the speed the angle changes. It's measured in degress per second and the actual value depends on the resolution being set up during initialization. The library's standard value is 250 degrees/s which will represented by 32767 (-32768 if the rotation is the other way around), so if the sensor e.g. returns 655 the current angular speed is ca. 5°/s.

    There is one problem though. If the library in use here is this implementation, the readout of the angular speed is not correct (it was copied from the library for the accelerometer). The readout of the accel-sensor is a 14-bit value, the code was copied without change to the gyro-library where 16-bit-values are returned. So by using gyro.readGyroData you get wrong results.

    I recommend you read Freescale's specification for this sensor to get a sense what the sensor can do and what it can't do. There is also an application note about Allan Variances which doesn't cover your question but is nice to read anyway ;-)
     
    Lingxiao Wang likes this.
  4. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Yes. See page 7 of the specification I just linked to above to see the schematics
     
  5. Lingxiao Wang

    Lingxiao Wang New Member

    Joined:
    Aug 18, 2016
    Messages:
    3
    Likes Received:
    0
    Thanks for your reply. Still have a question: since i need the speed of angle change on the x axis, so i can get this data by (gyroData.x/131.0), right? In other words, the result of gyroData.x/131.0 is the angular speed on x axis?
     
  6. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Depends on the configured resolution. I think a more robust approach is calling getGres(), i.e. calculating the angular speed with gyroSensor.gyroData.x * gyroSensor.getGres()
     
  7. William Warke

    William Warke New Member

    Joined:
    Oct 5, 2016
    Messages:
    7
    Likes Received:
    3
    Hello,

    I've been battling these same issues myself; mostly regarding the FXAS21002C library included with the Arduino library for the Neo (see http://www.udoo.org/docs-neo/Arduino_M4_Processor/Controlling_9-axis_motion_sensors.html). I don't understand how so many successful projects have utilized the gyro on the Neo without completely rewriting the library. Am I missing something?

    Not only does the "official" library assume a 14-bit ADC; it miscalculates the FSR by a mile. If I understand this correctly, you need to multiply the raw, 2's complement, 16-bit register reading by the respective sensitivity value (corresponding to the FS setting) in mdps/LSB from Table 5 of the datasheet to obtain an angular velocity reading in degrees per second. What doesn't make sense to me is that the Full-scale ranges don't perfectly line up with the sensitivity values, i.e., Sensitivity * 32767 is not equal to the Full-scale range, leading me to believe that the outlying ADC counts are outside of the range, or it's just rounded off to even multiples of 50.
     
    Last edited: Dec 11, 2016

Share This Page