working-est copy with class-based code. still open loop

Dependencies:   mbed

Fork of analoghalls6 by N K

Revision:
4:fdadf4a3577a
Parent:
1:1f58bdcf2956
Child:
5:ee1e6c84c302
--- a/statusupdater.cpp	Mon Mar 02 01:24:37 2015 +0000
+++ b/statusupdater.cpp	Mon Mar 02 11:17:15 2015 +0000
@@ -2,12 +2,13 @@
 #include "core.h"
 #include "sensors.h"
 #include "meta.h"
+#include "lut.h"
 
 unsigned long StatusUpdater::_time;
 
 StatusUpdater::StatusUpdater(Inverter *inverter, Motor *motor, User *user) {
     _inverter = inverter;
-    _motor = _motor;
+    _motor = motor;
     _user = user;
     _fast_sample_rate = 5000;
     _slow_sample_rate = 10;
@@ -21,7 +22,17 @@
 }
 
 void StatusUpdater::time_upd_isr() {
-    _time++;
+    _time+= 50;
+}
+
+float StatusUpdater::LutSin(float theta) {
+    if (theta < 0.0f) theta += 360.0f;
+    if (theta >= 360.0f) theta -= 360.0f;
+    return sinetab[(int) theta];
+}
+
+float StatusUpdater::LutCos(float theta) {
+    return LutSin(90.0f - theta);
 }
 
 void StatusUpdater::Start() {
@@ -32,17 +43,25 @@
     int last_fast = 0;
     int last_slow = 0;
     
-    for (;;) {
+    for(;;) {
+        
+        #ifdef __DEBUG
+        pc->printf("%f",LutSin(_motor->angle));
+        pc->printf("\n\r");
+        #endif
+        
         if (_time - last_fast > fast_us) {
             _motor->UpdateState();
             _inverter->UpdateVbus();
             last_fast = _time;
         }
+        
         if (_time - last_slow > slow_us) {
             _user->UpdateState();
             _motor->UpdateTemp();
             _inverter->UpdateTemp();
             last_slow = _time;
         }
+ 
     }
 }
\ No newline at end of file