运球上车前都ok了
This commit is contained in:
parent
e26c0c3aae
commit
ec3771a1a2
9
.gitignore
vendored
9
.gitignore
vendored
@ -99,3 +99,12 @@ JLinkLog.txt
|
|||||||
|
|
||||||
# Other Files
|
# Other Files
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
*.log
|
||||||
|
*.log.lock
|
||||||
|
|
||||||
|
# JSON files
|
||||||
|
*.json
|
||||||
|
|
||||||
|
# uVision Options
|
||||||
|
*.uvoptx
|
||||||
|
@ -121,7 +121,7 @@ void MX_GPIO_Init(void)
|
|||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = STOP_Pin;
|
GPIO_InitStruct.Pin = STOP_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(STOP_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(STOP_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
|
32
MDK-ARM/.vscode/keil-assistant.log
vendored
32
MDK-ARM/.vscode/keil-assistant.log
vendored
@ -22,3 +22,35 @@
|
|||||||
|
|
||||||
[info] Log at : 2025/4/16|16:20:32|GMT+0800
|
[info] Log at : 2025/4/16|16:20:32|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/19|19:27:22|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/19|21:14:34|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/19|23:02:49|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/20|14:28:49|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/20|15:44:16|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/20|16:25:11|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/21|17:04:22|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/22|10:54:46|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/22|19:20:19|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/23|14:36:25|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/23|17:15:10|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/24|22:10:33|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/24|23:29:19|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/25|18:41:24|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/25|18:59:20|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/4/26|16:18:23|GMT+0800
|
||||||
|
|
||||||
|
4
MDK-ARM/.vscode/settings.json
vendored
4
MDK-ARM/.vscode/settings.json
vendored
@ -9,6 +9,8 @@
|
|||||||
"task.h": "c",
|
"task.h": "c",
|
||||||
"djimotor.h": "c",
|
"djimotor.h": "c",
|
||||||
"nuc.h": "c",
|
"nuc.h": "c",
|
||||||
"crc_ccitt.h": "c"
|
"crc_ccitt.h": "c",
|
||||||
|
"functional": "cpp",
|
||||||
|
"vofa.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
6
MDK-ARM/.vscode/uv4.log
vendored
6
MDK-ARM/.vscode/uv4.log
vendored
@ -1,4 +1,8 @@
|
|||||||
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
|
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
|
||||||
Build target 'R1-shooter'
|
Build target 'R1-shooter'
|
||||||
|
compiling ball.cpp...
|
||||||
|
linking...
|
||||||
|
Program Size: Code=26644 RO-data=1812 RW-data=240 ZI-data=23520
|
||||||
|
FromELF: creating hex file...
|
||||||
"R1-shooter\R1-shooter.axf" - 0 Error(s), 0 Warning(s).
|
"R1-shooter\R1-shooter.axf" - 0 Error(s), 0 Warning(s).
|
||||||
Build Time Elapsed: 00:00:01
|
Build Time Elapsed: 00:00:03
|
||||||
|
2
MDK-ARM/.vscode/uv4.log.lock
vendored
2
MDK-ARM/.vscode/uv4.log.lock
vendored
@ -1 +1 @@
|
|||||||
2025/4/13 22:09:19
|
2025/4/26 16:32:18
|
@ -103,7 +103,7 @@
|
|||||||
<bEvRecOn>1</bEvRecOn>
|
<bEvRecOn>1</bEvRecOn>
|
||||||
<bSchkAxf>0</bSchkAxf>
|
<bSchkAxf>0</bSchkAxf>
|
||||||
<bTchkAxf>0</bTchkAxf>
|
<bTchkAxf>0</bTchkAxf>
|
||||||
<nTsel>6</nTsel>
|
<nTsel>3</nTsel>
|
||||||
<sDll></sDll>
|
<sDll></sDll>
|
||||||
<sDllPa></sDllPa>
|
<sDllPa></sDllPa>
|
||||||
<sDlgDll></sDlgDll>
|
<sDlgDll></sDlgDll>
|
||||||
@ -114,9 +114,14 @@
|
|||||||
<tDlgDll></tDlgDll>
|
<tDlgDll></tDlgDll>
|
||||||
<tDlgPa></tDlgPa>
|
<tDlgPa></tDlgPa>
|
||||||
<tIfile></tIfile>
|
<tIfile></tIfile>
|
||||||
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
||||||
</DebugOpt>
|
</DebugOpt>
|
||||||
<TargetDriverDllRegistry>
|
<TargetDriverDllRegistry>
|
||||||
|
<SetRegEntry>
|
||||||
|
<Number>0</Number>
|
||||||
|
<Key>CMSIS_AGDI</Key>
|
||||||
|
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||||
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>ARMRTXEVENTFLAGS</Key>
|
<Key>ARMRTXEVENTFLAGS</Key>
|
||||||
@ -135,7 +140,7 @@
|
|||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGUARM</Key>
|
<Key>DLGUARM</Key>
|
||||||
<Name>(105=-1,-1,-1,-1,0)</Name>
|
<Name></Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
@ -145,7 +150,7 @@
|
|||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>ST-LINKIII-KEIL_SWO</Key>
|
<Key>ST-LINKIII-KEIL_SWO</Key>
|
||||||
<Name>-U-O142 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
<Name>-U00160029510000164E574E32 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
</TargetDriverDllRegistry>
|
</TargetDriverDllRegistry>
|
||||||
<Breakpoint/>
|
<Breakpoint/>
|
||||||
@ -218,22 +223,22 @@
|
|||||||
<Ww>
|
<Ww>
|
||||||
<count>13</count>
|
<count>13</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>abc,0x0A</ItemText>
|
<ItemText>\\R1_shooter\../User/task/ballTask.cpp\ball,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>14</count>
|
<count>14</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>\\R1_shooter\../User/task/ballTask.cpp\ball,0x0A</ItemText>
|
<ItemText>currentState1</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>15</count>
|
<count>15</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>speedm,0x0A</ItemText>
|
<ItemText>abc,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>16</count>
|
<count>16</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>abc,0x0A</ItemText>
|
<ItemText>ball_state,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>17</count>
|
<count>17</count>
|
||||||
@ -243,7 +248,12 @@
|
|||||||
<Ww>
|
<Ww>
|
||||||
<count>18</count>
|
<count>18</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>ball_state,0x0A</ItemText>
|
<ItemText>triggerCount,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>19</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>last_ball_state,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<WatchWindow2>
|
<WatchWindow2>
|
||||||
@ -261,7 +271,7 @@
|
|||||||
<periodic>1</periodic>
|
<periodic>1</periodic>
|
||||||
<aLwin>1</aLwin>
|
<aLwin>1</aLwin>
|
||||||
<aCover>0</aCover>
|
<aCover>0</aCover>
|
||||||
<aSer1>0</aSer1>
|
<aSer1>1</aSer1>
|
||||||
<aSer2>0</aSer2>
|
<aSer2>0</aSer2>
|
||||||
<aPa>0</aPa>
|
<aPa>0</aPa>
|
||||||
<viewmode>1</viewmode>
|
<viewmode>1</viewmode>
|
||||||
|
@ -260,7 +260,7 @@ PE14.Locked=true
|
|||||||
PE14.Signal=GPIO_Output
|
PE14.Signal=GPIO_Output
|
||||||
PE9.GPIOParameters=GPIO_PuPd,GPIO_Label
|
PE9.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||||
PE9.GPIO_Label=STOP
|
PE9.GPIO_Label=STOP
|
||||||
PE9.GPIO_PuPd=GPIO_PULLUP
|
PE9.GPIO_PuPd=GPIO_PULLDOWN
|
||||||
PE9.Locked=true
|
PE9.Locked=true
|
||||||
PE9.Signal=GPIO_Input
|
PE9.Signal=GPIO_Input
|
||||||
PF6.GPIOParameters=GPIO_Speed,GPIO_Label
|
PF6.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||||
|
@ -32,3 +32,30 @@ void can_filter_init(void)
|
|||||||
HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);
|
HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// void can_filter_init(void)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// CAN_FilterTypeDef can_filter_st;
|
||||||
|
// can_filter_st.FilterActivation = ENABLE;
|
||||||
|
// can_filter_st.FilterMode = CAN_FILTERMODE_IDMASK;
|
||||||
|
// can_filter_st.FilterScale = CAN_FILTERSCALE_32BIT;
|
||||||
|
// can_filter_st.FilterIdHigh = 0x0000;
|
||||||
|
// can_filter_st.FilterIdLow = 0x0000;
|
||||||
|
// can_filter_st.FilterMaskIdHigh = 0x0000;
|
||||||
|
// can_filter_st.FilterMaskIdLow = 0x0000;
|
||||||
|
// can_filter_st.FilterBank = 0;
|
||||||
|
// can_filter_st.FilterFIFOAssignment = CAN_RX_FIFO0;
|
||||||
|
// HAL_CAN_ConfigFilter(&hcan1, &can_filter_st);
|
||||||
|
// HAL_CAN_Start(&hcan1);
|
||||||
|
// HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||||
|
|
||||||
|
|
||||||
|
// can_filter_st.SlaveStartFilterBank = 14;
|
||||||
|
// can_filter_st.FilterBank = 14;
|
||||||
|
// HAL_CAN_ConfigFilter(&hcan2, &can_filter_st);
|
||||||
|
// HAL_CAN_Start(&hcan2);
|
||||||
|
// HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
@ -24,7 +24,7 @@ void detect_init(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit);
|
BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit);
|
||||||
//BSP_GPIO_RegisterCallback(ext_up_Pin, detect_led);
|
// BSP_GPIO_RegisterCallback(ext_up_Pin, detect_led);
|
||||||
// 注册按键中断回调函数
|
// 注册按键中断回调函数
|
||||||
if (BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit) != BSP_OK) {
|
if (BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit) != BSP_OK) {
|
||||||
// 错误处理
|
// 错误处理
|
||||||
|
@ -160,6 +160,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static osEventFlagsId_t eventReceive;
|
static osEventFlagsId_t eventReceive;
|
||||||
|
static osThreadId_t thread_alert;
|
||||||
/**
|
/**
|
||||||
* @brief 自定义大疆电机回调函数
|
* @brief 自定义大疆电机回调函数
|
||||||
* @param[in] none
|
* @param[in] none
|
||||||
@ -169,8 +170,8 @@ void Dji_Motor_CB()
|
|||||||
{
|
{
|
||||||
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &dji_rx_header, dji_rx_data);
|
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &dji_rx_header, dji_rx_data);
|
||||||
|
|
||||||
|
osThreadFlagsSet(thread_alert, EVENT_CAN);
|
||||||
osEventFlagsSet(eventReceive, EVENT_CAN);
|
// osEventFlagsSet(eventReceive, EVENT_CAN);
|
||||||
}
|
}
|
||||||
void can2_Motor_CB(void)
|
void can2_Motor_CB(void)
|
||||||
{
|
{
|
||||||
@ -184,6 +185,7 @@ void can2_Motor_CB(void)
|
|||||||
*/
|
*/
|
||||||
void djiInit(void)
|
void djiInit(void)
|
||||||
{
|
{
|
||||||
|
thread_alert = osThreadGetId();
|
||||||
BSP_CAN_RegisterCallback(BSP_CAN_1, HAL_CAN_RX_FIFO0_MSG_PENDING_CB,
|
BSP_CAN_RegisterCallback(BSP_CAN_1, HAL_CAN_RX_FIFO0_MSG_PENDING_CB,
|
||||||
Dji_Motor_CB);
|
Dji_Motor_CB);
|
||||||
BSP_CAN_RegisterCallback(BSP_CAN_2, HAL_CAN_RX_FIFO1_MSG_PENDING_CB,
|
BSP_CAN_RegisterCallback(BSP_CAN_2, HAL_CAN_RX_FIFO1_MSG_PENDING_CB,
|
||||||
@ -197,8 +199,11 @@ void djiInit(void)
|
|||||||
*/
|
*/
|
||||||
uint32_t waitNewDji()
|
uint32_t waitNewDji()
|
||||||
{
|
{
|
||||||
return osEventFlagsWait(
|
// return osEventFlagsWait(
|
||||||
eventReceive, EVENT_CAN,osFlagsWaitAny, osWaitForever);
|
// eventReceive, EVENT_CAN,osFlagsWaitAny, osWaitForever);
|
||||||
|
return osThreadFlagsWait(
|
||||||
|
EVENT_CAN, osFlagsWaitAll, osWaitForever);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ void vofa_tx_main(float *data)
|
|||||||
//用dma用不了
|
//用dma用不了
|
||||||
|
|
||||||
//HAL_UART_Transmit_DMA(&huart6, ( uint8_t *)fdata, sizeof(fdata));
|
//HAL_UART_Transmit_DMA(&huart6, ( uint8_t *)fdata, sizeof(fdata));
|
||||||
HAL_UART_Transmit(&huart6, ( uint8_t *)fdata, sizeof(fdata),0xFFFF); //发送第一组数据
|
HAL_UART_Transmit(&huart1, ( uint8_t *)fdata, sizeof(fdata),0xFFFF); //发送第一组数据
|
||||||
osDelay(1);
|
osDelay(1);
|
||||||
//HAL_UART_Transmit_DMA(&huart6, tail, 4);
|
//HAL_UART_Transmit_DMA(&huart6, tail, 4);
|
||||||
HAL_UART_Transmit(&huart6, tail, 4,0xFFFF); //发送第二组数据
|
HAL_UART_Transmit(&huart1, tail, 4,0xFFFF); //发送第二组数据
|
||||||
osDelay(1);
|
osDelay(1);
|
||||||
|
|
||||||
//用虚拟串口c板开启不了
|
//用虚拟串口c板开启不了
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef _VOFA_H_
|
#ifndef _VOFA_H_
|
||||||
#define _VOFA_H_
|
#define _VOFA_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -12,6 +14,9 @@ void vofa_tx_main(float *data);
|
|||||||
|
|
||||||
extern float vofa_send[8];
|
extern float vofa_send[8];
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ int speedm1=0;
|
|||||||
|
|
||||||
#define MOTOR_SPEED 1000
|
#define MOTOR_SPEED 1000
|
||||||
|
|
||||||
const fp32 Ball:: M3508_speed_PID[3] = {5, 0, 0};
|
const fp32 Ball:: M3508_speed_PID[3] = {5, 0.01, 0};
|
||||||
|
|
||||||
//PE11 气缸
|
//PE11 气缸
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ Ball ::Ball()
|
|||||||
if(i <=3)
|
if(i <=3)
|
||||||
{
|
{
|
||||||
hand_Motor[i]->type = M3508;//设置电机类型
|
hand_Motor[i]->type = M3508;//设置电机类型
|
||||||
PID_init(&speed_pid[i],PID_POSITION,M3508_speed_PID,16000, 6000);//pid初始化
|
PID_init(&speed_pid[i],PID_POSITION,M3508_speed_PID,16000, 10000);//pid初始化
|
||||||
}
|
}
|
||||||
result[i] = 0;
|
result[i] = 0;
|
||||||
speedSet[i] = 0;
|
speedSet[i] = 0;
|
||||||
@ -37,29 +37,25 @@ Ball ::Ball()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HANDLING3 == 1
|
||||||
|
|
||||||
void Ball ::Spin(float speed,float speed2)
|
void Ball ::Spin(float speed,float speed2)
|
||||||
{
|
{
|
||||||
|
|
||||||
speedSet[MOTOR_1] = -speed;
|
speedSet[MOTOR_1] = -speed;
|
||||||
result[MOTOR_1] = PID_calc(&speed_pid[MOTOR_1],hand_Motor[MOTOR_1]->speed_rpm,speedSet[MOTOR_1]);
|
result[MOTOR_1] = PID_calc(&speed_pid[MOTOR_1],hand_Motor[MOTOR_1]->speed_rpm,speedSet[MOTOR_1]);
|
||||||
|
|
||||||
speedSet[MOTOR_2] = speed2;
|
speedSet[MOTOR_2] = speed;
|
||||||
result[MOTOR_2] = PID_calc(&speed_pid[MOTOR_2],hand_Motor[MOTOR_2]->speed_rpm,speedSet[MOTOR_2]);
|
result[MOTOR_2] = PID_calc(&speed_pid[MOTOR_2],hand_Motor[MOTOR_2]->speed_rpm,speedSet[MOTOR_2]);
|
||||||
|
|
||||||
speedSet[MOTOR_3] = speed;
|
speedSet[MOTOR_3] = speed2;
|
||||||
result[MOTOR_3] = PID_calc(&speed_pid[MOTOR_3],hand_Motor[MOTOR_3]->speed_rpm,speedSet[MOTOR_3]);
|
result[MOTOR_3] = PID_calc(&speed_pid[MOTOR_3],hand_Motor[MOTOR_3]->speed_rpm,speedSet[MOTOR_3]);
|
||||||
|
|
||||||
// for(int i = 1;i < MOTOR_NUM;i ++)
|
|
||||||
// {
|
|
||||||
// speedSet[i] = speed;
|
|
||||||
// result[i] = PID_calc(&speed_pid[i],hand_Motor[i]->speed_rpm,speedSet[i]);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int flag =0;
|
int flag =0;
|
||||||
int ball_state = 0;
|
int ball_state = 0;
|
||||||
|
|
||||||
void Ball::ballHadling(void)
|
void Ball::ballHadling(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -71,16 +67,16 @@ void Ball::ballHadling(void)
|
|||||||
if (key > 0) // 检测按键是否被按下
|
if (key > 0) // 检测按键是否被按下
|
||||||
{
|
{
|
||||||
speedm=-4500;
|
speedm=-4500;
|
||||||
speedm1=-3500;
|
speedm1=-4500;
|
||||||
currentState1 = BALL_FORWARD; // 切换到正转状态
|
currentState1 = BALL_FORWARD; // 切换到正转状态
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BALL_FORWARD:
|
case BALL_FORWARD:
|
||||||
|
|
||||||
if ( hand_Motor[MOTOR_1]->speed_rpm >= 4480&&hand_Motor[MOTOR_1]->speed_rpm <= 4520 &&
|
if ( hand_Motor[MOTOR_1]->speed_rpm >= 4480&&hand_Motor[MOTOR_1]->speed_rpm <= 4530 &&
|
||||||
hand_Motor[MOTOR_2]->speed_rpm <= -2980-500&&hand_Motor[MOTOR_2]->speed_rpm >= -3020-500 &&
|
hand_Motor[MOTOR_2]->speed_rpm <= -4480&&hand_Motor[MOTOR_2]->speed_rpm >= -4530 &&
|
||||||
hand_Motor[MOTOR_3]->speed_rpm <= -4480&&hand_Motor[MOTOR_3]->speed_rpm >= -4020-1000 )
|
hand_Motor[MOTOR_3]->speed_rpm <= -4480&&hand_Motor[MOTOR_3]->speed_rpm >= -4530 )
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET);// 打开气缸
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET);// 打开气缸
|
||||||
currentState1 = BALL_DROP; // 切换到球下落状态
|
currentState1 = BALL_DROP; // 切换到球下落状态
|
||||||
@ -92,8 +88,8 @@ void Ball::ballHadling(void)
|
|||||||
if (ball_state == 1) //读光电 有球 0 无球 1
|
if (ball_state == 1) //读光电 有球 0 无球 1
|
||||||
{
|
{
|
||||||
osDelay(200); // 延时200ms
|
osDelay(200); // 延时200ms
|
||||||
speedm=3000;
|
speedm=4500;
|
||||||
speedm1=3000;
|
speedm1=4500;
|
||||||
currentState1 = BALL_REVERSE; // 切换到反转状态
|
currentState1 = BALL_REVERSE; // 切换到反转状态
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +100,7 @@ void Ball::ballHadling(void)
|
|||||||
if (ball_state == 0)
|
if (ball_state == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
flag=2; //抽象的计次
|
//flag=2; //抽象的计次
|
||||||
speedm=0; // 停止电机
|
speedm=0; // 停止电机
|
||||||
speedm1=0;
|
speedm1=0;
|
||||||
currentState1 = BALL_CLOSE; // 切换到完成状态
|
currentState1 = BALL_CLOSE; // 切换到完成状态
|
||||||
@ -113,21 +109,26 @@ void Ball::ballHadling(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BALL_CLOSE:
|
case BALL_CLOSE:
|
||||||
osDelay(200); // 延时50ms
|
// osDelay(200); // 延时50ms
|
||||||
if (flag == 2)
|
|
||||||
{
|
|
||||||
if(ball_state == 0)
|
if(ball_state == 0)
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
||||||
currentState1 = BALL_FINISH; // 切换到完成状态
|
currentState1 = BALL_FINISH; // 切换到完成状态
|
||||||
}
|
}
|
||||||
|
// if (flag == 2)
|
||||||
|
// {
|
||||||
|
// if(ball_state == 0)
|
||||||
|
// {
|
||||||
|
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
||||||
|
// currentState1 = BALL_FINISH; // 切换到完成状态
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BALL_FINISH:
|
case BALL_FINISH:
|
||||||
osDelay(200); // 延时50ms
|
osDelay(200); // 延时50ms
|
||||||
key = 0; // 重置按键状态
|
key=0; // 重置按键状态
|
||||||
flag=0;
|
flag=0;
|
||||||
speedm=0;
|
speedm=0;
|
||||||
speedm1=0;
|
speedm1=0;
|
||||||
@ -144,6 +145,140 @@ void Ball::ballHadling(void)
|
|||||||
void Ball::Send_control()
|
void Ball::Send_control()
|
||||||
{
|
{
|
||||||
CAN_cmd_200(result[MOTOR_1],result[MOTOR_2],result[MOTOR_3],0,&hcan1);
|
CAN_cmd_200(result[MOTOR_1],result[MOTOR_2],result[MOTOR_3],0,&hcan1);
|
||||||
|
osDelay(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
int flag =0;
|
||||||
|
int ball_state = 0;
|
||||||
|
// void Ball::ballHadling(void)
|
||||||
|
// {
|
||||||
|
// ball_state =HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);//有球 0 无球 1
|
||||||
|
// switch (currentState1)
|
||||||
|
// {
|
||||||
|
// case BALL_IDLE:
|
||||||
|
|
||||||
|
// if (key > 0) // 检测按键是否被按下
|
||||||
|
// {
|
||||||
|
// currentState1 = BALL_FORWARD; // 切换到正转状态
|
||||||
|
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case BALL_FORWARD:
|
||||||
|
// HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_SET);
|
||||||
|
// osDelay(50);
|
||||||
|
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
// currentState1 = BALL_DROP; // 切换到球下落状态
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case BALL_DROP:
|
||||||
|
// osDelay(100); //
|
||||||
|
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET);
|
||||||
|
// currentState1 = BALL_CLOSE; // 切换到反转状态
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case BALL_CLOSE:
|
||||||
|
// osDelay(100);
|
||||||
|
// if(ball_state == 0)
|
||||||
|
// {
|
||||||
|
// HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_RESET);
|
||||||
|
// currentState1 = BALL_REVERSE; // 切换到反转状态
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case BALL_REVERSE:
|
||||||
|
// osDelay(50); // 延时200ms
|
||||||
|
// HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_RESET);
|
||||||
|
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET);
|
||||||
|
// key=0; // 重置按键状态
|
||||||
|
// currentState1 = BALL_IDLE; // 回到空闲状态
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// default:
|
||||||
|
// currentState1 = BALL_IDLE; // 默认回到空闲状态
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
int triggerCount = 0; // 光电传感器触发计数
|
||||||
|
int last_ball_state = 1; // 上一次的光电状态
|
||||||
|
void Ball::ballHadling(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 0,无球 1)
|
||||||
|
|
||||||
|
switch (currentState1)
|
||||||
|
{
|
||||||
|
case BALL_IDLE:
|
||||||
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保气缸闭合
|
||||||
|
if (key > 0) // 检测按键是否被按下
|
||||||
|
{
|
||||||
|
key = 0; // 重置按键状态
|
||||||
|
triggerCount = 0; // 重置触发计数
|
||||||
|
currentState1 = BALL_FORWARD; // 切换到正转状态
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_FORWARD:
|
||||||
|
HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_SET); // 打开气缸爪子
|
||||||
|
osDelay(10);
|
||||||
|
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_SET); // 打开下气缸
|
||||||
|
currentState1 = BALL_DROP; // 切换到球下落状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_DROP:
|
||||||
|
osDelay(100); // 延时 100ms
|
||||||
|
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 关闭下气缸
|
||||||
|
if (ball_state == 0 && last_ball_state == 1) // 检测到状态从无球变为有球
|
||||||
|
{
|
||||||
|
//osDelay(10); // 延时去抖动
|
||||||
|
triggerCount++; // 增加触发计数
|
||||||
|
if (triggerCount == 1) // 第一次触发
|
||||||
|
{
|
||||||
|
currentState1 = BALL_FLAG; // 切换到等待第二次触发状态
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_ball_state = ball_state; // 更新上一次的状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_FLAG:
|
||||||
|
osDelay(10); // 延时 50ms
|
||||||
|
if (triggerCount == 1 && ball_state == 0 && last_ball_state == 1) // 第二次检测到球
|
||||||
|
{
|
||||||
|
triggerCount++; // 增加触发计数
|
||||||
|
currentState1 = BALL_CLOSE; // 切换到闭合气缸状态
|
||||||
|
}
|
||||||
|
last_ball_state = ball_state; // 更新上一次的状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_CLOSE:
|
||||||
|
if (triggerCount == 2) // 确保是第二次触发
|
||||||
|
{
|
||||||
|
//osDelay(10); // 延时去抖
|
||||||
|
HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_RESET); // 闭合气缸爪子
|
||||||
|
currentState1 = BALL_REVERSE; // 切换到反转状态
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_REVERSE:
|
||||||
|
osDelay(50); // 延时 50ms
|
||||||
|
HAL_GPIO_WritePin(PAW_GPIO_Port, PAW_Pin, GPIO_PIN_RESET); // 确保气缸爪子闭合
|
||||||
|
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
|
||||||
|
key = 0; // 重置按键状态
|
||||||
|
triggerCount = 0; // 重置触发计数
|
||||||
|
currentState1 = BALL_IDLE; // 回到空闲状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
currentState1 = BALL_IDLE; // 默认回到空闲状态
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -7,12 +7,15 @@
|
|||||||
#include "djiMotor.h"
|
#include "djiMotor.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
|
|
||||||
|
#define HANDLING3 0
|
||||||
|
|
||||||
// 定义状态枚举
|
// 定义状态枚举
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BALL_IDLE, // 空闲状态
|
BALL_IDLE, // 空闲状态
|
||||||
BALL_FORWARD, // 正转状态
|
BALL_FORWARD, // 正转状态
|
||||||
BALL_DROP, // 球下落状态
|
BALL_DROP, // 球下落状态
|
||||||
BALL_REVERSE, // 反转状态
|
BALL_REVERSE, // 反转状态
|
||||||
|
BALL_FLAG,
|
||||||
BALL_CLOSE, // 关闭状态
|
BALL_CLOSE, // 关闭状态
|
||||||
BALL_FINISH // 完成状态
|
BALL_FINISH // 完成状态
|
||||||
} BallState_t;
|
} BallState_t;
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
#include "ball.hpp"
|
#include "ball.hpp"
|
||||||
#include "remote_control.h"
|
#include "remote_control.h"
|
||||||
|
#include "vofa.h"
|
||||||
extern RC_ctrl_t rc_ctrl;
|
extern RC_ctrl_t rc_ctrl;
|
||||||
Ball ball;
|
Ball ball;
|
||||||
|
float vofa[8];
|
||||||
|
|
||||||
int abc=0;
|
int abc=0;
|
||||||
extern int speedm;
|
extern int speedm;
|
||||||
@ -16,8 +18,8 @@ void FunctionBall(void *argument)
|
|||||||
{
|
{
|
||||||
(void)argument; /* 未使用argument,消除警告 */
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_BALL;
|
// const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_BALL;
|
||||||
uint32_t tick = osKernelGetTickCount();
|
// uint32_t tick = osKernelGetTickCount();
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
@ -25,12 +27,22 @@ void FunctionBall(void *argument)
|
|||||||
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
|
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
|
||||||
#endif
|
#endif
|
||||||
abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
|
abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
|
||||||
|
//abc=HAL_GPIO_ReadPin(STOP_GPIO_Port, STOP_Pin);
|
||||||
|
|
||||||
ball.ballHadling(); // 处理摩擦轮转动
|
ball.ballHadling(); // 处理摩擦轮转动
|
||||||
ball.Spin(speedm,speedm1);
|
// speedm=4000;
|
||||||
ball.Send_control();
|
// speedm1=4000;
|
||||||
|
// ball.Spin(speedm,speedm1);
|
||||||
|
// ball.Send_control();
|
||||||
|
|
||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
// vofa[0] = speedm; // 发送电机角度数据
|
||||||
osDelayUntil(tick);
|
// vofa[1] = -ball.hand_Motor[0]->speed_rpm; // 发送电机角度数据
|
||||||
|
// vofa[2] = ball.hand_Motor[1]->speed_rpm; // 发送电机速度数据
|
||||||
|
// vofa[3] = ball.hand_Motor[2]->speed_rpm; // 发送电机速度数据
|
||||||
|
|
||||||
|
// vofa_tx_main(vofa); // 发送数据到虚拟串口
|
||||||
|
|
||||||
|
// tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
|
// osDelayUntil(tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@ void FunctionCan(void *argument)
|
|||||||
{
|
{
|
||||||
(void)argument; /* 未使用argument,消除警告 */
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN;
|
//const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN;
|
||||||
|
|
||||||
djiInit();
|
djiInit();
|
||||||
|
|
||||||
uint32_t tick = osKernelGetTickCount();
|
//uint32_t tick = osKernelGetTickCount();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -30,7 +30,7 @@ void FunctionCan(void *argument)
|
|||||||
djiMotorEncode();
|
djiMotorEncode();
|
||||||
can2MotorEncode();
|
can2MotorEncode();
|
||||||
|
|
||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
// tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
osDelayUntil(tick);
|
// osDelayUntil(tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "TopDefine.h"//事件组的一些东西
|
#include "TopDefine.h"//事件组的一些东西
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ void Function_nuc(void *argument)
|
|||||||
|
|
||||||
NUC_Init(&cmd_fromnuc);
|
NUC_Init(&cmd_fromnuc);
|
||||||
|
|
||||||
|
|
||||||
uint32_t tick = osKernelGetTickCount();
|
uint32_t tick = osKernelGetTickCount();
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
@ -32,7 +34,7 @@ void Function_nuc(void *argument)
|
|||||||
|
|
||||||
NUC_RawParse(&cmd_fromnuc);
|
NUC_RawParse(&cmd_fromnuc);
|
||||||
|
|
||||||
NUC_SendPacket(&send, sizeof(send)); // 发送数据包
|
//NUC_SendPacket(&send, sizeof(send)); // 发送数据包
|
||||||
//掉线处理有空写
|
//掉线处理有空写
|
||||||
// if(NUC_WaitDmaCplt())
|
// if(NUC_WaitDmaCplt())
|
||||||
// {
|
// {
|
||||||
|
@ -24,7 +24,7 @@ const osThreadAttr_t attr_take = {
|
|||||||
const osThreadAttr_t attr_can = {
|
const osThreadAttr_t attr_can = {
|
||||||
.name = "can",
|
.name = "can",
|
||||||
.priority = osPriorityRealtime,
|
.priority = osPriorityRealtime,
|
||||||
.stack_size = 128 * 6,
|
.stack_size = 128 * 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
const osThreadAttr_t attr_rc = {
|
const osThreadAttr_t attr_rc = {
|
||||||
@ -36,7 +36,7 @@ const osThreadAttr_t attr_rc = {
|
|||||||
const osThreadAttr_t attr_ball = {
|
const osThreadAttr_t attr_ball = {
|
||||||
.name = "ball",
|
.name = "ball",
|
||||||
.priority = osPriorityRealtime,
|
.priority = osPriorityRealtime,
|
||||||
.stack_size = 128 * 4,
|
.stack_size = 128 * 8,
|
||||||
};
|
};
|
||||||
const osThreadAttr_t attr_nuc = {
|
const osThreadAttr_t attr_nuc = {
|
||||||
.name = "nuc",
|
.name = "nuc",
|
||||||
|
Loading…
Reference in New Issue
Block a user