mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-02 14:08:45 -04:00
AP_InertialSensor: auto-handle invensense sensor changes
some boards swap out MPU6000 for MPU9250 or ICM20608
This commit is contained in:
parent
8e61b15384
commit
4ebf3309f7
@ -636,13 +636,14 @@ AP_InertialSensor::init(uint16_t sample_rate)
|
||||
_have_sample = false;
|
||||
}
|
||||
|
||||
void AP_InertialSensor::_add_backend(AP_InertialSensor_Backend *backend)
|
||||
bool AP_InertialSensor::_add_backend(AP_InertialSensor_Backend *backend)
|
||||
{
|
||||
if (!backend)
|
||||
return;
|
||||
return false;
|
||||
if (_backend_count == INS_MAX_BACKENDS)
|
||||
AP_HAL::panic("Too many INS backends");
|
||||
_backends[_backend_count++] = backend;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -678,26 +679,37 @@ AP_InertialSensor::detect_backends(void)
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.i2c_mgr->get_device(HAL_INS_MPU60x0_I2C_BUS, HAL_INS_MPU60x0_I2C_ADDR)));
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME)));
|
||||
#elif HAL_INS_DEFAULT == HAL_INS_PX4 || HAL_INS_DEFAULT == HAL_INS_VRBRAIN
|
||||
if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_TEST_V1) {
|
||||
|
||||
if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PX4V1) {
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_MPU60x0_NAME)));
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_TEST_V2) {
|
||||
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK) {
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_MPU60x0_NAME), ROTATION_ROLL_180));
|
||||
_add_backend(AP_InertialSensor_LSM9DS0::probe(*this,
|
||||
hal.spi->get_device(HAL_INS_LSM9DS0_G_NAME),
|
||||
hal.spi->get_device(HAL_INS_LSM9DS0_A_NAME), ROTATION_ROLL_180));
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_TEST_V3) {
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_EXT_NAME), true, ROTATION_PITCH_180));
|
||||
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK2) {
|
||||
// older Pixhawk2 boards have the MPU6000 instead of MPU9250
|
||||
if (!_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_EXT_NAME), true, ROTATION_PITCH_180))) {
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_MPU60x0_EXT_NAME), ROTATION_PITCH_180));
|
||||
}
|
||||
_add_backend(AP_InertialSensor_LSM9DS0::probe(*this,
|
||||
hal.spi->get_device(HAL_INS_LSM9DS0_EXT_G_NAME),
|
||||
hal.spi->get_device(HAL_INS_LSM9DS0_EXT_A_NAME), ROTATION_ROLL_180_YAW_270));
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME), false, ROTATION_YAW_270));
|
||||
if (!_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME), false, ROTATION_YAW_270))) {
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_MPU60x0_NAME), ROTATION_YAW_270));
|
||||
}
|
||||
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXRACER) {
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_ICM20608_NAME), ROTATION_ROLL_180_YAW_90));
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME), false, ROTATION_ROLL_180_YAW_90));
|
||||
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PHMINI) {
|
||||
// PHMINI uses ICM20608 on the ACCEL_MAG device and a MPU9250 on the old MPU6000 CS line
|
||||
_add_backend(AP_InertialSensor_MPU6000::probe(*this, hal.spi->get_device(HAL_INS_ICM20608_AM_NAME), ROTATION_ROLL_180));
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME), false, ROTATION_ROLL_180));
|
||||
|
||||
} else if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PH2SLIM) {
|
||||
_add_backend(AP_InertialSensor_MPU9250::probe(*this, hal.spi->get_device(HAL_INS_MPU9250_NAME), true, ROTATION_YAW_270));
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ public:
|
||||
private:
|
||||
|
||||
// load backend drivers
|
||||
void _add_backend(AP_InertialSensor_Backend *backend);
|
||||
bool _add_backend(AP_InertialSensor_Backend *backend);
|
||||
void _start_backends();
|
||||
AP_InertialSensor_Backend *_find_backend(int16_t backend_id, uint8_t instance);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user