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: Add initialization support for UPixels UPFLOW optical flow sensor #24187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

discodyer
Copy link

I followed the instructions in the data sheet and modified the code of the Upflow optical flow driver to support LC306 and LC302-8B modules. For more information, please refer to this issue: #23720

uint8_t recv_buf[3];

//delay 100ms before initialization
hal.scheduler->delay(100);
Copy link
Member

Choose a reason for hiding this comment

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

Not really a fan of delays in the init, this is called from the main thread. However, there are a few existing examples in rangefinder...

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your feedback. I understand your concern about latency in the main thread, but this is to ensure the sensor is initialized correctly. It is necessary to wait 100 ms for the sensor to initialize after powering up. However, do you have any suggestions or a more elegant approach?

// if failed to receive response code, you can start over from 0xAA.
if ((recv_buf[0] ^ recv_buf[1]) != recv_buf[2]) {
UPFLOW_INIT_FAILED;
return;
Copy link
Member

Choose a reason for hiding this comment

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

What happens on this early return? We don't call init a second time, so does this mean the sensor never works ?

Copy link
Author

Choose a reason for hiding this comment

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

What happens on this early return? We don't call init a second time, so does this mean the sensor never works ?

The reason for early return is that if the user inserts the LC302-3C, the sensor will not return any data during the initialization operation, and there is no need to continue the initialization operation. LC302-3C and other sensor versions that do not require initialization will not be affected.

The UPFLOW_INIT_FAILED macro is what I've set during debugging to monitor whether the initialization is successful or not in the ground station.
And I have conducted multiple tests using the Pixhawk 2.4.8 flight controller. For LC306 and LC302-8B, they can be initialized without any issues.

@discodyer discodyer requested a review from IamPete1 November 12, 2023 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants