10#include "event_groups.h"
12#include "message_buffer.h"
16#include "devicelist.h"
23#include "hdataacquisition.h"
25#include "quaternion.h"
27extern EventGroupHandle_t xTaskEnableGroup;
28extern MessageBufferHandle_t xUsbTxBuff;
29extern SemaphoreHandle_t xUsbMutex;
31#define ACCEL_MOTION_THRESHOLD 1.125f
32#define GYRO_MOTION_THRESHOLD 2.0f
35#define EWMA(a, ewma, x) (((1 - a) * ewma) + (a * x))
36#define MAG(v) (sqrtf(SQ(v[0]) + SQ(v[1]) + SQ(v[2])))
38#define SWAP_AXES(device, oldIdx, newIdx) \
40 uint8_t temp = device->axes[oldIdx]; \
41 device->axes[oldIdx] = device->axes[newIdx]; \
42 device->axes[newIdx] = temp; \
45float gyroBiasX = 0.0f;
46float gyroBiasY = 0.0f;
47float gyroBiasZ = 0.0f;
48uint32_t numSamples = 0;
65void vHDataAcquisition(
void *argument) {
68 const TickType_t xFrequency = pdMS_TO_TICKS(2);
69 const TickType_t blockTime = pdMS_TO_TICKS(0);
78 Accel_t *accel = accelHandlePtr->device;
88 TickType_t xLastWakeTime = xTaskGetTickCount();
89 vTaskDelayUntil(&xLastWakeTime, xFrequency);
99 accelHandlePtr->device = (accel->
accelData[ZINDEX] < 15) ? lAccel : hAccel;
105 accelEWMA = EWMA(0.5, accelEWMA, MAG(accel->
accelData));
108 gyroEWMA = EWMA(0.5, gyroEWMA, MAG(gyro->
gyroData));
123 if (accelEWMA < ACCEL_MOTION_THRESHOLD && gyroEWMA < GYRO_MOTION_THRESHOLD) {
131 for (; oldIdx < ZINDEX; oldIdx++) {
132 if (accel->
axes[oldIdx] == ZINDEX)
138 for (
int i = 0; i < ZINDEX; i++) {
139 float indexedAxisAbsolute = fabs(accel->
accelData[accel->
axes[i]]);
140 float currentAxisAbsolute = fabs(accel->
accelData[accel->
axes[newIdx]]);
141 if (indexedAxisAbsolute > currentAxisAbsolute)
146 SWAP_AXES(hAccel, oldIdx, newIdx)
147 SWAP_AXES(lAccel, oldIdx, newIdx)
148 SWAP_AXES(gyro, oldIdx, newIdx)
152 lAccel->
sign[ZINDEX] *= -1;
153 hAccel->
sign[ZINDEX] *= -1;
154 gyro->
sign[ZINDEX] *= -1;
160 state->mem.append(&state->mem, HEADER_HIGHRES);
165 EventBits_t uxBits = xEventGroupWaitBits(xTaskEnableGroup, GROUP_TASK_ENABLE_HIGHRES, pdFALSE, pdFALSE, blockTime);
166 if (uxBits & GROUP_TASK_ENABLE_HIGHRES) {
168 Quaternion qDot = Quaternion_new();
171 (
float)(dt * gyro->
gyroData[ROLL_INDEX]),
172 (
float)(dt * gyro->
gyroData[PITCH_INDEX]),
173 (
float)(dt * gyro->
gyroData[YAW_INDEX])
175 state->rotation = Quaternion_mul(&state->rotation, &qDot);
176 state->rotation.normalise(&state->rotation);
179 state->rotation.fRotateVector3D(&state->rotation, state->launchAngle, state->attitude);
183 state->cosine = state->launchAngle[0] * state->attitude[0] + state->launchAngle[1] * state->attitude[1] + state->launchAngle[2] * state->attitude[2];
184 state->tilt = acosf(state->cosine) * (180 / 3.14159265);
186 state->flightTimeMs += 2;
Defines the API for the Accelerometer sensor.
uint8_t * rawAccelData
Pointer to driver defined raw data array.
void(* update)(struct Accel *accel)
Pointer to update method.
float * accelData
Pointer to driver defined data array.
uint8_t * axes
Pointer to driver defined axes.
int8_t * sign
Pointer to driver defined signs.
uint8_t dataSize
Total data size.
int8_t * sign
Array defining sign of axes.
float * gyroData
Processed angular rates array.
uint8_t * rawGyroData
Raw angular rates array.
void(* update)(struct Gyro *gyro)
Pointer to update method.
float * bias
Bias offset array.
uint8_t dataSize
Total data size.
DeviceHandle_t DeviceList_getDeviceHandle(DeviceKey)
Retrieve device handle from list by key.
DeviceHandle_t * DeviceList_getDeviceHandlePointer(DeviceKey)
Retrieve device handle pointer from list by key.
@ PRELAUNCH
Initial boot condition.
Defines the API for the Gyroscope sensor.