motor controller with P velocity control

Dependencies:   HIDScope PID QEI mbed EMG

Fork of PID_VelocityExample by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
ewoud
Date:
Mon Oct 12 09:33:34 2015 +0000
Parent:
21:4ddbe49c258a
Commit message:
integration issues

Changed in this revision

EMG.lib Show annotated file Show diff for this revision Revisions of this file
inits.h 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
diff -r 4ddbe49c258a -r ae8012b12890 EMG.lib
--- a/EMG.lib	Mon Oct 12 08:48:43 2015 +0000
+++ b/EMG.lib	Mon Oct 12 09:33:34 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Numero-Uno/code/EMG/#b5f7b64b0fe4
+https://developer.mbed.org/teams/Numero-Uno/code/EMG/#84ff5b0f5406
diff -r 4ddbe49c258a -r ae8012b12890 inits.h
--- a/inits.h	Mon Oct 12 08:48:43 2015 +0000
+++ b/inits.h	Mon Oct 12 09:33:34 2015 +0000
@@ -10,7 +10,7 @@
 // Globals
 //****************************************************************************/
 Serial pc(USBTX, USBRX);
-HIDScope    scope(3);        // Instantize a 2-channel HIDScope object
+HIDScope    scope(2);        // Instantize a 2-channel HIDScope object
 Ticker      scopeTimer;      // Instantize the timer for sending data to the PC 
 InterruptIn startButton(D3);
 InterruptIn stopButton(D2);
diff -r 4ddbe49c258a -r ae8012b12890 main.cpp
--- a/main.cpp	Mon Oct 12 08:48:43 2015 +0000
+++ b/main.cpp	Mon Oct 12 09:33:34 2015 +0000
@@ -3,11 +3,13 @@
 #include "PID.h"
 #include "QEI.h"
 #include "HIDScope.h"
+
+#include "inits.h" // all globals, pin and variable initialization 
 #include "EMG.h"
-#include "inits.h" // all globals, pin and variable initialization 
 
 void setGoFlag(){
     if (goFlag==true){
+        //pc.printf("rate too high, error in setGoFlag \n\r");
         // flag is already set true: code too slow or frequency too high    
     }
     goFlag=true;
@@ -36,11 +38,6 @@
     
     endTimer.start(); //Run for 100 seconds.
     while (true){
-        if(sample_go && systemOn==true)
-        {
-            sample_filter();
-            sample_go = 0;
-        }
         if (goFlag==true && systemOn==true){
             // get 'emg' signal
             request_pos=y1;
@@ -97,14 +94,22 @@
             }
             
             // User feedback
-            scope.set(0, request);
-            scope.set(1, leftPwmDuty);
-            scope.set(2, leftVelocity);
-            scope.send();
+            //scope.set(0, request);
+            //scope.set(1, leftPwmDuty);
+            //scope.set(2, leftVelocity);
+            //scope.send();
             pc.printf("pot2: %f, request: %f, lefVelocity: %f, output: %f \n\r",pot2.read(),request,leftVelocity,leftPwmDuty);
         
             goFlag=false;
         }
+        if(sample_go && systemOn==true)
+        {
+            sample_filter();
+            scope.set(0, y1);
+            scope.set(1, y2);
+            scope.send();
+            sample_go = 0;
+        }
     }
 
     //Stop motors.