9#include "hdataacquisition.h"
12char HdebugStr[100] = {};
14extern EventGroupHandle_t xTaskEnableGroup;
15extern MessageBufferHandle_t xUsbTxBuff;
16extern SemaphoreHandle_t xUsbMutex;
33void vHDataAcquisition(
void *argument) {
36 const TickType_t xFrequency = pdMS_TO_TICKS(2);
37 const TickType_t blockTime = pdMS_TO_TICKS(0);
40 MemBuff *mem = (MemBuff *)argument;
50 float *tilt = StateHandle_getHandle(
"Tilt").state;
51 float *cosine = StateHandle_getHandle(
"Cosine").state;
52 float *vLaunch = StateHandle_getHandle(
"LaunchVector").state;
53 float *vAttitude = StateHandle_getHandle(
"AttitudeVector").state;
54 Quaternion *qRot = StateHandle_getHandle(
"RotationQuaternion").state;
58 TickType_t xLastWakeTime = xTaskGetTickCount();
59 vTaskDelayUntil(&xLastWakeTime, xFrequency);
62 accelHandle.ref->device = (accel->
accelData[ZINDEX] < 15) ? lAccel : hAccel;
66 const unsigned long accelX_length = 0x00007568;
72 if (hDummyIdx < ACCELX_LENGTH - 1) {
74 uint32_t tempX = (uint32_t)accelX[hDummyIdx + 1] << 16 | accelX[hDummyIdx];
75 uint32_t tempY = (uint32_t)accelY[hDummyIdx + 1] << 16 | accelY[hDummyIdx];
76 uint32_t tempZ = (uint32_t)accelZ[hDummyIdx + 1] << 16 | accelZ[hDummyIdx];
77 memcpy(&accel->
accelData[0], &tempX,
sizeof(
float));
78 memcpy(&accel->
accelData[1], &tempY,
sizeof(
float));
79 memcpy(&accel->
accelData[2], &tempZ,
sizeof(
float));
93 tempX = (uint32_t)gyroX[hDummyIdx + 1] << 16 | gyroX[hDummyIdx];
94 tempY = (uint32_t)gyroY[hDummyIdx + 1] << 16 | gyroY[hDummyIdx];
95 tempZ = (uint32_t)gyroZ[hDummyIdx + 1] << 16 | gyroZ[hDummyIdx];
96 memcpy(&gyro->
gyroData[0], &tempX,
sizeof(
float));
97 memcpy(&gyro->
gyroData[1], &tempY,
sizeof(
float));
98 memcpy(&gyro->
gyroData[2], &tempZ,
sizeof(
float));
114 taskENTER_CRITICAL();
122 mem->append(mem, HEADER_HIGHRES);
123 mem->appendBytes(mem, accel->
rawAccelData, KX134_1211_DATA_TOTAL);
124 mem->appendBytes(mem, gyro->
rawGyroData, A3G4250D_DATA_TOTAL);
127 EventBits_t uxBits = xEventGroupWaitBits(xTaskEnableGroup, GROUP_TASK_ENABLE_HIGHRES, pdFALSE, pdFALSE, blockTime);
128 if (uxBits & GROUP_TASK_ENABLE_HIGHRES) {
131 Quaternion_init(&qDot);
134 (
float)(dt * gyro->
gyroData[ROLL_INDEX]),
135 (
float)(dt * gyro->
gyroData[PITCH_INDEX]),
136 (
float)(dt * gyro->
gyroData[YAW_INDEX])
138 *qRot = Quaternion_mul(qRot, &qDot);
139 qRot->normalise(qRot);
142 qRot->fRotateVector3D(qRot, vLaunch, vAttitude);
146 *cosine = vLaunch[0] * vAttitude[0] + vLaunch[1] * vAttitude[1] + vLaunch[2] * vAttitude[2];
147 *tilt = acos(*cosine) * 180 / M_PI;
153 if ((xSemaphoreTake(xUsbMutex, pdMS_TO_TICKS(0))) == pdTRUE) {
154 memset(HdebugStr, 100,
sizeof(
char));
156 snprintf(HdebugStr, 100,
"[HDataAcq] %d\tAccel\tX: %.3f\tY: %.3f\tZ: %.3f\n\r", hDummyIdx / 2, accel->
accelData[0], accel->
accelData[1], accel->
accelData[2]);
157 xMessageBufferSend(xUsbTxBuff, (
void *)HdebugStr, 100, pdMS_TO_TICKS(0));
159 snprintf(HdebugStr, 100,
"[HDataAcq] %d\tGyro\tX: %.3f\tY: %.3f\tZ: %.3f\n\r", hDummyIdx / 2, gyro->
gyroData[0], gyro->
gyroData[1], gyro->
gyroData[2]);
161 xMessageBufferSend(xUsbTxBuff, (
void *)HdebugStr, 100, pdMS_TO_TICKS(0));
162 xSemaphoreGive(xUsbMutex);
uint8_t rawGyroData[A3G4250D_DATA_TOTAL]
Raw gyro rates array.
float sensitivity
Gyroscope sensitivity.
void(* update)(struct A3G4250D *)
Gyro update method.
float gyroData[A3G4250D_DATA_COUNT]
Processed gyro rates array.
void(* update)(struct KX134_1211 *)
Accel update method.
float accelData[KX134_1211_DATA_COUNT]
Processed accelerations array.
uint8_t rawAccelData[KX134_1211_DATA_TOTAL]
Raw accelerations array.
float sensitivity
Accelerometer sensitivity.
DeviceType device
Enum specifier for device type.