AP_Compass: add support for custom board orientations

This commit is contained in:
Jacob Walser 2018-03-08 21:26:18 -05:00 committed by Francisco Ferreira
parent f97ac4af30
commit 6699c59ad3
3 changed files with 14 additions and 3 deletions

View File

@ -460,6 +460,7 @@ Compass::Compass(void) :
_backend_count(0),
_compass_count(0),
_board_orientation(ROTATION_NONE),
_custom_rotation(nullptr),
_null_init_done(false),
_hil_mode(false)
{
@ -1210,7 +1211,11 @@ void Compass::setHIL(uint8_t instance, float roll, float pitch, float yaw)
if (!_state[0].external) {
// and add in AHRS_ORIENTATION setting if not an external compass
_hil.field[instance].rotate(_board_orientation);
if (_board_orientation == ROTATION_CUSTOM && _custom_rotation) {
_hil.field[instance] = *_custom_rotation * _hil.field[instance];
} else {
_hil.field[instance].rotate(_board_orientation);
}
}
_hil.healthy[instance] = true;
}

View File

@ -205,8 +205,9 @@ public:
float get_declination() const;
// set overall board orientation
void set_board_orientation(enum Rotation orientation) {
void set_board_orientation(enum Rotation orientation, Matrix3f* custom_rotation = nullptr) {
_board_orientation = orientation;
_custom_rotation = custom_rotation;
}
/// Set the motor compensation type
@ -390,6 +391,7 @@ private:
// board orientation from AHRS
enum Rotation _board_orientation;
Matrix3f* _custom_rotation;
// primary instance
AP_Int8 _primary;

View File

@ -20,7 +20,11 @@ void AP_Compass_Backend::rotate_field(Vector3f &mag, uint8_t instance)
if (!state.external) {
// and add in AHRS_ORIENTATION setting if not an external compass
mag.rotate(_compass._board_orientation);
if (_compass._board_orientation == ROTATION_CUSTOM && _compass._custom_rotation) {
mag = *_compass._custom_rotation * mag;
} else {
mag.rotate(_compass._board_orientation);
}
} else {
// add user selectable orientation
mag.rotate((enum Rotation)state.orientation.get());