From 9a2bdac49c3e69d92a4095dedff591f30090d9c4 Mon Sep 17 00:00:00 2001 From: pip Date: Sat, 19 Feb 2011 09:33:03 +0000 Subject: [PATCH] Reduced CC CPU usage from 57% to 46% by moving the floating point multiplies outside of the accelerometer downsample/averaging loop in the updateSensors() function. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2809 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/Modules/Attitude/attitude.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/flight/Modules/Attitude/attitude.c b/flight/Modules/Attitude/attitude.c index 8cacde7fe..0565e654e 100644 --- a/flight/Modules/Attitude/attitude.c +++ b/flight/Modules/Attitude/attitude.c @@ -182,7 +182,7 @@ static void updateSensors(AttitudeRawData * attitudeRaw) // Get the accel data - uint8_t i = 0; +/* uint8_t i = 0; attitudeRaw->accels[ATTITUDERAW_ACCELS_X] = 0; attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] = 0; attitudeRaw->accels[ATTITUDERAW_ACCELS_Z] = 0; @@ -200,7 +200,24 @@ static void updateSensors(AttitudeRawData * attitudeRaw) attitudeRaw->accels[ATTITUDERAW_ACCELS_X] /= i; attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] /= i; attitudeRaw->accels[ATTITUDERAW_ACCELS_Z] /= i; - +*/ + int32_t x = 0; + int32_t y = 0; + int32_t z = 0; + uint8_t i = 0; + uint8_t samples_remaining; + do { + i++; + samples_remaining = PIOS_ADXL345_Read(&accel_data); + x += accel_data.x; + y += -accel_data.y; + z += -accel_data.z; + } while ( (i < 32) && (samples_remaining > 0) ); + attitudeRaw->gyrotemp[0] = samples_remaining; + attitudeRaw->gyrotemp[1] = i; + attitudeRaw->accels[ATTITUDERAW_ACCELS_X] = ((float)x * 0.004f * 9.81f) / i; + attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] = ((float)y * 0.004f * 9.81f) / i; + attitudeRaw->accels[ATTITUDERAW_ACCELS_Z] = ((float)z * 0.004f * 9.81f) / i; } static void updateAttitude(AttitudeRawData * attitudeRaw)