Prius IPM controller

Dependencies:   mbed

Fork of analoghalls5_5 by N K

Committer:
bwang
Date:
Mon Mar 16 15:40:07 2015 +0000
Revision:
35:83cf9564bd0c
Parent:
34:bfe180de813a
Set for 3A Iq, 0A Id, Ki = 1e-3, Kp = Kd = 0, loop still oscillates but is passable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang11:dccbaa9274c5 1#include "includes.h"
bwang11:dccbaa9274c5 2#include "transforms.h"
bwang11:dccbaa9274c5 3#include "filters.h"
bwang11:dccbaa9274c5 4#include "context.h"
bwang11:dccbaa9274c5 5#include "core.h"
bwang11:dccbaa9274c5 6#include "meta.h"
bwang11:dccbaa9274c5 7#include "sensors.h"
bwang24:f1ff9c7256b5 8#include "debug.h"
bwang11:dccbaa9274c5 9
bwang11:dccbaa9274c5 10void fast(Context *c) {
bwang11:dccbaa9274c5 11 float alpha, beta, d, q, ref_d, ref_q, valpha, vbeta;
nki21:da41c08e51bc 12 float I_b, I_c, angle, d_filtered, q_filtered, vd, vq;
bwang24:f1ff9c7256b5 13 dbg_ib = I_b = c->motor->GetCurrentB();
bwang24:f1ff9c7256b5 14 dbg_ic = I_c = c->motor->GetCurrentC();
bwang24:f1ff9c7256b5 15 dbg_angle = angle = c->motor->GetPosition();
bwang24:f1ff9c7256b5 16
bwang24:f1ff9c7256b5 17 Clarke(-(I_b + I_c), I_b, &alpha, &beta);
bwang11:dccbaa9274c5 18 Parke(alpha, beta, angle, &d, &q);
bwang11:dccbaa9274c5 19
nki34:bfe180de813a 20 dbg_d_filtered = d_filtered = c->filter_q->Update(q); //swapped
nki34:bfe180de813a 21 dbg_q_filtered = q_filtered = -c->filter_d->Update(d); //these and added a negative on this line.
nki34:bfe180de813a 22
nki34:bfe180de813a 23 //The necessary changes were analytically determined by observing that a postive vd command corresponded to a reading of negative q axis torque
nki34:bfe180de813a 24 //and that a positive vq command produced a reading of positive d axis torque.
nki34:bfe180de813a 25 //This may be the final step in aligning the handedness of the reference and the output.
bwang11:dccbaa9274c5 26
nki33:e7b132029bae 27 c->reference->GetReference(angle, c->user->throttle, &ref_d, &ref_q);
bwang24:f1ff9c7256b5 28
bwang24:f1ff9c7256b5 29 dbg_ref_d = ref_d;
bwang24:f1ff9c7256b5 30 dbg_ref_q = ref_q;
bwang24:f1ff9c7256b5 31 dbg_loop_d = vd = c->pid_d->Update(ref_d, d_filtered);
bwang24:f1ff9c7256b5 32 dbg_loop_q = vq = c->pid_q->Update(ref_q, q_filtered);
bwang11:dccbaa9274c5 33
nki34:bfe180de813a 34 InverseParke(vd, vq, angle, &valpha, &vbeta);
nki27:846c08fb3697 35
nki34:bfe180de813a 36 dbg_valpha = valpha;
nki34:bfe180de813a 37 dbg_vbeta = vbeta;
bwang11:dccbaa9274c5 38
bwang11:dccbaa9274c5 39 c->modulator->Update(valpha, vbeta);
bwang11:dccbaa9274c5 40}
bwang11:dccbaa9274c5 41
bwang11:dccbaa9274c5 42void slow(Context *c) {
bwang11:dccbaa9274c5 43 c->user->UpdateThrottle();
bwang11:dccbaa9274c5 44}
bwang11:dccbaa9274c5 45
bwang11:dccbaa9274c5 46void debug(Context *c) {
nki30:2b6d426f3bfc 47 //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);
nki34:bfe180de813a 48 //c->serial->printf("%f %f %f %f\n\r", dbg_d_filtered, dbg_q_filtered);
bwang24:f1ff9c7256b5 49}
bwang24:f1ff9c7256b5 50
bwang24:f1ff9c7256b5 51void log(Context *c) {
bwang35:83cf9564bd0c 52 //c->debugger->Write(0, dbg_d_filtered);
bwang35:83cf9564bd0c 53 //c->debugger->Write(1, dbg_q_filtered);
bwang11:dccbaa9274c5 54}