Skip to content

Commit

Permalink
AP_AHRS: Add support for custom board orientations
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxzer authored and OXINARF committed Apr 24, 2018
1 parent ad4e928 commit 74be9f0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
47 changes: 46 additions & 1 deletion libraries/AP_AHRS/AP_AHRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const AP_Param::GroupInfo AP_AHRS::var_info[] = {
// @Param: ORIENTATION
// @DisplayName: Board Orientation
// @Description: Overall board orientation relative to the standard orientation for the board type. This rotates the IMU and compass readings to allow the board to be oriented in your vehicle at any 90 or 45 degree angle. This option takes affect on next boot. After changing you will need to re-level your vehicle.
// @Values: 0:None,1:Yaw45,2:Yaw90,3:Yaw135,4:Yaw180,5:Yaw225,6:Yaw270,7:Yaw315,8:Roll180,9:Roll180Yaw45,10:Roll180Yaw90,11:Roll180Yaw135,12:Pitch180,13:Roll180Yaw225,14:Roll180Yaw270,15:Roll180Yaw315,16:Roll90,17:Roll90Yaw45,18:Roll90Yaw90,19:Roll90Yaw135,20:Roll270,21:Roll270Yaw45,22:Roll270Yaw90,23:Roll270Yaw136,24:Pitch90,25:Pitch270,26:Pitch180Yaw90,27:Pitch180Yaw270,28:Roll90Pitch90,29:Roll180Pitch90,30:Roll270Pitch90,31:Roll90Pitch180,32:Roll270Pitch180,33:Roll90Pitch270,34:Roll180Pitch270,35:Roll270Pitch270,36:Roll90Pitch180Yaw90,37:Roll90Yaw270,38:Yaw293Pitch68Roll180,39:Pitch315,40:Roll90Pitch315
// @Values: 0:None,1:Yaw45,2:Yaw90,3:Yaw135,4:Yaw180,5:Yaw225,6:Yaw270,7:Yaw315,8:Roll180,9:Roll180Yaw45,10:Roll180Yaw90,11:Roll180Yaw135,12:Pitch180,13:Roll180Yaw225,14:Roll180Yaw270,15:Roll180Yaw315,16:Roll90,17:Roll90Yaw45,18:Roll90Yaw90,19:Roll90Yaw135,20:Roll270,21:Roll270Yaw45,22:Roll270Yaw90,23:Roll270Yaw135,24:Pitch90,25:Pitch270,26:Pitch180Yaw90,27:Pitch180Yaw270,28:Roll90Pitch90,29:Roll180Pitch90,30:Roll270Pitch90,31:Roll90Pitch180,32:Roll270Pitch180,33:Roll90Pitch270,34:Roll180Pitch270,35:Roll270Pitch270,36:Roll90Pitch180Yaw90,37:Roll90Yaw270,38:Yaw293Pitch68Roll180,39:Pitch315,40:Roll90Pitch315,100:Custom
// @User: Advanced
AP_GROUPINFO("ORIENTATION", 9, AP_AHRS, _board_orientation, 0),

Expand Down Expand Up @@ -128,6 +128,33 @@ const AP_Param::GroupInfo AP_AHRS::var_info[] = {
AP_GROUPINFO("EKF_TYPE", 14, AP_AHRS, _ekf_type, 2),
#endif

// @Param: CUSTOM_ROLL
// @DisplayName: Board orientation roll offset
// @Description: Autopilot mounting position roll offset. Positive values = roll right, negative values = roll left. This parameter is only used when AHRS_ORIENTATION is set to CUSTOM.
// @Range: -180 180
// @Units: deg
// @Increment: 1
// @User: Advanced
AP_GROUPINFO("CUSTOM_ROLL", 15, AP_AHRS, _custom_roll, 0),

// @Param: CUSTOM_PIT
// @DisplayName: Board orientation pitch offset
// @Description: Autopilot mounting position pitch offset. Positive values = pitch up, negative values = pitch down. This parameter is only used when AHRS_ORIENTATION is set to CUSTOM.
// @Range: -180 180
// @Units: deg
// @Increment: 1
// @User: Advanced
AP_GROUPINFO("CUSTOM_PIT", 16, AP_AHRS, _custom_pitch, 0),

// @Param: CUSTOM_YAW
// @DisplayName: Board orientation yaw offset
// @Description: Autopilot mounting position yaw offset. Positive values = yaw right, negative values = yaw left. This parameter is only used when AHRS_ORIENTATION is set to CUSTOM.
// @Range: -180 180
// @Units: deg
// @Increment: 1
// @User: Advanced
AP_GROUPINFO("CUSTOM_YAW", 17, AP_AHRS, _custom_yaw, 0),

AP_GROUPEND
};

Expand Down Expand Up @@ -185,6 +212,24 @@ void AP_AHRS::add_trim(float roll_in_radians, float pitch_in_radians, bool save_
}
}

// Set the board mounting orientation, may be called while disarmed
void AP_AHRS::set_orientation()
{
enum Rotation orientation = (enum Rotation)_board_orientation.get();
if (orientation != ROTATION_CUSTOM) {
AP::ins().set_board_orientation(orientation);
if (_compass != nullptr) {
_compass->set_board_orientation(orientation);
}
} else {
_custom_rotation.from_euler(_custom_roll, _custom_pitch, _custom_yaw);
AP::ins().set_board_orientation(orientation, &_custom_rotation);
if (_compass != nullptr) {
_compass->set_board_orientation(orientation, &_custom_rotation);
}
}
}

// return a ground speed estimate in m/s
Vector2f AP_AHRS::groundspeed_vector(void)
{
Expand Down
12 changes: 6 additions & 6 deletions libraries/AP_AHRS/AP_AHRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ class AP_AHRS

// allow for runtime change of orientation
// this makes initial config easier
void set_orientation() {
AP::ins().set_board_orientation((enum Rotation)_board_orientation.get());
if (_compass != nullptr) {
_compass->set_board_orientation((enum Rotation)_board_orientation.get());
}
}
void set_orientation();

void set_airspeed(AP_Airspeed *airspeed) {
_airspeed = airspeed;
Expand Down Expand Up @@ -583,6 +578,11 @@ class AP_AHRS
AP_Int8 _gps_minsats;
AP_Int8 _gps_delay;
AP_Int8 _ekf_type;
AP_Float _custom_roll;
AP_Float _custom_pitch;
AP_Float _custom_yaw;

Matrix3f _custom_rotation;

// flags structure
struct ahrs_flags {
Expand Down

0 comments on commit 74be9f0

Please sign in to comment.