motor aansturing moet lineair zijn is het niet

Dependencies:   MODSERIAL Encoder mbed HIDScope

Revision:
12:e3c5c5acbd09
Parent:
11:d31b03b05f59
Child:
13:f6ecdd3f6db1
--- a/main.cpp	Mon Oct 05 10:51:49 2015 +0000
+++ b/main.cpp	Mon Oct 05 11:01:30 2015 +0000
@@ -4,9 +4,9 @@
 #include "HIDScope.h"
 
 // Serial pc(USBTX,USBRX);
-HIDScope scope(1);
+HIDScope scope(1);          // definieerd het aantal kanalen van de scope
 
-Ticker          mod;
+Ticker          mod;        // definieer de ticker die alles bijhoud.
 
 //motor 1 gegevens
 PwmOut motor1_aan(D6);      // PWM signaal motor 2 (uit sheets)
@@ -23,38 +23,46 @@
 double setpoint;
 const double K = 2 ;
 
+
+// send specified data to hidscope
+void send()
+{
+    scope.set(0,setpoint);
+    scope.send();
+}
+
 // counts 2 radians
-double get_radians(double counts)
+// this function takes the counts from the encoder and converts it to 
+// the amount of radians from the zero position.
+double get_radians(double counts)       
 {
     double pi = 3.14159265359;
     double radians = (counts/4200)*2*pi;
     return radians;
 }
 
+
+// this function takes a 0->1 input (in this case a potmeter and converts it
+// to a -2->2 range
 double setpoint_f(double input)
 {
-    double offset = 0.5;
-    double gain = 4;
+    double offset = 0.5;            // offset the inputsignal to -0.5->0.5
+    double gain = 4;                // increase the signal
     double output = (input-offset)*gain;
     return output;
 }
 
+// this function is a simple K control called by the motor function
 double K_control()
 {
-    double setpoint = setpoint_f(potright.read());
-    double rads = get_radians(motor1_enc.getPosition());
-    double error = (setpoint - rads);
-    double output = K*error;
+    double setpoint = setpoint_f(potright.read());      // determine the setpoint that has been set by the inputsignal
+    double rads = get_radians(motor1_enc.getPosition());    // determine the position of the motor
+    double error = (setpoint - rads);                       // determine the error (reference - position)
+    double output = K*error;                            // controller output K*e
     return output;
 }
 
-
-void send()
-{
-    scope.set(0,setpoint);
-    scope.send();
-}
-
+// this function controls the input for one of the electric motore and is called by a ticker
 void motor1_control()
 {
     double output = K_control();