ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot by ECE4333 - 2018 - Ahmed & Brandon

Files at this revision

API Documentation at this revision

Comitter:
asobhy
Date:
Sat Feb 03 00:37:57 2018 +0000
Parent:
1:3e9684e81312
Child:
3:4def4ca68910
Commit message:
before trying a different control algorithm

Changed in this revision

PiControlThread.cpp Show annotated file Show diff for this revision Revisions of this file
ui.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PiControlThread.cpp	Sat Feb 03 00:05:08 2018 +0000
+++ b/PiControlThread.cpp	Sat Feb 03 00:37:57 2018 +0000
@@ -58,7 +58,7 @@
     // in seconds between interrupts, and start interrupt generation:
     PeriodicInt.attach(&PeriodicInterruptISR, 0.05);   // 50ms sampling rate
     
-    Kp = 2;
+    Kp = 2.2;
     Ki = 0.01;
     
 }
@@ -85,7 +85,7 @@
         vel = (float)((6135.92 * dPosition) / dTime) ;
         
         setpoint_mutex.lock();
-        e = SaturatingSubtract(setpoint, vel);  // e is the velocity error
+        e = SaturatingSubtract(setpoint, dPosition);  // e is the velocity error
         setpoint_mutex.unlock();
         
         // disable integration if u is saturated
--- a/ui.cpp	Sat Feb 03 00:05:08 2018 +0000
+++ b/ui.cpp	Sat Feb 03 00:37:57 2018 +0000
@@ -14,15 +14,16 @@
 char x;
 
 extern int16_t dPosition, dTime;
-
 extern float Ki; 
 extern float Kp;
-
 extern int vel;
+extern int32_t e;
+extern int32_t xState;
+extern int32_t u;
 
 int16_t position;
 
-extern int32_t e;
+
 
 /******************************************************************************
             A function to test blutooth communication
@@ -109,7 +110,7 @@
         }
     }
     position += dPosition;
-    bluetooth.printf("\r\nPos: %d, dP: %d, dT: %d, Kp: %f, Ki: %f, vel: %d, e: %d", position, dPosition, dTime, Kp, Ki, vel, e);
+    bluetooth.printf("\r\nPos: %d, dP: %d, dT: %d, Kp: %f, Ki: %f, vel: %d, e: %d", position, dPosition, xState, dTime, Kp, Ki, vel, e);
     
 }
 
@@ -135,7 +136,7 @@
         // by incrementing u
         else if(x == 'w') {
             setpoint_mutex.lock();
-            if ( setpoint < 703 ) 
+            if ( setpoint < 506 ) 
             {
                 //setpoint = setpoint + SPEED_STEP;
                 setpoint = 200;
@@ -151,7 +152,7 @@
         else if(x == 's') {
 
             setpoint_mutex.lock();
-            if (setpoint > -703) 
+            if (setpoint > -560) 
             {
                 setpoint = -200;
                 //setpoint = setpoint - SPEED_STEP;
@@ -186,7 +187,11 @@
     }   
     
     position += dPosition;
+    
     //bluetooth.printf("\r\nPos: %d, dP: %d, dT: %d, Kp: %f, Ki: %f, vel: %d, e: %d", position, dPosition, dTime, Kp, Ki, vel, e);
-    bluetooth.printf("\r\nKp: %f, Ki: %f, vel: %d, e: %d", Kp, Ki, vel, e);
+    
+    bluetooth.printf("\r\ndP: %d, vel: %d, Kp: %f, Ki: %f, e: %d, xState: %d", dPosition, vel, Kp, Ki, e, xState);
+    
+    //bluetooth.printf("\r\ne: %d, Pos: %d, dP: %d, xState: %d, u: %d, dT: %d", e, position, dPosition, xState, u, dTime);
     
 }