From 0abece2ee1cdc6d8e81117575589dc952908649c Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Sat, 28 Jun 2025 02:22:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=BC=B9=E5=BC=8F=E6=8B=A8=E6=9D=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/.vscode/uv4.log | 5 +- MDK-ARM/.vscode/uv4.log.lock | 2 +- User/module/ball.cpp | 135 ++++++++++++++++++++++++++--------- User/task/ballTask.cpp | 6 -- User/task/shootTask.cpp | 9 +-- 5 files changed, 106 insertions(+), 51 deletions(-) diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index 6572ba7..1514023 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -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 diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock index 0b3378b..1cb57f9 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1 +1 @@ -2025/6/27 23:25:01 \ No newline at end of file +2025/6/28 2:01:18 \ No newline at end of file diff --git a/User/module/ball.cpp b/User/module/ball.cpp index 61bd7ef..c8f9ab2 100644 --- a/User/module/ball.cpp +++ b/User/module/ball.cpp @@ -120,53 +120,122 @@ 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(); + 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) + HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 + 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); //确保爪气缸关闭 - HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 - if (currentState1 == BALL_FINISH) + 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_IDLE; + currentState1 = BALL_FLAG; } - else { - currentState1 = BALL_IDLE; // 默认回到空闲状态 - } - break; - - - case DOWN2: - //Hadling(); - //exit_Handling(); - ballHadling(); - //test_up(); - + 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); // 确保下气缸关闭 + + currentState1 = BALL_IDLE; // 回到空闲状态 + + break; + default: + currentState1 = BALL_IDLE; // 默认回到空闲状态 + 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) { diff --git a/User/task/ballTask.cpp b/User/task/ballTask.cpp index 92c8bdd..c43d992 100644 --- a/User/task/ballTask.cpp +++ b/User/task/ballTask.cpp @@ -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); diff --git a/User/task/shootTask.cpp b/User/task/shootTask.cpp index aa16c41..e9f2dc1 100644 --- a/User/task/shootTask.cpp +++ b/User/task/shootTask.cpp @@ -33,15 +33,8 @@ while(1) shoot.distanceGet(nucData); } - shoot.shoot_control(); + // 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(); - tick += delay_tick; /* 计算下一个唤醒时刻 */ osDelayUntil(tick);