Ben Katz
/
Hobbyking_Cheetah_V1
FOC Implementation for putting multirotor motors in robots
Diff: CurrentRegulator/CurrentRegulator.cpp
- Revision:
- 4:c023f7b6f462
- Parent:
- 3:6a0015d88d06
- Child:
- 5:51c6560bf624
--- a/CurrentRegulator/CurrentRegulator.cpp Wed Mar 09 04:00:48 2016 +0000 +++ b/CurrentRegulator/CurrentRegulator.cpp Sat Mar 12 08:04:51 2016 +0000 @@ -32,9 +32,16 @@ Int_Max = .9; DTC_Max = .97; //theta_elec = _PositionSensor->GetElecPosition(); + //pc = new Serial(PA_2, PA_3); + //pc->baud(115200); } +void CurrentRegulator::SendSPI(){ + + + } + void CurrentRegulator::UpdateRef(float D, float Q){ IQ_Ref = Q; ID_Ref = D; @@ -51,7 +58,7 @@ //IQ_Ref = -IQ_Ref; // } - DAC->DHR12R1 = (int) (I_Q*490.648f) + 2048; + //DAC->DHR12R1 = (int) (I_Q*490.648f) + 2048; //DAC->DHR12R1 = (int) (I_Alpha*4096.0f) + 2048; } @@ -78,8 +85,23 @@ void CurrentRegulator::Commutate(){ + //count += 1; theta_elec = _PositionSensor->GetElecPosition(); SampleCurrent(); //Grab most recent current sample Update(); //Run control loop SetVoltage(); //Set inverter duty cycles + /* + 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)); + count = 0; + } + */ } \ No newline at end of file