157 lines
4.3 KiB
C
157 lines
4.3 KiB
C
/*
|
|
* 配置相关
|
|
*/
|
|
|
|
/* Includes ----------------------------------------------------------------- */
|
|
#include "module/config.h"
|
|
#include "bsp/can.h"
|
|
|
|
/* Private typedef ---------------------------------------------------------- */
|
|
/* Private define ----------------------------------------------------------- */
|
|
/* Private macro ------------------------------------------------------------ */
|
|
/* Private variables -------------------------------------------------------- */
|
|
|
|
/* Exported variables ------------------------------------------------------- */
|
|
|
|
// 机器人参数配置
|
|
Config_RobotParam_t robot_config = {
|
|
|
|
|
|
|
|
.shoot_param = {
|
|
.fric_num=6,
|
|
.extra_deceleration_ratio=1.0f,
|
|
.num_trig_tooth=8,
|
|
.shot_freq=20.0f,
|
|
.shot_burst_num=1,
|
|
.num_multilevel=2,
|
|
.jam_enable=true,
|
|
.jam_threshold=120.0f,
|
|
.jam_suspected_time=0.5f,
|
|
.trig_motor_param = {
|
|
.can = BSP_CAN_2,
|
|
.id = 0x207,
|
|
.module = MOTOR_M2006,
|
|
.reverse = true,
|
|
.gear=true,
|
|
},
|
|
.fric_follow = {
|
|
.k=1.0f,
|
|
.p=1.8f,
|
|
.i=0.0f,
|
|
.d=0.0f,
|
|
.i_limit=0.0f,
|
|
.out_limit=0.9f,
|
|
.d_cutoff_freq=30.0f,
|
|
.range=-1.0f,
|
|
},
|
|
.fric_err = {
|
|
.k=1.0f,
|
|
.p=4.0f,
|
|
.i=0.4f,
|
|
.d=0.04f,
|
|
.i_limit=0.25f,
|
|
.out_limit=0.25f,
|
|
.d_cutoff_freq=40.0f,
|
|
.range=-1.0f,
|
|
},
|
|
.trig_2006 = {
|
|
.k=2.5f,
|
|
.p=1.0f,
|
|
.i=0.1f,
|
|
.d=0.04f,
|
|
.i_limit=0.4f,
|
|
.out_limit=1.0f,
|
|
.d_cutoff_freq=-1.0f,
|
|
.range=M_2PI,
|
|
},
|
|
.trig_omg_2006 = {
|
|
.k=1.0f,
|
|
.p=1.5f,
|
|
.i=0.3f,
|
|
.d=0.5f,
|
|
.i_limit=0.2f,
|
|
.out_limit=1.0f,
|
|
.d_cutoff_freq=-1.0f,
|
|
.range=-1.0f,
|
|
},
|
|
.trig_3508 = {
|
|
.k=0.0f,
|
|
.p=0.0f,
|
|
.i=0.0f,
|
|
.d=0.00f,
|
|
.i_limit=0.0f,
|
|
.out_limit=0.0f,
|
|
.d_cutoff_freq=-1.0f,
|
|
.range=M_2PI,
|
|
},
|
|
.trig_omg_3508 = {
|
|
.k=0.0f,
|
|
.p=0.0f,
|
|
.i=0.0f,
|
|
.d=0.0f,
|
|
.i_limit=0.0f,
|
|
.out_limit=0.0f,
|
|
.d_cutoff_freq=-1.0f,
|
|
.range=-1.0f,
|
|
},
|
|
.filter.fric = {
|
|
.in = 30.0f,
|
|
.out = 30.0f,
|
|
},
|
|
.filter.trig = {
|
|
.in = 30.0f,
|
|
.out = 30.0f,
|
|
},
|
|
}
|
|
};
|
|
|
|
/* Private function prototypes ---------------------------------------------- */
|
|
/* Exported functions ------------------------------------------------------- */
|
|
|
|
/**
|
|
* @brief 获取机器人配置参数
|
|
* @return 机器人配置参数指针
|
|
*/
|
|
Config_RobotParam_t* Config_GetRobotParam(void) {
|
|
return &robot_config;
|
|
}
|
|
|
|
/**
|
|
* @brief 初始化机器人配置参数
|
|
* @return 初始化结果
|
|
*/
|
|
int8_t Config_ShootInit(void) {
|
|
int fric_num = robot_config.shoot_param.fric_num;
|
|
int num_multilevel = robot_config.shoot_param.num_multilevel;
|
|
|
|
robot_config.shoot_param.fric_motor_param = (Shoot_MOTOR_RM_Param_t *)BSP_Malloc(fric_num * sizeof(Shoot_MOTOR_RM_Param_t));
|
|
if (robot_config.shoot_param.fric_motor_param == NULL) {
|
|
return -1; // 内存分配失败
|
|
}
|
|
robot_config.shoot_param.ratio_multilevel = (float *)BSP_Malloc(num_multilevel * sizeof(float));
|
|
if (robot_config.shoot_param.ratio_multilevel == NULL) {
|
|
return -1; // 内存分配失败
|
|
}
|
|
// 初始化摩擦轮参数
|
|
for (uint8_t i = 0; i < fric_num; i++) {
|
|
robot_config.shoot_param.fric_motor_param[i].param = (MOTOR_RM_Param_t){
|
|
.can = BSP_CAN_2,
|
|
.id = 0x201 + i,
|
|
.module = MOTOR_M3508,
|
|
.reverse = (i == 0||1) ? true : false,
|
|
.gear = false,
|
|
};
|
|
}
|
|
robot_config.shoot_param.fric_motor_param[0].level=1;
|
|
robot_config.shoot_param.fric_motor_param[1].level=1;
|
|
if(num_multilevel==1){
|
|
robot_config.shoot_param.ratio_multilevel[0]=1.0f;
|
|
}
|
|
else if(num_multilevel>1){
|
|
robot_config.shoot_param.ratio_multilevel[0]=1.0f;
|
|
robot_config.shoot_param.ratio_multilevel[1]=1.1f;
|
|
}
|
|
|
|
return SHOOT_OK;
|
|
} |