From cdb8aa37a015955aae160d668d95d8513d12101b Mon Sep 17 00:00:00 2001 From: stac Date: Wed, 15 Sep 2010 14:21:05 +0000 Subject: [PATCH] ahrs: Only read mag data when it has been updated The AHRS mainloop was reading the mag data on every loop regardless of whether new data was actually available. Now that the MAG_DRDY signal is monitored, we can read only at the rate (10Hz) new data is actually produced by the sensor. This also enables future improvements that will remove the filtering work that is still being done on the mag data on every iteration. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1630 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/AHRS/ahrs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flight/AHRS/ahrs.c b/flight/AHRS/ahrs.c index feb65f635..316a0a74a 100644 --- a/flight/AHRS/ahrs.c +++ b/flight/AHRS/ahrs.c @@ -194,7 +194,6 @@ static uint8_t adc_oversampling = 15; * @} */ - /** * @brief AHRS Main function */ @@ -294,8 +293,10 @@ int main() } #if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C) - // Get magnetic readings - PIOS_HMC5843_ReadMag(mag_data.raw.axis); + // Get magnetic readings + if (PIOS_HMC5843_NewDataAvailable()) { + PIOS_HMC5843_ReadMag(mag_data.raw.axis); + } #endif // Delay for valid data