An auto car with 3 IR sensors.

Dependencies:   Ping

Revision:
13:87cd0ae37e06
Parent:
12:e95ed962be7a
Child:
15:1d440beb24d3
--- a/main.cpp	Sat Jun 30 13:08:00 2018 +0000
+++ b/main.cpp	Sun Jul 01 07:58:20 2018 +0000
@@ -8,12 +8,16 @@
 int lastButtonState = 0;
 bool ledState = false;
 
+// PID control params
+int values = 0;
+float Kp = 0.2, Ki = 0.0001, Kd = 1;
+
 // main() runs in its own thread in the OS
 int main()
 {
-    bool left = false;
+    /*bool left = false;
     bool middle = false;
-    bool right = false;
+    bool right = false;*/
 
     // here I use 500 as threshold
     int threshold = 500;
@@ -43,9 +47,11 @@
         if(ledState) {
             // not on track: > 500
             // on track (black): < 500
-            readIR(&left, &middle, &right, threshold);
+            //readIR(&left, &middle, &right, threshold);
+            values = readIRValues(); // read IR values
 
-            driveMotor(left, middle, right);
+            //driveMotor(left, middle, right);
+            driveMotorPID(values, Kp, Ki, Kd);
         }
     }
 }