From c2f8b5c8c39ad757189ffc81919879b7b300829e Mon Sep 17 00:00:00 2001 From: NeoZng Date: Sun, 1 Jan 2023 12:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86servo=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/usart/bsp_usart.c | 1 + modules/motor/servo_motor.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bsp/usart/bsp_usart.c b/bsp/usart/bsp_usart.c index 9eb33a3..f7171a4 100644 --- a/bsp/usart/bsp_usart.c +++ b/bsp/usart/bsp_usart.c @@ -42,6 +42,7 @@ USARTInstance *USARTRegister(USART_Init_Config_s *init_config) instance->module_callback = init_config->module_callback; usart_instance[idx++] = instance; + USARTServiceInit(instance); return instance; } diff --git a/modules/motor/servo_motor.c b/modules/motor/servo_motor.c index fb15863..5efded4 100644 --- a/modules/motor/servo_motor.c +++ b/modules/motor/servo_motor.c @@ -83,32 +83,30 @@ void Servo_Motor_Type_Select(ServoInstance *Servo_Motor, int16_t mode) void Servo_Motor_Control() { static ServoInstance *Servo_Motor; - static Servo_Type_e Servo_type; for (size_t i = 0; i < servo_idx; i++) { if (servo_motor_instance[i]) { Servo_Motor = servo_motor_instance[i]; - Servo_type = Servo_Motor->Servo_type; - switch (Servo_type) + switch (Servo_Motor->Servo_type) { case Servo180: - if (Servo_Motor->Servo_type == Start_mode) + if (Servo_Motor->Servo_Angle_Type == Start_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.Init_angle * 20000 / 20 / 90; - if (Servo_Motor->Servo_type == Final_mode) + if (Servo_Motor->Servo_Angle_Type == Final_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.Final_angle * 20000 / 20 / 90; - if (Servo_Motor->Servo_type == Free_Angle_mode) + if (Servo_Motor->Servo_Angle_Type == Free_Angle_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.free_angle * 20000 / 20 / 90; __HAL_TIM_SET_COMPARE(Servo_Motor->htim, Servo_Motor->Channel, compare_value[i]); break; case Servo270: - if (Servo_Motor->Servo_type == Start_mode) + if (Servo_Motor->Servo_Angle_Type == Start_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.Init_angle * 20000 / 20 / 135; - if (Servo_Motor->Servo_type == Final_mode) + if (Servo_Motor->Servo_Angle_Type == Final_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.Final_angle * 20000 / 20 / 135; - if (Servo_Motor->Servo_type == Free_Angle_mode) + if (Servo_Motor->Servo_Angle_Type == Free_Angle_mode) compare_value[i] = 0.5 * 20000 / 20 + Servo_Motor->Servo_Angle.free_angle * 20000 / 20 / 135; __HAL_TIM_SET_COMPARE(Servo_Motor->htim, Servo_Motor->Channel, compare_value[i]); break;