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:
24:f1ff9c7256b5
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
bwang 24:f1ff9c7256b5 1 #include "includes.h"
bwang 24:f1ff9c7256b5 2 #include "context.h"
bwang 24:f1ff9c7256b5 3 #include "debug.h"
bwang 24:f1ff9c7256b5 4
bwang 24:f1ff9c7256b5 5 BufferedDebugger::BufferedDebugger(Context *context, int channels, int size) {
bwang 24:f1ff9c7256b5 6 _context = context;
bwang 24:f1ff9c7256b5 7 _size = size;
bwang 24:f1ff9c7256b5 8 _channels = channels;
bwang 24:f1ff9c7256b5 9 _index = (int*)malloc(_channels*sizeof(int));
bwang 24:f1ff9c7256b5 10 for (int i = 0; i < _channels; i++) _index[i] = 0;
bwang 24:f1ff9c7256b5 11 _done = 0;
bwang 24:f1ff9c7256b5 12 _buffer = (float*)malloc(_size * _channels * sizeof(float));
bwang 24:f1ff9c7256b5 13 _context->serial->printf("Debugger channels: %d\n\r", _channels);
bwang 24:f1ff9c7256b5 14 _context->serial->printf("Debugger depth: %d\n\r", _size);
bwang 24:f1ff9c7256b5 15 }
bwang 24:f1ff9c7256b5 16
bwang 24:f1ff9c7256b5 17 void BufferedDebugger::Write(int channel, float f) {
bwang 24:f1ff9c7256b5 18 if (_index[channel] * _channels + channel < _size * _channels) {
bwang 24:f1ff9c7256b5 19 _buffer[_channels * _index[channel] + channel] = f;
bwang 24:f1ff9c7256b5 20 _index[channel]++;
bwang 24:f1ff9c7256b5 21 } else if (!_done) {
bwang 24:f1ff9c7256b5 22 Flush();
bwang 24:f1ff9c7256b5 23 _done = 1;
bwang 24:f1ff9c7256b5 24 }
bwang 24:f1ff9c7256b5 25 }
bwang 24:f1ff9c7256b5 26
bwang 24:f1ff9c7256b5 27 void BufferedDebugger::Flush() {
bwang 24:f1ff9c7256b5 28 _context->inverter->Disable();
bwang 24:f1ff9c7256b5 29 _context->serial->printf("%s\n\r", "--Begin Debug log--");
bwang 24:f1ff9c7256b5 30 for (int i = 0; i < _size; i++) {
bwang 24:f1ff9c7256b5 31 for (int j = 0; j < _channels; j++) {
bwang 24:f1ff9c7256b5 32 _context->serial->printf("%f", _buffer[i * _channels + j]);
bwang 24:f1ff9c7256b5 33 if (j < _channels - 1) _context->serial->printf(", ");
bwang 24:f1ff9c7256b5 34 }
bwang 24:f1ff9c7256b5 35 _context->serial->printf("%\n\r");
bwang 24:f1ff9c7256b5 36 }
bwang 24:f1ff9c7256b5 37 }
bwang 24:f1ff9c7256b5 38
bwang 24:f1ff9c7256b5 39 void BufferedDebugger::Restart() {
bwang 24:f1ff9c7256b5 40 _index = 0;
bwang 24:f1ff9c7256b5 41 _done = 0;
bwang 24:f1ff9c7256b5 42 }
bwang 24:f1ff9c7256b5 43