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;
78 UART *usb = DeviceHandle_getHandle(
"USB").device;
82 float *altitude = StateHandle_getHandle(
"Altitude").state;
83 float *cosine = StateHandle_getHandle(
"Cosine").state;
84 float *velocity = StateHandle_getHandle(
"Velocity").state;
85 SlidingWindow *avgVel = StateHandle_getHandle(
"AvgVelBuffer").state;
86 SlidingWindow *avgPress = StateHandle_getHandle(
"AvgPressBuffer").state;
90 TickType_t xLastWakeTime = xTaskGetTickCount();
91 vTaskDelayUntil(&xLastWakeTime, xFrequency);
95 const unsigned long press_length = 0x00003A5C;
96 if (lDummyIdx < PRESS_LENGTH - 1) {
97 uint32_t tempPress = (uint32_t)press[lDummyIdx + 1] << 16 | press[lDummyIdx];
98 memcpy(&baro->press, &tempPress,
sizeof(
float));
102 taskENTER_CRITICAL();
108 *altitude = 44330 * (1.0 - pow(baro->press / baro->groundPress, 0.1903));
111 mem->append(mem, HEADER_LOWRES);
112 mem->appendBytes(mem, baro->rawTemp, BMP581_DATA_SIZE);
113 mem->appendBytes(mem, baro->rawPress, BMP581_DATA_SIZE);
116 EventBits_t uxBits = xEventGroupWaitBits(xTaskEnableGroup, GROUP_TASK_ENABLE_LOWRES, pdFALSE, pdFALSE, blockTime);
117 if (uxBits & GROUP_TASK_ENABLE_LOWRES) {
119 z.pData[0] = *altitude;
120 z.pData[1] = (*cosine * 9.81 * accel->
accelData[ZINDEX] - 9.81);
123 *velocity = kf.x.pData[1];
124 avgPress->append(avgPress, baro->press);
125 avgVel->append(avgVel, *velocity);
131 if ((xSemaphoreTake(xUsbMutex, pdMS_TO_TICKS(0))) == pdTRUE) {
133 snprintf(debugStr, 100,
"[LDataAcq] %d\tBaro\tPressure: %.0f\tTemperature: %.1f\n\r", lDummyIdx / 2, baro->press, baro->temp);
134 xMessageBufferSend(xUsbTxBuff, (
void *)debugStr, 100, pdMS_TO_TICKS(10));
135 xSemaphoreGive(xUsbMutex);
Struct definition for UART interface.
float accelData[KX134_1211_DATA_COUNT]
Processed accelerations array.
DeviceType device
Enum specifier for device type.