diff --git a/include/math/operators.hpp b/include/math/operators.hpp index 586db6d..792c3c8 100644 --- a/include/math/operators.hpp +++ b/include/math/operators.hpp @@ -16,7 +16,7 @@ class integrator float output, input_prev, Ts; public: - integrator(); + integrator(float initial_value = 0); float loop(float input, float Ts); }; diff --git a/include/observers/bemf_observer.hpp b/include/observers/bemf_observer.hpp index 63443c5..02a8df9 100644 --- a/include/observers/bemf_observer.hpp +++ b/include/observers/bemf_observer.hpp @@ -15,16 +15,20 @@ struct BemfOutput class BemfObserver { - DQUpdate dq_update; - Tracker tracker; float speed_prev, angle_prev, Vbus_prev; public: + DQUpdate dq_update; + Tracker tracker; + BemfObserver(); - BemfOutput loop(math::FrameABC line_currents, math::FrameABC line_voltages, math::FrameABC duties, float Vbus, - const float Ts, const SetBemfParams& set_bemf_params, const SetTrackerParams& set_tracker_params, - const ExtBemfParams& ext_bemf_params, const ExtTrackerParams& ext_tracker_params, - uint8_t pos_obs_mode, uint8_t idle_mode, uint8_t opmode, const uint8_t num_rotor_poles, - const uint8_t freq_mode, bool force_bemf, bool en_dis_6_step_comm); + BemfOutput loop(const math::FrameABC& line_currents, const math::FrameABC& line_voltages, + const math::FrameABC& duties, float Vbus, const float Ts, + const SetBemfParams& set_bemf_params, + const SetTrackerParams& set_tracker_params, + const ExtBemfParams& ext_bemf_params, + const ExtTrackerParams& ext_tracker_params, const uint8_t pos_obs_mode, + const uint8_t idle_mode, const uint8_t opmode, const uint8_t num_rotor_poles, + const uint8_t freq_mode, const bool force_bemf, const bool en_dis_6_step_comm); }; } // namespace observers diff --git a/include/observers/dq_update.hpp b/include/observers/dq_update.hpp index 3eb9cfc..18106e6 100644 --- a/include/observers/dq_update.hpp +++ b/include/observers/dq_update.hpp @@ -71,10 +71,11 @@ class DQUpdate controllers::PIController d_axis, q_axis; public: - DQUpdate(); controllers::PIConfig config; BemfGains gains; + DQUpdate(); + DQUpdate(controllers::PIConfig config, BemfGains gains); float loop(math::FrameAlphaBeta currents, math::FrameAlphaBeta voltages, float angular_velocity, float rotor_angle, const SetBemfParams& set_params = SetBemfParams(), const ExtBemfParams& ext_params = ExtBemfParams()); math::FrameDQ get_emfs() const; diff --git a/include/observers/tracker.hpp b/include/observers/tracker.hpp index a9dde5e..1f0afab 100644 --- a/include/observers/tracker.hpp +++ b/include/observers/tracker.hpp @@ -36,7 +36,9 @@ class Tracker public: controllers::PIConfig config; + Tracker() = default; + Tracker(controllers::PIConfig config); float loop(float phase_error, const SetTrackerParams& params = SetTrackerParams(), const ExtTrackerParams& ext_params = ExtTrackerParams()); float speed_tracker(float angle_est, float Ts); diff --git a/src/math/operators.cpp b/src/math/operators.cpp index 83657b2..98dedad 100644 --- a/src/math/operators.cpp +++ b/src/math/operators.cpp @@ -11,7 +11,7 @@ float math::differentiator::loop(float input, float Ts) return output; } -math::integrator::integrator() : output(0), input_prev(0) +math::integrator::integrator(float initial_value) : output(0), input_prev(initial_value) { } diff --git a/src/observers/bemf_observer.cpp b/src/observers/bemf_observer.cpp index eb581e3..6c69fb1 100644 --- a/src/observers/bemf_observer.cpp +++ b/src/observers/bemf_observer.cpp @@ -4,14 +4,14 @@ observers::BemfObserver::BemfObserver() : speed_prev(0), angle_prev(0) { } -observers::BemfOutput observers::BemfObserver::loop(math::FrameABC line_currents, math::FrameABC line_voltages, - math::FrameABC duties, float Vbus, const float Ts, +observers::BemfOutput observers::BemfObserver::loop(const math::FrameABC& line_currents, const math::FrameABC& line_voltages, + const math::FrameABC& duties, float Vbus, const float Ts, const SetBemfParams& set_bemf_params, const SetTrackerParams& set_tracker_params, const ExtBemfParams& ext_bemf_params, - const ExtTrackerParams& ext_tracker_params, uint8_t pos_obs_mode, - uint8_t idle_mode, uint8_t opmode, const uint8_t num_rotor_poles, - const uint8_t freq_mode, bool force_bemf, bool en_dis_6_step_comm) + const ExtTrackerParams& ext_tracker_params, const uint8_t pos_obs_mode, + const uint8_t idle_mode, const uint8_t opmode, const uint8_t num_rotor_poles, + const uint8_t freq_mode, const bool force_bemf, const bool en_dis_6_step_comm) { observers::BemfOutput output; diff --git a/src/observers/dq_update.cpp b/src/observers/dq_update.cpp index e06f629..0121f15 100644 --- a/src/observers/dq_update.cpp +++ b/src/observers/dq_update.cpp @@ -5,6 +5,10 @@ observers::DQUpdate::DQUpdate() : I_prev(0, 0), X_prev(0, 0), E(0, 0) { } +observers::DQUpdate::DQUpdate(controllers::PIConfig config, BemfGains gains) : I_prev(0, 0), X_prev(0, 0), E(0, 0), config(config), gains(gains) +{ +} + float observers::DQUpdate::loop(math::FrameAlphaBeta currents, math::FrameAlphaBeta voltages, float angular_velocity, float rotor_angle, const SetBemfParams& set_params, const ExtBemfParams& ext_params) { diff --git a/src/observers/tracker.cpp b/src/observers/tracker.cpp index e9f5da9..d3365d6 100644 --- a/src/observers/tracker.cpp +++ b/src/observers/tracker.cpp @@ -1,6 +1,6 @@ #include -float observers::Tracker::loop(float phase_error, controllers::PIConfig config, const SetTrackerParams& set_params, +float observers::Tracker::loop(float phase_error, const SetTrackerParams& set_params, const ExtTrackerParams& ext_params) { if (set_params.error) @@ -12,6 +12,10 @@ float observers::Tracker::loop(float phase_error, controllers::PIConfig config, return angle_est; } +observers::Tracker::Tracker(controllers::PIConfig config) : config(config) +{ +} + float observers::Tracker::speed_tracker(float angle_est, float Ts) { return angle_integrator.loop(angle_est, Ts);