2020-08-04 17:42:52 -03:00
|
|
|
#pragma once
|
|
|
|
|
2021-12-23 20:05:30 -04:00
|
|
|
#include "AP_OpticalFlow.h"
|
2020-08-04 17:42:52 -03:00
|
|
|
#include <AP_HAL/utility/OwnPtr.h>
|
|
|
|
|
2020-09-01 04:54:50 -03:00
|
|
|
#if HAL_MSP_OPTICALFLOW_ENABLED
|
2020-08-04 17:42:52 -03:00
|
|
|
|
|
|
|
class AP_OpticalFlow_MSP : public OpticalFlow_backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// constructor
|
|
|
|
using OpticalFlow_backend::OpticalFlow_backend;
|
|
|
|
|
|
|
|
// initialise the sensor
|
|
|
|
void init() override {}
|
|
|
|
|
|
|
|
// read latest values from sensor and fill in x,y and totals.
|
|
|
|
void update(void) override;
|
|
|
|
|
|
|
|
// get update from msp
|
2020-09-07 19:28:22 -03:00
|
|
|
void handle_msp(const MSP::msp_opflow_data_message_t &pkt) override;
|
2020-08-04 17:42:52 -03:00
|
|
|
|
|
|
|
// detect if the sensor is available
|
2022-08-14 22:31:14 -03:00
|
|
|
static AP_OpticalFlow_MSP *detect(AP_OpticalFlow &_frontend);
|
2020-08-04 17:42:52 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
uint64_t prev_frame_us; // system time of last message when update was last called
|
|
|
|
uint64_t latest_frame_us; // system time of most recent messages processed
|
|
|
|
Vector2l flow_sum; // sum of sensor's flow_x and flow_y values since last call to update
|
|
|
|
uint16_t quality_sum; // sum of sensor's quality values since last call to update
|
|
|
|
uint16_t count; // number of sensor readings since last call to update
|
|
|
|
Vector2f gyro_sum; // sum of gyro sensor values since last frame from flow sensor
|
|
|
|
uint16_t gyro_sum_count; // number of gyro sensor values in sum
|
|
|
|
};
|
|
|
|
|
2020-09-01 04:54:50 -03:00
|
|
|
#endif // HAL_MSP_OPTICALFLOW_ENABLED
|