N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
callbacks.cpp
- Committer:
- bwang
- Date:
- 2015-04-16
- Revision:
- 44:1be63ea70fe8
- Parent:
- 43:fb4b7b0c8f34
- Parent:
- 42:e4f35ff78d91
- Child:
- 45:a478506acc92
File content as of revision 44:1be63ea70fe8:
#include "includes.h" #include "transforms.h" #include "filters.h" #include "context.h" #include "core.h" #include "meta.h" #include "sensors.h" #include "debug.h" void fast(Context *c) { float alpha, beta, d, q, ref_d, ref_q, valpha, vbeta; float I_b, I_c, angle, d_filtered, q_filtered, vd, vq; dbg_ib = I_b = c->motor->GetCurrentB(); dbg_ic = I_c = c->motor->GetCurrentC(); dbg_angle = angle = c->motor->GetPosition(); Clarke(-(I_b + I_c), I_b, &alpha, &beta); Parke(alpha, beta, angle, &d, &q); dbg_d_filtered = d_filtered = c->filter_q->Update(q); //swapped dbg_q_filtered = q_filtered = -c->filter_d->Update(d); //these and added a negative on this line. //The necessary changes were analytically determined by observing that a postive vd command corresponded to a reading of negative q axis torque //and that a positive vq command produced a reading of positive d axis torque. //This may be the final step in aligning the handedness of the reference and the output. c->reference->GetReference(angle, c->user->throttle, &ref_d, &ref_q); dbg_ref_d = ref_d; dbg_ref_q = ref_q; dbg_loop_d = vd = c->pid_d->Update(ref_d, d_filtered); dbg_loop_q = vq = c->pid_q->Update(ref_q, q_filtered); dbg_loop_d = vd = 0.0f; dbg_loop_q = vq = c->user->throttle / 2.0f; /* if(c->user->throttle <= 0.1f){ float ramp = (c->user->throttle*10.0f)*(c->user->throttle*10.0f); vd = ramp*vd; vq = ramp*vq; } dbg_loop_d = vd; dbg_loop_q = vq; */ InverseParke(vd, vq, angle, &valpha, &vbeta); dbg_valpha = valpha; dbg_vbeta = vbeta; c->modulator->Update(valpha, vbeta); } void fast_test(Context *c) { float angle, angle120, angle240; angle = c->motor->GetPosition(); angle120 = angle + 120.0f; if (angle120 >= 360.0f) angle120 -= 360.0f; if (angle120 < 0.0f) angle120 += 360.0f; angle240 = angle -120.0f; if (angle240 >= 360.0f) angle240 -= 360.0f; if (angle240 < 0.0f) angle240 += 360.0f; dbg_dtcA = 0.5f + 0.5f * FastSin(angle) * c->user->throttle; dbg_dtcC = 0.5f + 0.5f * FastSin(angle120) * c->user->throttle; dbg_dtcB = 0.5f + 0.5f * FastSin(angle240) * c->user->throttle; c->inverter->SetDtcA(dbg_dtcA); c->inverter->SetDtcB(dbg_dtcB); c->inverter->SetDtcC(dbg_dtcC); } void fast_test2(Context *c) { float vd, vq; vd = 0.0f; vq = c->user->throttle; InverseParke(vd, vq, angle, &valpha, &vbeta); c->modulator->Update(valpha, vbeta): } void slow(Context *c) { c->user->UpdateThrottle(); //c->user->throttle = c->filter_th->Update(c->user->throttle); } void debug(Context *c) { //c->serial->printf("%f %f %f %f %f %f\n\r", dbg_d_filtered, dbg_q_filtered, dbg_ref_d, dbg_ref_q, dbg_loop_d, dbg_loop_q); //c->serial->printf("%f\n\r", dbg_angle); //c->serial->printf("%f %f %f %f\n\r", c->user->throttle, dbg_dtcA, dbg_dtcB, dbg_dtcC); } void log(Context *c) { //c->debugger->Write(0, dbg_dtc_b); //c->debugger->Write(1, dbg_q_filtered); //c->debugger->Write(1, dbg_dtc_b); //c->debugger->Write(2, dbg_dtc_c); }