working-est copy with class-based code. still open loop
Fork of analoghalls6 by
Revision 10:b4abecccec7a, committed 2015-03-08
- Comitter:
- nki
- Date:
- Sun Mar 08 00:45:28 2015 +0000
- Parent:
- 9:d3b70c15baa9
- Commit message:
- uguu;
Changed in this revision
diff -r d3b70c15baa9 -r b4abecccec7a includes.h --- a/includes.h Fri Mar 06 19:12:53 2015 +0000 +++ b/includes.h Sun Mar 08 00:45:28 2015 +0000 @@ -17,5 +17,11 @@ extern float test_DtcB; extern float test_DtcC; +extern float *fbuffer; +extern int acquire; +extern int bufidx; +extern int bufsize; +extern int skip; + using namespace FastMath; #endif \ No newline at end of file
diff -r d3b70c15baa9 -r b4abecccec7a loopdriver.cpp --- a/loopdriver.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/loopdriver.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -89,28 +89,28 @@ d_mean = 0.01f*d + 0.99f*d_mean; q_mean = 0.01f*q + 0.99f*q_mean; - _reference->GetReference(_motor->angle, &ref_d, &ref_q); //this just returns d = 0 and q = 1 right now. doesn't care about angle + _reference->GetReference(_motor->angle, _user->throttle, &ref_d, &ref_q); //this just returns d = 0 and q = 1 right now. doesn't care about angle float vd = _pid_d->Update(ref_d, d_mean); float vq = _pid_q->Update(ref_q, q_mean); - test_alpha = vd; - test_beta = vq; + vd = 0.0f; + vq = _user->throttle; - /* - //overriding PI controller here because we're not actually doing current control yet - //These values are approximately what I saw coming out of the park transform. just feeding them back in here to test the loop - vd = 0.0f; - vq = -1.0f; - */ InverseParke(vd, vq, _motor->angle, &valpha, &vbeta); - + + if(acquire==1){ + if(bufidx < bufsize){ + fbuffer[bufidx] = _motor->angle; + } + else{ + acquire = 0; + } + } _modulator->Update(valpha, vbeta); /* - _inverter->SetDtcA((LutSin(_motor->angle)/2.0f)+0.5f); - _inverter->SetDtcB((LutSin(_motor->angle - 120.0f)/2.0f)+0.5f); - _inverter->SetDtcC((LutSin(_motor->angle + 120.0f)/2.0f)+0.5f); - */ - + test_alpha = valpha; + test_beta = vbeta; + */ }
diff -r d3b70c15baa9 -r b4abecccec7a main.cpp --- a/main.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/main.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -3,6 +3,28 @@ #include "sensors.h" #include "meta.h" +void txCallback() { +} + +// This function is called when a character goes into the RX buffer. +void rxCallback() { + if(pc->getc()=='r'){ + acquire = 1; + pc->putc('3'); + } + if((pc->getc()=='d')&(acquire==0)&(_user->throttle==0)){ + for (int i = 0; i < 10000; i++) { + pc->printf("%f,", fbuffer[i]); + } + } + pc->putc(pc->getc()); +} + + + + + + Serial *pc = new Serial(SERIAL_TX, SERIAL_RX); float test_alpha = 0; float test_beta = 0; @@ -14,9 +36,19 @@ float test_DtcB; float test_DtcC; +float *fbuffer; +int acquire = 0; +int bufidx = 0; +int bufsize = 10000; +int skip = 0; + int main() { pc->baud(115200); + pc->attach(&txCallback, Serial::TxIrq); + pc->attach(&rxCallback, Serial::RxIrq); pc->printf("%s\n\r", "Init Serial Comm"); + + fbuffer = (float*)malloc(bufsize*sizeof(float)); PositionSensor *sense_p = new AnalogHallPositionSensor(A4, A5, 0.249f, 0.497f, 0.231f, 0.499f, 205.0f); CurrentSensor *sense_ic = new AnalogCurrentSensor(A1, 0.01); @@ -24,10 +56,10 @@ VoltageSensor *sense_bus = new AnalogVoltageSensor(A5, 0.01); TempSensor *sense_t_motor = new TempSensor(); TempSensor *sense_t_inverter = new TempSensor(); - Throttle *throttle = new Throttle(A0, 0.5f, 3.0f); + Throttle *throttle = new Throttle(A0, 0.8f, 3.0f); - PidController *pid_d = new PidController(0.0001f, 0.0f, 0.0f, 5.0f, -5.0f); - PidController *pid_q = new PidController (0.0001f, 0.0f, 0.0f, 5.0f, -5.0f); + PidController *pid_d = new PidController(0.001f, 0.1f, 0.0f, 1.0f, -1.0f); + PidController *pid_q = new PidController (0.001f, 0.1f, 0.0f, 5.0f, -5.0f); Motor *motor = new Motor(sense_ic, sense_ib, sense_p, sense_t_motor); Inverter *inverter = new Inverter(D6, D13, D3, D8, sense_bus, sense_t_inverter);
diff -r d3b70c15baa9 -r b4abecccec7a meta.h --- a/meta.h Fri Mar 06 19:12:53 2015 +0000 +++ b/meta.h Sun Mar 08 00:45:28 2015 +0000 @@ -35,7 +35,7 @@ class ReferenceSynthesizer { public: ReferenceSynthesizer(float max_phase_current) {_max_phase_current = max_phase_current;} - virtual void GetReference(float angle, float *ref_d, float *ref_q) {*ref_d = 0; *ref_q = 0;} + virtual void GetReference(float angle, float throttle, float *ref_d, float *ref_q) {*ref_d = 0; *ref_q = 0;} protected: static float LutSin(float theta); static float LutCos(float theta); @@ -46,7 +46,7 @@ class SynchronousReferenceSynthesizer : public ReferenceSynthesizer { public: SynchronousReferenceSynthesizer(float max_phase_current):ReferenceSynthesizer(max_phase_current) {} - virtual void GetReference(float angle, float *ref_d, float *ref_q); + virtual void GetReference(float angle, float throttle, float *ref_d, float *ref_q); }; class StatusUpdater {
diff -r d3b70c15baa9 -r b4abecccec7a modulators.cpp --- a/modulators.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/modulators.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -9,9 +9,14 @@ _inverter->vb = vb; //inverse \alpha \beta (Clarke) transform - _inverter->SetDtcA(va/2.0f + 0.5f); - _inverter->SetDtcB(((-va + sqrt(3.0f)*vb)/2.0f)/2.0f + 0.5f); - _inverter->SetDtcC(((-va - sqrt(3.0f)*vb)/2.0f)/2.0f + 0.5f); + _inverter->SetDtcA(va); + _inverter->SetDtcB(((-va + sqrt(3.0f)*vb)/2.0f)); + _inverter->SetDtcC(((-va - sqrt(3.0f)*vb)/2.0f)); + + /* + test_alpha = va; + test_beta = ((-va + sqrt(3.0f)*vb)/2.0f); + */ /* _inverter->SetDtcA((LutSin(va)/2.0f)+0.5f);
diff -r d3b70c15baa9 -r b4abecccec7a pidcontroller.cpp --- a/pidcontroller.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/pidcontroller.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -11,9 +11,10 @@ _out_min = out_min; } -float PidController::Update(float ref, float in) { - float error = in - ref; - _integral += error; +float PidController::Update(float ref, float in) { //starts positive, integrator is adding up the error to get there. cranking throttle makes it go negative. that makes sense. + float error = ref - in; + //_integral += error; + _integral = 0.0f; if (_integral*_ki > _out_max) _integral = _out_max/_ki; if (_integral*_ki < _out_min) _integral = _out_min/_ki; float deriv = _last_in - in;
diff -r d3b70c15baa9 -r b4abecccec7a referencesynthesizers.cpp --- a/referencesynthesizers.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/referencesynthesizers.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -1,10 +1,12 @@ #include "includes.h" #include "meta.h" +#include "sensors.h" #include "lut.h" +#include "core.h" -void SynchronousReferenceSynthesizer::GetReference(float angle, float *ref_d, float *ref_q) { +void SynchronousReferenceSynthesizer::GetReference(float angle, float throttle, float *ref_d, float *ref_q) { *ref_d = 0.0f; - *ref_q = _max_phase_current; + *ref_q = _max_phase_current*throttle; } float ReferenceSynthesizer::LutSin(float theta) {
diff -r d3b70c15baa9 -r b4abecccec7a statusupdater.cpp --- a/statusupdater.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/statusupdater.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -69,7 +69,16 @@ _motor->UpdateTemp(); _inverter->UpdateTemp(); last_slow = _time; - pc->printf("%f %f\n\r", test_alpha, test_beta); + + + //pc->printf("%f %f\n\r", test_alpha, test_beta); + + /* + for (int i = 0; i < 10000; i++) { + pc.printf("%f,", fbuffer[i]); + } + */ + //pc->printf("%f %f\n\r", _inverter->va, _inverter->vb); }
diff -r d3b70c15baa9 -r b4abecccec7a throttle.cpp --- a/throttle.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/throttle.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -9,5 +9,8 @@ float Throttle::GetThrottle() { float v = _in->GetVoltage(); - return (v - _min) / (_max - _min); + v = (v - _min) / (_max - _min); + if (v > 1.0f) return 1.0f; + if (v < 0.0f) return 0.0f; + return v; } \ No newline at end of file
diff -r d3b70c15baa9 -r b4abecccec7a todo.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/todo.txt Sun Mar 08 00:45:28 2015 +0000 @@ -0,0 +1,3 @@ +serial dump waveforms - particularly d and q + +read in one of the old hall sensor inputs as a button or something. press once to save data. again to dump. \ No newline at end of file