Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: main.cpp
- Revision:
- 29:50e6e4e46580
- Parent:
- 28:ed9c1ca386fd
- Child:
- 30:c25c5bf0d951
diff -r ed9c1ca386fd -r 50e6e4e46580 main.cpp --- a/main.cpp Mon Nov 07 10:56:01 2016 +0000 +++ b/main.cpp Mon Nov 07 11:22:25 2016 +0000 @@ -10,6 +10,7 @@ #include "config_loop.h" #include "config_pins.h" #include "config_inverter.h" +#include "config_driving.h" FastPWM *a; FastPWM *b; @@ -73,8 +74,8 @@ if (dp_mech < -PI) dp_mech += 2 * PI; if (dp_mech > PI) dp_mech -= 2 * PI; float w_raw = dp_mech * F_SW; //rad/s - if (w_raw > W_MAX) w_raw = w; //with this limiting scheme noise < 0 - if (w_raw < -W_MAX) w_raw = w; //so we need to throw out the large deltas first + if (w_raw > W_LIMIT) w_raw = w; //with this limiting scheme noise < 0 + if (w_raw < -W_LIMIT) w_raw = w; //so we need to throw out the large deltas first w = W_FILTER_STRENGTH * w + (1.0f - W_FILTER_STRENGTH) * w_raw; } @@ -85,7 +86,9 @@ //fill in d, q ref based on torque cmd and current velocity void get_dq(float torque, float w, float *d, float *q) { *d = 0.0f; - *q = torque / KT < Q_MAX ? torque / KT : Q_MAX; + *q = torque / KT; + if (*q > IPHASE_MOTOR_LIMIT) *q = IPHASE_MOTOR_LIMIT; + if (*q > IPHASE_INVERTER_LIMIT) *q = IPHASE_INVERTER_LIMIT; } void commutate() {