Patch for Arbitrary IMU Orientation

Hi everyone,I've written a patch for APM that allows for the autopilot/IMU shield to be placed in any arbitrary orientation relative to the airframe. The patch (based on current trunk code) basically contains the code to add Euler angle offsets to the angles produced by the DCM code, along with a menu utility that automatically calculates the roll and pitch offsets, based on the gravity vector. A more detailed description of the patch is below (the patches, one for library code and one for the main APM code, are attached). As far as I can tell, this functionality is not currently present in APM or ACM.I would like to have this patch reviewed for possible inclusion into the APM project but I'm unsure of the standard procedure to get in contact with a developer (I apologize if I missed any obvious instructions). I figured either this forum is an acceptable channel or someone would be able to point me in the right direction.Any feedback on the patch code and/or underlying methods would also be appreciated.Thanks,Tim--- Summary ---IMU Arbitrary OrientationThis allows the IMU (and autopilot, if attached) to be placed in any convenient orientation relative to the airframe, especially to enable the autopilot to fit in smaller airframes.Currently, the IMU assumes it is completely level (roll = pitch = 0 relative to earth) on startup in order to calculate the bias of the accelerometers. If the pitch or roll is actually non-zero, the recorded bias will be incorrect. For larger values of pitch and roll, the incorrect bias values will effectively decouple the accelerometer and gyro axes so that, under static conditions, the orientation of the aircraft will seem correct (due to the correction of the accelerometers) but, during rotation transients, the estimated orientation of the aircraft from the IMU will be incorrect (e.g. a yaw will produce both roll and yaw changes from the IMU).In order to allow arbitrary IMU orientation, the constant roll, pitch, and yaw offsets of the aircraft relative to the IMU are calculated and added to each calculation of the Euler angles calculated by the DCM code. These angle offsets are hardcoded via constants in the configuration file. The accelerometer offset calibration is removed from ground startup (the gyro offset calibration is unchanged) and added to the Setup menu for manual setting.A utility has been added to the Test menu ("orient") that determines the IMU orientation offset by comparing the measured gravity unit vector to the z-axis unit vector and requires the airframe to be in the desired position for airframe roll = pitch = 0. The calculated values can then be copied into the airframe configuration. This gravity-vector approach does not allow for the automatic computation of the relative yaw offset and, if the relative pitch offset is +/-90 degrees (i.e. the front of the IMU is pointing directly upwards or downwards), relative roll offset is unable to be calculated.The accelerometer offset calibration menu option in the Setup menu ("accel") calls for the IMU to be placed on a flat surface so that roll = pitch = 0 relative to earth and runs the IMU::accel_init() function calculate and store accelerometer offsets. This behavior is the same as the original code, although, if IMU arbitrary orientation is enabled, this offset calculation is no longer run automatically on a ground start.By default, the IMU arbitrary orientation behavior is disabled and the currently existing code (including startup accelerometer bias calibration) is executed. IMU arbitrary orientation behavior can be enabled by adding the following line to the airframe configuration file:#define IMU_ARBITRARY_ORIENTATION ENABLEDOther constants related to IMU arbitrary orientation behavior:RELATIVE_IMU_ROLL // Angle between roll axis of IMU and airframe (relative to IMU)RELATIVE_IMU_PITCH // " " pitch " "RELATIVE_IMU_YAW // " " yaw " "An intended use example is as follows:1) Enable IMU arbitrary orientation by setting "#define IMU_ARBITRARY_ORIENTATION ENABLED" in the configuration file.2) IMU is placed on a level surface so that roll = pitch = 0 relative to earth.3) The "accel" utility from the Setup menu is run to calibrate accelerometer offsets (EEPROM is automatically updated).4) IMU is place in desired orientation on aircraft.5) Aircraft is held steady at the desired airframe roll = pitch = 0 orientation.6) The "orient" utility from the Test menu is run.7) The offset values are copied and pasted into the definitions of the desired configuration constants (i.e. RELATIVE_IMU_ROLL, RELATIVE_IMU_PITCH, RELATIVE_IMU_YAW). Any angles that could not be automatically calculated should be manually determined.8) Set the slider switch back to flight mode and upload the new autopilot firmware. The IMU should be correctly reporting the aircraft's orientation; check to ensure valid behavior.

ImuArbitraryOrientation_0_ArduPilotMega.diff

ImuArbitraryOrientation_0_libraries.diff

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Developer
    Your scheme will only work for certain orientations - for any orientation where the z axis is rotated this scheme will compromise the DCM drift correction algorithms.  That is to say if you want to mount the board so that the I/O pins are in the front instead of the back this will be OK, but if you want to mount it so that the components face the side instead of up, the drift correction will not work correctly.
  • Great!!!
This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…