Counts and Derivative of counts working in Putty, first changes for HIDScope made.

Dependencies:   MODSERIAL QEI mbed HIDScope

Revision:
2:915abd97ac16
Parent:
1:812a1637b6cb
diff -r 812a1637b6cb -r 915abd97ac16 main.cpp
--- a/main.cpp	Tue Oct 11 11:28:07 2016 +0000
+++ b/main.cpp	Tue Oct 11 11:38:43 2016 +0000
@@ -2,6 +2,7 @@
 #include <math.h>
 #include "MODSERIAL.h"
 #include "QEI.h"
+#include "HIDScope.h"
 
 DigitalIn encoder1A (D13); //Channel A van Encoder 1
 DigitalIn encoder1B (D12); //Channel B van Encoder 1
@@ -14,18 +15,19 @@
 
 
 Serial pc(USBTX,USBRX);
-Ticker MeasureTicker, sampleT, TimeTracker;
+Ticker MeasureTicker;// sampleT, TimeTracker;
+HIDScope    scope(2);
 int counts;
-float DerivativeCounts;
+double DerivativeCounts;
 int countsPrev = 0;
 
 float referenceVelocity = 0;
 
-volatile bool MeasureTicker_go=false, TimeTracker_go=false, sampleT_go=false;
+volatile bool MeasureTicker_go=false;// TimeTracker_go=false, sampleT_go=false;
 
 void MeasureTicker_act(){MeasureTicker_go=true;}; // Activates go-flags
-void TimeTracker_act(){TimeTracker_go=true;};
-void sampleT_act(){sampleT_go=true;};
+//void TimeTracker_act(){TimeTracker_go=true;};
+//void sampleT_act(){sampleT_go=true;};
 
 float GetReferenceVelocity()
 {
@@ -75,13 +77,6 @@
     float referenceVelocity = GetReferenceVelocity();
     float motorValue = FeedForwardControl(referenceVelocity);
     SetMotor1(motorValue);
-    //int countsPrev = 0;
-    /* QEI Encoder(D12, D13, NC, 32); // turns on encoder
-    counts = Encoder.getPulses();  // gives position
-    DerivativeCounts = ((float) counts-countsPrev)/0.01;
-    countsPrev = counts; 
-    pc.printf("Counts: %i rad/s \r\n", counts);
-    pc.printf("Derivative Counts: %d rad/s \r\n", DerivativeCounts);*/
 }
 
 void TimeTrackerF(){
@@ -114,12 +109,12 @@
  led2=0;
  float Potmeter = potMeterIn.read();
  MeasureTicker.attach(&MeasureTicker_act, 0.01f); 
- TimeTracker.attach(&TimeTracker_act, 0.1f);
+ //TimeTracker.attach(&TimeTracker_act, 0.1f);
  pc.baud(115200);  
  QEI Encoder(D12, D13, NC, 32); // turns on encoder
  //sampleT.attach(&sampleT_act, 0.1f);
- pc.printf("Reference velocity: %f rad/s \r\n", referenceVelocity);
- pc.printf("Potmeter: %f rad/s \r\n", Potmeter);
+ //pc.printf("Reference velocity: %f rad/s \r\n", referenceVelocity);
+ //pc.printf("Potmeter: %f rad/s \r\n", Potmeter);
  
  while(1)
     {
@@ -128,19 +123,19 @@
             MeasureAndControl();
             // Encoder part
             counts = Encoder.getPulses();  // gives position
-            DerivativeCounts = ((float) counts-countsPrev)/0.01;
+            DerivativeCounts = ((double) counts-countsPrev)/0.01;
             countsPrev = counts;
             scope.set(0,counts);
             scope.set(1,DerivativeCounts);
             scope.send();countsPrev = counts; 
-            pc.printf("Counts: %i rad/s \r\n", counts);
-            pc.printf("Derivative Counts: %f rad/s \r\n", DerivativeCounts);
+            //pc.printf("Counts: %i rad/s \r\n", counts);
+            //pc.printf("Derivative Counts: %f rad/s \r\n", DerivativeCounts);
         }
-        if (TimeTracker_go){
+        /*if (TimeTracker_go){
             TimeTracker_go=false;
             TimeTrackerF();
         }
-        /*if (sampleT_go){
+        if (sampleT_go){
             sampleT_go=false;
             sample();
         }*/