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.
Fork of priustroller_2 by
callbacks.cpp
- Committer:
- bwang
- Date:
- 2015-04-16
- Revision:
- 39:6f3d08745cd9
- Parent:
- 38:232c51b6853f
- Child:
- 40:b2bd9a097e3f
- Child:
- 42:e4f35ff78d91
File content as of revision 39:6f3d08745cd9:
#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 (angle120 >= 360.0f) angle240 -= 360.0f; if (angle120 < 0.0f) angle240 += 360.0f; c->inverter->SetDtcA(0.5f + 0.5f * FastSin(angle) * c->user->throttle); c->inverter->SetDtcB(0.5f + 0.5f * FastSin(angle120) * c->user->throttle); c->inverter->SetDtcC(0.5f + 0.5f * FastSin(angle240) * c->user->throttle); } 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\n\r", c->user->throttle); } 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); }