diff --git a/MDK-ARM/.vscode/keil-assistant.log b/MDK-ARM/.vscode/keil-assistant.log index b06872f..7f2107f 100644 --- a/MDK-ARM/.vscode/keil-assistant.log +++ b/MDK-ARM/.vscode/keil-assistant.log @@ -152,3 +152,15 @@ [info] Log at : 2025/7/13|16:42:25|GMT+0800 +[info] Log at : 2025/7/13|22:38:15|GMT+0800 + +[info] Log at : 2025/7/14|07:52:29|GMT+0800 + +[info] Log at : 2025/7/14|12:31:22|GMT+0800 + +[info] Log at : 2025/7/14|13:56:03|GMT+0800 + +[info] Log at : 2025/7/16|22:15:00|GMT+0800 + +[info] Log at : 2025/7/16|22:26:06|GMT+0800 + diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index 85b4dd4..d53ce22 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -1,18 +1,9 @@ *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin' Build target 'R1' -compiling userTask.c... -compiling remote_control.c... -compiling initTask.c... -compiling main.c... -compiling shootTask.cpp... -compiling djiMotor.c... -compiling nucTask.cpp... -compiling encodeCan.cpp... compiling ballTask.cpp... -compiling ball.cpp... -compiling shoot.cpp... +compiling shootTask.cpp... linking... -Program Size: Code=32032 RO-data=1832 RW-data=284 ZI-data=32268 +Program Size: Code=31984 RO-data=1832 RW-data=272 ZI-data=32264 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 c28d343..36bc0c7 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1 +1 @@ -2025/7/13 17:07:34 \ No newline at end of file +2025/7/16 22:30:59 \ No newline at end of file diff --git a/MDK-ARM/R1.uvoptx b/MDK-ARM/R1.uvoptx index 9e387cb..2a42658 100644 --- a/MDK-ARM/R1.uvoptx +++ b/MDK-ARM/R1.uvoptx @@ -155,6 +155,9 @@ <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 上层测试 0 @@ -169,26 +172,43 @@ 2 1 +<<<<<<< HEAD ball,0x0A +======= + ball +>>>>>>> 上层测试 3 1 +<<<<<<< HEAD nucbuf +======= + and1 +>>>>>>> 上层测试 4 1 +<<<<<<< HEAD nuc_v +======= + and1 +>>>>>>> 上层测试 5 1 +<<<<<<< HEAD abc,0x0A +======= + nucbuf +>>>>>>> 上层测试 6 1 +<<<<<<< HEAD shoot_wait,0x0A @@ -198,6 +218,11 @@ ======= +>>>>>>> 上层测试 +======= + drop_message,0x0A + + >>>>>>> 上层测试 @@ -965,7 +990,7 @@ User/device - 0 + 1 0 0 0 diff --git a/README.md b/README.md index b0f5193..227e946 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,60 @@ r1上层 ## 外设 + CAN1 - - 扳机2006 id:0x205 - - 三摩擦 id:123 + + 扳机2006 id:0x201 ++ CAN2 + + 小米电机 id:1 + UART - - uart1 波特率4000000 id:2 - - uart6 nuc - - uart3 遥控器接收 + + uart1 波特率4000000 id:2 + + uart6 nuc + + uart3 遥控器接收 + GPIO - - PI6运球光电 - - PE11 运球气缸 - - + + PI6运球光电 + + PE13 爪气缸 + + PE14 砸气缸 ## 遥控器 +## 待解决 ++ 用了将运球和伸缩绑定到一起 √ ++ 串口收数加个滤波 √ +## 思路 + ++ 👆 传球档 👆 配合档 ++ 中 初始档 中 初始档 ++ 👇 发射档 👇 运球档 ++ 起步遥控档我直接蓄力准备接球 + 可多次的运球 + + 缩回转移球 + + 蓄力到位,收到掉落信号和已伸出信号 + + 根据视觉拟合信息的动态调整 + + 拨置👇发射清空掉落信号 + ++ 用一个攻守方档 + + 初始移动到最上面 更待蓄力(不管攻方守方都在最上面等待) + + 攻方时拨下立马蓄力并伸出(可小角度) + + 守方时不动并保持缩回 + + 👇 运球档正常运球 + + 中 初始档直接缩回 + + 👆 配合档 完成配合并伸出才能发射 + ++ 传球模式 + + 自动 + + 底盘的传球对准档拨下 + + 我的蓄力进入传球拟合 + + 继续拨下发射 + + 手动 + + 目前只能打固定距离 + + 切相同传球档 自动蓄力到传球力度 + + 发射档发射 + + 图传多距离 + + 传球档 + + 旋钮+看图传点位调整 + ++ 修复 + + 6.29 发射误操作导致没有拟合作用就射了(已修复) + + 6.29 串口不稳定 重新拔插一下 + + 6.29 nuc位置更新慢 + + 6.29 添加光电上电保护防止跳尺(已添加) + \ No newline at end of file diff --git a/User/bsp/TopDefine.h b/User/bsp/TopDefine.h index 9d74009..9524760 100644 --- a/User/bsp/TopDefine.h +++ b/User/bsp/TopDefine.h @@ -16,7 +16,7 @@ #endif -#define ONE_CONTROL 0 +#define ONE_CONTROL 1 //是否使用大疆DT7遥控器 #ifndef DT7 diff --git a/User/module/ball.cpp b/User/module/ball.cpp index 0f2b98d..b0ff8cc 100644 --- a/User/module/ball.cpp +++ b/User/module/ball.cpp @@ -315,47 +315,6 @@ void Ball::ballDown(void) } } -// 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) -// { -// // 只在READY_TELL未置位时发送,防止重复 -// if ((osThreadFlagsGet() & READY_TELL) == 0) -// { -// 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; -// } void Ball::Idle_control() { diff --git a/User/module/gimbal.cpp b/User/module/gimbal.cpp deleted file mode 100644 index 0d64aa3..0000000 --- a/User/module/gimbal.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "TopDefine.h" -#include "gimbal.hpp" -#include "remote_control.h" -#include "calc_lib.h" -#include "FreeRTOS.h" -#include - -#define KP 0.12 -#define KD 0.008 -//可活动角度 -#define ANGLE_ALLOW 1.0f -extern RC_ctrl_t rc_ctrl; -NUC_t nuc; - -const fp32 Gimbal:: Gimbal_speed_PID[3] = {50, 0.1, 0}; -const fp32 Gimbal:: Gimbal_angle_PID[3]= { 5, 0.01, 0}; - -#if GM6020ING ==1 -Gimbal::Gimbal() -{ - // GM6020_Motor = get_motor_point(6); - // GM6020_Motor->type = GM6020; - // PID_init(&speed_pid,PID_POSITION,Gimbal_speed_PID,16000, 6000); - // PID_init(&angle_pid,PID_POSITION,Gimbal_angle_PID,5000, 2000); - - // result = 0; - // angleSet = 0; - -} - -void Gimbal::gimbalFlow() -{ - int16_t delta[1]; - //angleSet = angle1; - delta[0] = PID_calc(&angle_pid,GM6020_Motor->total_angle,angleSet); - result = PID_calc(&speed_pid, GM6020_Motor->speed_rpm, delta[0]); - - CAN_cmd_1FF(0,0,result,0,&hcan1); - osDelay(1); - -} - -void Gimbal::gimbalZero() -{ - angleSet=0; - //gimbalFlow(); - -} - -void Gimbal::gimbalVision(const NUC_t &nuc) -{ - int16_t delta[1]; - angleSet = nuc.vision.x; - delta[0] = PID_calc(&angle_pid,GM6020_Motor->total_angle,angleSet); - result = PID_calc(&speed_pid, GM6020_Motor->speed_rpm, delta[0]); - - CAN_cmd_1FF(0,0,result,0,&hcan1); - osDelay(1); -} - - - -#else -Gimbal::Gimbal() -{ - - Kp = KP; - Kd = KD; - allowRange = ANGLE_ALLOW; -} - -void Gimbal::gimbalInit(void) -{ - int i; - GO_M8010_init(); - for(i = 0;i < GO_NUM;i ++) - { - goData[i] = getGoPoint(i);//获取电机数据指针 - - angleSet[i] = 0; - offestAngle[i] = 0; - GO_M8010_send_data(&huart6, i,0,0,0,0,0,0); - offestAngle[i] = goData[i]->Pos; - HAL_Delay(100); - - } - -} - -void Gimbal::gimbalFlow(void) -{ - - //angleSet[0] = map_fp32((float)rc_ctrl.ch[3],-800.0f,800.0f,-allowRange,allowRange) + offestAngle[0]; - GO_M8010_send_data(&huart6, 0,0,0,angleSet[0],1,KP,KD); - osDelay(1); - - -} - - -void Gimbal::gimbalZero(void) -{ - GO_M8010_send_data(&huart6, 0,0,0,0,0,0,0); -} - -void Gimbal::gimbalVision(const NUC_t &nuc) -{ - angleSet[0] = nuc.vision.x; - GO_M8010_send_data(&huart6, 0,0,0,angleSet[0],1,KP,KD); - osDelay(1); -} - -#endif diff --git a/User/module/gimbal.hpp b/User/module/gimbal.hpp deleted file mode 100644 index 5d3306f..0000000 --- a/User/module/gimbal.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef GIMBAL_HPP -#define GIMBAL_HPP - -#include "GO_M8010_6_Driver.h" -#include "djiMotor.h" -#include "pid.h" -#include "nuc.h" - -class Gimbal -{ -public: - Gimbal(); - void gimbalFlow(void);//云台随遥控器转动 - void gimbalZero(void);//云台零阻尼模式 - void gimbalInit(void);//go初始化 - void gimbalVision(const NUC_t &nuc); // 接收 NUC_t 数据 - - int16_t result; - //暂存要发送的扭矩 - //float result[GO_NUM]; -// float Kp; -// float Kd; -private: - -#if GM6020ING == 1 -//GM6020电机数据 - motor_measure_t *GM6020_Motor; - - static const float Gimbal_speed_PID[3]; - static const float Gimbal_angle_PID[3]; - - //电机速度pid结构体 - pid_type_def speed_pid; - //位置环pid - pid_type_def angle_pid; - - float angleSet; - -#else - motor_measure_t *motorData[GO_NUM]; - //视觉发送的要调的角度 - float self_angleSet; - GO_Motorfield* goData[GO_NUM]; - //暂存目标位置 - float angleSet[GO_NUM]; - float offestAngle[GO_NUM];//go数据 - float Kp; - float Kd; - float allowRange; - -#endif -}; - - - - -#endif diff --git a/User/module/shoot.cpp b/User/module/shoot.cpp index 0246bbc..25a7c46 100644 --- a/User/module/shoot.cpp +++ b/User/module/shoot.cpp @@ -39,7 +39,7 @@ const fp32 Shoot::M2006_angle_PID[3] = {15, 0.1, 0}; #define CHANEGE_POS -205 #define GO_ERROR 1.0f #define Tigger_DO -10 -#define Tigger_ZERO 115 +#define Tigger_ZERO 125 #define Tigger_ERROR 3 float knob_increment; @@ -171,6 +171,9 @@ int Shoot::GO_SendData(float pos, float limit) // sw[5] 👆 200 👇1800 // 左旋 sw[7] 200 --1800 + +float and1=0.0f; + void Shoot::rc_mode() { // 底部光电检测(假设0为到位,1为未到位,根据实际硬件调整) @@ -222,23 +225,44 @@ void Shoot::rc_mode() { ready_key = DEFENSE; } + //400--640为1 730--860为2 900到1200为3档中间 1300--1500为4 + if(rc_ctrl.sw[7]<=300) + { + and1=0.0f; + } + if(rc_ctrl.sw[7]>=400&&rc_ctrl.sw[7]<=640) + { + and1=-2.0f; + } + if(rc_ctrl.sw[7]>=730&&rc_ctrl.sw[7]<=860) + { + and1=-1.0f; + } + if(rc_ctrl.sw[7]>=900&&rc_ctrl.sw[7]<=1200) + { + and1=0.0f; + } + if(rc_ctrl.sw[7]>=1300&&rc_ctrl.sw[7]<=1500) + { + and1=1.0f; + } - // 旋钮映射部分不变 - const int knob_min = 200; - const int knob_max = 1800; - const float map_min = 130.0f; - const float map_max = -60.0f; - int current_knob_value = rc_ctrl.sw[7]; - if (current_knob_value < knob_min) - current_knob_value = knob_min; - if (current_knob_value > knob_max) - current_knob_value = knob_max; - knob_increment = map_min + (map_max - map_min) * (current_knob_value - knob_min) / (knob_max - knob_min); + // // 旋钮映射部分不变 + // const int knob_min = 200; + // const int knob_max = 1800; + // const float map_min = 130.0f; + // const float map_max = -60.0f; + // int current_knob_value = rc_ctrl.sw[7]; + // if (current_knob_value < knob_min) + // current_knob_value = knob_min; + // if (current_knob_value > knob_max) + // current_knob_value = knob_max; + // knob_increment = map_min + (map_max - map_min) * (current_knob_value - knob_min) / (knob_max - knob_min); } #if ONE_CONTROL == 0 -float and1=0.0f; + void Shoot::shoot_control() { @@ -249,8 +273,8 @@ void Shoot::shoot_control() { case VSION: //fire_pos = distance; // 视觉拟合的力 - fire_pos =shoot_fitting(distance)+and1; - //fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置 + //fire_pos =shoot_fitting(distance)+and1; + fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置 switch (rc_key) { @@ -415,8 +439,6 @@ void Shoot::RemoveError() #if ONE_CONTROL -//float and1=-1.5f; -float and1=0; float and2=0; void Shoot::shoot_control() @@ -433,7 +455,7 @@ void Shoot::shoot_control() switch (mode_key) { case VSION: - fire_pos = shoot_fitting(distance)+and1; // 视觉拟合的力 + fire_pos = shoot_fitting(distance)+and1; //fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置 switch (rc_key) @@ -489,11 +511,10 @@ void Shoot::shoot_control() switch (rc_key) { case MIDDLE1: - fire_pos = pass_fitting(pass_distance)+and2; + fire_pos = shoot_fitting(distance)+and1; if ((shoot_thread & READY_TELL) && !(shoot_thread & EXTEND_OK)) { - // 只收到READY_TELL且未收到EXTEND_OK时,顶部蓄力流程 - ball_receive(); // ball_receive内部写go1.Pos + ball_receive(); } else if (shoot_thread & EXTEND_OK) { @@ -618,7 +639,7 @@ void Shoot ::ball_receive() break; case BAKC: control_pos = BOTTOM_POS; - limit_speed = TO_BOTTOM; // 慢速下来 + limit_speed = 8.0f; // 慢速下来 if (feedback.fd_gopos >= BOTTOM_POS - 1.0f && feedback.fd_gopos <= BOTTOM_POS + 1.0f) { diff --git a/User/task/ballTask.cpp b/User/task/ballTask.cpp index 86a6556..0886f72 100644 --- a/User/task/ballTask.cpp +++ b/User/task/ballTask.cpp @@ -8,11 +8,7 @@ #include "vofa.h" extern RC_ctrl_t rc_ctrl; Ball ball; -//float vofa[8]; -//检查光电 -int abc=0; -int aaaa=146; extern int speedm; @@ -32,20 +28,10 @@ void FunctionBall(void *argument) #ifdef DEBUG task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId()); #endif - - //abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); - abc=HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位 - ball.rc_mode(); // 遥控器模式 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/gimbalTask.cpp b/User/task/gimbalTask.cpp deleted file mode 100644 index 2b37f5c..0000000 --- a/User/task/gimbalTask.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "TopDefine.h" -#include "FreeRTOS.h" -#include "userTask.h" -#include -#include "gimbalTask.hpp" -#include "gimbal.hpp" -#include "main.h" -#include "remote_control.h" -#include "nuc.h" -Gimbal gimbal; -// NUC_t nucData; // 用于存储从队列接收的数据 -extern RC_ctrl_t rc_ctrl; -int cnt1=0; - -void FunctionGimbal(void *argument) -{ - (void)argument; /* 未使用argument,消除警告 */ - - const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_GIMBAL; - - HAL_GPIO_WritePin(LED_G_GPIO_Port,LED_G_Pin,GPIO_PIN_SET); - - uint32_t tick = osKernelGetTickCount(); - - while(1) - { - #ifdef DEBUG - task_struct.stack_water_mark.gimbal = osThreadGetStackSpace(osThreadGetId()); - #endif - - //cnt1++; - - // gimbal.gimbalFlow(); - // 从消息队列接收视觉数据 - // if (osMessageQueueGet(task_struct.msgq.nuc, &nucData, NULL, 0) == osOK) - // { - // // 使用接收到的视觉数据调整云台 - // //gimbal.gimbalVision(nucData); - // } - - osDelay(1); - - tick += delay_tick; /* 计算下一个唤醒时刻 */ - osDelayUntil(tick); - } -} - diff --git a/User/task/gimbalTask.hpp b/User/task/gimbalTask.hpp deleted file mode 100644 index 71998d5..0000000 --- a/User/task/gimbalTask.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef GIMBALTASK_HPP -#define GIMBALTASK_HPP - - -#endif diff --git a/User/task/shootTask.cpp b/User/task/shootTask.cpp index 822dab7..b4fd579 100644 --- a/User/task/shootTask.cpp +++ b/User/task/shootTask.cpp @@ -10,7 +10,7 @@ extern RC_ctrl_t rc_ctrl; Shoot shoot; NUC_t nucData; // 自瞄 -int aaaxxx=0; + void FunctionShoot(void *argument) { @@ -35,13 +35,6 @@ while(1) 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);