From f04a8304873301a749f4317d3e1aae5508355f59 Mon Sep 17 00:00:00 2001 From: Shobuj Paul Date: Sat, 23 Mar 2024 23:27:42 +0530 Subject: [PATCH] Run pre-commit --- include/observers/bemf_observer.hpp | 9 ++++---- src/math/foc.cpp | 33 +++++++++++++++++------------ src/observers/bemf_observer.cpp | 16 ++++++-------- tests/bemf_observer_test.cpp | 5 ++--- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/include/observers/bemf_observer.hpp b/include/observers/bemf_observer.hpp index 7a78448..0a28df0 100644 --- a/include/observers/bemf_observer.hpp +++ b/include/observers/bemf_observer.hpp @@ -21,11 +21,10 @@ class BemfObserver float Ts; BemfObserver(const float Ts = 0, const uint8_t num_rotor_poles = 0); - float loop(const math::FrameABC& line_currents, const math::FrameABC& line_voltages, - const math::FrameABC& duties, float Vbus, const SetBemfParams& set_bemf_params, - const SetTrackerParams& set_tracker_params, const ExtBemfParams& ext_bemf_params, - const ExtTrackerParams& ext_tracker_params, const uint8_t idle_mode, const bool force_bemf, - const bool en_dis_6_step_comm); + float loop(const math::FrameABC& line_currents, const math::FrameABC& line_voltages, const math::FrameABC& duties, + float Vbus, const SetBemfParams& set_bemf_params, const SetTrackerParams& set_tracker_params, + const ExtBemfParams& ext_bemf_params, const ExtTrackerParams& ext_tracker_params, const uint8_t idle_mode, + const bool force_bemf, const bool en_dis_6_step_comm); float get_m_speed_rpm() const; float get_m_speed_rpm_raw() const; float get_phase_error_rad() const; diff --git a/src/math/foc.cpp b/src/math/foc.cpp index 9287ce5..6272d9d 100644 --- a/src/math/foc.cpp +++ b/src/math/foc.cpp @@ -45,37 +45,41 @@ math::FrameABC math::space_vector_modulation(math::FrameAlphaBeta U) float X = U.beta; // Sector 1 - if ((-Y <= 0.F) && (-Z > 0.F) && (X > 0.F)) { + if ((-Y <= 0.F) && (-Z > 0.F) && (X > 0.F)) + { float T1 = (Z - X + 1.F) / 2; float T2 = T1 + X; float T3 = T2 - Z; - + duty.a = T3; duty.b = T2; duty.c = T1; } // Sector 2 - else if ((-Y <= 0.F) && (-Z <= 0.F)) { + else if ((-Y <= 0.F) && (-Z <= 0.F)) + { float T1 = (1.F - Y - Z) / 2; float T2 = T1 + Y; float T3 = T2 + Z; - + duty.a = T2; duty.b = T3; duty.c = T1; } // Sector 3 - else if ((-Y > 0.F) && (-Z <= 0.F) && (X > 0.F)) { + else if ((-Y > 0.F) && (-Z <= 0.F) && (X > 0.F)) + { float T1 = (Y - X + 1.F) / 2; float T2 = T1 - Y; float T3 = T2 + X; - + duty.a = T1; duty.b = T3; duty.c = T2; } // Sector 4 - else if ((-Y > 0.F) && (-Z <= 0.F) && (X <= 0.F)) { + else if ((-Y > 0.F) && (-Z <= 0.F) && (X <= 0.F)) + { float T1 = (X - Z + 1.F) / 2; float T2 = T1 + Z; float T3 = T2 - X; @@ -85,17 +89,19 @@ math::FrameABC math::space_vector_modulation(math::FrameAlphaBeta U) duty.c = T3; } // Sector 5 - else if ((-Y > 0.F) && (-Z > 0.F)) { + else if ((-Y > 0.F) && (-Z > 0.F)) + { float T1 = (Z + Y + 1.F) / 2; float T2 = T1 - Z; float T3 = T2 - Y; - + duty.a = T2; duty.b = T1; duty.c = T3; } // Sector 6 - else if ((-Y <= 0.F) && (-Z > 0.F) && (X <= 0.F)) { + else if ((-Y <= 0.F) && (-Z > 0.F) && (X <= 0.F)) + { float T1 = (X - Y + 1.F) / 2; float T2 = T1 - X; float T3 = T2 + Y; @@ -105,7 +111,8 @@ math::FrameABC math::space_vector_modulation(math::FrameAlphaBeta U) duty.c = T2; } // Default - else { + else + { duty.a = 0.F; duty.b = 0.F; duty.c = 0.F; @@ -134,6 +141,6 @@ math::FrameABC math::space_vector_modulation(math::FrameAlphaBeta U) duty.c = 0.F; else duty.c = duty.c; - + return duty; -} \ No newline at end of file +} diff --git a/src/observers/bemf_observer.cpp b/src/observers/bemf_observer.cpp index b7c0662..88b6d25 100644 --- a/src/observers/bemf_observer.cpp +++ b/src/observers/bemf_observer.cpp @@ -7,13 +7,11 @@ observers::BemfObserver::BemfObserver(const float Ts, const uint8_t num_rotor_po dq_update = std::make_unique(); } -float observers::BemfObserver::loop(const math::FrameABC& line_currents, - const math::FrameABC& line_voltages, const math::FrameABC& duties, - float Vbus, const SetBemfParams& set_bemf_params, - const SetTrackerParams& set_tracker_params, - const ExtBemfParams& ext_bemf_params, - const ExtTrackerParams& ext_tracker_params, const uint8_t idle_mode, - const bool force_bemf, const bool en_dis_6_step_comm) +float observers::BemfObserver::loop(const math::FrameABC& line_currents, const math::FrameABC& line_voltages, + const math::FrameABC& duties, float Vbus, const SetBemfParams& set_bemf_params, + const SetTrackerParams& set_tracker_params, const ExtBemfParams& ext_bemf_params, + const ExtTrackerParams& ext_tracker_params, const uint8_t idle_mode, + const bool force_bemf, const bool en_dis_6_step_comm) { math::FrameAlphaBeta currents = math::clarke_transform(line_currents); math::FrameAlphaBeta voltages; @@ -23,7 +21,7 @@ float observers::BemfObserver::loop(const math::FrameABC& line_currents, { // Vbus Filter constexpr float alpha = 0.01; - Vbus = alpha * Vbus + (1-alpha) * Vbus_prev; + Vbus = alpha * Vbus + (1 - alpha) * Vbus_prev; Vbus_prev = Vbus; // Duty Correction @@ -61,7 +59,7 @@ float observers::BemfObserver::loop(const math::FrameABC& line_currents, if (set_tracker_params.speed) return set_tracker_params.speed; else - return speed * alpha + (1 - alpha) * speed_prev; // Speed FIR Filter + return speed * alpha + (1 - alpha) * speed_prev; // Speed FIR Filter }(); this->m_speed_rpm = angular_velocity * 30 / (PI * num_rotor_poles / 2); this->e_theta_deg = [angular_velocity, angle, this]() -> float { diff --git a/tests/bemf_observer_test.cpp b/tests/bemf_observer_test.cpp index 4a0de2f..e856640 100644 --- a/tests/bemf_observer_test.cpp +++ b/tests/bemf_observer_test.cpp @@ -26,9 +26,8 @@ int main() for (float t = 0; t < 10; t += Ts) { math::FrameABC duties = math::inverse_clarke_transform(math::inverse_park_transform(U, angle)); - angle = - bemf_observer.loop(line_currents, line_voltages, duties, Vbus, set_bemf_params, set_tracker_params, - ext_bemf_params, ext_tracker_params, idle_mode, force_bemf, en_dis_6_step_comm); + angle = bemf_observer.loop(line_currents, line_voltages, duties, Vbus, set_bemf_params, set_tracker_params, + ext_bemf_params, ext_tracker_params, idle_mode, force_bemf, en_dis_6_step_comm); std::cout << "Duties: " << duties.a << " " << duties.b << " " << duties.c << std::endl; } }