Line data Source code
1 : #pragma once 2 : 3 : #include "AP_OpticalFlow_config.h" 4 : 5 : #if AP_OPTICALFLOW_MAV_ENABLED 6 : 7 : #include "AP_OpticalFlow_Backend.h" 8 : #include <AP_HAL/utility/OwnPtr.h> 9 : 10 : class AP_OpticalFlow_MAV : public OpticalFlow_backend 11 : { 12 : public: 13 : /// constructor 14 : using OpticalFlow_backend::OpticalFlow_backend; 15 : 16 : // initialise the sensor 17 0 : void init() override {} 18 : 19 : // read latest values from sensor and fill in x,y and totals. 20 : void update(void) override; 21 : 22 : // get update from mavlink 23 : void handle_msg(const mavlink_message_t &msg) override; 24 : 25 : // detect if the sensor is available 26 : static AP_OpticalFlow_MAV *detect(AP_OpticalFlow &_frontend); 27 : 28 : private: 29 : 30 : uint64_t prev_frame_us; // system time of last message when update was last called 31 : uint64_t latest_frame_us; // system time of most recent messages processed 32 : Vector2f flow_sum; // sum of sensor's flow_x and flow_y values since last call to update 33 : bool flow_sum_is_rads; // true if flow_sum holds values in rad/s, if false flow_sum holds dpi 34 : uint16_t quality_sum; // sum of sensor's quality values since last call to update 35 : uint16_t count; // number of sensor readings since last call to update 36 : uint8_t sensor_id; // sensor_id received in latest mavlink message 37 : Vector2f gyro_sum; // sum of gyro sensor values since last frame from flow sensor 38 : uint16_t gyro_sum_count; // number of gyro sensor values in sum 39 : }; 40 : 41 : #endif // AP_OPTICALFLOW_MAV_ENABLED