1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-10 18:24:11 +01:00

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
This commit is contained in:
pip 2011-02-19 09:33:03 +00:00 committed by pip
parent ec634ef3e7
commit 9a2bdac49c

View File

@ -182,7 +182,7 @@ static void updateSensors(AttitudeRawData * attitudeRaw)
// Get the accel data // Get the accel data
uint8_t i = 0; /* uint8_t i = 0;
attitudeRaw->accels[ATTITUDERAW_ACCELS_X] = 0; attitudeRaw->accels[ATTITUDERAW_ACCELS_X] = 0;
attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] = 0; attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] = 0;
attitudeRaw->accels[ATTITUDERAW_ACCELS_Z] = 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_X] /= i;
attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] /= i; attitudeRaw->accels[ATTITUDERAW_ACCELS_Y] /= i;
attitudeRaw->accels[ATTITUDERAW_ACCELS_Z] /= 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) static void updateAttitude(AttitudeRawData * attitudeRaw)