9#include "ldataacquisition.h"
13extern EventGroupHandle_t xTaskEnableGroup;
14extern SemaphoreHandle_t xUsbMutex;
15extern MessageBufferHandle_t xUsbTxBuff;
17char LdebugStr[100] = {};
35void vLDataAcquisition(
void *argument) {
38 KalmanFilter_init(&kf);
43 1.0, dt, 0.5 * (dt * dt),
67 arm_matrix_instance_f32 z;
68 float zData[2] = {0.0, 0.0};
69 arm_mat_init_f32(&z, 2, 1, zData);
71 TickType_t xLastWakeTime;
72 const TickType_t xFrequency = pdMS_TO_TICKS(20);
73 const TickType_t blockTime = pdMS_TO_TICKS(0);
75 MemBuff *mem = (MemBuff *)argument;
81 float *altitude = StateHandle_getHandle(
"Altitude").state;
82 float *cosine = StateHandle_getHandle(
"Cosine").state;
83 float *velocity = StateHandle_getHandle(
"Velocity").state;
84 SlidingWindow *avgVel = StateHandle_getHandle(
"AvgVelBuffer").state;
85 SlidingWindow *avgPress = StateHandle_getHandle(
"AvgPressBuffer").state;
89 TickType_t xLastWakeTime = xTaskGetTickCount();
90 vTaskDelayUntil(&xLastWakeTime, xFrequency);
94 const unsigned long press_length = 0x00003A5C;
95 if (lDummyIdx < PRESS_LENGTH - 1) {
96 uint32_t tempPress = (uint32_t)press[lDummyIdx + 1] << 16 | press[lDummyIdx];
97 memcpy(&baro->press, &tempPress,
sizeof(
float));
101 taskENTER_CRITICAL();
107 *altitude = 44330 * (1.0 - pow(baro->press / baro->groundPress, 0.1903));
110 mem->append(mem, HEADER_LOWRES);
111 mem->appendBytes(mem, baro->rawTemp, BMP581_DATA_SIZE);
112 mem->appendBytes(mem, baro->rawPress, BMP581_DATA_SIZE);
115 EventBits_t uxBits = xEventGroupWaitBits(xTaskEnableGroup, GROUP_TASK_ENABLE_LOWRES, pdFALSE, pdFALSE, blockTime);
116 if (uxBits & GROUP_TASK_ENABLE_LOWRES) {
118 z.pData[0] = *altitude;
119 z.pData[1] = (*cosine * 9.81 * accel->
accelData[ZINDEX] - 9.81);
122 *velocity = kf.x.pData[1];
123 avgPress->append(avgPress, baro->press);
124 avgVel->append(avgVel, *velocity);
130 if ((xSemaphoreTake(xUsbMutex, pdMS_TO_TICKS(0))) == pdTRUE) {
132 snprintf(debugStr, 100,
"[LDataAcq] %d\tBaro\tPressure: %.0f\tTemperature: %.1f\n\r", lDummyIdx / 2, baro->press, baro->temp);
133 xMessageBufferSend(xUsbTxBuff, (
void *)debugStr, 100, pdMS_TO_TICKS(10));
134 xSemaphoreGive(xUsbMutex);
DeviceHandle_t DeviceList_getDeviceHandle(DeviceKey)
Retrieve device handle from list by key.
Struct definition for UART interface.
float accelData[KX134_1211_DATA_COUNT]
Processed accelerations array.