Line data Source code
1 : #pragma once 2 : 3 : #include "AP_OpticalFlow_config.h" 4 : 5 : #if AP_OPTICALFLOW_PX4FLOW_ENABLED 6 : 7 : #include "AP_OpticalFlow_Backend.h" 8 : #include <AP_HAL/utility/OwnPtr.h> 9 : 10 : class AP_OpticalFlow_PX4Flow : public OpticalFlow_backend 11 : { 12 : public: 13 : /// constructor 14 : using OpticalFlow_backend::OpticalFlow_backend; 15 : 16 : CLASS_NO_COPY(AP_OpticalFlow_PX4Flow); 17 : 18 : // init - initialise the sensor 19 0 : void init() override {} 20 : 21 : // update - read latest values from sensor and fill in x,y and totals. 22 : void update(void) override; 23 : 24 : // detect if the sensor is available 25 : static AP_OpticalFlow_PX4Flow *detect(AP_OpticalFlow &_frontend); 26 : 27 : private: 28 : AP_HAL::OwnPtr<AP_HAL::Device> dev; 29 : 30 : static const uint8_t REG_INTEGRAL_FRAME = 0x16; 31 : 32 : // I2C data on register REG_INTEGRAL_FRAME 33 : struct PACKED i2c_integral_frame { 34 : uint16_t frame_count_since_last_readout; 35 : int16_t pixel_flow_x_integral; 36 : int16_t pixel_flow_y_integral; 37 : int16_t gyro_x_rate_integral; 38 : int16_t gyro_y_rate_integral; 39 : int16_t gyro_z_rate_integral; 40 : uint32_t integration_timespan; 41 : uint32_t sonar_timestamp; 42 : uint16_t ground_distance; 43 : int16_t gyro_temperature; 44 : uint8_t qual; 45 : }; 46 : 47 : // scan I2C bus addresses and buses 48 : bool scan_buses(void); 49 : 50 : // setup sensor 51 : bool setup_sensor(void); 52 : 53 : void timer(void); 54 : }; 55 : 56 : #endif // AP_OPTICALFLOW_PX4FLOW_ENABLED