From 721796e1053fad4c1564a20fa96df7ffa3630352 Mon Sep 17 00:00:00 2001 From: BoomPC Date: Fri, 17 May 2024 01:11:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=B5=E6=B5=81=E9=99=90?= =?UTF-8?q?=E5=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/APP_Task.c | 12 ++++++------ BoooomCTL/Controller/Controller.c | 21 +++++++++------------ BoooomCTL/Controller/Controller.h | 6 +++--- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/APP/APP_Task.c b/APP/APP_Task.c index 71a35ce..56085e9 100644 --- a/APP/APP_Task.c +++ b/APP/APP_Task.c @@ -40,11 +40,11 @@ void High_Frequency_Task() { number++; - if (number >= 1 && number <= 50000) { - Speedtarget = 0.1; - } else if (number >= 50000 && number <= 100000) { + if (number >= 1 && number <= 10000) { + Speedtarget = 1.0; + } else if (number >= 10000 && number <= 20000) { Speedtarget = -1.0; - } else if (number >= 100001) { + } else if (number >= 20001) { number = 0; } // Test_Angle += 0.01f; @@ -63,8 +63,8 @@ void High_Frequency_Task() { // Generate_SVM(0.0f, 0.05f, Data.Angle.getAngle()); // float32_t Eangle = Data.Angle.getAngle(); - SpeedControl(Speedtarget, MT_ReadAngle()); - FOC_current(0, 5.0f, Data.Angle.getAngle(), 5000); + SpeedControl(Speedtarget, MT_ReadAngle(),10.0f); + FOC_current(0, 10.0f, Data.Angle.getAngle(), 5000); // SendCurrent_Vofa(Test_Angle,A, (FOC.dtc_a * (float) HALF_PWM_PERIOD_CYCLES)); diff --git a/BoooomCTL/Controller/Controller.c b/BoooomCTL/Controller/Controller.c index d73f0e0..6d78dd4 100644 --- a/BoooomCTL/Controller/Controller.c +++ b/BoooomCTL/Controller/Controller.c @@ -34,7 +34,7 @@ float32_t id_curr_pi_error; float32_t id_curr_pi_errMin = 0.0f; float32_t id_curr_pi_errSum; -float32_t id_curr_pi_errSumMax = 5.0f; +float32_t id_curr_pi_errSumMax = 30.0f; float32_t id_curr_pi_result; @@ -48,12 +48,11 @@ float32_t iq_curr_pi_error; float32_t iq_curr_pi_errMin = 0.0f; float32_t iq_curr_pi_errSum; -float32_t iq_curr_pi_errSumMax = 5.0f; +float32_t iq_curr_pi_errSumMax = 30.0f; float32_t iq_curr_pi_result; - float32_t Speed_target = 0.0f; float32_t Speedpid_error; @@ -61,14 +60,12 @@ float32_t Speedpid_errSum; float32_t Speedpid_kp = 1.0f; float32_t Speedpid_ki = 0.1f; float32_t Speedpid_kd = 1.0f; -float32_t Speedpid_errSumMax = 5.0f; +float32_t Speedpid_errSumMax = 30.0f; float32_t Speedpid_lastErr; float32_t Speedpid_errDt; float32_t Speedpid_result; - - float32_t u_d, u_q; @@ -141,13 +138,13 @@ static float32_t PIDGetResult(float32_t Speedpid_value, float32_t valMax, float3 } -void SpeedControl(float32_t target,float32_t angleVal) { +void SpeedControl(float32_t target, float32_t angleVal, float32_t valMax) { Speed_target = target; float32_t motorControl_speedValue = GetSpeed(angleVal); - SendCurrent_Vofa(motorControl_speedValue, target, 0); +// SendCurrent_Vofa(motorControl_speedValue, target, 0); // speedPID_value = motorControl_speedValue; - iq_curr_pi_target = PIDGetResult(motorControl_speedValue, angleVal, 0.0f); + iq_curr_pi_target = PIDGetResult(motorControl_speedValue, valMax, 0.0f); } @@ -155,8 +152,8 @@ void SpeedControl(float32_t target,float32_t angleVal) { //bool Generate_SVM(float ud, float uq, float Theta) { bool FOC_current(float Id_set, float Iq_set, float Theta, float bw) { - if (id_curr_pi_target>Id_set){id_curr_pi_target=Id_set;} - if (iq_curr_pi_target>Iq_set){iq_curr_pi_target=Iq_set;} + if (id_curr_pi_target > Id_set) { id_curr_pi_target = Id_set; } + if (iq_curr_pi_target > Iq_set) { iq_curr_pi_target = Iq_set; } // id_curr_pi_target = Id_set; // iq_curr_pi_target = Iq_set; @@ -229,7 +226,7 @@ bool FOC_current(float Id_set, float Iq_set, float Theta, float bw) { // FOC.dtc_a = FOC.dtc_a * 0.01; // FOC.dtc_b = FOC.dtc_b * 0.01; // FOC.dtc_c = FOC.dtc_c * 0.01; -// SendCurrent_Vofa(mod_d, mod_q, current1); + SendCurrent_Vofa(mod_d, mod_q, iq_curr_pi_target); TIM1->CCR1 = (uint16_t) (FOC.dtc_c * (float) HALF_PWM_PERIOD_CYCLES); TIM1->CCR2 = (uint16_t) (FOC.dtc_b * (float) HALF_PWM_PERIOD_CYCLES); TIM1->CCR3 = (uint16_t) (FOC.dtc_a * (float) HALF_PWM_PERIOD_CYCLES); diff --git a/BoooomCTL/Controller/Controller.h b/BoooomCTL/Controller/Controller.h index 0622fc9..bd3b684 100644 --- a/BoooomCTL/Controller/Controller.h +++ b/BoooomCTL/Controller/Controller.h @@ -7,8 +7,7 @@ #include "arm_math.h" -typedef struct sFOC -{ +typedef struct sFOC { bool is_armed; float v_bus, v_bus_filt, i_a, i_b, i_c; @@ -23,7 +22,8 @@ typedef struct sFOC extern tFOC FOC; -extern void SpeedControl(float32_t target,float32_t angleVal); +extern void SpeedControl(float32_t target, float32_t angleVal, float32_t valMax); + extern bool FOC_current(float Id_set, float Iq_set, float Theta, float bw);