Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dev-f303 FastPWM3
Diff: CurrentRegulator/CurrentRegulator.cpp
- Revision:
- 12:c473a25f54f7
- Parent:
- 11:c83b18d41e54
- Child:
- 13:a3fa0a31b114
--- a/CurrentRegulator/CurrentRegulator.cpp Sun May 22 00:14:59 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.cpp Sun May 22 03:38:19 2016 +0000
@@ -7,10 +7,11 @@
using namespace Transforms;
-CurrentRegulator::CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, float Kp, float Ki){
+CurrentRegulator::CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, PositionSensor *velocity_sensor, float L, float Kp, float Ki){
_Inverter = inverter;
PWM = new SVPWM(inverter, 2.0);
_PositionSensor = position_sensor;
+ _VelocitySensor = velocity_sensor;
IQ_Ref = 0;
Q_Max = 40.0f;
ID_Ref = 0;
@@ -29,6 +30,7 @@
I_Alpha = 0;
I_Beta = 0;
count = 0;
+ _L = L;
_Kp = Kp;
_Ki = Ki;
Q_Integral = 0;
@@ -108,6 +110,7 @@
void CurrentRegulator::Update(){
float Q_Error = IQ_Ref - I_Q;
float D_Error = ID_Ref - I_D;
+ float w_elec = _velocitySensor.GetElecVelocity();
Q_Integral += Q_Error*_Ki*_Kp;
D_Integral += D_Error*_Ki*_Kp;
@@ -118,7 +121,9 @@
else if(D_Integral < -Int_Max) D_Integral = -Int_Max;
V_Q = Q_Integral + _Kp*Q_Error;
- V_D = D_Integral + _Kp*D_Error;
+ //V_Q = V_Q - w_elec*I_D;
+ V_D = D_Integral + _Kp*D_Error;
+ //V_D = V_D + w_elec*I_Q; //decoupling needs moar testing
}
void CurrentRegulator::SetVoltage(){