Feed Optical Flow from custom sensor/algorithm to Ardupilot

I have implemented an optical flow algorithm in Python, and I would like to send the retrieved information to Ardupilot.

I am a beginner with Ardupilot, and as such I am wondering if it is possible/how I can do it.
My guess is that sending the proper Mavlink message would do the trick and optical flow from my algorithm could be accounted. Is this correct? If so, which is the correct MAVLink message to send?

Can you please advise?

If it makes a difference, I am using the Navio2 board with a Raspberry Pi 2.

Thank you.

Hi Yannis,

ArduPilot has many libraries, some of which have different backends/drivers. For your specific case you need to create a new Optical Flow backend (https://github.com/ArduPilot/ardupilot/tree/master/libraries/AP_OpticalFlow) that updates the frontend (from where all the optical flow is gathered by other libraries). How your backend gets information from your algorithm is something you’ll have to thing about - you are running Linux so there are multiple ways for process inter-communication.

As far as I’m aware there is no MAVLink message to send the needed optical flow information to a flight controller (and if there is, ArduPilot doesn’t support it at the moment).

Thank you Francisco for your answer.

I’ve been looking at the AP_OpticalFlow code as you suggested, which seems quite straightforward.

Apart from subclassing and implementing OpticalFlow_Backend (and recompiling of course), is there any other step that I should do to enable my custom sensor in the GCS to appear? I.e. should it be registered somehow, somewhere?

Thank you.

Also, I understand from the OpticalFlow_state struct that both optical flow based rate as well as body based rate (using a gyro) can be reported by the sensor implementation.

My question is, do we need to do gyro compensation at the sensor implementation (ie our own code), or is it done at the Ardupilot EKF? If it is the second, is the bodyRate vector taken into account at all?

Thanks

Hi @OXINARF,

I’m wondering if you would have any information to share re. the questions above.

Thank you.

Hi Yannis,

Sorry for taking so long to get back to you. Whoever made days with only 24 hours was a crazy person :smile:

Yes, look at https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_OpticalFlow/OpticalFlow.cpp#L84
As you’ll see there, each board basically has its own fixed optical flow backend. That can be enhanced so that we have a parameter where a user can choose which backend/driver he wants to use. You can also put your driver as the last option if no other optical flow driver was used (look at Pixart/PX4Flow case).

Now you are doing questions that are out my league :wink: I’m almost sure that gyro compensation has to be done by the driver (for example, PX4Flow hardware has a gyro and does its own compensation before data arrives at the ArduPilot side), but I can’t answer the second part. I’ll suggest that you go to our Gitter chat (http://gitter.im/ArduPilot/ardupilot) and ask there as developers hang around there more.

Hi Francisco,

Thanks a lot for your reply. 24h doesn’t cut it anymore for sure :sweat_smile:

I’ve started implementing my backend partially from my own code and partially by looking at the existing drivers, so the information you provided is really helpful.

I’ll drop by Gitter at some point as you suggested for further info.

Thanks!

1 Like