diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow.cpp b/libraries/AP_OpticalFlow/AP_OpticalFlow.cpp index 93a4c10b54..b9aa1914b8 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow.cpp +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow.cpp @@ -160,7 +160,7 @@ void AP_OpticalFlow::init(uint32_t log_bit) #endif break; case Type::SITL: -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL +#if AP_OPTICALFLOW_SITL_ENABLED backend = new AP_OpticalFlow_SITL(*this); #endif break; diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow.h b/libraries/AP_OpticalFlow/AP_OpticalFlow.h index 6b91b2ad0b..67de7287c8 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow.h +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow.h @@ -24,6 +24,10 @@ #define HAL_MSP_OPTICALFLOW_ENABLED (AP_OPTICALFLOW_ENABLED && (HAL_MSP_ENABLED && !HAL_MINIMIZE_FEATURES)) #endif +#ifndef AP_OPTICALFLOW_SITL_ENABLED +#define AP_OPTICALFLOW_SITL_ENABLED AP_SIM_ENABLED +#endif + #if AP_OPTICALFLOW_ENABLED /* diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_Backend.h b/libraries/AP_OpticalFlow/AP_OpticalFlow_Backend.h index 565d02ea05..059e5b92d1 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_Backend.h +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_Backend.h @@ -32,7 +32,7 @@ public: CLASS_NO_COPY(OpticalFlow_backend); // init - initialise sensor - virtual void init() = 0; + virtual void init() {} // read latest values from sensor and fill in x,y and totals. virtual void update() = 0; diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.cpp b/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.cpp index e2b387b64d..5ac842daba 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.cpp +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.cpp @@ -17,26 +17,17 @@ * AP_OpticalFlow_SITL.cpp - SITL emulation of optical flow sensor. */ -#include - -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL - #include "AP_OpticalFlow_SITL.h" -extern const AP_HAL::HAL& hal; +#if AP_OPTICALFLOW_SITL_ENABLED -AP_OpticalFlow_SITL::AP_OpticalFlow_SITL(AP_OpticalFlow &_frontend) : - OpticalFlow_backend(_frontend), - _sitl(AP::sitl()) -{ -} - -void AP_OpticalFlow_SITL::init(void) -{ -} +#include +#include void AP_OpticalFlow_SITL::update(void) { + auto *_sitl = AP::sitl(); + if (!_sitl->flow_enable) { return; } @@ -128,4 +119,4 @@ void AP_OpticalFlow_SITL::update(void) _update_frontend(state); } -#endif // CONFIG_HAL_BOARD +#endif // AP_OPTICALFLOW_SITL_ENABLED diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.h b/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.h index bcf2157c83..e54cdc8e9c 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.h +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_SITL.h @@ -1,27 +1,25 @@ #pragma once #include "AP_OpticalFlow.h" -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL -#include + +#if AP_OPTICALFLOW_SITL_ENABLED class AP_OpticalFlow_SITL : public OpticalFlow_backend { public: /// constructor - AP_OpticalFlow_SITL(AP_OpticalFlow &_frontend); - - // init - initialise the sensor - void init() override; + using OpticalFlow_backend::OpticalFlow_backend; // update - read latest values from sensor and fill in x,y and totals. void update(void) override; private: - SITL::SIM *_sitl; + uint32_t last_flow_ms; uint8_t next_optflow_index; uint8_t optflow_delay; AP_OpticalFlow::OpticalFlow_state optflow_data[20]; }; -#endif // CONFIG_HAL_BOARD + +#endif // AP_OPTICALFLOW_SITL_ENABLED