改了方向

This commit is contained in:
Robofish 2025-03-01 20:28:09 +08:00
parent 9fe34c0bf8
commit 78712e5918
9 changed files with 9410 additions and 9348 deletions

View File

@ -367,6 +367,26 @@
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>gimbal</ItemText> <ItemText>gimbal</ItemText>
</Ww> </Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>shoot</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>param_hero</ItemText>
</Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>ref</ItemText>
</Ww>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<ItemText>for_chassis</ItemText>
</Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow4> <MemoryWindow4>
<Mm> <Mm>

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ static void CMD_PcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
cmd->gimbal.delta_eulr.yaw = cmd->gimbal.delta_eulr.yaw =
(float)rc->mouse.x * dt_sec * cmd->param->sens_mouse; (float)rc->mouse.x * dt_sec * cmd->param->sens_mouse;
cmd->gimbal.delta_eulr.pit = cmd->gimbal.delta_eulr.pit =
(float)(-rc->mouse.y) * dt_sec * cmd->param->sens_mouse; (float)(rc->mouse.y) * dt_sec * cmd->param->sens_mouse;
cmd->chassis.ctrl_vec.vx = cmd->chassis.ctrl_vec.vy = 0.0f; cmd->chassis.ctrl_vec.vx = cmd->chassis.ctrl_vec.vy = 0.0f;
cmd->shoot.reverse_trig = false; cmd->shoot.reverse_trig = false;

View File

@ -68,7 +68,8 @@ static bool inited = false;
/* Private function -------------------------------------------------------- */ /* Private function -------------------------------------------------------- */
static void CAN_Motor_Decode(CAN_MotorFeedback_t *feedback, static void CAN_Motor_Decode(CAN_MotorFeedback_t *feedback,
const uint8_t *raw) { const uint8_t *raw)
{
uint16_t raw_angle = (uint16_t)((raw[0] << 8) | raw[1]); uint16_t raw_angle = (uint16_t)((raw[0] << 8) | raw[1]);
int16_t raw_current = (int16_t)((raw[4] << 8) | raw[5]); int16_t raw_current = (int16_t)((raw[4] << 8) | raw[5]);
@ -79,36 +80,44 @@ static void CAN_Motor_Decode(CAN_MotorFeedback_t *feedback,
feedback->temp = raw[6]; feedback->temp = raw[6];
} }
void CAN_Cap_Decode(CAN_CapFeedback_t *feedback, const uint8_t *raw) { void CAN_Cap_Decode(CAN_CapFeedback_t *feedback, const uint8_t *raw)
{
feedback->input_volt = (float)((raw[1] << 8) | raw[0]) / (float)CAN_CAP_RES; feedback->input_volt = (float)((raw[1] << 8) | raw[0]) / (float)CAN_CAP_RES;
feedback->cap_volt = (float)((raw[3] << 8) | raw[2]) / (float)CAN_CAP_RES; feedback->cap_volt = (float)((raw[3] << 8) | raw[2]) / (float)CAN_CAP_RES;
feedback->input_curr = (float)((raw[5] << 8) | raw[4]) / (float)CAN_CAP_RES; feedback->input_curr = (float)((raw[5] << 8) | raw[4]) / (float)CAN_CAP_RES;
feedback->target_power = (float)((raw[7] << 8) | raw[6]) / (float)CAN_CAP_RES; feedback->target_power = (float)((raw[7] << 8) | raw[6]) / (float)CAN_CAP_RES;
} }
void CAN_Tof_Decode(CAN_Tof_t *tof, const uint8_t *raw) { void CAN_Tof_Decode(CAN_Tof_t *tof, const uint8_t *raw)
{
tof->dist = (float)((raw[2] << 16) | (raw[1] << 8) | raw[0]) / 1000.0f; tof->dist = (float)((raw[2] << 16) | (raw[1] << 8) | raw[0]) / 1000.0f;
tof->status = raw[3]; tof->status = raw[3];
tof->signal_strength = (raw[5] << 8) | raw[4]; tof->signal_strength = (raw[5] << 8) | raw[4];
} }
static void CAN_CAN1RxFifoMsgPendingCallback(void) { static void CAN_CAN1RxFifoMsgPendingCallback(void)
{
HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_1), CAN_MOTOR_RX_FIFO, HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_1), CAN_MOTOR_RX_FIFO,
&raw_rx1.rx_header, raw_rx1.rx_data); &raw_rx1.rx_header, raw_rx1.rx_data);
osMessageQueuePut(gcan->msgq_raw, &raw_rx1, 0, 0); osMessageQueuePut(gcan->msgq_raw, &raw_rx1, 0, 0);
} }
static void CAN_CAN2RxFifoMsgPendingCallback(void) { static void CAN_CAN2RxFifoMsgPendingCallback(void)
{
HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_2), CAN_CAP_RX_FIFO, HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_2), CAN_CAP_RX_FIFO,
&raw_rx2.rx_header, raw_rx2.rx_data); &raw_rx2.rx_header, raw_rx2.rx_data);
osMessageQueuePut(gcan->msgq_raw, &raw_rx2, 0, 0); osMessageQueuePut(gcan->msgq_raw, &raw_rx2, 0, 0);
} }
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param) { int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param)
if (can == NULL) return DEVICE_ERR_NULL; {
if (inited) return DEVICE_ERR_INITED; if (can == NULL)
if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL; return DEVICE_ERR_NULL;
if (inited)
return DEVICE_ERR_INITED;
if ((thread_alert = osThreadGetId()) == NULL)
return DEVICE_ERR_NULL;
can->msgq_raw = osMessageQueueNew(32, sizeof(CAN_RawRx_t), NULL); can->msgq_raw = osMessageQueueNew(32, sizeof(CAN_RawRx_t), NULL);
@ -150,13 +159,16 @@ int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param) {
} }
int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output, int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
CAN_t *can) { CAN_t *can)
if (output == NULL) return DEVICE_ERR_NULL; {
if (output == NULL)
return DEVICE_ERR_NULL;
int16_t motor1, motor2, motor3, motor4; int16_t motor1, motor2, motor3, motor4;
int16_t yaw_motor, pit_motor; int16_t yaw_motor, pit_motor;
int16_t fric1_motor, fric2_motor, trig_motor; int16_t fric1_motor, fric2_motor, fric3_motor, trig_motor;
switch (group) { switch (group)
{
case CAN_MOTOR_GROUT_CHASSIS: case CAN_MOTOR_GROUT_CHASSIS:
motor1 = motor1 =
(int16_t)(output->chassis.named.m1 * (float)CAN_M3508_MAX_ABS_LSB); (int16_t)(output->chassis.named.m1 * (float)CAN_M3508_MAX_ABS_LSB);
@ -222,6 +234,8 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
(int16_t)(output->shoot.named.fric1 * (float)CAN_M3508_MAX_ABS_LSB); (int16_t)(output->shoot.named.fric1 * (float)CAN_M3508_MAX_ABS_LSB);
fric2_motor = fric2_motor =
(int16_t)(output->shoot.named.fric2 * (float)CAN_M3508_MAX_ABS_LSB); (int16_t)(output->shoot.named.fric2 * (float)CAN_M3508_MAX_ABS_LSB);
fric3_motor =
(int16_t)(output->shoot.named.fric3 * (float)CAN_M3508_MAX_ABS_LSB);
trig_motor = trig_motor =
(int16_t)(output->shoot.named.trig * (float)CAN_M2006_MAX_ABS_LSB); (int16_t)(output->shoot.named.trig * (float)CAN_M2006_MAX_ABS_LSB);
@ -234,10 +248,10 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
raw_tx.tx_data[1] = (uint8_t)(fric1_motor & 0xFF); raw_tx.tx_data[1] = (uint8_t)(fric1_motor & 0xFF);
raw_tx.tx_data[2] = (uint8_t)((fric2_motor >> 8) & 0xFF); raw_tx.tx_data[2] = (uint8_t)((fric2_motor >> 8) & 0xFF);
raw_tx.tx_data[3] = (uint8_t)(fric2_motor & 0xFF); raw_tx.tx_data[3] = (uint8_t)(fric2_motor & 0xFF);
raw_tx.tx_data[4] = (uint8_t)((trig_motor >> 8) & 0xFF); raw_tx.tx_data[4] = (uint8_t)((fric3_motor >> 8) & 0xFF);
raw_tx.tx_data[5] = (uint8_t)(trig_motor & 0xFF); raw_tx.tx_data[5] = (uint8_t)(fric3_motor & 0xFF);
raw_tx.tx_data[6] = 0; raw_tx.tx_data[6] = (uint8_t)((trig_motor >> 8) & 0xFF);
raw_tx.tx_data[7] = 0; raw_tx.tx_data[7] = (uint8_t)(trig_motor & 0xFF);
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot), HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot),
&raw_tx.tx_header, raw_tx.tx_data, &raw_tx.tx_header, raw_tx.tx_data,
@ -246,19 +260,20 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
&raw_tx.tx_header, raw_tx.tx_data, &raw_tx.tx_header, raw_tx.tx_data,
&(can->mailbox.shoot)); &(can->mailbox.shoot));
break; break;
default:
break;
} }
return DEVICE_OK; return DEVICE_OK;
} }
int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx) { int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx)
if (can == NULL) return DEVICE_ERR_NULL; {
if (can_rx == NULL) return DEVICE_ERR_NULL; if (can == NULL)
return DEVICE_ERR_NULL;
if (can_rx == NULL)
return DEVICE_ERR_NULL;
uint32_t index; uint32_t index;
switch (can_rx->rx_header.StdId) { switch (can_rx->rx_header.StdId)
{
case CAN_M3508_M1_ID: case CAN_M3508_M1_ID:
case CAN_M3508_M2_ID: case CAN_M3508_M2_ID:
case CAN_M3508_M3_ID: case CAN_M3508_M3_ID:
@ -270,12 +285,12 @@ int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx) {
case CAN_M3508_FRIC1_ID: case CAN_M3508_FRIC1_ID:
case CAN_M3508_FRIC2_ID: case CAN_M3508_FRIC2_ID:
case CAN_M3508_FRIC3_ID:
case CAN_M2006_TRIG_ID: case CAN_M2006_TRIG_ID:
index = can_rx->rx_header.StdId - CAN_M3508_FRIC1_ID; index = can_rx->rx_header.StdId - CAN_M3508_FRIC1_ID;
can->recive_flag |= 1 << (index + 6); can->recive_flag |= 1 << (index + 6);
CAN_Motor_Decode(&(can->motor.shoot.as_array[index]), can_rx->rx_data); CAN_Motor_Decode(&(can->motor.shoot.as_array[index]), can_rx->rx_data);
break; break;
case CAN_GM6020_YAW_ID: case CAN_GM6020_YAW_ID:
case CAN_GM6020_PIT_ID: case CAN_GM6020_PIT_ID:
index = can_rx->rx_header.StdId - CAN_GM6020_YAW_ID; index = can_rx->rx_header.StdId - CAN_GM6020_YAW_ID;
@ -296,18 +311,23 @@ int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx) {
return DEVICE_OK; return DEVICE_OK;
} }
bool CAN_CheckFlag(CAN_t *can, uint32_t flag) { bool CAN_CheckFlag(CAN_t *can, uint32_t flag)
if (can == NULL) return false; {
if (can == NULL)
return false;
return (can->recive_flag & flag) == flag; return (can->recive_flag & flag) == flag;
} }
int8_t CAN_ClearFlag(CAN_t *can, uint32_t flag) { int8_t CAN_ClearFlag(CAN_t *can, uint32_t flag)
if (can == NULL) return DEVICE_ERR_NULL; {
if (can == NULL)
return DEVICE_ERR_NULL;
can->recive_flag &= ~flag; can->recive_flag &= ~flag;
return DEVICE_OK; return DEVICE_OK;
} }
int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can) { int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can)
{
float power_limit = output->power_limit; float power_limit = output->power_limit;
uint16_t cap = (uint16_t)(power_limit * CAN_CAP_RES); uint16_t cap = (uint16_t)(power_limit * CAN_CAP_RES);
@ -326,7 +346,8 @@ int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can) {
} }
void CAN_CAP_HandleOffline(CAN_Capacitor_t *cap, CAN_CapOutput_t *cap_out, void CAN_CAP_HandleOffline(CAN_Capacitor_t *cap, CAN_CapOutput_t *cap_out,
float power_chassis) { float power_chassis)
{
cap->cap_status = CAN_CAP_STATUS_OFFLINE; cap->cap_status = CAN_CAP_STATUS_OFFLINE;
cap_out->power_limit = power_chassis; cap_out->power_limit = power_chassis;
} }

View File

@ -22,9 +22,10 @@ extern "C" {
#define CAN_MOTOR_GIMBAL_PIT_RECV (1 << 5) #define CAN_MOTOR_GIMBAL_PIT_RECV (1 << 5)
#define CAN_MOTOR_SHOOT_FRIC1_RECV (1 << 6) #define CAN_MOTOR_SHOOT_FRIC1_RECV (1 << 6)
#define CAN_MOTOR_SHOOT_FRIC2_RECV (1 << 7) #define CAN_MOTOR_SHOOT_FRIC2_RECV (1 << 7)
#define CAN_MOTOR_SHOOT_TRIG_RECV (1 << 8) #define CAN_MOTOR_SHOOT_FRIC3_RECV (1 << 8)
#define CAN_MOTOR_CAP_RECV (1 << 9) #define CAN_MOTOR_SHOOT_TRIG_RECV (1 << 9)
#define CAN_TOF_RECV (1 << 10) #define CAN_MOTOR_CAP_RECV (1 << 10)
#define CAN_TOF_RECV (1 << 11)
#define CAN_REC_CHASSIS_FINISHED \ #define CAN_REC_CHASSIS_FINISHED \
(CAN_MOTOR_CHASSIS_1_RECV | CAN_MOTOR_CHASSIS_2_RECV | \ (CAN_MOTOR_CHASSIS_1_RECV | CAN_MOTOR_CHASSIS_2_RECV | \
@ -33,7 +34,7 @@ extern "C" {
(CAN_MOTOR_GIMBAL_YAW_RECV | CAN_MOTOR_GIMBAL_PIT_RECV) (CAN_MOTOR_GIMBAL_YAW_RECV | CAN_MOTOR_GIMBAL_PIT_RECV)
#define CAN_REC_SHOOT_FINISHED \ #define CAN_REC_SHOOT_FINISHED \
(CAN_MOTOR_SHOOT_FRIC1_RECV | CAN_MOTOR_SHOOT_FRIC2_RECV | \ (CAN_MOTOR_SHOOT_FRIC1_RECV | CAN_MOTOR_SHOOT_FRIC2_RECV | \
CAN_MOTOR_SHOOT_TRIG_RECV) CAN_MOTOR_SHOOT_FRIC3_RECV |CAN_MOTOR_SHOOT_TRIG_RECV)
#define CAN_REC_CAP_FINISHED CAN_MOTOR_CAP_RECV #define CAN_REC_CAP_FINISHED CAN_MOTOR_CAP_RECV
#define CAN_REC_TOF_FINISHED CAN_TOF_RECV #define CAN_REC_TOF_FINISHED CAN_TOF_RECV
@ -72,7 +73,8 @@ typedef enum {
CAN_M3508_FRIC1_ID = 0x205, /* 5 */ CAN_M3508_FRIC1_ID = 0x205, /* 5 */
CAN_M3508_FRIC2_ID = 0x206, /* 6 */ CAN_M3508_FRIC2_ID = 0x206, /* 6 */
CAN_M2006_TRIG_ID = 0x207, /* 7 */ CAN_M3508_FRIC3_ID = 0x207, /* 7 */
CAN_M2006_TRIG_ID = 0x208, /* 8 */
CAN_GM6020_YAW_ID = 0x209, /* 5 */ CAN_GM6020_YAW_ID = 0x209, /* 5 */
CAN_GM6020_PIT_ID = 0x20A, /* 6 */ CAN_GM6020_PIT_ID = 0x20A, /* 6 */
@ -116,6 +118,7 @@ enum CAN_MotorGimbal_e {
enum CAN_MotorShoot_e { enum CAN_MotorShoot_e {
CAN_MOTOR_SHOOT_FRIC1 = 0, CAN_MOTOR_SHOOT_FRIC1 = 0,
CAN_MOTOR_SHOOT_FRIC2, CAN_MOTOR_SHOOT_FRIC2,
CAN_MOTOR_SHOOT_FRIC3,
CAN_MOTOR_SHOOT_TRIG, CAN_MOTOR_SHOOT_TRIG,
CAN_MOTORSHOOT_NUM, CAN_MOTORSHOOT_NUM,
}; };
@ -153,6 +156,7 @@ typedef union {
struct { struct {
float fric1; float fric1;
float fric2; float fric2;
float fric3;
float trig; float trig;
} named; } named;
} CAN_ShootOutput_t; } CAN_ShootOutput_t;
@ -206,6 +210,7 @@ typedef union {
struct { struct {
CAN_MotorFeedback_t fric1; CAN_MotorFeedback_t fric1;
CAN_MotorFeedback_t fric2; CAN_MotorFeedback_t fric2;
CAN_MotorFeedback_t fric3;
CAN_MotorFeedback_t trig; CAN_MotorFeedback_t trig;
} named; } named;
} CAN_ShootMotor_t; } CAN_ShootMotor_t;

View File

@ -202,7 +202,11 @@ static const Config_RobotParam_t param_default = {
}, /* can */ }, /* can */
}; /* param_default */ }; /* param_default */
#ifdef DEBUG
Config_RobotParam_t param_hero = {
#else
static const Config_RobotParam_t param_hero = { static const Config_RobotParam_t param_hero = {
#endif
.model = ROBOT_MODEL_HERO, .model = ROBOT_MODEL_HERO,
.chassis = { /* 底盘模块参数 */ .chassis = { /* 底盘模块参数 */
@ -236,7 +240,7 @@ static const Config_RobotParam_t param_hero = {
}, },
.reverse = { .reverse = {
.yaw = true, .yaw = false,
}, },
}, /* chassis */ }, /* chassis */
@ -285,7 +289,7 @@ static const Config_RobotParam_t param_hero = {
}, },
}, /* pid */ }, /* pid */
.pitch_travel_rad = 1.07685447f, .pitch_travel_rad = 0.9685447f,
.low_pass_cutoff_freq = { .low_pass_cutoff_freq = {
.out = -1.0f, .out = -1.0f,
@ -293,8 +297,8 @@ static const Config_RobotParam_t param_hero = {
}, },
.reverse = { .reverse = {
.yaw = true, .yaw = false,
.pit = true, .pit = false,
}, },
}, /* gimbal */ }, /* gimbal */
@ -329,8 +333,8 @@ static const Config_RobotParam_t param_hero = {
.trig = -1.0f, .trig = -1.0f,
}, },
}, },
.num_trig_tooth = 6.0f, .num_trig_tooth = 5.0f,
.trig_gear_ratio = 3591.0f / 187.0f, .trig_gear_ratio = 19.0f,
.fric_radius = 0.03f, .fric_radius = 0.03f,
.cover_open_duty = 0.125f, .cover_open_duty = 0.125f,
.cover_close_duty = 0.075f, .cover_close_duty = 0.075f,
@ -434,17 +438,21 @@ static const Config_PilotCfgMap_t pilot_cfg_map[] = {
* *
* \param cfg * \param cfg
*/ */
void Config_Get(Config_t *cfg) { void Config_Get(Config_t *cfg)
{
BSP_Flash_ReadBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg)); BSP_Flash_ReadBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg));
cfg->pilot_cfg = Config_GetPilotCfg(cfg->pilot_cfg_name); cfg->pilot_cfg = Config_GetPilotCfg(cfg->pilot_cfg_name);
cfg->robot_param = Config_GetRobotParam(cfg->robot_param_name); cfg->robot_param = Config_GetRobotParam(cfg->robot_param_name);
/* 防止第一次烧写后访问NULL指针 */ /* 防止第一次烧写后访问NULL指针 */
if (cfg->robot_param == NULL) cfg->robot_param = &param_default; if (cfg->robot_param == NULL)
if (cfg->pilot_cfg == NULL) cfg->pilot_cfg = &cfg_qs; cfg->robot_param = &param_default;
if (cfg->pilot_cfg == NULL)
cfg->pilot_cfg = &cfg_qs;
/* 防止擦除后全为1 */ /* 防止擦除后全为1 */
if ((uint32_t)(cfg->robot_param) == UINT32_MAX) if ((uint32_t)(cfg->robot_param) == UINT32_MAX)
cfg->robot_param = &param_default; cfg->robot_param = &param_default;
if ((uint32_t)(cfg->pilot_cfg) == UINT32_MAX) cfg->pilot_cfg = &cfg_qs; if ((uint32_t)(cfg->pilot_cfg) == UINT32_MAX)
cfg->pilot_cfg = &cfg_qs;
} }
/** /**
@ -452,7 +460,8 @@ void Config_Get(Config_t *cfg) {
* *
* \param cfg * \param cfg
*/ */
void Config_Set(Config_t *cfg) { void Config_Set(Config_t *cfg)
{
osKernelLock(); osKernelLock();
BSP_Flash_EraseSector(11); BSP_Flash_EraseSector(11);
BSP_Flash_WriteBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg)); BSP_Flash_WriteBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg));
@ -465,10 +474,14 @@ void Config_Set(Config_t *cfg) {
* @param robot_param_name * @param robot_param_name
* @return const Config_RobotParam_t* * @return const Config_RobotParam_t*
*/ */
const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name) { const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name)
if (robot_param_name == NULL) return NULL; {
for (size_t j = 0; robot_param_map[j].name != NULL; j++) { if (robot_param_name == NULL)
if (strcmp(robot_param_map[j].name, robot_param_name) == 0) { return NULL;
for (size_t j = 0; robot_param_map[j].name != NULL; j++)
{
if (strcmp(robot_param_map[j].name, robot_param_name) == 0)
{
return robot_param_map[j].param; return robot_param_map[j].param;
} }
} }
@ -481,20 +494,26 @@ const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name) {
* @param pilot_cfg_name * @param pilot_cfg_name
* @return const Config_PilotCfg_t* * @return const Config_PilotCfg_t*
*/ */
const Config_PilotCfg_t *Config_GetPilotCfg(const char *pilot_cfg_name) { const Config_PilotCfg_t *Config_GetPilotCfg(const char *pilot_cfg_name)
if (pilot_cfg_name == NULL) return NULL; {
for (size_t j = 0; pilot_cfg_map[j].name != NULL; j++) { if (pilot_cfg_name == NULL)
if (strcmp(pilot_cfg_map[j].name, pilot_cfg_name) == 0) { return NULL;
for (size_t j = 0; pilot_cfg_map[j].name != NULL; j++)
{
if (strcmp(pilot_cfg_map[j].name, pilot_cfg_name) == 0)
{
return pilot_cfg_map[j].param; return pilot_cfg_map[j].param;
} }
} }
return NULL; /* No match. */ return NULL; /* No match. */
} }
const Config_PilotCfgMap_t *Config_GetPilotNameMap(void) { const Config_PilotCfgMap_t *Config_GetPilotNameMap(void)
{
return pilot_cfg_map; return pilot_cfg_map;
} }
const Config_RobotParamMap_t *Config_GetRobotNameMap(void) { const Config_RobotParamMap_t *Config_GetRobotNameMap(void)
{
return robot_param_map; return robot_param_map;
} }

View File

@ -35,7 +35,7 @@ static int8_t Shoot_SetMode(Shoot_t *s, CMD_ShootMode_t mode) {
if (mode == s->mode) return SHOOT_OK; if (mode == s->mode) return SHOOT_OK;
/* 切换模式后重置PID和滤波器 */ /* 切换模式后重置PID和滤波器 */
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 3; i++) {
PID_Reset(s->pid.fric + i); PID_Reset(s->pid.fric + i);
LowPassFilter2p_Reset(s->filter.in.fric + i, 0.0f); LowPassFilter2p_Reset(s->filter.in.fric + i, 0.0f);
LowPassFilter2p_Reset(s->filter.out.fric + i, 0.0f); LowPassFilter2p_Reset(s->filter.out.fric + i, 0.0f);
@ -117,7 +117,7 @@ int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq) {
s->param = param; /* 初始化参数 */ s->param = param; /* 初始化参数 */
s->mode = SHOOT_MODE_RELAX; /* 设置默认模式 */ s->mode = SHOOT_MODE_RELAX; /* 设置默认模式 */
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 3; i++) {
/* PI控制器初始化PID */ /* PI控制器初始化PID */
PID_Init(s->pid.fric + i, KPID_MODE_NO_D, target_freq, PID_Init(s->pid.fric + i, KPID_MODE_NO_D, target_freq,
&(param->fric_pid_param)); &(param->fric_pid_param));
@ -154,7 +154,7 @@ int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can) {
if (s == NULL) return -1; if (s == NULL) return -1;
if (can == NULL) return -1; if (can == NULL) return -1;
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 3; i++) {
s->feedback.fric_rpm[i] = can->motor.shoot.as_array[i].rotor_speed; s->feedback.fric_rpm[i] = can->motor.shoot.as_array[i].rotor_speed;
} }
@ -245,20 +245,26 @@ int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
} }
/* 计算摩擦轮转速的目标值 */ /* 计算摩擦轮转速的目标值 */
s->setpoint.fric_rpm[1] = // s->setpoint.fric_rpm[1] =
CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius, // CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius,
// (s->param->model == SHOOT_MODEL_17MM));
// s->setpoint.fric_rpm[0] = -s->setpoint.fric_rpm[1];
float fric_rpm = CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius,
(s->param->model == SHOOT_MODEL_17MM)); (s->param->model == SHOOT_MODEL_17MM));
s->setpoint.fric_rpm[0] = -s->setpoint.fric_rpm[1]; s->setpoint.fric_rpm[0] = -fric_rpm;
s->setpoint.fric_rpm[1] = fric_rpm;
s->setpoint.fric_rpm[2] = -fric_rpm;
/* 计算拨弹电机位置的目标值 */ /* 计算拨弹电机位置的目标值 */
if (((now - s->fire_ctrl.last_shoot) >= s->fire_ctrl.period_ms) && if (((now - s->fire_ctrl.last_shoot) >= s->fire_ctrl.period_ms) &&
(s_cmd->fire)) { (s_cmd->fire)) {
/* 将拨弹电机角度进行循环加法,每次加(减)射出一颗弹丸的弧度变化 */ /* 将拨弹电机角度进行循环加法,每次加(减)射出一颗弹丸的弧度变化 */
if (s_cmd->reverse_trig) { /* 反转拨弹 */ if (s_cmd->reverse_trig) { /* 反转拨弹 */
CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth, CircleAdd(&(s->setpoint.trig_angle), -M_2PI / s->param->num_trig_tooth,
M_2PI); M_2PI);
} else { } else {
CircleAdd(&(s->setpoint.trig_angle), -M_2PI / s->param->num_trig_tooth, CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth,
M_2PI); M_2PI);
s->fire_ctrl.shooted++; s->fire_ctrl.shooted++;
s->fire_ctrl.last_shoot = now; s->fire_ctrl.last_shoot = now;
@ -285,7 +291,7 @@ int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
s->out[SHOOT_ACTR_TRIG_IDX] = LowPassFilter2p_Apply( s->out[SHOOT_ACTR_TRIG_IDX] = LowPassFilter2p_Apply(
&(s->filter.out.trig), s->out[SHOOT_ACTR_TRIG_IDX]); &(s->filter.out.trig), s->out[SHOOT_ACTR_TRIG_IDX]);
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 3; i++) {
/* 控制摩擦轮 */ /* 控制摩擦轮 */
s->feedback.fric_rpm[i] = LowPassFilter2p_Apply( s->feedback.fric_rpm[i] = LowPassFilter2p_Apply(
&(s->filter.in.fric[i]), s->feedback.fric_rpm[i]); &(s->filter.in.fric[i]), s->feedback.fric_rpm[i]);

View File

@ -2,45 +2,46 @@
* *
*/ */
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Includes ----------------------------------------------------------------- */ /* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h> #include <cmsis_os2.h>
#include "component\cmd.h" #include "component\cmd.h"
#include "component\filter.h" #include "component\filter.h"
#include "component\pid.h" #include "component\pid.h"
#include "device\can.h" #include "device\can.h"
#include "device\referee.h" #include "device\referee.h"
/* Exported constants ------------------------------------------------------- */ /* Exported constants ------------------------------------------------------- */
#define SHOOT_OK (0) /* 运行正常 */ #define SHOOT_OK (0) /* 运行正常 */
#define SHOOT_ERR (-1) /* 运行时发现了其他错误 */ #define SHOOT_ERR (-1) /* 运行时发现了其他错误 */
#define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */ #define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */
#define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */ #define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */
/* Exported macro ----------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */
/* 用enum组合所有PID方便访问配合数组使用 */ /* 用enum组合所有PID方便访问配合数组使用 */
enum Shoot_Acuator_e { enum Shoot_Acuator_e {
SHOOT_ACTR_FRIC1_IDX = 0, /* 1号摩擦轮相关的索引值 */ SHOOT_ACTR_FRIC1_IDX = 0, /* 1号摩擦轮相关的索引值 */
SHOOT_ACTR_FRIC2_IDX, /* 2号摩擦轮相关的索引值 */ SHOOT_ACTR_FRIC2_IDX, /* 2号摩擦轮相关的索引值 */
SHOOT_ACTR_FRIC3_IDX, /* 3号摩擦轮相关的索引值 */
SHOOT_ACTR_TRIG_IDX, /* 扳机电机相关的索引值 */ SHOOT_ACTR_TRIG_IDX, /* 扳机电机相关的索引值 */
SHOOT_ACTR_NUM, /* 总共的动作器数量 */ SHOOT_ACTR_NUM, /* 总共的动作器数量 */
}; };
/* 发射机构型号 */ /* 发射机构型号 */
typedef enum { typedef enum {
SHOOT_MODEL_17MM = 0, /* 17mm发射机构 */ SHOOT_MODEL_17MM = 0, /* 17mm发射机构 */
SHOOT_MODEL_42MM, /* 42mm发射机构 */ SHOOT_MODEL_42MM, /* 42mm发射机构 */
} Shoot_Model_t; } Shoot_Model_t;
/* 射击参数的结构体包含所有初始化用的参数通常是const存好几组。*/ /* 射击参数的结构体包含所有初始化用的参数通常是const存好几组。*/
typedef struct { typedef struct {
KPID_Params_t fric_pid_param; /* 摩擦轮电机控制PID的参数 */ KPID_Params_t fric_pid_param; /* 摩擦轮电机控制PID的参数 */
KPID_Params_t trig_pid_param; /* 扳机电机控制PID的参数 */ KPID_Params_t trig_pid_param; /* 扳机电机控制PID的参数 */
/* 低通滤波器截止频率 */ /* 低通滤波器截止频率 */
@ -66,9 +67,9 @@ typedef struct {
Shoot_Model_t model; /* 发射机构型号 */ Shoot_Model_t model; /* 发射机构型号 */
float bullet_speed; /* 弹丸初速度 */ float bullet_speed; /* 弹丸初速度 */
uint32_t min_shoot_delay; /* 通过设置最小射击间隔来设置最大射频 */ uint32_t min_shoot_delay; /* 通过设置最小射击间隔来设置最大射频 */
} Shoot_Params_t; } Shoot_Params_t;
typedef struct { typedef struct {
float heat; /* 现在热量水平 */ float heat; /* 现在热量水平 */
float last_heat; /* 之前的热量水平 */ float last_heat; /* 之前的热量水平 */
float heat_limit; /* 热量上限 */ float heat_limit; /* 热量上限 */
@ -78,9 +79,9 @@ typedef struct {
float last_bullet_speed; /* 之前的弹丸速度 */ float last_bullet_speed; /* 之前的弹丸速度 */
uint32_t available_shot; /* 热量范围内还可以发射的数量 */ uint32_t available_shot; /* 热量范围内还可以发射的数量 */
} Shoot_HeatCtrl_t; } Shoot_HeatCtrl_t;
typedef struct { typedef struct {
uint32_t last_shoot; /* 上次射击时间 单位ms */ uint32_t last_shoot; /* 上次射击时间 单位ms */
bool last_fire; /* 上次开火状态 */ bool last_fire; /* 上次开火状态 */
bool first_fire; /* 第一次收到开火指令 */ bool first_fire; /* 第一次收到开火指令 */
@ -89,13 +90,13 @@ typedef struct {
float bullet_speed; /* 弹丸初速度 */ float bullet_speed; /* 弹丸初速度 */
uint32_t period_ms; /* 弹丸击发延迟 */ uint32_t period_ms; /* 弹丸击发延迟 */
CMD_FireMode_t fire_mode; CMD_FireMode_t fire_mode;
} Shoot_FireCtrl_t; } Shoot_FireCtrl_t;
/* /*
* *
* *
*/ */
typedef struct { typedef struct {
uint32_t lask_wakeup; uint32_t lask_wakeup;
float dt; float dt;
@ -106,20 +107,20 @@ typedef struct {
/* 反馈信息 */ /* 反馈信息 */
struct { struct {
float fric_rpm[2]; /* 摩擦轮电机转速单位RPM */ float fric_rpm[3]; /* 摩擦轮电机转速单位RPM */
float trig_motor_angle; /* 拨弹电机角度,单位:弧度 */ float trig_motor_angle; /* 拨弹电机角度,单位:弧度 */
float trig_angle; /* 拨弹转盘角度,单位:弧度 */ float trig_angle; /* 拨弹转盘角度,单位:弧度 */
} feedback; } feedback;
/* PID计算的目标值 */ /* PID计算的目标值 */
struct { struct {
float fric_rpm[2]; /* 摩擦轮电机转速单位RPM */ float fric_rpm[3]; /* 摩擦轮电机转速单位RPM */
float trig_angle; /* 拨弹电机角度,单位:弧度 */ float trig_angle; /* 拨弹电机角度,单位:弧度 */
} setpoint; } setpoint;
/* 反馈控制用的PID */ /* 反馈控制用的PID */
struct { struct {
KPID_t fric[2]; /* 控制摩擦轮 */ KPID_t fric[3]; /* 控制摩擦轮 */
KPID_t trig; /* 控制拨弹电机 */ KPID_t trig; /* 控制拨弹电机 */
} pid; } pid;
@ -127,13 +128,13 @@ typedef struct {
struct { struct {
/* 反馈值滤波器 */ /* 反馈值滤波器 */
struct { struct {
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */ LowPassFilter2p_t fric[3]; /* 过滤摩擦轮 */
LowPassFilter2p_t trig; /* 过滤拨弹电机 */ LowPassFilter2p_t trig; /* 过滤拨弹电机 */
} in; } in;
/* 输出值滤波器 */ /* 输出值滤波器 */
struct { struct {
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */ LowPassFilter2p_t fric[3]; /* 过滤摩擦轮 */
LowPassFilter2p_t trig; /* 过滤拨弹电机 */ LowPassFilter2p_t trig; /* 过滤拨弹电机 */
} out; } out;
} filter; } filter;
@ -143,11 +144,11 @@ typedef struct {
float out[SHOOT_ACTR_NUM]; /* 输出数组通过Shoot_Acuator_e里的值访问 */ float out[SHOOT_ACTR_NUM]; /* 输出数组通过Shoot_Acuator_e里的值访问 */
} Shoot_t; } Shoot_t;
/* Exported functions prototypes -------------------------------------------- */ /* Exported functions prototypes -------------------------------------------- */
/** /**
* \brief * \brief
* *
* \param s * \param s
@ -156,9 +157,9 @@ typedef struct {
* *
* \return * \return
*/ */
int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq); int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
/** /**
* \brief * \brief
* *
* \param s * \param s
@ -166,9 +167,9 @@ int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
* *
* \return * \return
*/ */
int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can); int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can);
/** /**
* \brief * \brief
* *
* \param s * \param s
@ -178,32 +179,33 @@ int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can);
* *
* \return * \return
*/ */
int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd, int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
Referee_ForShoot_t *s_ref, uint32_t now); Referee_ForShoot_t *s_ref, uint32_t now);
/** /**
* \brief * \brief
* *
* \param s * \param s
* \param out CAN设备射击输出结构体 * \param out CAN设备射击输出结构体
*/ */
void Shoot_DumpOutput(Shoot_t *s, CAN_ShootOutput_t *out); void Shoot_DumpOutput(Shoot_t *s, CAN_ShootOutput_t *out);
/** /**
* \brief * \brief
* *
* \param output * \param output
*/ */
void Shoot_ResetOutput(CAN_ShootOutput_t *output); void Shoot_ResetOutput(CAN_ShootOutput_t *output);
/** /**
* @brief UI数据 * @brief UI数据
* *
* @param s * @param s
* @param ui UI结构体 * @param ui UI结构体
*/ */
void Shoot_DumpUI(Shoot_t *s, Referee_ShootUI_t *ui); void Shoot_DumpUI(Shoot_t *s, Referee_ShootUI_t *ui);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif