motor aansturing moet lineair zijn is het niet

Dependencies:   MODSERIAL Encoder mbed HIDScope

Revision:
13:f6ecdd3f6db1
Parent:
12:e3c5c5acbd09
Child:
14:92614abdb7e3
--- a/main.cpp	Mon Oct 05 11:01:30 2015 +0000
+++ b/main.cpp	Mon Oct 05 11:56:30 2015 +0000
@@ -4,7 +4,7 @@
 #include "HIDScope.h"
 
 // Serial pc(USBTX,USBRX);
-HIDScope scope(1);          // definieerd het aantal kanalen van de scope
+HIDScope scope(2);          // definieerd het aantal kanalen van de scope
 
 Ticker          mod;        // definieer de ticker die alles bijhoud.
 
@@ -19,18 +19,11 @@
 //POTMETERS
 AnalogIn potright(A0);
 
-
 double setpoint;
+double rads;
 const double K = 2 ;
 
 
-// send specified data to hidscope
-void send()
-{
-    scope.set(0,setpoint);
-    scope.send();
-}
-
 // counts 2 radians
 // this function takes the counts from the encoder and converts it to 
 // the amount of radians from the zero position.
@@ -56,7 +49,10 @@
 double K_control()
 {
     double setpoint = setpoint_f(potright.read());      // determine the setpoint that has been set by the inputsignal
+    scope.set(0,setpoint);
     double rads = get_radians(motor1_enc.getPosition());    // determine the position of the motor
+    scope.set(1,rads);
+    scope.send();
     double error = (setpoint - rads);                       // determine the error (reference - position)
     double output = K*error;                            // controller output K*e
     return output;
@@ -65,8 +61,8 @@
 // this function controls the input for one of the electric motore and is called by a ticker
 void motor1_control()
 {
-    double output = K_control();
-    if(output > 0) {
+    double output = K_control();        // bereken de controller output (zie hierboven)
+    if(output > 0) {                    // 
         motor1_rich.write(0);
         motor1_aan.write(1);
     } else if(output < 0) {
@@ -75,11 +71,18 @@
     }
 }
 
+// send specified data to hidscope
+// word nu in control loop gedaan
+void send()
+{
+    scope.set(0,setpoint);
+    scope.set(1,rads);
+    scope.send();
+}
 
 int main()
 {
-    double output ;
-    mod.attach(&send,0.01);
+    // mod.attach(&send,0.01);         // send a signal to hidscope
     mod.attach(&motor1_control, 0.1);
     while(true) 
     {