From 25bdadf8783b925ff31010a1bb1259322f86395b Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Thu, 27 Mar 2025 23:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9F=E5=BA=A6=E5=A4=A7=E4=BA=86=E4=BC=9A?= =?UTF-8?q?=E5=8D=A1=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- User/device/read_spi.c | 19 +++++++++++++++++++ User/device/read_spi.h | 2 +- User/module/shoot.c | 25 ++++++++++++++++++++----- User/module/shoot.h | 2 +- User/task/shoot_task.c | 2 +- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/User/device/read_spi.c b/User/device/read_spi.c index c4beb10..9a88165 100644 --- a/User/device/read_spi.c +++ b/User/device/read_spi.c @@ -61,6 +61,25 @@ void Update_Encoder(Encoder_t *ptr) { ptr->last_ecd = ptr->ecd; } +// void Update_Encoder(Encoder_t *ptr) { +// ptr->ecd = AS5047_read(ANGLEUNC); + +// // 检测编码器的圈数变化 +// if (ptr->ecd - ptr->last_ecd > 4096) { +// ptr->round_cnt -= 1.0f; // 减去一圈 +// } else if (ptr->ecd - ptr->last_ecd < -4096) { +// ptr->round_cnt += 1.0f; // 加上一圈 +// } + +// // 计算总角度 +// ptr->total_angle = (double)((ptr->round_cnt * 8192 + ptr->ecd - ptr->offset_ecd)); + +// // 更新 round_cnt 为小数圈数 +// ptr->round_cnt = (float)(ptr->total_angle / 8192.0f); // 将总角度转换为圈数(浮点数) + +// ptr->last_ecd = ptr->ecd; +// } + int32_t Get_Encoder_Rounds(Encoder_t *ptr) { return ptr->round_cnt; } diff --git a/User/device/read_spi.h b/User/device/read_spi.h index 1f3674a..014560e 100644 --- a/User/device/read_spi.h +++ b/User/device/read_spi.h @@ -19,7 +19,7 @@ #define SETTINGS2 0x0019 typedef struct { - int32_t round_cnt; + float round_cnt; uint16_t ecd; uint16_t last_ecd; uint16_t offset_ecd; diff --git a/User/module/shoot.c b/User/module/shoot.c index 27b8745..1dfbf60 100644 --- a/User/module/shoot.c +++ b/User/module/shoot.c @@ -8,6 +8,7 @@ extern motor_measure_t *trigger_motor_data;//3508电机数据 int mode=0; int shoot=0; +int xxx=0; #define Stop 0 #define Hasten 1 @@ -15,7 +16,7 @@ int shoot=0; #define Shoot 3 #define VESC_ID 77 -int speed_6384=10000; +int speed_6384=-1500; void control_clutch_shoot(void) { @@ -35,9 +36,10 @@ void control_clutch_shoot(void) { if(shoot ==0) { - if(encoder.round_cnt <= 4) + if(encoder.round_cnt <= 2) { + xxx=1; CAN_VESC_RPM(VESC_ID, speed_6384); } @@ -45,16 +47,23 @@ void control_clutch_shoot(void) } else if(shoot ==Shoot) { - if(encoder.round_cnt <= 4) + if(encoder.round_cnt <= 3) { - + xxx=3; HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET); CAN_VESC_RPM(VESC_ID, speed_6384); } - else if(encoder.round_cnt >= 4) + + // xxx=3; + // HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET); + // CAN_VESC_RPM(VESC_ID, speed_6384); + + if(encoder.round_cnt >= 3) { + xxx=4; + shoot=Slow; HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_RESET); CAN_VESC_HEAD(VESC_ID); @@ -62,6 +71,12 @@ void control_clutch_shoot(void) } + else if(shoot == Slow) + { + + CAN_VESC_HEAD(VESC_ID); + + } } } diff --git a/User/module/shoot.h b/User/module/shoot.h index 6878b1a..d451fcf 100644 --- a/User/module/shoot.h +++ b/User/module/shoot.h @@ -7,6 +7,6 @@ #include "pid.h" #include "main.h" - +void control_clutch_shoot(void); #endif diff --git a/User/task/shoot_task.c b/User/task/shoot_task.c index b6b66d0..93ba555 100644 --- a/User/task/shoot_task.c +++ b/User/task/shoot_task.c @@ -30,7 +30,7 @@ void Task_Shoot(void *argument) // 更新编码器数据 Update_Encoder(&encoder); - + control_clutch_shoot(); tick += delay_tick; /* 计算下一个唤醒时刻 */ osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */