motor controller with P velocity control
Dependencies: HIDScope PID QEI mbed EMG
Fork of PID_VelocityExample by
Diff: main.cpp
- Revision:
- 22:ae8012b12890
- Parent:
- 20:8064435d21da
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.