Dependencies:   QEI RemoteIR mbed

Fork of encoder_v2 by Joshua Cheung

Revision:
12:e44dd0d4f1ee
Parent:
11:e647b14ff4ef
diff -r e647b14ff4ef -r e44dd0d4f1ee PID_control.cpp
--- a/PID_control.cpp	Fri Dec 01 03:25:53 2017 +0000
+++ b/PID_control.cpp	Sun Dec 03 00:03:43 2017 +0000
@@ -24,7 +24,7 @@
 PwmOut m_Left_F(PA_7);
 PwmOut m_Left_B(PB_6);
 double i_speed = 0.15;
-double C_speed(0);
+double C_speed = 0;
 int integrator = 0;
 int decayFactor = 1;
 double Error = 0;
@@ -301,23 +301,25 @@
 void testStop() //rev1
 {
     //printf("\nAnalogIn example\n");
-    LF_IRE.write(1);
-    RF_IRE.write(1);
-    forward();  
-    while(1) {
-        if (RF_IRR.read() > turnThreshold && LF_IRR.read() > turnThreshold)
+    LF_IRE.write(1); //turn on Left Front IR LED
+    RF_IRE.write(1); //turn on Right Front IR LED
+    forward(); //move forward slowly
+    while(1) { //loop
+        
+        if (RF_IRR.read() > threshold && LF_IRR.read() > threshold) //IR Receivers will read higher analog values than Threshold if wall is near
         {
-            stop();
+            stop(); //stop the rat
             forwardSlow();
             if (RF_IRR.read() > threshold && LF_IRR.read() > threshold)
             {
                 stop();
                 break;
             }
+            
         }
         float value1 = LF_IRR.read();
         float value2 = RF_IRR.read(); 
-        printf("LF Led: %f\n", value1);
+        printf("LF Led: %f\n", value1); //output the read values from IR Receiver
         wait(0.25);
         printf("RF Led: %f\n\r", value2);
     }
@@ -379,19 +381,20 @@
 int main()
 {
     systicker.attach_us(&systick, 1000);    //rev1
-    
     testStop();
 }
 
 
 
 
+
+
     /*while(RF_IRR.read() * 100000 < 175 && LF_IRR.read() * 100000 < 175) {
         
-        /*meas = LS_IRR.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+        meas = LS_IRR.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
         meas = meas * 100000; // Change the value to be in the 0 to 3300 range
         printf("measure = %.0f mV\n", meas);
-        */
+        
         /*if (meas > 2000) { // If the value is greater than 2V then switch the LED on
           LS_IRE = 1;
         }