Prius IPM controller

Dependencies:   mbed

Fork of analoghalls5_5 by N K

Revision:
10:b4abecccec7a
Parent:
9:d3b70c15baa9
Child:
11:dccbaa9274c5
--- 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);