stock mbed AnalogReads current loop closed and working

Dependencies:   mbed

Fork of priustroller_2 by N K

Files at this revision

API Documentation at this revision

Comitter:
bwang
Date:
Sun Jan 31 06:44:58 2016 +0000
Parent:
55:f102d271e808
Commit message:
latest rev

Changed in this revision

callbacks.cpp Show annotated file Show diff for this revision Revisions of this file
context.cpp Show annotated file Show diff for this revision Revisions of this file
core/inverter.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
--- a/callbacks.cpp	Thu May 21 02:19:25 2015 +0000
+++ b/callbacks.cpp	Sun Jan 31 06:44:58 2016 +0000
@@ -9,12 +9,18 @@
 
 void fast(Context *c) {
     float alpha, beta, d, q, ref_d, ref_q, valpha, vbeta;
-    float I_b, I_c, angle, d_filtered, q_filtered, vd, vq;
+    float I_b, I_c, angle, d_filtered, q_filtered, vd, vq, speed;
     dbg_ib = I_b = c->motor->GetCurrentB();
     dbg_ic = I_c = c->motor->GetCurrentC();
     dbg_angle = angle = c->motor->GetPosition();
     float speed_raw = c->motor->GetSpeed();
-    dbg_speed = c->filter_sp->Update(speed_raw);
+    dbg_speed = speed = c->filter_sp->Update(speed_raw);
+    //float delta = speed / 5.0f;
+    float delta = 0.0f;
+    if (delta > 70.0f) delta = 70.0f;
+    angle += delta;
+    if (angle >= 360.0f) angle -= 360.0f;
+    if (angle < 0.0f) angle += 360.0f;
     
     Clarke(-(I_b + I_c), I_b, &alpha, &beta);
     Parke(alpha, beta, angle, &d, &q);
@@ -74,7 +80,7 @@
 
 void log(Context *c) {
     //c->debugger->Write(0, dbg_speed);
-    //c->debugger->Write(1, dbg_q_filtered);
-    //c->debugger->Write(2, dbg_d_filtered);
-    //c->debugger->Write(3, dbg_angle);
+    //c->debugger->Write(1, dbg_ib);
+    //c->debugger->Write(2, dbg_ic);
+    //c->debugger->Write(3, dbg_q_filtered);
 }
\ No newline at end of file
--- a/context.cpp	Thu May 21 02:19:25 2015 +0000
+++ b/context.cpp	Sun Jan 31 06:44:58 2016 +0000
@@ -110,7 +110,7 @@
     filter_d = new MeanFilter(_filter_strength);
     filter_q = new MeanFilter(_filter_strength);
     filter_th = new MeanFilter(_th_filter_strength);
-    filter_sp = new MeanFilter(0.99);
+    filter_sp = new MeanFilter(0.999);
     
     
     serial = new Serial(USBTX, USBRX);
--- a/core/inverter.cpp	Thu May 21 02:19:25 2015 +0000
+++ b/core/inverter.cpp	Sun Jan 31 06:44:58 2016 +0000
@@ -9,9 +9,9 @@
     _pwm_a = new PwmOut(ph_a);
     _pwm_b = new PwmOut(ph_b);
     _pwm_c = new PwmOut(ph_c);
-    _pwm_a->period_us(200);
-    _pwm_b->period_us(200);
-    _pwm_c->period_us(200);
+    _pwm_a->period_us(100);
+    _pwm_b->period_us(100);
+    _pwm_c->period_us(100);
     
     _sense_bus = sense_bus;
     _sense_t = sense_t;
--- a/main.cpp	Thu May 21 02:19:25 2015 +0000
+++ b/main.cpp	Sun Jan 31 06:44:58 2016 +0000
@@ -11,11 +11,11 @@
     Context *context = new Context();
     context->ConfigureOutputs(D13, D3, D6, D2);
     context->ConfigureCurrentSensors(A1, A2, 0.0016f, 0.7f); //scale in V/A, filter strength
-    context->ConfigureIdPidController(0.0000032f, 0.0f, 0.0f, 1.0f, -1.0f);
-    context->ConfigureIqPidController(0.0000032f, 0.0f, 0.0f, 1.0f, -1.0f);
+    context->ConfigureIdPidController(0.0000012f, 0.0f, 0.0f, 1.0f, -1.0f);
+    context->ConfigureIqPidController(0.0000012f, 0.0f, 0.0f, 1.0f, -1.0f);
     context->ConfigureThrottle(A0, 0.9f, 2.5f, 0.99f);  //last term is LPF strength
-    context->ConfigurePositionSensor(A3, A4, 0.366f, 0.655f, 0.355f, 0.626f, 275.0f); //205 is default
-    context->ConfigureReference(200.0f);  // max phase current
+    context->ConfigurePositionSensor(A3, A4, 0.366f, 0.655f, 0.355f, 0.626f, 260.0f); //205 is default
+    context->ConfigureReference(300.0f);  // max phase current
     context->ConfigureDebugger(4, 2000);
     context->AttachCallBack(&fast, 5000);
     context->AttachCallBack(&slow, 10);