2021-03-12 07:56:34 -04:00
|
|
|
#pragma once
|
|
|
|
|
2021-12-23 20:05:30 -04:00
|
|
|
#include "AP_OpticalFlow.h"
|
2021-12-24 01:47:21 -04:00
|
|
|
|
|
|
|
#ifndef AP_OPTICALFLOW_UPFLOW_ENABLED
|
|
|
|
#define AP_OPTICALFLOW_UPFLOW_ENABLED AP_OPTICALFLOW_ENABLED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_OPTICALFLOW_UPFLOW_ENABLED
|
|
|
|
|
2021-03-12 07:56:34 -04:00
|
|
|
#include <AP_HAL/utility/OwnPtr.h>
|
|
|
|
|
|
|
|
class AP_OpticalFlow_UPFLOW : public OpticalFlow_backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// constructor
|
2022-08-14 22:31:14 -03:00
|
|
|
AP_OpticalFlow_UPFLOW(AP_OpticalFlow &_frontend, AP_HAL::UARTDriver *uart);
|
2021-03-12 07:56:34 -04:00
|
|
|
|
|
|
|
// initialise the sensor
|
|
|
|
void init() override;
|
|
|
|
|
|
|
|
// read latest values from sensor and fill in x,y and totals.
|
|
|
|
void update(void) override;
|
|
|
|
|
|
|
|
// detect if the sensor is available
|
2022-08-14 22:31:14 -03:00
|
|
|
static AP_OpticalFlow_UPFLOW *detect(AP_OpticalFlow &_frontend);
|
2021-03-12 07:56:34 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct PACKED UpixelsOpticalFlow {
|
|
|
|
int16_t flow_x_integral; //unit:10^-4 radians multiply by 10^-4 to get radians
|
|
|
|
int16_t flow_y_integral; //unit:10^-4 radians multiply by 10^-4 to get radians
|
|
|
|
uint16_t integration_timespan; //dt in us
|
|
|
|
uint16_t ground_distance; //reserved, always 999
|
|
|
|
uint8_t quality; //0 for not valid, 245 for valid.
|
|
|
|
uint8_t version;
|
|
|
|
};
|
|
|
|
AP_HAL::UARTDriver *uart; // uart connected to flow sensor
|
|
|
|
struct UpixelsOpticalFlow updata; // struct for received data
|
|
|
|
uint16_t recv_count; // amount of bytes received
|
|
|
|
uint8_t sum; //checksum
|
|
|
|
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
|
|
|
|
};
|
2021-12-24 01:47:21 -04:00
|
|
|
|
|
|
|
#endif // AP_OPTICALFLOW_UPFLOW_ENABLED
|