初步功率控制

This commit is contained in:
shentou 2025-12-07 14:35:28 +08:00
parent c0d4ae6c90
commit 4443235b6a
24 changed files with 555 additions and 52 deletions

View File

@ -2,6 +2,7 @@ CompileFlags:
Add:
- '-ferror-limit=0'
- '-Wno-implicit-int'
- "-I/usr/lib/arm-none-eabi/include"
CompilationDatabase: build/Debug
Diagnostics:
Suppress:
@ -9,3 +10,4 @@ Diagnostics:
- unknown_typename
- unknown_typename_suggest
- typename_requires_specqual

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
build
mx.scratch
!.settings
!.settings
.cache
compile_commands.json

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@ set(CMAKE_C_EXTENSIONS ON)
# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Set the project name
@ -63,15 +63,17 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
User/component/user_math.c
User/component/crc16.c
/home/shentou/workspace/SuperCap/god-yuan-hero/User/component/PowerControl.c
# User/device sources
User/device/dr16.c
User/device/at9s_pro.c
User/device/AT9S_Pro.c
User/device/bmi088.c
User/device/motor.c
User/device/motor_dm.c
User/device/motor_rm.c
User/device/vofa.c
/home/shentou/workspace/SuperCap/god-yuan-hero/User/device/supercap.c
# User/module sources
User/module/chassis.c
User/module/config.c
@ -88,6 +90,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
User/task/init.c
User/task/rc.c
User/task/user_task.c
/home/shentou/workspace/SuperCap/god-yuan-hero/User/task/supercap.c
)
# Add include paths

View File

@ -69,7 +69,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)0x6000)
#define configTOTAL_HEAP_SIZE ((size_t)0x10000)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0

View File

@ -0,0 +1,88 @@
#include "PowerControl.h"
#include "stdint.h"
#include "math.h"
void power_calu(power_model_t* param,float* in_array,float* rpm_array)
{
float InitialGivePower[param->motor_num];
float totalpower=0;
float in[4];
float ve[4];
for (uint8_t i = 0; i < param->motor_num; i++) // first get all the initial motor power and total motor power
{
in[i] = in_array[i];
ve[i] = rpm_array[i];
InitialGivePower[i] = in[i] * param->toque_coefficient * ve[i] +
param->k2 * ve[i] * ve[i]+ param->k1 * in[i]*in[i] + param->constant;
param->power[i] = InitialGivePower[i];
if (InitialGivePower[i] < 0) // negative power not included (transitory)
continue;
totalpower += InitialGivePower[i];
}
param->total_power = totalpower;
}
float power_scale_calu(power_model_t** param_array,uint8_t num,float max_power)
{
float total_power=0;
for(uint8_t i=0;i<num;i++)
{
total_power+=param_array[i]->total_power;
}
if(total_power>max_power)
{return max_power/total_power;}
else
{return 2;}
}
void power_out_calu(power_model_t* param,float scale,float* in_array,float* rpm_array,float* out_array)
{
float in[4];
float ve[4];
if(scale<1)
{
float ScaledGivePower[4];
for (uint8_t i = 0; i < param->motor_num; i++)
{
in[i] = in_array[i];
ve[i] = rpm_array[i];
ScaledGivePower[i] = param->power[i] * scale; // get scaled power
if (ScaledGivePower[i] < 0)
{
continue;
}
float b = param->toque_coefficient * ve[i];
float c = param->k2 * ve[i]*ve[i] - ScaledGivePower[i] + param->constant;
float inside = b * b - 4 * param->k1 * c;
if (inside < 0)
{
continue;
}
else if (in[i] > 0) // Selection of the calculation formula according to the direction of the original moment
{
float temp = (-b + sqrt(inside)) / (2 * param->k1);
if (temp > 16000)
{
out_array[i] = 16000;
}
else
out_array[i] = temp;
}
else
{
float temp = (-b - sqrt(inside)) / (2 * param->k1);
if (temp < -16000)
{
out_array[i] = -16000;
}
else
out_array[i] = temp;
}
}
}
}

View File

@ -0,0 +1,30 @@
#ifndef CHASSIS_POWER_CONTROL_WITH_SUPERCAP_H
#define CHASSIS_POWER_CONTROL_WITH_SUPERCAP_H
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
typedef struct power_model_t
{
uint8_t motor_num;
float total_power;
float* power;
float toque_coefficient;
float k1;
float k2 ;
float constant;
}power_model_t;
void power_calu(power_model_t* param,float* in_array,float* rpm_array);
float power_scale_calu(power_model_t** param_array,uint8_t num,float max_power);
void power_out_calu(power_model_t* param,float scale,float* in_array,float* rpm_array,float* out_array);
#ifdef __cplusplus
}
#endif
#endif

158
User/device/supercap.c Normal file
View File

@ -0,0 +1,158 @@
#include "device/supercap.h"
/* 全局变量 */
CAN_SuperCapRXDataTypeDef CAN_SuperCapRXData = {0};
uint8_t PowerOffset =0;
uint32_t LastCapTick = 0; //上一次收到超电信号的时间戳
uint32_t NowCapTick = 0; //现在收到超电信号的时间戳
uint32_t chassis_energy_in_gamming =0;
/* 静态变量 - 用于CAN接收管理 */
static bool supercap_inited = false;
static osMessageQueueId_t supercap_rx_queue = NULL;
/**
* @brief 线1线0线
*/
uint8_t get_supercap_online_state(void){
NowCapTick = HAL_GetTick(); //更新时间戳
uint32_t DeltaCapTick = 0;
DeltaCapTick = NowCapTick - LastCapTick; //计算时间差
// if(get_game_progress() == 4){
// //比赛开始的时候,开始统计消耗的能量
chassis_energy_in_gamming += CAN_SuperCapRXData.BatPower * DeltaCapTick *0.001f;
// 因为STM32的系统定时器是1ms的周期所以*0.001单位化为秒S能量单位才是焦耳J
// }
if(DeltaCapTick > 1000){
//如果时间差大于1s说明超电信号丢失返回超电离线的标志
return 0;
}else {
//如果时间差小于1s说明超电信号正常返回超电在线的标志
return 1;
}
}
/**
* @brief J
*/
uint32_t get_chassis_energy_from_supercap(void){
return chassis_energy_in_gamming;
}
/******************超级电容数据从CAN传到结构体******************/
int8_t SuperCap_Init(void)
{
if (supercap_inited) {
return DEVICE_OK; // 已经初始化过
}
if (BSP_CAN_RegisterId( SUPERCAP_CAN , SUPERCAP_RX_ID, 3) != BSP_OK) {
return DEVICE_ERR;
}
supercap_inited = true;
return DEVICE_OK;
}
int8_t SuperCap_Update(void)
{
if (!supercap_inited) {
return DEVICE_ERR;
}
BSP_CAN_Message_t rx_msg;
// 从CAN队列获取数据
if (BSP_CAN_GetMessage( SUPERCAP_CAN , SUPERCAP_RX_ID, &rx_msg, BSP_CAN_TIMEOUT_IMMEDIATE) == BSP_OK) {
// 处理接收到的数据
transfer_SuperCap_measure(rx_msg.data);
return DEVICE_OK;
}
return DEVICE_ERR; // 没有新数据
}
void transfer_SuperCap_measure(uint8_t *data)
{
LastCapTick = HAL_GetTick();
CAN_SuperCapRXData.SuperCapReady = (SuperCap_Status_t)data[0];
CAN_SuperCapRXData.SuperCapState = (SuperCap_Status_t)data[1];
CAN_SuperCapRXData.SuperCapEnergy = data[2];
CAN_SuperCapRXData.ChassisPower = data[3] << 1; //左移一位是为了扩大范围,超电发出来的的时候右移了一位
CAN_SuperCapRXData.BatVoltage = data[4];
CAN_SuperCapRXData.BatPower = data[5];
}
/**
* @brief SuperCapStateEnum
* @retval none
*/
SuperCapStateEnum get_supercap_state(void){
return (SuperCapStateEnum)CAN_SuperCapRXData.SuperCapState;
}
/**
* @brief V
* @retval none
*/
float get_battery_voltage_from_supercap(void){
return (float)CAN_SuperCapRXData.BatVoltage * 0.1f;
}
/**
* @brief 0-100%
* @retval none
*/
uint8_t get_supercap_energy(void){
return CAN_SuperCapRXData.SuperCapEnergy;
}
/**
* @brief
* @retval none
*/
void set_supercap_power_offset(uint8_t offset){
PowerOffset = offset;
}
/**
* @brief
* @param[in] Enable: 使
* @param[in] Charge: PLUS版本中无效
* @param[in] PowerLimit:
* @param[in] Chargepower: PLUS版本中无效
* @retval none
*/
int8_t CAN_TX_SuperCapData(CAN_SuperCapTXDataTypeDef * TX_Temp)
{
if (TX_Temp == NULL) return DEVICE_ERR_NULL;
BSP_CAN_StdDataFrame_t tx_frame;
tx_frame.id = SUPERCAP_TX_ID;
tx_frame.dlc = 0x08;
tx_frame.data[0] = TX_Temp-> Enable;
tx_frame.data[1] = TX_Temp-> Charge;//PLUS disabled
tx_frame.data[2] = TX_Temp-> Powerlimit - PowerOffset;
tx_frame.data[3] = TX_Temp-> ChargePower;//PLUS disabled
tx_frame.data[4] = 0;
tx_frame.data[5] = 0;
tx_frame.data[6] = 0;
tx_frame.data[7] = 0;
return BSP_CAN_TransmitStdDataFrame( SUPERCAP_CAN , &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR;
}

102
User/device/supercap.h Normal file
View File

@ -0,0 +1,102 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "bsp/can.h"
#include "device/device.h"
//#include "referee.h"
#define SUPERCAP_CAN BSP_CAN_1
//#define SUPERCAP_CAN BSP_CAN_2
#define SUPERCAP_TX_ID 0x001 //C板发给超级电容的ID
#define SUPERCAP_RX_ID 0x100 //超级电容发给C板的ID
//超级电容的状态标志位,超级电容运行或者保护的具体状态反馈
typedef enum
{
DISCHARGE =0 , //放电状态
CHARGE =1, //充电状态
WAIT =2, //待机状态
SOFTSTART_PROTECTION =3,//处于软起动状态
OVER_LOAD_PROTECTION = 4, //超电过载保护状态
BAT_OVER_VOLTAGE_PROTECTION =5, //过压保护状态
BAT_UNDER_VOLTAGE_PROTECTION =6, //电池欠压保护,电池要没电了,换电池
CAP_UNDER_VOLTAGE_PROTECTION =7, //超级电容欠压保护,超级电容用完电了,要充一会才能用
OVER_TEMPERATURE_PROTECTION =8, //过温保护,太热了
BOOM = 9, //超电爆炸了
}SuperCapStateEnum;
//超级电容准备状态,用于判断超级电容是否可以使用
typedef enum
{
SUPERCAP_STATUS_OFFLINE =0 ,
SUPERCAP_STATUS_RUNNING =1,
}SuperCap_Status_t;
// 发送给超级电容的数据
typedef struct {
FunctionalState Enable ; //超级电容使能。1使能0失能
SuperCapStateEnum Charge ; //V1.1超级电容充电。1充电0放电在PLUS版本中此标志位无效超电的充放电是自动的
uint8_t Powerlimit; //裁判系统功率限制
uint8_t ChargePower; //V1.1超级电容充电功率在PLUS版本中此参数超电的充电功率随着底盘功率变化
}CAN_SuperCapTXDataTypeDef;
// 从超级电容接收到的数据
typedef struct {
uint8_t SuperCapEnergy;//超级电容可用能量0-100%
uint16_t ChassisPower; //底盘功率0-512由于传输的时候为了扩大量程右移了一位所以接收的时候需要左移还原丢精度
SuperCap_Status_t SuperCapReady;//超级电容【可用标志】1为可用0为不可用
SuperCapStateEnum SuperCapState;//超级电容【状态标志】各个状态对应的状态码查看E_SuperCapState枚举。
uint8_t BatVoltage; //通过超级电容监控电池电压*10
uint8_t BatPower;
}CAN_SuperCapRXDataTypeDef;
extern CAN_SuperCapRXDataTypeDef CAN_SuperCapRXData;
void set_supercap_power_offset(uint8_t offset);
// 以下函数是超电控制所需要调用的函数
void transfer_SuperCap_measure( uint8_t *data);
int8_t CAN_TX_SuperCapData(CAN_SuperCapTXDataTypeDef * TX_Temp);
/**
* @brief 线1线0线
*/
uint8_t get_supercap_online_state(void);
/**
* @brief SuperCapStateEnum
*/
SuperCapStateEnum get_supercap_state(void);
/**
* @brief V
*/
float get_battery_voltage_from_supercap(void);
/**
* @brief 0-100%
*/
uint8_t get_supercap_energy(void);
/**
* @brief J
*/
uint32_t get_chassis_energy_from_supercap(void);
int8_t SuperCap_Init(void);
int8_t SuperCap_Update(void);
#ifdef __cplusplus
}
#endif /*SUPERCAP_H*/

View File

@ -10,7 +10,9 @@
#include "device/motor_rm.h"
#include "device/motor.h"
#include "module/chassis.h"
#include "component/PowerControl.h"
#include "config.h"
#include "math.h"
/**
* @brief µ×ÅÌСÍÓÂÝģʽÏà¹Ø²ÎÊý
*/
@ -251,10 +253,22 @@ int8_t Chassis_Control(Chassis_t *c, const Chassis_CMD_t *c_cmd, uint32_t now) {
Clip(&c->out.motor[i], -c->param->limit.max_current, c->param->limit.max_current);
}
return CHASSIS_OK;
}
void Chassis_Power_Control(Chassis_t *c,float max_power)
{
float* rpm=(float[4]){c->motors[0]->feedback.rotor_speed,c->motors[1]->feedback.rotor_speed,c->motors[2]->feedback.rotor_speed,c->motors[3]->feedback.rotor_speed};
power_model_t* param = (c->mode == CHASSIS_MODE_ROTOR) ? &cha2 : &cha;
power_calu(param,(float[4]){c->out.motor[0],c->out.motor[1],c->out.motor[2],c->out.motor[3]},rpm);
float scale = power_scale_calu(&param,1,max_power);
power_out_calu(param,scale,(float[4]){c->out.motor[0],c->out.motor[1],c->out.motor[2],c->out.motor[3]},rpm,c->out.motor);
}
/**
* @brief µç»úÊä³ö
* @param c µ×Å̽ṹÌåÖ¸Õë
@ -263,13 +277,14 @@ void Chassis_Output(Chassis_t *c) {
if (!c)
return;
//ÿ¸öµç»úÄ¿±êÊä³ö
for (uint8_t i = 0; i < c->num_wheel; i++) {
MOTOR_RM_t *rm = c->motors[i];
if (!rm) continue;
MOTOR_RM_SetOutput(&rm->param, c->out.motor[i]);
}
//µ÷ÓÃctrl
for (uint8_t i = 0; i < c->num_wheel; i++) {
MOTOR_RM_t *rm = c->motors[i];

View File

@ -11,10 +11,10 @@ extern "C" {
/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include "bsp/can.h"
#include "component\filter.h"
#include "component\mixer.h"
#include "component\pid.h"
#include "component\ahrs.h"
#include "component/filter.h"
#include "component/mixer.h"
#include "component/pid.h"
#include "component/ahrs.h"
#include "device/motor_rm.h"
/* Exported constants ------------------------------------------------------- */
#define CHASSIS_OK (0) /* ÔËÐÐÕý³£ */
@ -208,6 +208,7 @@ void Chassis_Output(Chassis_t *c);
void Chassis_ResetOutput(Chassis_t *c);
void Chassis_Power_Control(Chassis_t *c,float max_power);
/**
* @brief µ×Å̹¦ÂÊÏÞÖÆ
*

View File

@ -360,6 +360,26 @@ Config_RobotParam_t robot_config = {
};
power_model_t cha=
{
.motor_num =4,
.constant= 0.7910660075305308,
.k1 = 98.97509148647588,
.k2= 0.00018014375383727376,
.toque_coefficient =0.4568913750568248,
.power = (float[4]){}
};
power_model_t cha2=
{
.motor_num =4,
.constant= 2.354223704504904,
.k1 = 94.85324024176896,
.k2= 0.00012622263917529537,
.toque_coefficient =0.3680225540649464,
.power = (float[4]){}
};
/* Private function prototypes ---------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
@ -369,4 +389,4 @@ Config_RobotParam_t robot_config = {
*/
Config_RobotParam_t* Config_GetRobotParam(void) {
return &robot_config;
}
}

View File

@ -16,6 +16,7 @@ extern "C" {
#include "module/gimbal.h"
#include "module/chassis.h"
#include "module/cmd.h"
#include "component/PowerControl.h"
typedef struct {
Shoot_Params_t shoot_param;
Gimbal_Params_t gimbal_param;
@ -23,6 +24,8 @@ typedef struct {
CMD_Params_t cmd_param;
} Config_RobotParam_t;
extern power_model_t cha;
extern power_model_t cha2;
/* Exported functions prototypes -------------------------------------------- */
/**

View File

@ -16,7 +16,7 @@
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
/* USER STRUCT END */
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */

View File

@ -7,7 +7,7 @@
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/dr16.h"
#include "device/at9s_pro.h"
#include "device/AT9S_Pro.h"
#include "module/config.h"
#include "module/chassis.h"
#include "module/gimbal.h"

View File

@ -47,3 +47,10 @@
function: Task_cmd
name: cmd
stack: 256
- delay: 0
description: ''
freq_control: true
frequency: 500.0
function: Task_supercap
name: supercap
stack: 512

View File

@ -4,10 +4,11 @@
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "module/chassis.h"
#include "module/config.h"
#include "device/supercap.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@ -18,6 +19,7 @@
Chassis_t chassis;
Chassis_CMD_t chassis_cmd;
Chassis_IMU_t chassis_imu;
float max =50;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@ -33,6 +35,7 @@ void Task_ctrl_chassis(void *argument) {
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
Config_RobotParam_t *cfg = Config_GetRobotParam();
Chassis_Init(&chassis, &cfg->chassis_param, (float)CTRL_CHASSIS_FREQ);
chassis.mech_zero=0.57f;
@ -41,14 +44,18 @@ void Task_ctrl_chassis(void *argument) {
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
osMessageQueueGet(task_runtime.msgq.chassis.yaw, &chassis.feedback.encoder_gimbalYawMotor, NULL, 0);
osMessageQueueGet(task_runtime.msgq.chassis.cmd, &chassis_cmd, NULL, 0);//遥控器
Chassis_UpdateFeedback(&chassis);
Chassis_Control(&chassis, &chassis_cmd, osKernelGetTickCount());
Chassis_Power_Control(&chassis,max);
Chassis_Output(&chassis);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}
}

View File

@ -8,7 +8,7 @@
/* USER INCLUDE BEGIN */
#include "device/dr16.h"
#include "device/at9s_pro.h"
#include "device/AT9S_Pro.h"
#include "module/gimbal.h"
#include "module/shoot.h"
#include "module/chassis.h"
@ -42,6 +42,7 @@ void Task_Init(void *argument) {
task_runtime.thread.ctrl_gimbal = osThreadNew(Task_ctrl_gimbal, NULL, &attr_ctrl_gimbal);
task_runtime.thread.ctrl_shoot = osThreadNew(Task_ctrl_shoot, NULL, &attr_ctrl_shoot);
task_runtime.thread.cmd = osThreadNew(Task_cmd, NULL, &attr_cmd);
task_runtime.thread.supercap = osThreadNew(Task_supercap, NULL, &attr_supercap);
// 创建消息队列
/* USER MESSAGE BEGIN */

View File

@ -3,11 +3,11 @@
*/
// #define AT9S
#define DR16
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#define DR16
#ifdef AT9S
#include "device/at9s_pro.h"
#endif

50
User/task/supercap.c Normal file
View File

@ -0,0 +1,50 @@
/*
supercap Task
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/supercap.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
CAN_SuperCapTXDataTypeDef SuperCap_CanTX;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void Task_supercap(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / SUPERCAP_FREQ;
osDelay(SUPERCAP_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
SuperCap_Init();
SuperCap_CanTX.Enable = 1 ; //超级电容使能。1使能0失能
SuperCap_CanTX.Charge = 1 ; //V1.1超级电容充电。1充电0放电在PLUS版本中此标志位无效超电的充放电是自动的
SuperCap_CanTX.Powerlimit = 120 ; //裁判系统功率限制
SuperCap_CanTX.ChargePower = 1 ; //V1.1超级电容充电功率在PLUS版本中此参数超电的充电功率随着底盘功率变化
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
SuperCap_Update();
CAN_TX_SuperCapData(&SuperCap_CanTX);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}

View File

@ -27,7 +27,7 @@ const osThreadAttr_t attr_blink = {
const osThreadAttr_t attr_ctrl_chassis = {
.name = "ctrl_chassis",
.priority = osPriorityNormal,
.stack_size = 256 * 4,
.stack_size = 512 * 16,
};
const osThreadAttr_t attr_ctrl_gimbal = {
.name = "ctrl_gimbal",
@ -37,10 +37,15 @@ const osThreadAttr_t attr_ctrl_gimbal = {
const osThreadAttr_t attr_ctrl_shoot = {
.name = "ctrl_shoot",
.priority = osPriorityNormal,
.stack_size = 512 * 4,
.stack_size = 256 * 4,
};
const osThreadAttr_t attr_cmd = {
.name = "cmd",
.priority = osPriorityNormal,
.stack_size = 256 * 4,
};
};
const osThreadAttr_t attr_supercap = {
.name = "supercap",
.priority = osPriorityNormal,
.stack_size = 512 * 4,
};

View File

@ -14,12 +14,13 @@ extern "C" {
/* Exported constants ------------------------------------------------------- */
/* 任务运行频率 */
#define RC_FREQ (500.0)
#define ATTI_ESTI_FREQ (500.0)
#define ATTI_ESTI_FREQ (1000.0)
#define BLINK_FREQ (100.0)
#define CTRL_CHASSIS_FREQ (500.0)
#define CTRL_GIMBAL_FREQ (500.0)
#define CTRL_SHOOT_FREQ (1000.0)
#define CTRL_SHOOT_FREQ (500.0)
#define CMD_FREQ (500.0)
#define SUPERCAP_FREQ (500.0)
/* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u)
@ -30,6 +31,7 @@ extern "C" {
#define CTRL_GIMBAL_INIT_DELAY (0)
#define CTRL_SHOOT_INIT_DELAY (0)
#define CMD_INIT_DELAY (0)
#define SUPERCAP_INIT_DELAY (0)
/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
@ -46,6 +48,7 @@ typedef struct {
osThreadId_t ctrl_gimbal;
osThreadId_t ctrl_shoot;
osThreadId_t cmd;
osThreadId_t supercap;
} thread;
/* USER MESSAGE BEGIN */
@ -95,6 +98,7 @@ typedef struct {
UBaseType_t ctrl_gimbal;
UBaseType_t ctrl_shoot;
UBaseType_t cmd;
UBaseType_t supercap;
} stack_water_mark;
/* 各任务运行频率 */
@ -106,6 +110,7 @@ typedef struct {
float ctrl_gimbal;
float ctrl_shoot;
float cmd;
float supercap;
} freq;
/* 任务最近运行时间 */
@ -117,6 +122,7 @@ typedef struct {
float ctrl_gimbal;
float ctrl_shoot;
float cmd;
float supercap;
} last_up_time;
} Task_Runtime_t;
@ -133,6 +139,7 @@ extern const osThreadAttr_t attr_ctrl_chassis;
extern const osThreadAttr_t attr_ctrl_gimbal;
extern const osThreadAttr_t attr_ctrl_shoot;
extern const osThreadAttr_t attr_cmd;
extern const osThreadAttr_t attr_supercap;
/* 任务函数声明 */
void Task_Init(void *argument);
@ -143,6 +150,7 @@ void Task_ctrl_chassis(void *argument);
void Task_ctrl_gimbal(void *argument);
void Task_ctrl_shoot(void *argument);
void Task_cmd(void *argument);
void Task_supercap(void *argument);
#ifdef __cplusplus
}

View File

@ -87,7 +87,7 @@ Dma.USART6_TX.5.Priority=DMA_PRIORITY_LOW
Dma.USART6_TX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode
FREERTOS.IPParameters=Tasks01,configTOTAL_HEAP_SIZE
FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL
FREERTOS.configTOTAL_HEAP_SIZE=0x6000
FREERTOS.configTOTAL_HEAP_SIZE=0x10000
File.Version=6
GPIO.groupedBy=Group By Peripherals
I2C3.I2C_Mode=I2C_Fast