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
Revision 12:c473a25f54f7, committed 2016-05-22
- Comitter:
- benkatz
- Date:
- Sun May 22 03:38:19 2016 +0000
- Parent:
- 11:c83b18d41e54
- Child:
- 13:a3fa0a31b114
- Commit message:
- experimental feed-forward decoupling;
Changed in this revision
--- 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(){
--- a/CurrentRegulator/CurrentRegulator.h Sun May 22 00:14:59 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.h Sun May 22 03:38:19 2016 +0000
@@ -7,13 +7,13 @@
class CurrentRegulator{
public:
- CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, float Kp, float Ki);
+ CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, PositionSensor *velocity_sensor, float L, float Kp, float Ki);
void UpdateRef(float D, float Q);
void Commutate();
void Reset();
virtual float GetQ();
private:
- float IQ_Ref, ID_Ref, V_Q, V_D, V_Alpha, V_Beta, V_A, V_B, V_C, I_Q, I_D, I_A, I_B, I_C, I_Alpha, I_Beta, theta_elec, _Kp, _Ki;
+ float IQ_Ref, ID_Ref, V_Q, V_D, V_Alpha, V_Beta, V_A, V_B, V_C, I_Q, I_D, I_A, I_B, I_C, I_Alpha, I_Beta, theta_elec, _Kp, _Ki, _L;
float Q_Integral, D_Integral, Q_Error, D_Error, Int_Max, DTC_Max, Q_Max;
void SampleCurrent();
void SetVoltage();
@@ -21,6 +21,7 @@
void SendSPI();
Inverter* _Inverter;
PositionSensor* _PositionSensor;
+ PositionSensor* _VelocitySensor;
SVM* PWM;
//Serial* pc;
int count;
--- a/PositionSensor/PositionSensor.cpp Sun May 22 00:14:59 2016 +0000
+++ b/PositionSensor/PositionSensor.cpp Sun May 22 03:38:19 2016 +0000
@@ -140,9 +140,7 @@
}
float PositionSensorEncoder::GetElecVelocity(){
- float rawPeriod = TIM2->CCR1; //Clock Ticks
- float dir = (((TIM3->CR1)>>4)&1)*2-1; // +/- 1
- return dir*_ppairs*90000000.0f*(6.28318530718f/(float)_CPR)/rawPeriod;
+ return _ppairs*GetMechVelocity();
}
float PositionSensorEncoder::GetMechVelocity(){
--- a/main.cpp Sun May 22 00:14:59 2016 +0000 +++ b/main.cpp Sun May 22 03:38:19 2016 +0000 @@ -28,7 +28,7 @@ -CurrentRegulator foc(&inverter, &spi, .005, .5); +CurrentRegulator foc(&inverter, &spi, &encoder, 0.000033, .005, .5); TorqueController torqueController(.031f, &foc); ImpedanceController impedanceController(&torqueController, &spi, &encoder);