New Robotics Code

Dependencies:   mbed-rtos mbed

Fork of Project by Thomas Elliott

Welcome to the robot wiki.

Files at this revision

API Documentation at this revision

Comitter:
IanTheMBEDMaster
Date:
Wed Apr 10 13:16:29 2013 +0000
Parent:
21:c5713aafdc9d
Child:
23:806c9b8af77c
Commit message:
updated some things

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 09 18:11:38 2013 +0000
+++ b/main.cpp	Wed Apr 10 13:16:29 2013 +0000
@@ -61,7 +61,7 @@
 float DR = 0;
 float TSpeedL = 0;
 float TSpeedR = 0;
-float Turn = 0.05;
+float Turn = 0.075;
 float aeW = 0;
 float eW = 0;
 float uW = 0; 
@@ -69,8 +69,8 @@
 
 float Nominal = 35;
 float Kpos = 0.01;
-float Kor = 0.0;
-float KpW = 0.3;
+float Kor = 0.005;
+float KpW = 0.4;
 float KiW = 0.0;
 
 
@@ -201,22 +201,45 @@
                 switch(c)
                 {
                     case('w'):
-                        userSetL = userSetL + 0.075;
-                        userSetR = userSetR + 0.075;
+                        userSetL = userSetL + 0.08;
+                        userSetR = userSetR + 0.08;
                         break;
                     case('s'):
-                        userSetL = userSetL - 0.075;
-                        userSetR = userSetR - 0.075;
+                        userSetL = userSetL - 0.08;
+                        userSetR = userSetR - 0.08;
                         break;
                     case('a'):
-                        userSetL = userSetL - 0.025;
-                        userSetR = userSetR + 0.025;
+                        userSetL = userSetL - 0.04;
+                        userSetR = userSetR + 0.04;
                         break;
                     case('d'):
-                        userSetL = userSetL + 0.025;
-                        userSetR = userSetR - 0.025;
-                        break;               
+                        userSetL = userSetL + 0.04;
+                        userSetR = userSetR - 0.04;
+                        break;          
+                    case('e'):
+                        Ramp(0.4, 500, 0);
+                        break;
+                    case('r'):
+                        Ramp(0, 500, 0);
+                        break;
+                }
+                if (userSetL > 0.5)
+                {
+                    userSetL = 0.5;
                 }
+                if (userSetL < -0.5)
+                {
+                    userSetL = -0.5;
+                }
+                if (userSetR > 0.5)
+                {
+                    userSetR = 0.5;
+                }
+                if (userSetR < -0.5)
+                {
+                    userSetR = -0.5;
+                }
+                
                 continue;
             }
             
@@ -240,10 +263,10 @@
                         Turn = Turn - 0.005;
                         break;
                     case(','):
-                        Nominal = Nominal - 5;
+                        Nominal = Nominal - 2.5;
                         break;
                     case('.'):
-                        Nominal = Nominal + 5;
+                        Nominal = Nominal + 2.5;
                         break; 
                     case('n'):
                         BtS.printf("\n\r Current constants: Ki %.3f:, Kp: %.3f, Kor: %.3f, Kpos: %.3f \n\r Select the constant you wish to change:", KiW, KpW, Kor, Kpos);    
@@ -408,8 +431,6 @@
         led2= !led2; // Alive status
         
         float prevu1, prevu2;
-        //float eL = 0;
-        //float eR = 0;
 
         // Kp = 0.1, Ki = 0.5
         const float Kp = 0.5f;
@@ -654,8 +675,9 @@
 
 void GetSpeeds()
 {
-    float leftMaxPos = 1480.0f;
-    float rightMaxPos = 1480.0f;
+    // when using a interrupt period of 50ms: 1480
+    float leftMaxPos = 1184.0f;
+    float rightMaxPos = 1184.0f;
     
     // Restart the SPI module each time
     SpiStart = 1;
@@ -747,16 +769,6 @@
         DR = 10;
     }
     
-   
-    
-    // TODO: conditions when something is too close to the sensor
-    
-    //if ((DR - prevDR) > 5 || (prevDR - DR) > 5)
-    //{
-    //    DR = prevDR 
-    
-    //
-    
     // calculate errors
     eW = Kpos*(Nominal - (DF + DR)/2) + Kor*(DR - DF);