回弹式拨杆

This commit is contained in:
ws 2025-06-28 02:22:44 +08:00
parent 117acf4142
commit 0abece2ee1
5 changed files with 106 additions and 51 deletions

View File

@ -1,8 +1,9 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Build target 'R1'
compiling ballTask.cpp...
compiling ball.cpp...
linking...
Program Size: Code=31208 RO-data=1832 RW-data=272 ZI-data=32248
Program Size: Code=28860 RO-data=1832 RW-data=276 ZI-data=32252
FromELF: creating hex file...
"R1\R1.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:09
Build Time Elapsed: 00:00:05

View File

@ -1 +1 @@
2025/6/27 23:25:01
2025/6/28 2:01:18

View File

@ -120,54 +120,123 @@ void Ball::Move_Extend()
}
}
// void Ball::ball_control()
// {
// ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 0无球 1)
// //ball_state = HAL_GPIO_ReadPin(TEST_GPIO_Port, TEST_Pin); // 读取光电状态(有球 0无球 1)
// Move_Extend();
// switch (rc_key){
// case MIDDLE2:
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); //确保爪气缸关闭
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
// if (currentState1 == BALL_FINISH)
// {
// currentState1 = BALL_IDLE;
// }
// else {
// currentState1 = BALL_IDLE; // 默认回到空闲状态
// }
// break;
// case UP2:
// //ballDown();
// //Close();
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); //确保爪气缸关闭
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
// if (currentState1 == BALL_FINISH)
// {
// currentState1 = BALL_IDLE;
// }
// else {
// currentState1 = BALL_IDLE; // 默认回到空闲状态
// }
// break;
// case DOWN2:
// ballHadling();
// break;
// }
// Send_control();
// }
//int ball_state = 0;
int last_ball_state = 0; // 上一次的光电状态
int step = 0; // 0:持球 1:击球 2:反弹 3:完全离开
void Ball::ball_control()
{
ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 0无球 1)
//ball_state = HAL_GPIO_ReadPin(TEST_GPIO_Port, TEST_Pin); // 读取光电状态(有球 0无球 1)
Move_Extend();
switch (rc_key){
case MIDDLE2:
switch (currentState1)
{
case BALL_IDLE:
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); //确保爪气缸关闭
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
if (currentState1 == BALL_FINISH)
if (rc_key == DOWN2) // 检测按键是否被按下
{
currentState1 = BALL_IDLE;
}
else {
currentState1 = BALL_IDLE; // 默认回到空闲状态
currentState1 = BALL_FORWARD;
}
break;
case UP2:
//ballDown();
//Close();
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); //确保爪气缸关闭
case BALL_FORWARD:
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); // 打开气缸爪子
osDelay(5);
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); // 关闭下气缸
// 一直检测有球ball_state == 0等球离开
if (ball_state == 1 && last_ball_state == 0) // 球离开
{
currentState1 = BALL_FLAG;
}
last_ball_state = ball_state;
break;
case BALL_FLAG:
osDelay(10); // 延时 50ms
// 等待球弹回再次检测到球
if (ball_state == 0 && last_ball_state == 1) // 球弹回
{
currentState1 = BALL_CLOSE;
}
last_ball_state = ball_state;
break;
case BALL_CLOSE:
osDelay(100);
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 闭合气缸爪子
currentState1 = BALL_FINISH; // 切换到反转状态
break;
case BALL_FINISH:
osDelay(50); // 延时 50ms
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保气缸爪子闭合
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
if (currentState1 == BALL_FINISH)
{
currentState1 = BALL_IDLE;
}
else {
currentState1 = BALL_IDLE; // 回到空闲状态
break;
default:
currentState1 = BALL_IDLE; // 默认回到空闲状态
}
break;
case DOWN2:
//Hadling();
//exit_Handling();
ballHadling();
//test_up();
break;
}
//ballHadling_two(); // 执行运球处理
Send_control();
}
@ -270,9 +339,7 @@ void Ball::exit_Handling(void)
}
}
int ball_state = 0;
int last_ball_state = 0; // 上一次的光电状态
int step = 0; // 0:持球 1:击球 2:反弹 3:完全离开
void Ball::test_up(void)
{

View File

@ -39,12 +39,6 @@ void FunctionBall(void *argument)
ball.ball_control(); // 控制球的动作
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); // 确保气缸爪子闭合
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_SET); // 确保下气缸关闭
// ball.xiaomi.position = aaaa;
// CAN_XiaoMi(1,&ball.xiaomi,&hcan2);
tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick);

View File

@ -33,14 +33,7 @@ while(1)
shoot.distanceGet(nucData);
}
shoot.shoot_control();
// shoot.t_posSet=aaaxxx;
// shoot.trigger_control();
// shoot.GO_SendData(goangle,5);
// shoot.shoot_control();
// shoot.t_posSet=goangle;
// shoot.trigger_control();
// shoot.shoot_control();
tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick);