Motor control

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
4:e7d50c6a7c53
Parent:
3:07fedd2e252c
Child:
5:17aa878564d0
--- a/main.cpp	Fri Oct 11 12:02:22 2019 +0000
+++ b/main.cpp	Fri Oct 11 12:18:08 2019 +0000
@@ -40,6 +40,8 @@
 float u_i;
 float u_d;
 
+//Hidscope
+HIDScope scope(3); //Going to send 3 channels of data. To access data go to 'http:/localhost:18082/' after starting HIDScope application.
 // PC connection
 MODSERIAL pc(USBTX, USBRX);
 
@@ -48,6 +50,7 @@
 Ticker controlTicker;
 Ticker directionTicker;
 Ticker encoderTicker;
+Ticker scopeTicker;
 
 const float PWM_period = 1e-6;
 
@@ -81,6 +84,14 @@
     return u_k+u_i+u_d;    
 }
 
+
+void readEncoder()
+{
+    counts = encoder.getPulses();
+    deltaCounts = counts - countsPrev;
+
+    countsPrev = counts;
+}
 void motorControl()
 {
     angle = counts * factorin / gearratio; // Angle of motor shaft in rad
@@ -100,14 +111,17 @@
     motor1Direction= motordir;
 }
 
-void readEncoder()
+void Plotje()
 {
-    counts = encoder.getPulses();
-    deltaCounts = counts - countsPrev;
+    scope.set(0,u1); //gewenste hoek
+    scope.set(1,angle); //Gemeten hoek
+    scope.set(2,e); //verschil in gewenste en gemeten hoek
 
-    countsPrev = counts;
+    scope.send(); //send what's in scope memory to PC
 }
 
+
+
 int main()
 {
     pc.baud(115200);
@@ -115,8 +129,7 @@
     
     motor1Power.period(PWM_period);
     motorTicker.attach(motorControl, 0.01);
-    
-    
+    scopeTicker.attach(Plotje, 0.01);
     encoderTicker.attach(readEncoder, Ts);
    
     while (true) {