-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bemf observer test and fixed libfoc error
- Loading branch information
1 parent
fde25f3
commit 809c262
Showing
8 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# pragma once | ||
|
||
#include <observers/dq_update.hpp> | ||
#include <observers/tracker.hpp> | ||
#include <math/foc.hpp> | ||
|
||
namespace observers | ||
{ | ||
class bemf_observer | ||
{ | ||
bemf_solver dq_update; | ||
position_tracker tracker; | ||
float speed, angle, Ts; | ||
public: | ||
bemf_observer(const bemf_gains& gains, const controllers::pi_config& update_config, const controllers::pi_config& tracker_config, float Ts); | ||
float loop(math::frame_abc line_currents, math::frame_abc line_voltages); | ||
}; | ||
} // namespace observers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
#include <math/foc.hpp> | ||
#include <math/functions.hpp> | ||
|
||
math::frame_alpha_beta clarke_transform(math::frame_abc X) | ||
math::frame_alpha_beta math::clarke_transform(math::frame_abc X) | ||
{ | ||
math::frame_alpha_beta Y; | ||
Y.alpha = X.a; | ||
Y.beta = (X.b - X.c) * 0.5773; | ||
return Y; | ||
} | ||
|
||
math::frame_dq park_transform(math::frame_alpha_beta X, float angle) | ||
math::frame_dq math::park_transform(math::frame_alpha_beta X, float angle) | ||
{ | ||
math::frame_dq Y; | ||
float cosine = math::cos(angle), sine = math::sin(angle); | ||
Y.d = X.alpha * cosine + X.beta * sine; | ||
Y.q = -X.alpha * sine + X.beta * cosine; | ||
return Y; | ||
} | ||
|
||
math::frame_abc math::inverse_clarke_transform(math::frame_alpha_beta X) | ||
{ | ||
math::frame_abc Y; | ||
Y.a = X.alpha; | ||
Y.b = -0.5 * X.alpha + 0.866 * X.beta; | ||
Y.c = -0.5 * X.alpha - 0.866 * X.beta; | ||
return Y; | ||
} | ||
|
||
math::frame_alpha_beta math::inverse_park_transform(math::frame_dq X, float angle) | ||
{ | ||
math::frame_alpha_beta Y; | ||
float cosine = math::cos(angle), sine = math::sin(angle); | ||
Y.alpha = X.d * cosine - X.q * sine; | ||
Y.beta = X.d * sine + X.q * cosine; | ||
return Y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <observers/bemf_observer.hpp> | ||
|
||
observers::bemf_observer::bemf_observer(const bemf_gains& gains, const controllers::pi_config& update_config, const controllers::pi_config& tracker_config, float Ts) | ||
: dq_update(update_config, gains, Ts), tracker(tracker_config, Ts), Ts(Ts) | ||
{ | ||
} | ||
|
||
float observers::bemf_observer::loop(math::frame_abc line_currents, math::frame_abc line_voltages) | ||
{ | ||
float phase_error = dq_update.loop(line_currents, line_voltages, speed, angle); | ||
float angle_est = tracker.loop(phase_error); | ||
speed = tracker.speed_tracker(angle_est); | ||
angle = angle_est; | ||
return angle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
#include <math/foc.hpp> | ||
#include <observers/bemf_observer.hpp> | ||
#include <observers/dq_update.hpp> | ||
#include <observers/tracker.hpp> | ||
#include <controllers/pi_controller.hpp> | ||
#define Ts 1e-4 | ||
|
||
int main() | ||
{ | ||
observers::bemf_gains gains(1, 1, 1, Ts, 0); | ||
controllers::pi_config update_config = {1, 1, Ts, 180, -180}; | ||
controllers::pi_config tracker_config = {1, 1, Ts, 180,-180}; | ||
observers::bemf_observer bemf_observer(gains, update_config, tracker_config, Ts); | ||
|
||
math::frame_abc line_currents; | ||
math::frame_abc line_voltages; | ||
math::frame_dq U; | ||
|
||
for(float t = 0; t < 10; t += Ts) | ||
{ | ||
float angle = bemf_observer.loop(line_currents, line_voltages); | ||
math::frame_abc duties = math::inverse_clarke_transform(math::inverse_park_transform(U, angle)); | ||
std::cout << "Duties: " << duties.a << " " << duties.b << " " << duties.c << std::endl; | ||
} | ||
} |