Controller for 1 motor with button control

Dependencies:   MODSERIAL QEI biquadFilter mbed

Fork of Controller by Ruben Lucas

Revision:
2:0a61483f4515
Parent:
1:76e57b695115
Child:
3:f1fc5216f6a5
--- a/main.cpp	Mon Oct 15 14:57:07 2018 +0000
+++ b/main.cpp	Mon Oct 15 15:08:54 2018 +0000
@@ -15,10 +15,8 @@
 DigitalOut DirectionPin(D4);
 AnalogIn Potmeter1(A1);
 AnalogIn Potmeter2(A0);
-DigitalIn button1(D8);
 
 //Global variables
-const double Ts = 0.01; //Sample time of Ticker measure and control (100 Hz)
 volatile bool PrintFlag = false;
 
 //Global variables for printing on screen
@@ -36,21 +34,11 @@
 // Positive velocity (if button is pressed) means clockwise(CW) rotation.
     
 
-    const double MaxVelocity = 6.28; //60 RPM max velocity in rad/s
-    double VelocityRef; // Reference Velocity
+    
     double ValuePot = Potmeter1.read(); // Read value from potmeter (range from 0-1)
-    static double PositionRef = 0; // Initial position value in rad
     
-        if (button1)
-        {
-            VelocityRef = ValuePot*MaxVelocity; //CW
-        }
-        else 
-        {
-            VelocityRef = -1*ValuePot*MaxVelocity; //CCW
-        }
         
-        PositionRef = PositionRef + VelocityRef*Ts;
+        double PositionRef = 3*6.2830*ValuePot - 3*3.1415; // position reference ranging from -1.5 rotations till 1.5 rotations
         
         return PositionRef; //rad
 }
@@ -90,9 +78,9 @@
         DirectionPin = 0;
     }
     
-    if (fabs(MotorValue)>1)
+    if (fabs(MotorValue)>1) // if error more than 1 radian, full duty cycle
     {
-        PwmPin = 1; // if error more than 1 radian, full duty cycle
+        PwmPin = 1; 
     }
     else
     {