Index: Accel.c =================================================================== diff -u -re6b38d1e5fbb5eab5cf62e850890632ebcfeb1a7 -r9a59cef171550b5a9cb4f3028520c5d3f9d0c4c0 --- Accel.c (.../Accel.c) (revision e6b38d1e5fbb5eab5cf62e850890632ebcfeb1a7) +++ Accel.c (.../Accel.c) (revision 9a59cef171550b5a9cb4f3028520c5d3f9d0c4c0) @@ -16,6 +16,8 @@ #ifndef _VECTORCAST_ #include +#else + #define _VC_OVERRIDE_MATH_ #endif #include "Accel.h" @@ -63,7 +65,7 @@ static ACCEL_STATE_T accelState = ACCELEROMETER_START_STATE; ///< current state of accelerometer monitor state machine static U32 accelDataPublicationTimerCounter = 0; ///< used to schedule accelerometer data publication to CAN bus -static S32 accelCalOffsets[ NUM_OF_ACCEL_AXES ] = { 0, 0, 0 }; ///< accelerometer calibration offsets. +static F32 accelCalOffsets[ NUM_OF_ACCEL_AXES ] = { 0, 0, 0 }; ///< accelerometer calibration offsets. static OVERRIDE_U32_T accelDataPublishInterval = { ACCEL_DATA_PUB_INTERVAL, ACCEL_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms/task interval) at which to publish accelerometer data to CAN bus. static OVERRIDE_F32_T accelAxes[ NUM_OF_ACCEL_AXES ]; ///< Measured accelerometer axis readings (calibrated, converted to gravities). @@ -203,22 +205,14 @@ #endif } - // apply calibration (axis offsets) - x += accelCalOffsets[ ACCEL_AXIS_X ]; - y += accelCalOffsets[ ACCEL_AXIS_Y ]; - z += accelCalOffsets[ ACCEL_AXIS_Z ]; - xm += accelCalOffsets[ ACCEL_AXIS_X ]; - ym += accelCalOffsets[ ACCEL_AXIS_Y ]; - zm += accelCalOffsets[ ACCEL_AXIS_Z ]; + // convert to gravities and apply calibration (axis offsets) + accelAxes[ ACCEL_AXIS_X ].data = (F32)x * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_X ]; + accelAxes[ ACCEL_AXIS_Y ].data = (F32)y * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Y ]; + accelAxes[ ACCEL_AXIS_Z ].data = (F32)z * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Z ]; + accelMaxs[ ACCEL_AXIS_X ].data = (F32)xm * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_X ]; + accelMaxs[ ACCEL_AXIS_Y ].data = (F32)ym * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Y ]; + accelMaxs[ ACCEL_AXIS_Z ].data = (F32)zm * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Z ]; - // convert to gravities - accelAxes[ ACCEL_AXIS_X ].data = (F32)x * G_PER_LSB; - accelAxes[ ACCEL_AXIS_Y ].data = (F32)y * G_PER_LSB; - accelAxes[ ACCEL_AXIS_Z ].data = (F32)z * G_PER_LSB; - accelMaxs[ ACCEL_AXIS_X ].data = (F32)xm * G_PER_LSB; - accelMaxs[ ACCEL_AXIS_Y ].data = (F32)ym * G_PER_LSB; - accelMaxs[ ACCEL_AXIS_Z ].data = (F32)zm * G_PER_LSB; - // filter readings to get a stable vector for tilt filterAccelReadings(); @@ -608,7 +602,7 @@ * @param offsetZ : offset calibration factor for Z axis * @return TRUE if calibration factors successfully set/stored, FALSE if not *************************************************************************/ -BOOL setAccelCalibration( S32 offsetX, S32 offsetY, S32 offsetZ ) +BOOL setAccelCalibration( F32 offsetX, F32 offsetY, F32 offsetZ ) { BOOL result = FALSE; @@ -644,7 +638,7 @@ * @param offsetZ : value to populate with Z axis offset calibration factor * @return none *************************************************************************/ -void getAccelCalibration( S32 *offsetX, S32 *offsetY, S32 *offsetZ ) +void getAccelCalibration( F32 *offsetX, F32 *offsetY, F32 *offsetZ ) { *offsetX = accelCalOffsets[ ACCEL_AXIS_X ]; *offsetY = accelCalOffsets[ ACCEL_AXIS_Y ];