From f50817a2182dbf5f1b2742f6d6113ab48e7ceb6c Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Sat, 15 Mar 2025 16:42:56 +0800 Subject: [PATCH] =?UTF-8?q?DJI=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- User/device/djiMotor.c | 17 ++++++++++++++--- User/device/djiMotor.h | 3 ++- User/task/dji_task.c | 2 +- User/task/shoot_task.c | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/User/device/djiMotor.c b/User/device/djiMotor.c index 8bfc6cb..cbb5947 100644 --- a/User/device/djiMotor.c +++ b/User/device/djiMotor.c @@ -37,7 +37,7 @@ (ptr)->temperate = (data)[6]; \ (ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \ - (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE; \ + (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_3508; \ }//ptr指向电机测量数据结构体的指针,data包含电机测量数据的数组. /*(ptr)->real_angle = (ptr)->real_angle % 360; */ #define get_motor_offset(ptr, data) \ @@ -55,7 +55,18 @@ (ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_6020; \ - } + } +#define get_2006_motor_measure(ptr, data) \ + { \ + (ptr)->last_ecd = (ptr)->ecd; \ + (ptr)->ecd = (uint16_t)((data)[0] << 8 | (data)[1]); \ + (ptr)->speed_rpm = (uint16_t)((data)[2] << 8 | (data)[3]); \ + (ptr)->given_current = (uint16_t)((data)[4] << 8 | (data)[5]); \ + (ptr)->temperate = (data)[6]; \ + (ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \ + (ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \ + (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_2006; \ + } // 解析出初始编码器值 // #define get_5065motor_measure(ptr, data) \ // { \ @@ -132,7 +143,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) } #else -static osEventFlagsId_t eventReceive; +static osEventFlagsId_t eventReceive;//事件标志 /** * @brief 自定义大疆电机回调函数 * @param[in] none diff --git a/User/device/djiMotor.h b/User/device/djiMotor.h index 4ebbdad..c07c14d 100644 --- a/User/device/djiMotor.h +++ b/User/device/djiMotor.h @@ -47,7 +47,8 @@ typedef struct //motor calc ecd to angle -#define MOTOR_ECD_TO_ANGLE (360.0 / 8191.0 / (3591.0/187.0)) +#define MOTOR_ECD_TO_ANGLE_3508 (360.0 / 8191.0 / (3591.0/187.0)) +#define MOTOR_ECD_TO_ANGLE_2006 (360.0 / 8191.0 / 36) #define MOTOR_ECD_TO_RAD 0.000766990394f #define MOTOR_ECD_TO_ANGLE_6020 (360.0 / 8191.0 ) diff --git a/User/task/dji_task.c b/User/task/dji_task.c index 1ffb213..1846b45 100644 --- a/User/task/dji_task.c +++ b/User/task/dji_task.c @@ -48,7 +48,7 @@ void Task_Motor(void *argument) //当最高点时进入离合 if(encoder.round_cnt>=8) { - trigger_angle_o=-1; + trigger_angle_o=2; trigger_pos(m); } diff --git a/User/task/shoot_task.c b/User/task/shoot_task.c index b01558a..26911cc 100644 --- a/User/task/shoot_task.c +++ b/User/task/shoot_task.c @@ -19,8 +19,8 @@ extern int mode; //odrive发射 #define SHOOT3 12 -#define TOP 8 -#define MIDDLE 4 +#define TOP 6 +#define MIDDLE 3 #define BOTTOM 0 void Task_Shoot(void *argument)