rm_balance/User/task/cap.c
2026-03-15 10:51:08 +08:00

77 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
super_cap Task
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/supercap.h"
#include "device/referee.h"
#include "module/cap.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
float power_limit = 120;
bool cap_online;
CAN_SuperCapTXDataTypeDef SuperCap_CanTX;
Referee_ForCap_t referee_cap;
Cap_RefereeUI_t cap_ui;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* USER PRIVATE CODE BEGIN */
/* USER PRIVATE CODE END */
/* Exported functions ------------------------------------------------------- */
void Task_super_cap(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / SUPER_CAP_FREQ;
osDelay(SUPER_CAP_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
SuperCap_Init();
SuperCap_CanTX.Enable = 1 ; //超级电容使能。1使能0失能
SuperCap_CanTX.Charge = 0 ; //此标志位无效,超电的充放电是自动的
SuperCap_CanTX.Powerlimit = 120 ; //裁判系统功率限制
SuperCap_CanTX.ChargePower = 1 ; //此参数无效,超电的充电功率随着底盘功率变化
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
//osMessageQueueGet(task_runtime.msgq.referee.ui.tocap, , NULL, 0);
cap_online = get_supercap_online_state();
osKernelLock(); /* 锁住RTOS内核防止控制过程中断造成错误 */
/* 根据裁判系统数据计算输出功率 */
SuperCap_CanTX.Powerlimit = power_limit;
Cap_Control(&CAN_SuperCapRXData, &referee_cap);
SuperCap_Update();
CAN_TX_SuperCapData(&SuperCap_CanTX);
osKernelUnlock();
/* 将电容状态发送到Chassis */
// osMessageQueueReset(task_runtime.msgq.cap.for_chassis);
// osMessageQueuePut(task_runtime.msgq.cap.for_chassis, &CAN_SuperCapRXData, 0, 0);
osMessageQueueReset(task_runtime.msgq.cap.power_limit);
osMessageQueuePut(task_runtime.msgq.cap.power_limit, &power_limit, 0, 0);
/* 超电UI */
Cap_DumpUI(&CAN_SuperCapRXData,&cap_ui);
osMessageQueueReset(task_runtime.msgq.referee.ui.tocap);
osMessageQueuePut(task_runtime.msgq.referee.ui.tocap, &cap_ui, 0, 0);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}