Gyroscopes/ADXRS613

From PaparazziUAV
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This page describes the setup of the ADXRS613 150 deg/sec gyro (breakout board from SparkFun) to measure roll rates with Twog v1.

Note 1: Some steps may have been inadvertently left out below
Note 2: The ADXRS613 is a 5V sensor while the PPZ MCU runs on 3.3V

Physical Setup

Solder wires onto the 5V, GND, RATE, and TEMP holes. Put the other ends of the wires into the connector housing. (The connector will be connected to port ADC2 on the PPZ board.)

Using port ADC2 and GND as pin 1:

  • PPZ pin 1 (GND) -> gyro's GND
  • PPZ pin 2 (+5V) -> gyro's 5V
  • PPZ pin 4 (ADC6) -> gyro's TEMP
  • PPZ pin 5 (ADC5) -> gyro's RATE
  • PPZ pin 3 (+3.3V) is left unconnected

ADC5 is used for the gyro's RATE as the voltage divider on the Twog divides a +5V signal down to a +3.3V signal.

The voltage divider connected to ADC6 on our board divides a +18V signal down to +3.3V so, at this time, we are not using the TEMP compensation. You may be able to use this ADC as-is with the TEMP signal but we have not yet tried. We plan on replacing this voltage divider with a +5V to +3.3V divider, as is found on ADC5.

Software Setup

Now that the gyro board can be physically interfaced with the PPZ, the airframe file must be updated.

Enable Gyro Code and ADCs

Add the following lines to the Makefile portion of the airframe file to include the gyro code:

ap.CFLAGS += -DGYRO -DADXRS150
ap.srcs   += gyro.c

Enable ADC5 and ADC6 by placing the following on the proper line:

-DUSE_ADC_5 -DUSE_ADC_6

Our ADC section (with the "proper" line) looks like this:

ap.CFLAGS += -DADC -DUSE_ADC_0 -DUSE_ADC_1 -DUSE_ADC_2 -DUSE_ADC_5 -DUSE_ADC_6
ap.srcs   += $(SRC_ARCH)/adc_hw.c

Map ADCs to Gyro

Add the following to the "adc" section in the airframe to map the ADCs and set the gyro sample buffer size:

<define name="GYRO_ROLL"       value="ADC_5"/>
<define name="GYRO_NB_SAMPLES" value="16"/> 
<define name="GYRO_TEMP"       value="ADC_6"/>

Configure Gyro

Add the following new section to the airframe:

<section name="GYRO" prefix="GYRO_">
    <define name="ADC_ROLL_NEUTRAL" value="500"/>
    <define name="ROLL_DIRECTION"   value="1"/>   <!-- Set to -1 to reverse -->
    <define name="ROLL_SCALE"       value="0.3"/> <!-- +/- 150 degrees / (1023-NEUTRAL) or +/- 150 degrees / (NEUTRAL) if NEUTRAL < 512 -->
    <define name="ADC_TEMP_NEUTRAL" value="385"/>
    <define name="ADC_TEMP_SLOPE"   value="0"/>   <!-- Temp compensation not used -->
</section>
  • ADC_ROLL_NEUTRAL - The ADC value of the RATE reading when the gyro is held still (read from the Messages window)
  • ROLL_DIRECTION - Reverses the direction of a positive roll (right wing dipping should be positive). Should be either "1" or "-1"
  • ROLL_SCALE - Degrees/second per ADC count from neutral
  • ADC_TEMP_NEUTRAL - ADC value of TEMP at temperature the ADC_ROLL_NEUTRAL was determined
  • ADC_TEMP_SLOPE - Volts of increased SCALE output voltage per TEMP ADC count from neutral (should be negative to offset positive temperature coefficient of output)

(The last two descriptions have not been tested and may not be completely correct.)

ROLL_SCALE Calibration
Messages window with gyro telemetry

The GYRO_RATES tab in the Messages window provides access to telemetry from the gyro sensor.

  • roll_adc - the current value of the RATE ADC minus the current RATE neutral value (RATE - neutral)
  • roll - the estimated roll rate of the gyro with the current calibration
  • pitch - the current value of the TEMP ADC minus the current TEMP neutral value (TEMP - neutral). Note: this will actually be the pitch reading if the gyro is 2-axis and IDG300 is defined in the airframe file (see gyro.c and ap_downlink.h for more information)

Our calibration was fairly rough but the following is how we did it. The roll neutral value was measured at 500 (average roll_adc + current neutral when the gyro is still). Since the gyro is specified to be able to measure at least +/-150 deg/sec, we assumed 0 ADC count to be 150 deg/sec (and 1023 counts would be greater than 150 deg/sec as more ADC counts are on that side of neutral).

(150 deg/sec) / (500 counts) = 0.3 (deg/sec)/count

The major assumptions with this calibration technique are:

  1. Either 0 or 1023 represents exactly 150 deg/sec, ignoring the sign of the rotational rate
  2. The +5V to +3.3V voltage divider is 100% accurate (i.e. a +5V signal fed into the divider will produce a +3.3V output, exactly)

This second assumption is easier to address (e.g. you can physically measure the voltage divider ratio and correct the ROLL_SCALE accordingly).

For confirmation, the gyro was set to measure the yaw access angular rates (the plane was easier to spin in this configuration), the fuselage was placed in a chair, and the chair was spun at roughly 90 deg/sec. The output of the gyro was read from the Messages window and was confirmed to be close to 90 deg/sec. After this testing, the gyro was mounted in its final roll-axis position.

Configure PPZ to Use Gyro

To have the PPZ use the gyro data when computing the roll attitude estimator, the "HORIZONTAL CONTROL" section of the airframe must also be edited. Our inner roll parameters look like this:

<!-- Inner roll loop parameters -->
<define name="ROLL_ATTITUDE_GAIN" value="-7500."/>
<define name="ROLL_RATE_GAIN"     value="-900."/>    <!-- Gyro -->
<!--<define name="ROLL_PGAIN"     value="8000."/>--> <!-- Ignored when H_CTL_ROLL_ATTITUDE_GAIN is defined -->

As is mentioned in the last (commented) line, ROLL_PGAIN is ignored when using ROLL_ATTITUDE_GAIN. ROLL_RATE_GAIN is used only when ROLL_ATTITUDE_GAIN is defined. ROLL_ATTITUDE_GAIN is the proportional coefficient of the roll attitude loop; ROLL_RATE_GAIN is the derivative coefficient of the loop.