motor aansturing moet lineair zijn is het niet

Dependencies:   MODSERIAL Encoder mbed HIDScope

Revision:
16:acf850a87e01
Parent:
15:a90c450b1e0e
Child:
17:d643e5954165
--- a/main.cpp	Tue Oct 06 18:12:47 2015 +0000
+++ b/main.cpp	Wed Oct 07 12:07:37 2015 +0000
@@ -39,6 +39,13 @@
 const double K1 = 1 ;       // P constant motorcontrolle 1
 const double K2 = 1;        // p constant motorcontroller 2
 
+// define storage variables for setpoint values
+double c_setpoint1 = 0;
+double c_setpoint2 = 0;
+
+// define the maximum rate of change for the setpoint (velocity)
+double Vmax = 5;            // rad/sec
+
 
 // counts 2 radians
 // this function takes the counts from the encoder and converts it to 
@@ -53,12 +60,13 @@
 
 // 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 setpoint_f(double input, double &c_setpoint)
 {
     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;
+    double gain = 2;                // increase the signal
+    double potset = (input-offset)*gain;
+    double setpoint = c_setpoint + potset * controlstep * Vmax ;
+    return setpoint;
 }
 
 // this function is a simple K control called by the motor function
@@ -93,7 +101,7 @@
 // // // // // // // // // //
 void motor1_control()
 {
-    double setpoint1 = setpoint_f(potright.read());      // determine the setpoint that has been set by the inputsignal
+    double setpoint1 = 5 ;// 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);
@@ -113,7 +121,7 @@
 // // // // // // //
 void motor2_control()
 {
-    double setpoint2 = setpoint_f(potleft.read());      // determine the setpoint that has been set by the inputsignal
+    double setpoint2 = 5 ;// 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);