From 4de285abfb6ca949270b7f98b774255b635453e4 Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Tue, 1 Jul 2025 00:14:45 +0800 Subject: [PATCH] =?UTF-8?q?ok=E5=8E=BB=E8=AF=95=E8=AF=95=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E8=BF=90=E4=B8=A4=E6=AC=A1=E7=90=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/.vscode/keil-assistant.log | 2 + MDK-ARM/.vscode/uv4.log | 14 +- MDK-ARM/.vscode/uv4.log.lock | 6 +- User/lib/calc_lib.c | 1 + User/module/ball.cpp | 360 +++++++++++------------------ User/task/ballTask.cpp | 2 - 6 files changed, 144 insertions(+), 241 deletions(-) diff --git a/MDK-ARM/.vscode/keil-assistant.log b/MDK-ARM/.vscode/keil-assistant.log index 5cf43ab..33239a6 100644 --- a/MDK-ARM/.vscode/keil-assistant.log +++ b/MDK-ARM/.vscode/keil-assistant.log @@ -92,3 +92,5 @@ [info] Log at : 2025/6/30|23:49:51|GMT+0800 +[info] Log at : 2025/7/1|00:00:07|GMT+0800 + diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index a8a2b29..cb7385e 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -1,18 +1,8 @@ *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin' Build target 'R1' -<<<<<<< HEAD -compiling ballTask.cpp... compiling ball.cpp... linking... -Program Size: Code=28860 RO-data=1832 RW-data=276 ZI-data=32252 +Program Size: Code=28876 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:05 -======= -compiling ball.cpp... -linking... -Program Size: Code=31096 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:04 ->>>>>>> 7b54a46bd3c69e44a04ffd669bb7d3b115fc9e9b +Build Time Elapsed: 00:00:06 diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock index 27e15e3..fffa201 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1,5 +1 @@ -<<<<<<< HEAD -2025/6/28 2:01:18 -======= -2025/6/26 4:03:58 ->>>>>>> 7b54a46bd3c69e44a04ffd669bb7d3b115fc9e9b +2025/7/1 0:14:15 \ No newline at end of file diff --git a/User/lib/calc_lib.c b/User/lib/calc_lib.c index bcf12e8..7ad5097 100644 --- a/User/lib/calc_lib.c +++ b/User/lib/calc_lib.c @@ -165,5 +165,6 @@ fp32 abs_limit_min_max_fp(fp32 *num, fp32 Limit_min,fp32 Limit_max) return Limit_min; } + return *num; } diff --git a/User/module/ball.cpp b/User/module/ball.cpp index c00c01d..40cc84b 100644 --- a/User/module/ball.cpp +++ b/User/module/ball.cpp @@ -77,14 +77,17 @@ void Ball::rc_mode() extern_key=OUT; } - if(rc_ctrl.sw[5]==1800) - { - ready_key=SIDE; - } - if(rc_ctrl.sw[5]==200) - { - ready_key=0; //默认不准备 - } + // if (rc_ctrl.sw[5] == 200 && last_sw5 == 1800) // 只在1800->200的瞬间触发 + // { + // rc_key = DOWN2; + // } + // else + // { + // rc_key = 0; // 其他情况不触发 + // } + // last_sw5 = rc_ctrl.sw[5]; + + } void Ball::Send_control() @@ -166,44 +169,156 @@ void Ball::Move_Extend() // } //int ball_state = 0; + int runCount = 0; // 运球次数计数 int last_ball_state = 0; // 上一次的光电状态 int step = 0; // 0:持球 1:击球 2:反弹 3:完全离开 -void Ball::ball_control() + void Ball::ball_control() { ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_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) + HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 + if (rc_key == DOWN2) // 检测按键是否被按下 { - currentState1 = BALL_IDLE; - } - else { - currentState1 = BALL_IDLE; // 默认回到空闲状态 + runCount = 0; // 每次拨动重新计数 + currentState1 = BALL_FORWARD; } break; - case UP2: - ballDown(); + 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 DOWN2: - ballHadling(); - //test_Handling(); - + 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); // 确保下气缸关闭 + runCount++; + if (runCount < 2) + { + currentState1 = BALL_FORWARD; // 继续下一次运球 + } + else + { + currentState1 = BALL_IDLE; // 完成两次,回到空闲 + } + break; + + default: + currentState1 = BALL_IDLE; // 默认回到空闲状态 + break; } + Send_control(); } +// void Ball::ball_control() +// { +// ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 0,无球 1) + +// Move_Extend(); + +// 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 (rc_key == DOWN2) // 检测按键是否被按下 +// { +// currentState1 = BALL_FORWARD; +// } +// break; + +// 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); // 确保下气缸关闭 + +// currentState1 = BALL_IDLE; // 回到空闲状态 + +// break; +// default: +// currentState1 = BALL_IDLE; // 默认回到空闲状态 +// break; +// } + + +// Send_control(); + +// } + void Ball::Close(void) { HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭 @@ -433,7 +548,6 @@ void Ball::ballHadling(void) } - int runCount = 0; // 运球次数计数 void Ball::ballHadling_two(void) { @@ -504,203 +618,5 @@ void Ball::ballHadling_two(void) -#endif - -#if ONE_CONTROL - -void Ball::ball_control() -{ - hand_thread = osThreadFlagsGet(); // 获取任务通知标志位 - ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 1,无球 0) - - //进攻 - if(ready_key==SIDE) - { - switch (rc_key){ - case MIDDLE2: - Idle_control(); - break; - - case UP2: - ballDown(); - break; - - case DOWN2: - ballHadling(); - break; - - } - } - //防守 - else - { - xiaomi.position = I_ANGLE; // 保持收回 - HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭 - HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 - - } - - - - Send_control(); - -} - - -//任务通知来作全过程 - -void Ball::ballDown(void) -{ - switch(currentState1) - { - case BALL_IDLE: - xiaomi.position = I_ANGLE; // 保持收回 - if(feedback->position_deg >= I_ANGLE-0.8 && feedback->position_deg <= I_ANGLE+0.8) - { - currentState1 = EXTEND_DOWN; - } - break; - - case EXTEND_DOWN: - HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); - // 检测到球自由下落一次就切换状态 - if(ball_state == 1) - { - currentState1 = EXTEND_OUT; - } - break; - - case EXTEND_OUT: - xiaomi.position = O_ANGLE; // 保持伸出 - if(feedback->position_deg >= O_ANGLE-0.2 && feedback->position_deg <= O_ANGLE+0.2) - { - osThreadFlagsSet(task_struct.thread.shoot, EXTEND_OK); - currentState1 = EXTEND_FINISH; // 保持伸出,直到拨杆复位 - } - break; - - case EXTEND_FINISH: - xiaomi.position = O_ANGLE; // 一直保持伸出 - // 等待拨杆复位(如切到MIDDLE2),Idle_control会负责回位 - break; - - default: - currentState1 = BALL_IDLE; - break; - } -} - -void Ball::Idle_control() -{ - HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭 - HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 - - - osThreadFlagsClear(EXTEND_OK); - - if(ready_key==SIDE) // 检测是否准备好 - { - xiaomi.position = WAIT_POS; - if(feedback->position_deg >= WAIT_POS-3) - { - osThreadFlagsSet(task_struct.thread.shoot, READY_TELL); - } - } - else - { - xiaomi.position = I_ANGLE; // 默认回到收回位置 - } - - // 拨杆回到中间挡位时,回位并重置状态机 - if(currentState1==EXTEND_FINISH)//转移后 - { - xiaomi.position = I_ANGLE; - currentState1 = BALL_IDLE; - } - if(currentState1==BALL_FINISH)//运球完成 - { - xiaomi.position = O_ANGLE; - currentState1 = BALL_IDLE; - } - else - { - currentState1 = BALL_IDLE; - } - //xiaomi.position = I_ANGLE; - -} - - int ball_state = 0; - int last_ball_state = 0; // 上一次的光电状态 - -void Ball::ballHadling(void) -{ - - switch (currentState1) - { - case BALL_IDLE: - if (rc_key == DOWN2) - { - xiaomi.position = O_ANGLE;//外伸 - if(feedback->position_deg>= O_ANGLE-1)// 确保伸缩电机到位 - { - currentState1 = BALL_FORWARD; - } - - } - break; - - 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(25); - HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 闭合气缸爪子 - currentState1 = BALL_FINISH; // 切换到反转状态 - break; - - case BALL_FINISH: - osDelay(50); // 延时 50ms - //osThreadFlagsSet(task_struct.thread.ball, HANDING_FINISH); - HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保气缸爪子闭合 - HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 - break; - - default: - currentState1 = BALL_IDLE; // 默认回到空闲状态 - break; - } - - - } - - #endif diff --git a/User/task/ballTask.cpp b/User/task/ballTask.cpp index c43d992..954d407 100644 --- a/User/task/ballTask.cpp +++ b/User/task/ballTask.cpp @@ -8,11 +8,9 @@ #include "vofa.h" extern RC_ctrl_t rc_ctrl; Ball ball; -//float vofa[8]; //检查光电 int abc=0; -int aaaa=146; extern int speedm;