motor aansturing moet lineair zijn is het niet

Dependencies:   MODSERIAL Encoder mbed HIDScope

Revision:
17:d643e5954165
Parent:
16:acf850a87e01
Child:
18:e3b41351ee71
--- a/main.cpp	Wed Oct 07 12:07:37 2015 +0000
+++ b/main.cpp	Wed Oct 07 12:33:19 2015 +0000
@@ -1,10 +1,10 @@
 #include "mbed.h"
-// #include "MODSERIAL.h"
+#include "MODSERIAL.h"
 #include "encoder.h"
-#include "HIDScope.h"
+// #include "HIDScope.h"
 
-// Serial pc(USBTX,USBRX);
-HIDScope scope(4);          // definieerd het aantal kanalen van de scope
+Serial pc(USBTX,USBRX);
+// HIDScope scope(4);          // definieerd het aantal kanalen van de scope
 
 Ticker          controller1, controller2;        // definieer de ticker die controler1 doet
 
@@ -47,6 +47,7 @@
 double Vmax = 5;            // rad/sec
 
 
+
 // counts 2 radians
 // this function takes the counts from the encoder and converts it to 
 // the amount of radians from the zero position.
@@ -66,6 +67,7 @@
     double gain = 2;                // increase the signal
     double potset = (input-offset)*gain;
     double setpoint = c_setpoint + potset * controlstep * Vmax ;
+        c_setpoint = setpoint;
     return setpoint;
 }
 
@@ -101,12 +103,12 @@
 // // // // // // // // // //
 void motor1_control()
 {
-    double setpoint1 = 5 ;// setpoint_f(potright.read(), c_setpoint1);      // determine the setpoint that has been set by the inputsignal
+    double setpoint1 = setpoint_f(potright.read(), c_setpoint1);      // determine the setpoint that has been set by the inputsignal
     double rads1 = get_radians(motor1_enc.getPosition());    // determine the position of the motor
     double error1 = (setpoint1 - rads1);                       // determine the error (reference - position)
-    scope.set(0,setpoint1);
-    scope.set(1,rads1);
-    scope.send();
+    // scope.set(0,setpoint1);
+    // scope.set(1,rads1);
+    // scope.send();
     double output1 = K_control(error1, K1);        // bereken de controller output voor motor 1(zie hierboven)
     if(output1 > 0) {                    // 
         motor1_rich.write(0);
@@ -121,12 +123,12 @@
 // // // // // // //
 void motor2_control()
 {
-    double setpoint2 = 5 ;// setpoint_f(potleft.read(), c_setpoint2);      // determine the setpoint that has been set by the inputsignal
+    double setpoint2 = setpoint_f(potleft.read(), c_setpoint2);      // determine the setpoint that has been set by the inputsignal
     double rads2 = get_radians(motor2_enc.getPosition());    // determine the position of the motor
     double error2 = (setpoint2 - rads2);                       // determine the error (reference - position)
-    scope.set(3,setpoint2);
-    scope.set(4,rads2);
-    scope.send();
+    // scope.set(3,setpoint2);
+    // scope.set(4,rads2);
+    // scope.send();
     double output2 = K_control(error2, K2);        // bereken de controller output voor motor 1(zie hierboven)
     if(output2 > 0) {                    // 
         motor2_rich.write(0);