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

Allow aligning the mag to any rotation #2833

Merged
merged 2 commits into from
Mar 23, 2018

Conversation

fiam
Copy link
Member

@fiam fiam commented Feb 24, 2018

Introduce 3 new variables which allow setting the decidegrees
for the mag sensor alignment. When any of these 3 variables
are non-zero, mag is assumed to be mounted off-board and
"align_mag" as well as the board alignment are ignored.

Settings are named align_mag_roll, align_mag_pitch and
align_mag_yaw.

Fixes #86
Fixes #1029

@fiam fiam added this to the 2.0 milestone Feb 24, 2018
@fiam
Copy link
Member Author

fiam commented Feb 24, 2018

Closes #2014

.angles.yaw = DECIDEGREES_TO_RADIANS(compassConfig()->yawDeciDegrees),
};

rotateV(&v, &r);
Copy link
Member

Choose a reason for hiding this comment

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

rotateV is quite expensive because it builds rotation matrix every time.

@fiam
Copy link
Member Author

fiam commented Feb 25, 2018

@digitalentity Just moved the matrix computation to compass initialization. I'm wondering if we should do this also for on-board mag alignment. The 9 mul + 6 add used by the rotation might be faster than the current branching + muls used by applySensorAlignment() + applyBoardAlignment(). I'll profile it later.

@fiam
Copy link
Member Author

fiam commented Feb 25, 2018

Just profiled this. First graph is on-board alignment with no board rotation, second is on-board alignment with some board rotation and third is the new code for off-board alignment:

On-board alignment, no board rotation
screen shot 2018-02-25 at 19 12 22

On-board alignment, board rotated
screen shot 2018-02-25 at 19 22 13

Off-board alignment
screen shot 2018-02-25 at 19 13 07

With a non-rotated board, performance of both approaches is basically the same. However, once board rotation is non-zero, the off-board alignment is faster. Upon reviewing the code for applySensorAlignment() and applyBoardAlignment(), it becomes clear that this happens because applyBoardAlignment() returns early when board has no rotation but performs a multiplication by a pre-calculated matrix when it's not, so it does as much as off-board alignment just in applyBoardAlignment() and then we still need to add applySensorAlignment() on top. There's, however, a drawback for the additional pre-computed matrix and it's that it takes 36 bytes of RAM.

With this said, and given that right now it doesn't make much sense to have an off-board aligned acc nor gyro, I think we should leave the on-board alignment code in since there's no good reason to spend 36 bytes of RAM per sensor to have a single matrix for each (specially on F3 targets where memory is already close to the limit).

@digitalentity digitalentity modified the milestones: 2.0, 1.9.1 Mar 5, 2018
Introduce 3 new variables which allow setting the decidegrees
for the mag sensor alignment. When any of these 3 variables
are non-zero, mag is assumed to be mounted off-board and
"align_mag" as well as the board alignment are ignored.

Settings are named align_mag_roll, align_mag_pitch and
align_mag_yaw.

Fixes #86
Fixes #1029
Introduce rotateByMatrix(), which rotates a vector by the given
matrix. Initialize the matrix on mag initialization, so it's not
recalculated on every mag reading.
@digitalentity digitalentity merged commit 07342d2 into development Mar 23, 2018
@digitalentity digitalentity deleted the agh_free_mag_alignment branch March 23, 2018 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants