Browse Source

AP_Compass: use a separate slot for the custom compass rotation

zr-v5.1
Andy Piper 5 years ago committed by Andrew Tridgell
parent
commit
63b5711a4d
  1. 8
      libraries/AP_Compass/AP_Compass.h
  2. 12
      libraries/AP_Compass/AP_Compass_Backend.cpp

8
libraries/AP_Compass/AP_Compass.h

@ -224,10 +224,8 @@ public:
// set overall board orientation // set overall board orientation
void set_board_orientation(enum Rotation orientation, Matrix3f* custom_rotation = nullptr) { void set_board_orientation(enum Rotation orientation, Matrix3f* custom_rotation = nullptr) {
_board_orientation = orientation; _board_orientation = orientation;
if (custom_rotation) {
_custom_rotation = custom_rotation; _custom_rotation = custom_rotation;
} }
}
/// Set the motor compensation type /// Set the motor compensation type
/// ///
@ -438,9 +436,13 @@ private:
// board orientation from AHRS // board orientation from AHRS
enum Rotation _board_orientation = ROTATION_NONE; enum Rotation _board_orientation = ROTATION_NONE;
// custom rotation matrix
// custom board rotation matrix
Matrix3f* _custom_rotation; Matrix3f* _custom_rotation;
// custom external compass rotation matrix
Matrix3f* _custom_external_rotation;
// declination in radians // declination in radians
AP_Float _declination; AP_Float _declination;

12
libraries/AP_Compass/AP_Compass_Backend.cpp

@ -32,8 +32,8 @@ void AP_Compass_Backend::rotate_field(Vector3f &mag, uint8_t instance)
// add user selectable orientation // add user selectable orientation
#if !APM_BUILD_TYPE(APM_BUILD_AP_Periph) #if !APM_BUILD_TYPE(APM_BUILD_AP_Periph)
Rotation rotation = Rotation(state.orientation.get()); Rotation rotation = Rotation(state.orientation.get());
if (rotation == ROTATION_CUSTOM && _compass._custom_rotation) { if (rotation == ROTATION_CUSTOM && _compass._custom_external_rotation) {
mag = *_compass._custom_rotation * mag; mag = *_compass._custom_external_rotation * mag;
} else { } else {
mag.rotate(rotation); mag.rotate(rotation);
} }
@ -234,9 +234,11 @@ void AP_Compass_Backend::set_rotation(uint8_t instance, enum Rotation rotation)
_compass._state[Compass::StateIndex(instance)].rotation = rotation; _compass._state[Compass::StateIndex(instance)].rotation = rotation;
#if !APM_BUILD_TYPE(APM_BUILD_AP_Periph) #if !APM_BUILD_TYPE(APM_BUILD_AP_Periph)
// lazily create the custom rotation matrix // lazily create the custom rotation matrix
if (!_compass._custom_rotation && Rotation(_compass._state[Compass::StateIndex(instance)].orientation.get()) == ROTATION_CUSTOM) { if (!_compass._custom_external_rotation && Rotation(_compass._state[Compass::StateIndex(instance)].orientation.get()) == ROTATION_CUSTOM) {
_compass._custom_rotation = new Matrix3f(); _compass._custom_external_rotation = new Matrix3f();
_compass._custom_rotation->from_euler(radians(_compass._custom_roll), radians(_compass._custom_pitch), radians(_compass._custom_yaw)); if (_compass._custom_external_rotation) {
_compass._custom_external_rotation->from_euler(radians(_compass._custom_roll), radians(_compass._custom_pitch), radians(_compass._custom_yaw));
}
} }
#endif #endif
} }

Loading…
Cancel
Save