Optical Flow to PID Control in ArduCoptor


I have an optical-flow sensor which is capable of reporting relative x and y offsets, so I would like to integrate it into my ArduCoptor drone in the future. Since I haven’t got a platform yet, I am trying to understand how optical-flow sensing gets work in current ArduPilot design.

The optical-flow sensor driver can be extensible by implementing a new backend in ardupilot/libraries/AP_OpticalFlow. The copter system periodically updates optical-flow output (in ardupilot/ArduCopter/sensor.cpp) to do Extendes Kalman Filters EKF2 & EKF3 (in ardupilot/libraries/AP_AHRS/AP_AHRS_NavEKF.cpp).

On the other hand, I read the basic PID controls from this article, which described two-level close loops for roll, pitch, yaw, and their rates. Even though it was for APM 2.9, I think it also can be applied to APM 3.x because this design is common and general (Correct me if I am wrong).

Now I get stuck. I lose the connection between these two parts, optical-flow output and PID controllers. Could anyone give me some hints to help me link these two parts? Thank you!