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:
- 8:10ae7bc88d6e
- Parent:
- 7:dc5f27756e02
- Child:
- 9:d7eb815cb057
--- a/CurrentRegulator/CurrentRegulator.cpp Tue Mar 29 01:05:46 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.cpp Wed Apr 13 04:09:56 2016 +0000
@@ -11,7 +11,7 @@
_Inverter = inverter;
PWM = new SPWM(inverter, 2.0);
_PositionSensor = position_sensor;
- IQ_Ref = 2;
+ IQ_Ref = 0;
ID_Ref = 0;
V_Q = 0;
V_D = 0;
@@ -27,7 +27,7 @@
I_C = 0;
I_Alpha = 0;
I_Beta = 0;
- //count = 0;
+ count = 0;
_Kp = Kp;
_Ki = Ki;
Q_Integral = 0;
@@ -35,9 +35,9 @@
Int_Max = .9;
DTC_Max = .97;
//theta_elec = _PositionSensor->GetElecPosition();
- //pc = new Serial(PA_2, PA_3);
- //pc->baud(115200);
-
+ pc = new Serial(PA_2, PA_3);
+ pc->baud(115200);
+
}
void CurrentRegulator::SendSPI(){
@@ -93,26 +93,20 @@
void CurrentRegulator::Commutate(){
- //count += 1;
+ count += 1;
GPIOC->ODR = (1 << 4); //Toggle pin for debugging
theta_elec = _PositionSensor->GetElecPosition();
+ _PositionSensor->GetMechPosition();
SampleCurrent(); //Grab most recent current sample
Update(); //Run control loop
SetVoltage(); //Set inverter duty cycles
GPIOC->ODR = (0 << 4); //Toggle pin for debugging
/*
- if (count==500){
- //printf("%d %d %d %d\n\r", (int) (I_Q*1000), (int) (I_D*1000), (int) (I_A*1000), int (I_B*1000));
- pc->putc((unsigned char) (theta_elec*40.0f));
- pc->putc((unsigned char) (I_A*100.0f+127));
- pc->putc((unsigned char) (I_B*100.0f+127));
- pc->putc((unsigned char) (I_Alpha*100.0f+127));
- pc->putc((unsigned char) (I_Beta*100.0f+127));
- pc->putc((unsigned char) (I_Q*100.0f+127));
- pc->putc((unsigned char) (I_D*100.0f+127));
- pc->putc((0xff));
+ if (count==1000){
+ pc->printf("%f\n\r", _PositionSensor->GetMechPosition());
count = 0;
}
*/
+
}
\ No newline at end of file