Compare commits

...

3 Commits
main ... 原版

Author SHA1 Message Date
RB
87f56647b1 修改了pid 2025-03-05 16:04:09 +08:00
78712e5918 改了方向 2025-03-01 20:28:09 +08:00
9fe34c0bf8 英雄单独(can未兼容) 2025-03-01 01:44:52 +08:00
11 changed files with 10137 additions and 7336 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"functional": "cpp"
}
}

View File

@ -10,7 +10,7 @@
<aExt>*.s*; *.src; *.a*</aExt> <aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj; *.o</oExt> <oExt>*.obj; *.o</oExt>
<lExt>*.lib</lExt> <lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc</tExt> <tExt>*.txt; *.h; *.inc; *.md</tExt>
<pExt>*.plm</pExt> <pExt>*.plm</pExt>
<CppX>*.cpp</CppX> <CppX>*.cpp</CppX>
<nMigrate>0</nMigrate> <nMigrate>0</nMigrate>
@ -360,7 +360,7 @@
<Ww> <Ww>
<count>0</count> <count>0</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>chassis</ItemText> <ItemText>param_default</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>1</count> <count>1</count>
@ -370,24 +370,32 @@
<Ww> <Ww>
<count>2</count> <count>2</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>gimbal_out</ItemText> <ItemText>shoot</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>3</count> <count>3</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>for_chassis</ItemText> <ItemText>param_hero</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>4</count> <count>4</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>task_runtime</ItemText> <ItemText>ref</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>5</count> <count>5</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ref</ItemText> <ItemText>for_chassis</ItemText>
</Ww> </Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow4>
<Mm>
<WinNumber>4</WinNumber>
<SubType>0</SubType>
<ItemText>for_chassis</ItemText>
<AccSizeX>0</AccSizeX>
</Mm>
</MemoryWindow4>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>
@ -1250,7 +1258,7 @@
<Group> <Group>
<GroupName>User/bsp</GroupName> <GroupName>User/bsp</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@ -1474,7 +1482,7 @@
<Group> <Group>
<GroupName>User/component</GroupName> <GroupName>User/component</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@ -1786,7 +1794,7 @@
<GroupNumber>12</GroupNumber> <GroupNumber>12</GroupNumber>
<FileNumber>105</FileNumber> <FileNumber>105</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\User\module\shoot.c</PathWithFileName> <PathWithFileName>..\User\module\shoot.c</PathWithFileName>

View File

@ -16,7 +16,7 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F407IGHx</Device> <Device>STM32F407IGHx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.2.14.0</PackID> <PackID>Keil.STM32F4xx_DFP.2.15.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x2001FFFF) IRAM2(0x10000000-0x1000FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4")</Cpu> <Cpu>IRAM(0x20000000-0x2001FFFF) IRAM2(0x10000000-0x1000FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
@ -1726,13 +1726,13 @@
<TargetName>Debug</TargetName> <TargetName>Debug</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>6140000::V6.14::ARMCLANG</pCCUsed> <pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
<uAC6>1</uAC6> <uAC6>1</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F407IGHx</Device> <Device>STM32F407IGHx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.2.14.0</PackID> <PackID>Keil.STM32F4xx_DFP.2.15.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x2001FFFF) IRAM2(0x10000000-0x1000FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4")</Cpu> <Cpu>IRAM(0x20000000-0x2001FFFF) IRAM2(0x10000000-0x1000FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
@ -3443,11 +3443,6 @@
<Layers> <Layers>
<Layer> <Layer>
<LayName>DevC</LayName> <LayName>DevC</LayName>
<LayDesc></LayDesc>
<LayUrl></LayUrl>
<LayKeys></LayKeys>
<LayCat></LayCat>
<LayLic></LayLic>
<LayTarg>0</LayTarg> <LayTarg>0</LayTarg>
<LayPrjMark>1</LayPrjMark> <LayPrjMark>1</LayPrjMark>
</Layer> </Layer>

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,158 +159,175 @@ 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: {
motor1 = case CAN_MOTOR_GROUT_CHASSIS:
(int16_t)(output->chassis.named.m1 * (float)CAN_M3508_MAX_ABS_LSB); motor1 =
motor2 = (int16_t)(output->chassis.named.m1 * (float)CAN_M3508_MAX_ABS_LSB);
(int16_t)(output->chassis.named.m2 * (float)CAN_M3508_MAX_ABS_LSB); motor2 =
motor3 = (int16_t)(output->chassis.named.m2 * (float)CAN_M3508_MAX_ABS_LSB);
(int16_t)(output->chassis.named.m3 * (float)CAN_M3508_MAX_ABS_LSB); motor3 =
motor4 = (int16_t)(output->chassis.named.m3 * (float)CAN_M3508_MAX_ABS_LSB);
(int16_t)(output->chassis.named.m4 * (float)CAN_M3508_MAX_ABS_LSB); motor4 =
(int16_t)(output->chassis.named.m4 * (float)CAN_M3508_MAX_ABS_LSB);
raw_tx.tx_header.StdId = CAN_M3508_M2006_CTRL_ID_BASE; raw_tx.tx_header.StdId = CAN_M3508_M2006_CTRL_ID_BASE;
raw_tx.tx_header.IDE = CAN_ID_STD; raw_tx.tx_header.IDE = CAN_ID_STD;
raw_tx.tx_header.RTR = CAN_RTR_DATA; raw_tx.tx_header.RTR = CAN_RTR_DATA;
raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE; raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE;
raw_tx.tx_data[0] = (uint8_t)((motor1 >> 8) & 0xFF); raw_tx.tx_data[0] = (uint8_t)((motor1 >> 8) & 0xFF);
raw_tx.tx_data[1] = (uint8_t)(motor1 & 0xFF); raw_tx.tx_data[1] = (uint8_t)(motor1 & 0xFF);
raw_tx.tx_data[2] = (uint8_t)((motor2 >> 8) & 0xFF); raw_tx.tx_data[2] = (uint8_t)((motor2 >> 8) & 0xFF);
raw_tx.tx_data[3] = (uint8_t)(motor2 & 0xFF); raw_tx.tx_data[3] = (uint8_t)(motor2 & 0xFF);
raw_tx.tx_data[4] = (uint8_t)((motor3 >> 8) & 0xFF); raw_tx.tx_data[4] = (uint8_t)((motor3 >> 8) & 0xFF);
raw_tx.tx_data[5] = (uint8_t)(motor3 & 0xFF); raw_tx.tx_data[5] = (uint8_t)(motor3 & 0xFF);
raw_tx.tx_data[6] = (uint8_t)((motor4 >> 8) & 0xFF); raw_tx.tx_data[6] = (uint8_t)((motor4 >> 8) & 0xFF);
raw_tx.tx_data[7] = (uint8_t)(motor4 & 0xFF); raw_tx.tx_data[7] = (uint8_t)(motor4 & 0xFF);
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->chassis), HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->chassis),
&raw_tx.tx_header, raw_tx.tx_data, &raw_tx.tx_header, raw_tx.tx_data,
&(can->mailbox.chassis)); &(can->mailbox.chassis));
break; break;
case CAN_MOTOR_GROUT_GIMBAL1: case CAN_MOTOR_GROUT_GIMBAL1:
case CAN_MOTOR_GROUT_GIMBAL2: case CAN_MOTOR_GROUT_GIMBAL2:
yaw_motor = yaw_motor =
(int16_t)(output->gimbal.named.yaw * (float)CAN_GM6020_MAX_ABS_LSB); (int16_t)(output->gimbal.named.yaw * (float)CAN_GM6020_MAX_ABS_LSB);
pit_motor = pit_motor =
(int16_t)(output->gimbal.named.pit * (float)CAN_GM6020_MAX_ABS_LSB); (int16_t)(output->gimbal.named.pit * (float)CAN_GM6020_MAX_ABS_LSB);
raw_tx.tx_header.StdId = CAN_GM6020_CTRL_ID_EXTAND; raw_tx.tx_header.StdId = CAN_GM6020_CTRL_ID_EXTAND;
raw_tx.tx_header.IDE = CAN_ID_STD; raw_tx.tx_header.IDE = CAN_ID_STD;
raw_tx.tx_header.RTR = CAN_RTR_DATA; raw_tx.tx_header.RTR = CAN_RTR_DATA;
raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE; raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE;
raw_tx.tx_data[0] = (uint8_t)((yaw_motor >> 8) & 0xFF); raw_tx.tx_data[0] = (uint8_t)((yaw_motor >> 8) & 0xFF);
raw_tx.tx_data[1] = (uint8_t)(yaw_motor & 0xFF); raw_tx.tx_data[1] = (uint8_t)(yaw_motor & 0xFF);
raw_tx.tx_data[2] = (uint8_t)((pit_motor >> 8) & 0xFF); raw_tx.tx_data[2] = (uint8_t)((pit_motor >> 8) & 0xFF);
raw_tx.tx_data[3] = (uint8_t)(pit_motor & 0xFF); raw_tx.tx_data[3] = (uint8_t)(pit_motor & 0xFF);
raw_tx.tx_data[4] = 0; raw_tx.tx_data[4] = 0;
raw_tx.tx_data[5] = 0; raw_tx.tx_data[5] = 0;
raw_tx.tx_data[6] = 0; raw_tx.tx_data[6] = 0;
raw_tx.tx_data[7] = 0; raw_tx.tx_data[7] = 0;
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal), HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal.yaw),
&raw_tx.tx_header, raw_tx.tx_data, &raw_tx.tx_header, raw_tx.tx_data,
&(can->mailbox.gimbal)); &(can->mailbox.gimbal));
// HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot), HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal.pitch),
// &raw_tx.tx_header, raw_tx.tx_data, &raw_tx.tx_header, raw_tx.tx_data,
// &(can->mailbox.gimbal)); &(can->mailbox.gimbal));
break; // HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot),
// &raw_tx.tx_header, raw_tx.tx_data,
// &(can->mailbox.gimbal));
break;
case CAN_MOTOR_GROUT_SHOOT1: case CAN_MOTOR_GROUT_SHOOT1:
case CAN_MOTOR_GROUT_SHOOT2: case CAN_MOTOR_GROUT_SHOOT2:
fric1_motor = fric1_motor =
(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);
trig_motor = fric3_motor =
(int16_t)(output->shoot.named.trig * (float)CAN_M2006_MAX_ABS_LSB); (int16_t)(output->shoot.named.fric3 * (float)CAN_M3508_MAX_ABS_LSB);
trig_motor =
(int16_t)(output->shoot.named.trig * (float)CAN_M2006_MAX_ABS_LSB);
raw_tx.tx_header.StdId = CAN_M3508_M2006_CTRL_ID_EXTAND; raw_tx.tx_header.StdId = CAN_M3508_M2006_CTRL_ID_EXTAND;
raw_tx.tx_header.IDE = CAN_ID_STD; raw_tx.tx_header.IDE = CAN_ID_STD;
raw_tx.tx_header.RTR = CAN_RTR_DATA; raw_tx.tx_header.RTR = CAN_RTR_DATA;
raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE; raw_tx.tx_header.DLC = CAN_MOTOR_TX_BUF_SIZE;
raw_tx.tx_data[0] = (uint8_t)((fric1_motor >> 8) & 0xFF); raw_tx.tx_data[0] = (uint8_t)((fric1_motor >> 8) & 0xFF);
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,
&(can->mailbox.shoot)); &(can->mailbox.shoot));
break; HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->trig),
&raw_tx.tx_header, raw_tx.tx_data,
default: &(can->mailbox.shoot));
break; 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_M2_ID: case CAN_M3508_M1_ID:
case CAN_M3508_M3_ID: case CAN_M3508_M2_ID:
case CAN_M3508_M4_ID: case CAN_M3508_M3_ID:
index = can_rx->rx_header.StdId - CAN_M3508_M1_ID; case CAN_M3508_M4_ID:
CAN_Motor_Decode(&(can->motor.chassis.as_array[index]), can_rx->rx_data); index = can_rx->rx_header.StdId - CAN_M3508_M1_ID;
can->recive_flag |= 1 << index; CAN_Motor_Decode(&(can->motor.chassis.as_array[index]), can_rx->rx_data);
break; can->recive_flag |= 1 << index;
break;
case CAN_M3508_FRIC1_ID: case CAN_M3508_FRIC1_ID:
case CAN_M3508_FRIC2_ID: case CAN_M3508_FRIC2_ID:
case CAN_M2006_TRIG_ID: case CAN_M3508_FRIC3_ID:
index = can_rx->rx_header.StdId - CAN_M3508_FRIC1_ID; case CAN_M2006_TRIG_ID:
can->recive_flag |= 1 << (index + 6); index = can_rx->rx_header.StdId - CAN_M3508_FRIC1_ID;
CAN_Motor_Decode(&(can->motor.shoot.as_array[index]), can_rx->rx_data); can->recive_flag |= 1 << (index + 6);
break; CAN_Motor_Decode(&(can->motor.shoot.as_array[index]), can_rx->rx_data);
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;
can->recive_flag |= 1 << (index + 4); can->recive_flag |= 1 << (index + 4);
CAN_Motor_Decode(&(can->motor.gimbal.as_array[index]), can_rx->rx_data); CAN_Motor_Decode(&(can->motor.gimbal.as_array[index]), can_rx->rx_data);
break; break;
case CAN_CAP_FB_ID_BASE: case CAN_CAP_FB_ID_BASE:
can->recive_flag |= 1 << 9; can->recive_flag |= 1 << 9;
CAN_Cap_Decode(&(can->cap.cap_feedback), can_rx->rx_data); CAN_Cap_Decode(&(can->cap.cap_feedback), can_rx->rx_data);
break; break;
case CAN_TOF_ID_BASE: case CAN_TOF_ID_BASE:
can->recive_flag |= 1 << 10; can->recive_flag |= 1 << 10;
CAN_Tof_Decode(&(can->tof), can_rx->rx_data); CAN_Tof_Decode(&(can->tof), can_rx->rx_data);
break; break;
default: default:
break; break;
} }
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);
@ -320,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,16 +73,23 @@ 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 */
} CAN_MotorId_t; } CAN_MotorId_t;
typedef struct {
BSP_CAN_t yaw;
BSP_CAN_t pitch;
} Gimbal_CAN_t;
typedef struct { typedef struct {
BSP_CAN_t chassis; BSP_CAN_t chassis;
BSP_CAN_t gimbal; Gimbal_CAN_t gimbal;
BSP_CAN_t shoot; BSP_CAN_t shoot;
BSP_CAN_t trig;
BSP_CAN_t cap; BSP_CAN_t cap;
} CAN_Params_t; } CAN_Params_t;
@ -110,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,
}; };
@ -147,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;
@ -200,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

@ -194,13 +194,19 @@ static const Config_RobotParam_t param_default = {
.can = { .can = {
.chassis = BSP_CAN_1, .chassis = BSP_CAN_1,
.gimbal = BSP_CAN_2, .gimbal.yaw = BSP_CAN_2,
.gimbal.pitch = BSP_CAN_2,
.shoot = BSP_CAN_2, .shoot = BSP_CAN_2,
.trig = BSP_CAN_2,
.cap = BSP_CAN_1, .cap = BSP_CAN_1,
}, /* 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 = { /* 底盘模块参数 */
@ -234,7 +240,7 @@ static const Config_RobotParam_t param_hero = {
}, },
.reverse = { .reverse = {
.yaw = true, .yaw = false,
}, },
}, /* chassis */ }, /* chassis */
@ -242,20 +248,20 @@ static const Config_RobotParam_t param_hero = {
.pid = { .pid = {
{ {
/* GIMBAL_PID_YAW_OMEGA_IDX */ /* GIMBAL_PID_YAW_OMEGA_IDX */
.k = 0.45f, .k = 0.24f,
.p = 1.0f, .p = 1.0f,
.i = 6.0f, .i = 0.5f,
.d = 0.0008f, .d = 0.0f,
.i_limit = 1.0f, .i_limit = 1.0f,
.out_limit = 1.0f, .out_limit = 1.0f,
.d_cutoff_freq = -1.0f, .d_cutoff_freq = -1.0f,
.range = -1.0f, .range = -1.0f,
}, { }, {
/* GIMBAL_PID_YAW_ANGLE_IDX */ /* GIMBAL_PID_YAW_ANGLE_IDX */
.k = 20.0f, .k = 10.0f,
.p = 1.0f, .p = 1.0f,
.i = 0.0f, .i = 0.0f,
.d = 0.0f, .d = 0.05f,
.i_limit = 0.0f, .i_limit = 0.0f,
.out_limit = 10.0f, .out_limit = 10.0f,
.d_cutoff_freq = -1.0f, .d_cutoff_freq = -1.0f,
@ -272,9 +278,9 @@ static const Config_RobotParam_t param_hero = {
.range = -1.0f, .range = -1.0f,
}, { }, {
/* GIMBAL_PID_PIT_ANGLE_IDX */ /* GIMBAL_PID_PIT_ANGLE_IDX */
.k = 12.0f, .k = 2.0f,
.p = 1.0f, .p = 5.0f,
.i = 0.0f, .i = 2.5f,
.d = 0.0f, .d = 0.0f,
.i_limit = 0.0f, .i_limit = 0.0f,
.out_limit = 10.0f, .out_limit = 10.0f,
@ -283,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,
@ -291,8 +297,8 @@ static const Config_RobotParam_t param_hero = {
}, },
.reverse = { .reverse = {
.yaw = true, .yaw = false,
.pit = true, .pit = false,
}, },
}, /* gimbal */ }, /* gimbal */
@ -327,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,
@ -339,8 +345,10 @@ static const Config_RobotParam_t param_hero = {
.can = { .can = {
.chassis = BSP_CAN_1, .chassis = BSP_CAN_1,
.gimbal = BSP_CAN_2, .gimbal.yaw = BSP_CAN_1,
.gimbal.pitch = BSP_CAN_2,
.shoot = BSP_CAN_2, .shoot = BSP_CAN_2,
.trig = BSP_CAN_1,
.cap = BSP_CAN_1, .cap = BSP_CAN_1,
}, /* can */ }, /* can */
}; /* param_hero */ }; /* param_hero */
@ -430,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;
} }
/** /**
@ -448,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));
@ -461,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;
} }
} }
@ -477,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->param->model == SHOOT_MODEL_17MM));
s->setpoint.fric_rpm[0] = -s->setpoint.fric_rpm[1]; // 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->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,208 +2,210 @@
* *
*/ */
#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_TRIG_IDX, /* 扳机电机相关的索引值 */ SHOOT_ACTR_FRIC3_IDX, /* 3号摩擦轮相关的索引值 */
SHOOT_ACTR_NUM, /* 总共的动作器数量 */ SHOOT_ACTR_TRIG_IDX, /* 扳机电机相关的索引值 */
}; 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的参数 */
/* 低通滤波器截止频率 */ /* 低通滤波器截止频率 */
struct { struct {
/* 输入 */ /* 输入 */
struct { struct {
float fric; /* 摩擦轮电机 */ float fric; /* 摩擦轮电机 */
float trig; /* 扳机电机 */ float trig; /* 扳机电机 */
} in; } in;
/* 输出 */ /* 输出 */
struct { struct {
float fric; /* 摩擦轮电机 */ float fric; /* 摩擦轮电机 */
float trig; /* 扳机电机 */ float trig; /* 扳机电机 */
} out; } out;
} low_pass_cutoff_freq; } low_pass_cutoff_freq;
float num_trig_tooth; /* 拨弹盘中一圈能存储几颗弹丸 */ float num_trig_tooth; /* 拨弹盘中一圈能存储几颗弹丸 */
float trig_gear_ratio; /* 拨弹电机减速比 3508:19, 2006:36 */ float trig_gear_ratio; /* 拨弹电机减速比 3508:19, 2006:36 */
float fric_radius; /* 摩擦轮半径,单位:米 */ float fric_radius; /* 摩擦轮半径,单位:米 */
float cover_open_duty; /* 弹舱盖打开时舵机PWM占空比 */ float cover_open_duty; /* 弹舱盖打开时舵机PWM占空比 */
float cover_close_duty; /* 弹舱盖关闭时舵机PWM占空比 */ float cover_close_duty; /* 弹舱盖关闭时舵机PWM占空比 */
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; /* 热量上限 */
float speed_limit; /* 弹丸初速是上限 */ float speed_limit; /* 弹丸初速是上限 */
float cooling_rate; /* 冷却速率 */ float cooling_rate; /* 冷却速率 */
float heat_increase; /* 每发热量增加值 */ float heat_increase; /* 每发热量增加值 */
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; /* 第一次收到开火指令 */
uint32_t shooted; /* 已经发射的弹丸 */ uint32_t shooted; /* 已经发射的弹丸 */
uint32_t to_shoot; /* 计划发射的弹丸 */ uint32_t to_shoot; /* 计划发射的弹丸 */
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;
const Shoot_Params_t *param; /* 射击的参数用Shoot_Init设定 */ const Shoot_Params_t *param; /* 射击的参数用Shoot_Init设定 */
/* 模块通用 */ /* 模块通用 */
CMD_ShootMode_t mode; /* 射击模式 */ CMD_ShootMode_t mode; /* 射击模式 */
/* 反馈信息 */ /* 反馈信息 */
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;
/* 过滤器 */ /* 过滤器 */
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;
Shoot_HeatCtrl_t heat_ctrl; Shoot_HeatCtrl_t heat_ctrl;
Shoot_FireCtrl_t fire_ctrl; Shoot_FireCtrl_t fire_ctrl;
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
* \param param * \param param
* \param target_freq * \param target_freq
* *
* \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
* \param can CAN设备结构体 * \param can CAN设备结构体
* *
* \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
* \param s_cmd * \param s_cmd
* \param s_ref * \param s_ref
* \param dt_sec * \param dt_sec
* *
* \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