Skip to content

Commit

Permalink
Run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shobuj-Paul committed Mar 23, 2024
1 parent 1142178 commit f04a830
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
9 changes: 4 additions & 5 deletions include/observers/bemf_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 20 additions & 13 deletions src/math/foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -134,6 +141,6 @@ math::FrameABC math::space_vector_modulation(math::FrameAlphaBeta U)
duty.c = 0.F;
else
duty.c = duty.c;

return duty;
}
}
16 changes: 7 additions & 9 deletions src/observers/bemf_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ observers::BemfObserver::BemfObserver(const float Ts, const uint8_t num_rotor_po
dq_update = std::make_unique<observers::DQUpdate>();
}

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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions tests/bemf_observer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit f04a830

Please sign in to comment.