ArduPilot开源代码之AP_OpticalFlow_CXOF
1. 源由
AP_OpticalFlow_CXOF
是就是一个光流计,与前面传感模块:MATEKSYS Optical Flow & LIDAR 3901-L0X不一样。
MATEKSYS Optical Flow & LIDAR 3901-L0X不仅仅只有一个光流计,还有一个Lidar高度计。而本次研读的是基于CXOF串口协议的光流传感器。
2. Library设计
设备相关的重要函数:
- init
- update
- detect
class AP_OpticalFlow_CXOF : public OpticalFlow_backend
{
public:
/// 构造函数
AP_OpticalFlow_CXOF(AP_OpticalFlow &_frontend, AP_HAL::UARTDriver *uart);
// 初始化传感器
void init() override;
// 从传感器读取最新值并填充 x, y 和 totals
void update(void) override;
// 检测传感器是否可用
static AP_OpticalFlow_CXOF *detect(AP_OpticalFlow &_frontend);
private:
AP_HAL::UARTDriver *uart; // 连接到光流传感器的 UART
uint64_t last_frame_us; // 上次从光流传感器接收到消息的系统时间
uint8_t buf[10]; // 从光流传感器接收到的字符缓冲区
uint8_t buf_len; // 缓冲区中的字符数
Vector2f gyro_sum; // 自上次从光流传感器接收到消息以来的陀螺仪传感器值的总和
uint16_t gyro_sum_count; // 陀螺仪传感器值总和中的数量
};
3. 重要例程
3.1 AP_OpticalFlow_CXOF::init
模块默认波特率19200 bps。