Bayley Wang / Mbed 2 deprecated priustroller

Dependencies:   mbed

Fork of analoghalls5_5 by N K

Files at this revision

API Documentation at this revision

Comitter:
nki
Date:
Tue Mar 03 06:28:10 2015 +0000
Parent:
4:fdadf4a3577a
Child:
6:99ee0ce47fb2
Commit message:
hi there;

Changed in this revision

includes.h Show annotated file Show diff for this revision Revisions of this file
loopdriver.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
modulators.cpp Show annotated file Show diff for this revision Revisions of this file
positionsensors.cpp Show annotated file Show diff for this revision Revisions of this file
referencesynthesizers.cpp Show annotated file Show diff for this revision Revisions of this file
statusupdater.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/includes.h	Mon Mar 02 11:17:15 2015 +0000
+++ b/includes.h	Tue Mar 03 06:28:10 2015 +0000
@@ -3,6 +3,7 @@
 
 #include "mbed.h"
 #include "config.h"
+#include "math.h"
 
 #ifdef __DEBUG
 extern Serial *pc;
--- a/loopdriver.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/loopdriver.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -52,7 +52,7 @@
 float LoopDriver::LutSin(float theta) {
     if (theta < 0.0f) theta += 360.0f;
     if (theta >= 360.0f) theta -= 360.0f;
-    return sinetab[(int) theta];
+    return (sinetab[(int) theta]*2)-1.0f; //shift range 0:1 to -1:1
 }
 
 float LoopDriver::LutCos(float theta) {
@@ -60,11 +60,11 @@
 }
 
 void LoopDriver::update() {
-    _blinky_toggle = !_blinky_toggle;
-    
+    /*
     _inverter->SetDtcA(LutSin(_motor->angle));
     _inverter->SetDtcB(LutSin(_motor->angle - 120.0f));
     _inverter->SetDtcC(LutSin(_motor->angle + 120.0f));
+    */
     
     float alpha, beta, d, q, ref_d, ref_q, valpha, vbeta;
     Clarke(_motor->I_a, _motor->I_b, &alpha, &beta);
@@ -73,4 +73,7 @@
     float vd = _pid_d->Update(ref_d, d);
     float vq = _pid_q->Update(ref_q, q);
     InverseParke(vd, vq, _motor->angle, &valpha, &vbeta);
+    _modulator->Update(valpha, vbeta);
+    
+    
 }
--- a/main.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/main.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -7,7 +7,7 @@
 
 int main() {
     pc->baud(115200);
-    PositionSensor *sense_p = new AnalogHallPositionSensor(A4, A5, 0.256f, 0.484f, 0.254f, 0.474f, 205.0f);
+    PositionSensor *sense_p = new AnalogHallPositionSensor(A4, A5, 0.249f, 0.497f, 0.231f, 0.499f, 200.0f);
     CurrentSensor *sense_ia = new AnalogCurrentSensor(A1, 0.01);
     CurrentSensor *sense_ib = new AnalogCurrentSensor(A2, 0.01);
     VoltageSensor *sense_bus = new AnalogVoltageSensor(A5, 0.01);
@@ -15,8 +15,8 @@
     TempSensor *sense_t_inverter = new TempSensor();
     Throttle *throttle = new Throttle(A0, 0.5f, 3.0f);
     
-    PidController *pid_d = new PidController(1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
-    PidController *pid_q = new PidController (1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
+    PidController *pid_d = new PidController(0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
+    PidController *pid_q = new PidController (0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
     
     Motor *motor = new Motor(sense_ia, sense_ib, sense_p, sense_t_motor);
     Inverter *inverter = new Inverter(D6, D13, D3, D8, sense_bus, sense_t_inverter);
--- a/modulators.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/modulators.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -1,8 +1,8 @@
 #include "includes.h"
 #include "meta.h"
 
-void SinusoidalModulator::Update(float va, float vb) {
-    _inverter->SetDtcA(va);
-    _inverter->SetDtcB(vb);
-    _inverter->SetDtcC(1.0f - va - vb);
+void SinusoidalModulator::Update(float vb, float va) {
+    _inverter->SetDtcC(vb);
+    _inverter->SetDtcA(-vb/2.0f + sqrt(3.0f)/2.0f * va);
+    _inverter->SetDtcB(-vb/2.0f - sqrt(3.0f)/2.0f * va);
 }
\ No newline at end of file
--- a/positionsensors.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/positionsensors.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -40,6 +40,17 @@
     angle -= _offset;
     if (angle < 0.0f) angle += 360.0f;
     if (angle >= 360.0f) angle -= 360.0f;
+    /*
+    #ifdef __DEBUG
+    pc->printf("%f",angle);
+    pc->printf("\t");
+    pc->printf("%f",ascaled);
+    pc->printf("\t");
+    pc->printf("%f",bscaled);
+    pc->printf("\t");
+    pc->printf("\n\r");
+    #endif
+    */
     
     return angle;
 }
\ No newline at end of file
--- a/referencesynthesizers.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/referencesynthesizers.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -10,7 +10,7 @@
 float ReferenceSynthesizer::LutSin(float theta) {
     if (theta < 0.0f) theta += 360.0f;
     if (theta >= 360.0f) theta -= 360.0f;
-    return sinetab[(int) theta];
+    return (sinetab[(int) theta]*2)-1.0f; //shift range 0:1 to -1:1
 }
 
 float ReferenceSynthesizer::LutCos(float theta) {
--- a/statusupdater.cpp	Mon Mar 02 11:17:15 2015 +0000
+++ b/statusupdater.cpp	Tue Mar 03 06:28:10 2015 +0000
@@ -45,10 +45,7 @@
     
     for(;;) {
         
-        #ifdef __DEBUG
-        pc->printf("%f",LutSin(_motor->angle));
-        pc->printf("\n\r");
-        #endif
+        
         
         if (_time - last_fast > fast_us) {
             _motor->UpdateState();