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_OpticalFlow: fix for msp opflow sensor alignment #16226

Merged
merged 1 commit into from
Jan 8, 2021

Conversation

yaapu
Copy link
Contributor

@yaapu yaapu commented Jan 4, 2021

This fixes a bug in the MSP opflow driver.

It has been tested by @tenten8401, waiting for more testers to confirm the issue is solved.

@yaapu yaapu changed the title AP_OpticalFlow: fix for msp opflow sensor alignement AP_OpticalFlow: fix for msp opflow sensor alignment Jan 4, 2021
@rmackay9
Copy link
Contributor

rmackay9 commented Jan 5, 2021

Txs for this. So there are no changes to the flow rates (the changes to these lines is just cosmetic) but the body rates are reversed? Seems OK to me.

@yaapu
Copy link
Contributor Author

yaapu commented Jan 5, 2021

@rmackay9 yes, the bug was reversing only the flow, by installing the sensor as suggested by matek one could align body and flow but imu was reversed and had to apply a flow orient of 180°, by inverting both flow and body before applying flow orient you get aligned flow, body and imu with flow_orient = 0 as expected
Edit: this fix worked only when sensor alignment was 0°

@yaapu
Copy link
Contributor Author

yaapu commented Jan 6, 2021

@rmackay9 now I got it right, but I think there's a bug in the mavlink opflow driver I used as a reference when writing the MSP one, the state.bodyRate vector comes from the gyros and we should not apply the FLOW_ORIENT_YAW compensation since gyro info comes from ahrs and not from onboard the flow sensor, what do you think?

mavlink opflow bugged code is here

_applyYaw(state.flowRate);
_applyYaw(state.bodyRate);

I tested the MSP code against a Matek 3901
FLOW_TYPE = 7
OPFLOW_FXSCALER = -800
OPFLOW_FYSCALER = -800

sensor pointing forwards
FLOW_ORIENT_YAW = 0
image

sensor pointing right
FLOW_ORIENT_YAW = 9000
image

sensor pointing left
FLOW_ORIENT_YAW = -9000
image

sensor pointing backwards
FLOW_ORIENT_YAW = 18000
image

@rmackay9
Copy link
Contributor

rmackay9 commented Jan 6, 2021

@yaapu, yes, I think you are right. The issue exists in the CXOF driver as well. This would mean that these drivers wouldn't work correctly unless the sensor was placed in its default position (i.e. FLOW_ORIENT_YAW = 0).

Maybe create a separate PR to fix the other drivers too? We will have a bit of an issue because we will need to find someone to test them probably.

@yaapu
Copy link
Contributor Author

yaapu commented Jan 7, 2021

@rmackay9 ok, I might have a CXOF sensor somewhere and should be able to test by myself but we'll need help for the mavlink one, thanks

@yaapu
Copy link
Contributor Author

yaapu commented Jan 7, 2021

related PR #16256 for MAVLink and CXOF

@rmackay9 rmackay9 merged commit 480c9f1 into ArduPilot:master Jan 8, 2021
@rmackay9
Copy link
Contributor

rmackay9 commented Jan 8, 2021

Merged, thanks!

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.

None yet

2 participants