diff --git a/MDK-ARM/.vscode/settings.json b/MDK-ARM/.vscode/settings.json index 57a9ad9..3b49383 100644 --- a/MDK-ARM/.vscode/settings.json +++ b/MDK-ARM/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { "djimotor.h": "c", - "user_math.h": "c" + "user_math.h": "c", + "buzzer.h": "c" } } \ No newline at end of file diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index a7fed36..950b1a5 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -1,8 +1,8 @@ *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin' Build target 'R1' -compiling user_math.c... +compiling calc_lib.c... linking... -Program Size: Code=30000 RO-data=1884 RW-data=284 ZI-data=33268 +Program Size: Code=31512 RO-data=1884 RW-data=5820 ZI-data=33276 FromELF: creating hex file... "R1\R1.axf" - 0 Error(s), 0 Warning(s). -Build Time Elapsed: 00:00:05 +Build Time Elapsed: 00:00:03 diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock index bb95b32..5ab4faf 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1 +1 @@ -2025/6/13 23:04:00 \ No newline at end of file +2025/6/14 19:24:55 \ No newline at end of file diff --git a/MDK-ARM/R1.uvoptx b/MDK-ARM/R1.uvoptx index 1cf92bb..799a22c 100644 --- a/MDK-ARM/R1.uvoptx +++ b/MDK-ARM/R1.uvoptx @@ -103,7 +103,7 @@ 1 0 0 - 6 + 3 @@ -114,9 +114,14 @@ - STLink\ST-LINKIII-KEIL_SWO.dll + BIN\CMSIS_AGDI.dll + + 0 + CMSIS_AGDI + -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) + 0 ARMRTXEVENTFLAGS @@ -135,7 +140,7 @@ 0 DLGUARM - (105=-1,-1,-1,-1,0) + 0 @@ -145,7 +150,7 @@ 0 ST-LINKIII-KEIL_SWO - -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) + -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) @@ -183,17 +188,7 @@ 6 1 - jy,0x0A - - - 7 - 1 - angle1,0x0A - - - 8 - 1 - angle2,0x0A + knob_increment @@ -954,7 +949,7 @@ User/device - 0 + 1 0 0 0 @@ -1046,7 +1041,7 @@ User/module - 0 + 1 0 0 0 diff --git a/User/device/buzzer.c b/User/device/buzzer.c index 2b1e7fd..cff27ea 100644 --- a/User/device/buzzer.c +++ b/User/device/buzzer.c @@ -24,6 +24,8 @@ unsigned int notes[] = { 1, 1, 1, 3, 1, 2, 1, 1, 4 }; + + void buzzer_on(uint16_t note) { Frequency = CLOCK / note; // 计算定时器的重载值 diff --git a/User/device/buzzer.h b/User/device/buzzer.h index 8e54552..1f157cb 100644 --- a/User/device/buzzer.h +++ b/User/device/buzzer.h @@ -51,7 +51,8 @@ extern "C" { void buzzer_on(uint16_t note); void noTone(void); void playSong(void); - void see_you_again(void); + void see_you_again(void); + #ifdef __cplusplus } diff --git a/User/device/remote_control.c b/User/device/remote_control.c index c035507..a7ab280 100644 --- a/User/device/remote_control.c +++ b/User/device/remote_control.c @@ -295,7 +295,7 @@ static void sbus_to_rc(volatile const uint8_t *sbus_buf, RC_ctrl_t *rc_ctrl) if(rc_ctrl->ch[1]>-30&&rc_ctrl->ch[1]<-10) rc_ctrl->ch[1]=0; if(rc_ctrl->ch[2]>=0&&rc_ctrl->ch[2]<=7) rc_ctrl->ch[2]=0; if(rc_ctrl->ch[3]>-22&&rc_ctrl->ch[3]<-2) rc_ctrl->ch[3]=0; - + //MRobot remote_ready = 1; } diff --git a/User/lib/calc_lib.c b/User/lib/calc_lib.c index 16b2c0e..577fab2 100644 --- a/User/lib/calc_lib.c +++ b/User/lib/calc_lib.c @@ -1,4 +1,5 @@ #include "calc_lib.h" +#include //΢ʱ void user_delay_us(uint16_t us) @@ -111,4 +112,8 @@ fp32 map_fp32(fp32 x, fp32 in_min, fp32 in_max, fp32 out_min, fp32 out_max) // return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } +// ?????????????????????? +float expo_map(float value, float expo_factor) { + return value * (1 - expo_factor) + value * fabs(value) * expo_factor; +} diff --git a/User/lib/calc_lib.h b/User/lib/calc_lib.h index c6fe2e5..3e01c4d 100644 --- a/User/lib/calc_lib.h +++ b/User/lib/calc_lib.h @@ -29,7 +29,7 @@ fp32 loop_fp32_constrain(fp32 Input, fp32 minValue, fp32 maxValue); int32_t loop_int32_constrain(int32_t Input, int32_t minValue, int32_t maxValue); int map(int x, int in_min, int in_max, int out_min, int out_max); fp32 map_fp32(fp32 x, fp32 in_min, fp32 in_max, fp32 out_min, fp32 out_max); - +float expo_map(float value, float expo_factor); #ifdef __cplusplus } #endif diff --git a/User/module/ball.cpp b/User/module/ball.cpp index f0f45d4..9b20c47 100644 --- a/User/module/ball.cpp +++ b/User/module/ball.cpp @@ -16,18 +16,18 @@ extern int16_t M2006_result; // D键 sw[6]👆 200 👇1800 #define M_SPEED 4000 -#define I_ANGLE1 185 +#define I_ANGLE1 180 #define I_ANGLE2 -75 #define O_ANGLE1 340 -#define O_ANGLE2 -235 +#define O_ANGLE2 -240 #if HANDLING3 == 1 //三摩擦轮运球!!! //添加平移3508 得跑位置吧 const fp32 Ball:: M3508_speed_PID[3] = {15, 0.03, 0}; -const fp32 Ball:: Extend_speed_PID[3] = { 25, 0, 0.}; -const fp32 Ball:: Extend_angle_PID[3]= { 50, 0, 0.1}; +const fp32 Ball:: Extend_speed_PID[3] = { 25, 0.0, 0.1}; +const fp32 Ball:: Extend_angle_PID[3]= { 25, 0.1, 0}; //摩擦轮转速 int speedm=0; @@ -57,11 +57,11 @@ Ball ::Ball() Extern_Motor[0]->type = GM6020; Extern_Motor[1]->type = GM6020; - PID_init(&extend_speed_pid[0],PID_POSITION,Extend_speed_PID,20000, 2000); - PID_init(&extend_angle_pid[0],PID_POSITION,Extend_angle_PID,10000, 1000); + PID_init(&extend_speed_pid[0],PID_POSITION,Extend_speed_PID,10000, 2000); + PID_init(&extend_angle_pid[0],PID_POSITION,Extend_angle_PID,20000, 1000); - PID_init(&extend_speed_pid[1],PID_POSITION,Extend_speed_PID,20000, 2000); - PID_init(&extend_angle_pid[1],PID_POSITION,Extend_angle_PID,10000, 1000); + PID_init(&extend_speed_pid[1],PID_POSITION,Extend_speed_PID,10000, 2000); + PID_init(&extend_angle_pid[1],PID_POSITION,Extend_angle_PID,20000, 1000); e_result[0] = 0; e_result[1] = 0; diff --git a/User/module/shoot.cpp b/User/module/shoot.cpp index 294b878..1c1110f 100644 --- a/User/module/shoot.cpp +++ b/User/module/shoot.cpp @@ -23,11 +23,14 @@ NUC_t nuc_v; const fp32 Shoot:: M2006_speed_PID[3] = {5, 0, 0}; const fp32 Shoot:: M2006_angle_PID[3] = { 25, 0, 0.1}; -#define INIT_POS -100 +#define INIT_POS -130 #define TOP_POS -210 +#define GO_ERROR 1.0f #define Tigger_DO -5 -#define Tigger_ZERO 130 +#define Tigger_ZERO 100 +#define Tigger_ERROR 3 +//💩 int16_t M2006_result =0; float knob_increment; @@ -145,13 +148,15 @@ void Shoot::rc_mode() // 计算旋钮增量 if (current_knob_value >= 200 && current_knob_value <= 1800) { - knob_increment = (current_knob_value - last_knob_value) / 20.0f; // 每80单位对应一个增量 + knob_increment = (current_knob_value - last_knob_value) / 15.0f; // 每80单位对应一个增量 } else { knob_increment = 0; // 如果旋钮值超出范围,不产生增量 } + } + void Shoot::shoot_control() { //方便调试 @@ -160,18 +165,18 @@ void Shoot::shoot_control() { switch (rc_key) { case DOWN1: - // 中间挡位:调节拉簧蓄力电机位置 + control_pos = INIT_POS; // 默认中间挡位位置 - //fire_pos = control_pos + 10; // 发射位置(可调节) + //fire_pos = control_pos + knob_increment; // 根据旋钮值调整发射位置 fire_pos = control_pos + knob_increment; // 根据旋钮值调整发射位置 - //fire_pos +=knob_increment; go1.Pos = fire_pos; // 设置蓄力电机位置 + t_posSet = Tigger_ZERO; // 扳机松开 if (currentState == SHOOT_READY) { // 如果当前状态是准备发射,松开钩子发射 t_posSet = Tigger_ZERO; // 扳机扣动 BSP_Buzzer_Stop(); - if (t_posSet >= 120) { // 假设120度为发射完成角度 + if (t_posSet >= 95) { // 假设120度为发射完成角度 currentState = SHOOT_IDLE; // 切换到空闲状态 is_hooked = false; // 重置钩子状态 } @@ -193,7 +198,7 @@ void Shoot::shoot_control() { } // 发送数据到蓄力电机 - GO_SendData(go1.Pos, 5.0f); + //GO_SendData(go1.Pos, 5.0f); // 控制扳机电机 trigger_control(); @@ -215,8 +220,7 @@ void Shoot :: shoot_Current() case SHOOT_TOP: t_posSet = Tigger_DO; // 扳机扣动钩住 - osDelay(1000); // 等待一段时间,确保扳机动作完成 - if (fd_tpos <1) + if (trigger_Motor->total_angle<-2) { //判定为钩住 is_hooked = true; // 标记钩子已钩住 @@ -228,9 +232,10 @@ void Shoot :: shoot_Current() if (is_hooked) { go1.Pos = fire_pos; // 下拉到中间挡位位置 - if (feedback.fd_gopos >= fire_pos - 0.3f && feedback.fd_gopos <= fire_pos + 0.3f) { + if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR) { BSP_Buzzer_Start(); - BSP_Buzzer_Set(1,5000); + // BSP_Buzzer_Set(1,5000); + see_you_again(); //currentState = SHOOT_WAIT; // 等待发射信号 //在拨杆切换时触发了 } diff --git a/User/module/shoot.hpp b/User/module/shoot.hpp index 5309a17..3ec82f4 100644 --- a/User/module/shoot.hpp +++ b/User/module/shoot.hpp @@ -93,7 +93,7 @@ private: //位置环pid pid_type_def angle_pid; - bool is_hooked; // 标记钩子是否已经钩住拉簧 + bool is_hooked;// 标记钩子是否已经钩住拉簧