From e297b9960e7d4e82761fdc5febbf57d75d77b5ed Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Sun, 6 Apr 2025 16:15:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=BD=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- User/device/djiMotor.c | 4 ++-- User/device/djiMotor.h | 2 +- User/module/ball.c | 14 +++++++++++--- User/module/shoot.c | 39 ++++++++++++++++++++++++++++++++++++- User/module/shoot.h | 1 + User/task/ball_task.c | 9 ++++++++- User/task/dji_task.c | 10 ++++------ User/task/shoot_task.c | 44 ++++-------------------------------------- 8 files changed, 69 insertions(+), 54 deletions(-) diff --git a/User/device/djiMotor.c b/User/device/djiMotor.c index a0b42a7..8062ef6 100644 --- a/User/device/djiMotor.c +++ b/User/device/djiMotor.c @@ -410,7 +410,7 @@ motor_measure_t *get_2006_motor_point(uint8_t i) vesc_send_data[2] = data >> 8 ; vesc_send_data[3] = data ; - HAL_CAN_AddTxMessage(&hcan1, &vesc_tx_message, vesc_send_data, &send_mail_box); + HAL_CAN_AddTxMessage(&hcan2, &vesc_tx_message, vesc_send_data, &send_mail_box); } @@ -431,5 +431,5 @@ motor_measure_t *get_2006_motor_point(uint8_t i) vesc_tx_message.RTR = CAN_RTR_DATA; vesc_tx_message.DLC = 0x04; - HAL_CAN_AddTxMessage(&hcan1, &vesc_tx_message, vesc_send_data, &send_mail_box); + HAL_CAN_AddTxMessage(&hcan2, &vesc_tx_message, vesc_send_data, &send_mail_box); } diff --git a/User/device/djiMotor.h b/User/device/djiMotor.h index 1dab77b..cb262ee 100644 --- a/User/device/djiMotor.h +++ b/User/device/djiMotor.h @@ -88,7 +88,7 @@ typedef struct { #define MOTOR_ECD_TO_RAD 0.000766990394f #define MOTOR_ECD_TO_ANGLE_6020 (360.0 / 8191.0 ) -#define wtrcfg_VESC_COMMAND_ERPM_MAX 35000 +#define wtrcfg_VESC_COMMAND_ERPM_MAX 40000 #define CAN_VESC_CTRL_ID_BASE (0x300) #if FREERTOS_DJI == 1 diff --git a/User/module/ball.c b/User/module/ball.c index 765186f..30900f6 100644 --- a/User/module/ball.c +++ b/User/module/ball.c @@ -8,8 +8,8 @@ // PC6 ball_up_Pin读运球 检测到输出0,未检测到输出1 // PE13 down_Pin 下推 // PE14 paw_Pin 爪子 -// PI6 ball_in1_Pin 读接球 -// PI7 ball_in2_Pin 读接球 +// PI6 ball_in2_Pin 读接球 +// PI7 ball_in1_Pin 读接球 // PE11 key_Pin 收网 #define ballcome 1 #define balldown 0 @@ -31,7 +31,7 @@ int pass_ball(void) //运球 void handling_ball(int hand, int angle) { - GO_TURN_ball(TURN,go,angle);//停止运球 + int ball_state =0;//有球 int paw_state =0;//获取爪子开合状态 if( hand==1) @@ -40,11 +40,19 @@ void handling_ball(int hand, int angle) paw_state =1;//爪子开 // osDelay(5); HAL_GPIO_WritePin(down_GPIO_Port, down_Pin, GPIO_PIN_RESET);//打出 + osDelay(500); + angle=80; + GO_TURN_ball(TURN,go,angle);//停止运球 ball_state =1;//无球 osDelay(500); HAL_GPIO_WritePin(down_GPIO_Port, down_Pin, GPIO_PIN_SET);//收回 ball_state =ball_in();//获取爪子有无球状态 } + else if (hand==0) + { + angle=20; + GO_TURN_ball(TURN,go,angle);//停止运球 + } if (paw_state==1&&ball_state==0) { HAL_GPIO_WritePin(paw_GPIO_Port, paw_Pin, GPIO_PIN_RESET);//爪子合 diff --git a/User/module/shoot.c b/User/module/shoot.c index e8d0cc8..3d9af0b 100644 --- a/User/module/shoot.c +++ b/User/module/shoot.c @@ -1,14 +1,51 @@ #include "shoot.h" #include "remote_control.h" #include "go.h" - +#include "calc_lib.h" extern RC_mess_t RC_mess; extern motor_measure_t *trigger_motor_data;//3508电机数据 extern GO go; +int shoot_flag = 0; +int speed_5065=0; + #define KP 0.12 #define KD 0.008 +//sw[1] 306--1694 +void control_shoot(void) +{ + if(RC_mess.RC_data.sw[1]>800) + { + + if(HAL_GPIO_ReadPin(ball_in1_GPIO_Port, ball_in1_Pin) == GPIO_PIN_RESET) + { + CAN_VESC_HEAD(1); + CAN_VESC_HEAD(2); + } + else + { + //speed_5065=5000; + speed_5065=map_fp32(RC_mess.RC_data.ch[2],0,100,0,25000); + CAN_VESC_RPM(1, speed_5065); //发射电机转速 + CAN_VESC_RPM(2, speed_5065); //发射电机转速 + + } + + } + if(shoot_flag == 2 || RC_mess.RC_data.sw[5]==1694)//返回//不拨动为306 + { + speed_5065=-5000; + CAN_VESC_RPM(1, speed_5065); //发射电机转速 + CAN_VESC_RPM(2, speed_5065); //发射电机转速 + osDelay(2000); + speed_5065=0; + + } + + osDelay(1); + +} diff --git a/User/module/shoot.h b/User/module/shoot.h index 0aa1da4..3794ba1 100644 --- a/User/module/shoot.h +++ b/User/module/shoot.h @@ -20,6 +20,7 @@ typedef struct float allowRange; }GO_SHOOT; +void control_shoot(void); #endif diff --git a/User/task/ball_task.c b/User/task/ball_task.c index 6a12ef7..061db6f 100644 --- a/User/task/ball_task.c +++ b/User/task/ball_task.c @@ -28,7 +28,14 @@ void Task_Ball(void *argument) { // Turn_pos=20; - + if(RC_mess.RC_data.sw[0]==306)//加速 + { + basketball.hand=1; + } + else if(RC_mess.RC_data.sw[0]==1694)//减速 + { + basketball.hand=0; + } handling_ball(basketball.hand,Turn_pos); bb=ball_in(); if(bb==1) diff --git a/User/task/dji_task.c b/User/task/dji_task.c index 65a7f02..73c249f 100644 --- a/User/task/dji_task.c +++ b/User/task/dji_task.c @@ -40,17 +40,15 @@ void Task_Motor(void *argument) if(RC_mess.RC_data.sw[4]==306||shoot_f==3) { pos2006=200; - trigger_pos(pos2006); } - else if(RC_mess.RC_data.sw[4]==1694) + else { pos2006=0; - trigger_pos(pos2006); - } - - + } + + trigger_pos(pos2006); CAN_cmd_1FF(t_result,0,0,0,&hcan1); osDelay(1); diff --git a/User/task/shoot_task.c b/User/task/shoot_task.c index 2478165..47d9c88 100644 --- a/User/task/shoot_task.c +++ b/User/task/shoot_task.c @@ -5,20 +5,15 @@ #include #include "remote_control.h" #include "shoot.h" -#include "odrive_shoot.h" -#include "read_spi.h" #include "dji.h" #include "go.h" + extern RC_mess_t RC_mess; -extern Encoder_t encoder; extern motor_measure_t *trigger_motor_data;//3508电机数据 extern GO go; -int shoot_flag = 0; -int trigger_flag = 0; -int pos=0; + int gopos=0; -int speed_5065=0; #define VESC_SHOOT 1 @@ -44,40 +39,9 @@ void Task_Shoot(void *argument) #if VESC_SHOOT == 1 gopos=35;//云台位置 GO_TURN_ball(GIMBAL,go,gopos); //锁云台 + control_shoot(); - - if(shoot_flag==1||RC_mess.RC_data.sw[0]==306)//加速 - { - - if(HAL_GPIO_ReadPin(ball_in1_GPIO_Port, ball_in1_Pin) == GPIO_PIN_RESET) - { - CAN_VESC_HEAD(1); - CAN_VESC_HEAD(2); - } - else - { - speed_5065=35000; - CAN_VESC_RPM(1, speed_5065); //发射电机转速 - CAN_VESC_RPM(2, speed_5065); //发射电机转速 - - } - - - } - else if(shoot_flag == 2 || RC_mess.RC_data.sw[5]==1694)//返回//不拨动为306 - { - speed_5065=-5000; - CAN_VESC_RPM(1, speed_5065); //发射电机转速 - CAN_VESC_RPM(2, speed_5065); //发射电机转速 - - } - else if(shoot_flag == 0) - { - CAN_VESC_RPM(1, 0); //发射电机转速 - CAN_VESC_RPM(2, 0); //发射电机转速 - - } - + #endif tick += delay_tick; /* 计算下一个唤醒时刻 */