/* height_cal Task */ /* Includes ----------------------------------------------------------------- */ #include "task/user_task.h" /* USER INCLUDE BEGIN */ #include "task\user_task.h" #include "timers.h" #include "device/bmi088.h" #include "BarometerDriver/spl06.h" #include "component/ahrs.h" #include "module/HeightEstimation.h" /* USER INCLUDE END */ /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ /* Private macro ------------------------------------------------------------ */ /* Private variables -------------------------------------------------------- */ /* USER STRUCT BEGIN */ float accl_z_buffer; float estimated_velocity; float estimated_height; /* USER STRUCT END */ /* Private function --------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */ void Task_height_cal(void *argument) { (void)argument; /* 未使用argument,消除警告 */ /* 计算任务运行到指定频率需要等待的tick数 */ const uint32_t delay_tick = osKernelGetTickFreq() / HEIGHT_CAL_FREQ; osDelay(HEIGHT_CAL_INIT_DELAY); /* 延时一段时间再开启任务 */ uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ /* USER CODE INIT BEGIN */ HeightEstimation_Init(HEIGHT_CAL_FREQ); /* USER CODE INIT END */ while (1) { tick += delay_tick; /* 计算下一个唤醒时刻 */ /* USER CODE BEGIN */ osMessageQueueGet(task_runtime.msgq.heightestimation.accl_z, &accl_z_buffer, NULL, 0); HeightEstimation_GetHeight(&estimated_height, &estimated_velocity, accl_z_buffer); osMessageQueuePut(task_runtime.msgq.quad.alt, &estimated_height, 0, 0); osMessageQueuePut(task_runtime.msgq.quad.vel, &estimated_velocity, 0, 0); /* USER CODE END */ osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ } }