FOC Implementation for putting multirotor motors in robots

Dependencies:   FastPWM3 mbed

Revision:
7:dc5f27756e02
Parent:
6:4ee1cdc43aa8
Child:
8:10ae7bc88d6e
--- a/CurrentRegulator/CurrentRegulator.cpp	Sat Mar 12 19:55:52 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.cpp	Tue Mar 29 01:05:46 2016 +0000
@@ -9,9 +9,9 @@
 
 CurrentRegulator::CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, float Kp, float Ki){
     _Inverter = inverter;
-    PWM = new SVPWM(inverter, 2.0);
+    PWM = new SPWM(inverter, 2.0);
     _PositionSensor = position_sensor;
-    IQ_Ref = .5;
+    IQ_Ref = 2;
     ID_Ref = 0;
     V_Q = 0;
     V_D = 0;
@@ -79,6 +79,7 @@
          
         V_Q = Q_Integral + _Kp*Q_Error;
         V_D = D_Integral + _Kp*D_Error;
+        //V_D = 0;
         
         
     }
@@ -93,10 +94,13 @@
     
 void CurrentRegulator::Commutate(){
     //count += 1;
+    GPIOC->ODR = (1 << 4); //Toggle pin for debugging
     theta_elec = _PositionSensor->GetElecPosition();
     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));