代码风格更新以及加入超电的对接

This commit is contained in:
lyf committed 2026-11-25 17:24:46 +08:00
1 parent 957c535bda
commit 9de485e4ef
117 files changed
+9046 -6457

No files matched your search

+112
View File
@@ -0,0 +1,112 @@
#ifndef HLJ_PC_H
#define HLJ_PC_H
#include <stdint.h>
#include "robot_param.h"
/* 电机功率模型参数结构体(默认针对M3508+C620) */
typedef struct
{
float k_torque; //机械功率转矩系数
float k_a; //铜损系数
float k_speed_sq; //铁损/风阻系数
float k_constant; //静态偏置功耗(W)
} hlj_pc_model_param_t;
/* 功率预算输入参数结构体 */
typedef struct
{
uint8_t ref_online; //裁判系统是否在线
float ref_power_limit; //裁判系统功率上限(W)
float buffer_energy; //裁判系统缓冲能量(J,无缓冲传0)
uint8_t cap_online; //超电是否在线
uint8_t cap_ready; //超电是否就绪
uint8_t cap_enable; //是否请求使用超电放电
uint8_t cap_energy; //超电剩余能量百分比(0~100)
} hlj_pc_input_t;
/* HLJ_PC系统诊断与状态信息结构体 */
typedef struct
{
float ref_limit_w; //本周期采用的基础功率上限(W)
float buf_delta_w; //缓冲能量闭环修正量(W)
float cap_extra_w; //超电额外释放功率(W)
float total_budget_w; //本周期总可用功率预算(W)
float planned_est_power_w;//速度规划后的预计底盘功率(W)
float kv_scale; //平移速度缩放因子[0,1]
float kw_scale; //小陀螺角速度缩放因子[0,1]
float initial_total_power;//四轮PID原始预计总正功率(W)
float final_power_scale; //四轮电流级功率缩放因子(<=1.0)
uint8_t velocity_limited; //速度规划层是否触发限幅
uint8_t current_limited; //电流分配层是否触发限幅
} hlj_pc_info_t;
extern hlj_pc_model_param_t g_hlj_pc_param;//全局功率模型参数
extern hlj_pc_info_t g_hlj_pc_info; //全局HLJ_PC诊断状态
/*
*函数简介:初始化HLJ_PC功率控制系统(缓冲能量PID与默认预算)
*参数说明:无
*返回类型:无
*备注:在CAN_Task初始化阶段调用一次
*/
extern void hlj_pc_init(void);
/*
*函数简介:计算单颗M3508电机的估计输入功率(W)
*参数说明:speed_rpm:转子转速(RPM)
*参数说明:cmd_current:电流控制指令(counts)
*参数说明:p_mech:输出机械功率指针(可为NULL)
*参数说明:p_loss:输出损耗功率指针(可为NULL)
*返回类型:float:估计输入总功率(W,带符号)
*备注:基于module_test已验证的功率估计模型
*/
extern float hlj_pc_calc_single_power(float speed_rpm, float cmd_current,
float * p_mech, float * p_loss);
/*
*函数简介:根据目标功率逆解单颗电机允许的最大电流指令(counts)
*参数说明:speed_rpm:转子转速(RPM)
*参数说明:raw_cmd:原始期望电流指令(counts)
*参数说明:target_power:目标消耗功率(W)
*返回类型:int16_t:限幅后的电流指令(±16000以内)
*备注:无解时取二次函数最小功耗顶点并限幅,避免失控放行大电流
*/
extern int16_t hlj_pc_solve_single_cmd(float speed_rpm, int16_t raw_cmd, float target_power);
/*
*函数简介:更新本周期底盘总功率预算(裁判上限+缓冲能量+超电剩余)
*参数说明:in:输入状态结构体指针
*返回类型:float:本周期底盘允许消耗的总功率预算(W)
*备注:每2ms由chassis_task调用一次
*/
extern float hlj_pc_update_budget(const hlj_pc_input_t * in);
/*
*函数简介:在当前功率预算下对底盘平移与小陀螺速度进行最优规划
*参数说明:vx_in:期望底盘系前后速度(m/s)
*参数说明:vy_in:期望底盘系左右速度(m/s)
*参数说明:w_in:期望自旋角速度(rad/s)
*参数说明:is_spin:1=小陀螺模式,0=非小陀螺模式
*参数说明:wheel_rpm:四轮当前实测转子转速(RPM)
*参数说明:vx_out:规划后前后速度输出指针
*参数说明:vy_out:规划后左右速度输出指针
*参数说明:w_out:规划后自旋角速度输出指针
*返回类型:无
*备注:边小陀螺边前进时优先保证平移方向不偏,依次压缩小陀螺转速与等比平移量
*/
extern void hlj_pc_plan_velocity(float vx_in, float vy_in, float w_in,
uint8_t is_spin, const float wheel_rpm[4],
float * vx_out, float * vy_out, float * w_out);
/*
*函数简介:四轮最终电流指令功率闭环限幅(兜底分配)
*参数说明:wheel_rpm:四轮当前实测转子转速(RPM)
*参数说明:motor_cmds:四轮PID原始指令数组(原地写回限幅后指令)
*返回类型:无
*备注:由chassis_control()在CAN发送前调用
*/
extern void hlj_pc_limit_motors(const float wheel_rpm[4], int16_t motor_cmds[4]);
#endif