Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_AHRS: avoid unecessary work in update_orientation #11742

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion libraries/AP_AHRS/AP_AHRS.cpp
Expand Up @@ -229,7 +229,14 @@ 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::update_orientation()
{
const enum Rotation orientation = (enum Rotation)_board_orientation.get();
const Rotation orientation = (enum Rotation)_board_orientation.get();
if (last_orientation == orientation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks any changes to the orientation on the custom orientation, and would need to be done inside the first if block on line 240.

// nothing to do
return;
}

last_orientation = orientation;

if (orientation != ROTATION_CUSTOM) {
AP::ins().set_board_orientation(orientation);
if (_compass != nullptr) {
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_AHRS/AP_AHRS.h
Expand Up @@ -682,6 +682,9 @@ class AP_AHRS
uint32_t _last_AOA_update_ms;

private:

enum Rotation last_orientation = ROTATION_INVALID;

static AP_AHRS *_singleton;

AP_NMEA_Output* _nmea_out;
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Math/rotations.h
Expand Up @@ -75,6 +75,7 @@ enum Rotation : uint8_t {
///////////////////////////////////////////////////////////////////////
ROTATION_MAX,
ROTATION_CUSTOM = 100,
ROTATION_INVALID = 101,
};
/*
Here are the same values in a form sutable for a @Values attribute in
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Math/vector3.cpp
Expand Up @@ -30,6 +30,7 @@ void Vector3<T>::rotate(enum Rotation rotation)
T tmp;
switch (rotation) {
case ROTATION_NONE:
case ROTATION_INVALID:
case ROTATION_MAX:
return;
case ROTATION_YAW_45: {
Expand Down