AP_InertialSensor: make sure we wait for a sample before update()

This commit is contained in:
Andrew Tridgell 2013-12-11 13:50:50 +11:00
parent 3c5dcc7862
commit e54fc6b8e3
2 changed files with 9 additions and 2 deletions

View File

@ -71,6 +71,9 @@ uint16_t AP_InertialSensor_Oilpan::_init_sensor( Sample_rate sample_rate)
bool AP_InertialSensor_Oilpan::update() bool AP_InertialSensor_Oilpan::update()
{ {
if (!wait_for_sample(100)) {
return false;
}
float adc_values[6]; float adc_values[6];
Vector3f gyro_offset = _gyro_offset[0].get(); Vector3f gyro_offset = _gyro_offset[0].get();
Vector3f accel_scale = _accel_scale[0].get(); Vector3f accel_scale = _accel_scale[0].get();

View File

@ -131,6 +131,10 @@ uint8_t AP_InertialSensor_PX4::get_accel_count(void) const
bool AP_InertialSensor_PX4::update(void) bool AP_InertialSensor_PX4::update(void)
{ {
if (!wait_for_sample(100)) {
return false;
}
// get the latest sample from the sensor drivers // get the latest sample from the sensor drivers
_get_sample(); _get_sample();
@ -235,7 +239,7 @@ bool AP_InertialSensor_PX4::healthy(void) const
uint8_t AP_InertialSensor_PX4::_get_primary_gyro(void) const uint8_t AP_InertialSensor_PX4::_get_primary_gyro(void) const
{ {
for (uint8_t i=0; i<INS_MAX_INSTANCES; i++) { for (uint8_t i=0; i<_num_gyro_instances; i++) {
if (get_gyro_health(i)) return i; if (get_gyro_health(i)) return i;
} }
return 0; return 0;
@ -243,7 +247,7 @@ uint8_t AP_InertialSensor_PX4::_get_primary_gyro(void) const
uint8_t AP_InertialSensor_PX4::_get_primary_accel(void) const uint8_t AP_InertialSensor_PX4::_get_primary_accel(void) const
{ {
for (uint8_t i=0; i<INS_MAX_INSTANCES; i++) { for (uint8_t i=0; i<_num_accel_instances; i++) {
if (get_accel_health(i)) return i; if (get_accel_health(i)) return i;
} }
return 0; return 0;