From 91a226fc12d4e242cb873901f9e7c4452879814e Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sat, 3 Mar 2012 13:19:02 -0600 Subject: [PATCH] Sometimes the mag stops updating so kickstart it --- flight/Modules/Sensors/sensors.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flight/Modules/Sensors/sensors.c b/flight/Modules/Sensors/sensors.c index 01d301734..c7823215b 100644 --- a/flight/Modules/Sensors/sensors.c +++ b/flight/Modules/Sensors/sensors.c @@ -192,6 +192,7 @@ static void SensorsTask(void *parameters) // Main task loop lastSysTime = xTaskGetTickCount(); bool error = false; + uint32_t mag_update_time = PIOS_DELAY_GetRaw(); while (1) { // TODO: add timeouts to the sensor reads and set an error if the fail sensor_dt_us = PIOS_DELAY_DiffuS(timeval); @@ -347,7 +348,8 @@ static void SensorsTask(void *parameters) // and make it average zero (weakly) MagnetometerData mag; bool mag_updated = false; - if (PIOS_HMC5883_NewDataAvailable()) { + + if (PIOS_HMC5883_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 150000) { mag_updated = true; int16_t values[3]; PIOS_HMC5883_ReadMag(values); @@ -355,6 +357,7 @@ static void SensorsTask(void *parameters) mag.y = values[0] * mag_scale[1] - mag_bias[1]; mag.z = -values[2] * mag_scale[2] - mag_bias[2]; MagnetometerSet(&mag); + mag_update_time = PIOS_DELAY_GetRaw(); } // For debugging purposes here we can output all of the sensors. Do it as a single transaction