diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.cpp b/libraries/AP_InertialSensor/AP_InertialSensor.cpp index 510742323c..9009acfb27 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor.cpp @@ -1011,13 +1011,16 @@ AP_InertialSensor::detect_backends(void) } #endif -#if defined(HAL_INS_PROBE_LIST) - // IMUs defined by IMU lines in hwdef.dat - HAL_INS_PROBE_LIST; -#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL +#if AP_SIM_INS_ENABLED for (uint8_t i=0; iimu_count; i++) { ADD_BACKEND(AP_InertialSensor_SITL::detect(*this, i==1?INS_SITL_SENSOR_B:INS_SITL_SENSOR_A)); } + return; +#endif + +#if defined(HAL_INS_PROBE_LIST) + // IMUs defined by IMU lines in hwdef.dat + HAL_INS_PROBE_LIST; #if defined(HAL_SITL_INVENSENSEV3) ADD_BACKEND(AP_InertialSensor_Invensensev3::probe(*this, hal.i2c_mgr->get_device(1, 1), ROTATION_NONE)); #endif diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.h b/libraries/AP_InertialSensor/AP_InertialSensor.h index 3085d7cd34..73ce9b9d47 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor.h @@ -47,6 +47,10 @@ #include #include +#ifndef AP_SIM_INS_ENABLED +#define AP_SIM_INS_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + class AP_InertialSensor_Backend; class AuxiliaryBus; class AP_AHRS; diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_SITL.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_SITL.cpp index 0084de73c1..d1b94c6d12 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_SITL.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_SITL.cpp @@ -3,7 +3,7 @@ #include #include -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL +#if AP_SIM_INS_ENABLED const extern AP_HAL::HAL& hal; @@ -347,4 +347,4 @@ void AP_InertialSensor_SITL::start() hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&AP_InertialSensor_SITL::timer_update, void)); } -#endif // HAL_BOARD_SITL +#endif // AP_SIM_INS_ENABLED diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_SITL.h b/libraries/AP_InertialSensor/AP_InertialSensor_SITL.h index 3abaeebba9..d1f4c9b1e9 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_SITL.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor_SITL.h @@ -1,15 +1,17 @@ #pragma once -#include - -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL #include "AP_InertialSensor.h" + +#if AP_SIM_INS_ENABLED + #include "AP_InertialSensor_Backend.h" // simulated sensor rates in Hz. This matches a pixhawk1 const uint16_t INS_SITL_SENSOR_A[] = { 1000, 1000 }; const uint16_t INS_SITL_SENSOR_B[] = { 760, 800 }; +#include + class AP_InertialSensor_SITL : public AP_InertialSensor_Backend { public: @@ -47,4 +49,4 @@ private: static uint8_t bus_id; }; -#endif // CONFIG_HAL_BOARD +#endif // AP_SIM_INS_ENABLED