control of polulu motor

Dependencies:   MODSERIAL QEI mbed biquadFilter

Files at this revision

API Documentation at this revision

Comitter:
rubenlucas
Date:
Mon Oct 15 15:08:54 2018 +0000
Parent:
1:76e57b695115
Commit message:
position reference not based anymore on velocity. script works as wanted

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 76e57b695115 -r 0a61483f4515 main.cpp
--- 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
     {