GT ECE 4180 Lab Team - Raj Madisetti and Arjun Sonti

Dependencies:   mbed Servo Motordriver X_NUCLEO_53L0A1 HC_SR04_Ultrasonic_Library

Remote Control Car

Georgia Tech ECE 4180 Embedded Systems Design Final Project

Team Members

Raj Madisetti Arjun Sonti

Revision:
2:5c9526ccb055
Parent:
1:1c1ad0c1c260
Child:
3:4956cc0efdf3
--- a/main.cpp	Sun Nov 15 23:01:55 2020 +0000
+++ b/main.cpp	Tue Nov 17 18:27:13 2020 +0000
@@ -4,7 +4,7 @@
 #include "motordriver.h"
 #include <stdio.h>
 Serial pc(USBTX,USBRX);
-Serial blue(p28,p27);
+Serial blue(p9,p10);
 DigitalOut shdn(p26);
 DigitalOut myled(LED1);      
 
@@ -32,14 +32,6 @@
         pc.printf("Failed to init board! \r\n");
         status = board->init_board();
     }
-    //loop taking and printing distance
-    while (1) {
-        status = board->sensor_centre->get_distance(&distance);
-        if (status == VL53L0X_ERROR_NONE) {
-            pc.printf("D=%ld mm\r\n", distance);
-        }
-    }
-    
     
     
     //Logic for AdaFruit App
@@ -53,22 +45,28 @@
                 if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
                     myled = bnum - '0'; //current button number will appear on LEDs
                     switch (bnum) {
-                        case '1': //AutoPilot Mode
-                            if (bhit=='1') {
-                                //loop taking and printing distance
-                                while (1) {
-                                    status = board->sensor_centre->get_distance(&distance);
-                                    if (distance <= 50) {
-                                        //turn left or right depending on location of sensor
-                                    }
-                                }
-                            break;
+                        //case '1': //AutoPilot Mode
+//                            if (bhit=='1') {
+//                                M.speed(1.0);
+//                                //loop taking and printing distance
+//                                status = board->sensor_centre->get_distance(&distance);
+//                                if (distance <= 50) {
+//                                    //turn left or right depending on location of sensor
+//                                    M.speed(0);
+//                                }
+//                            }
+//                            break;
                         case '5': //forward
                             if (bhit=='1') {
-                                M.speed(1.0); //drive forward
+                                status = board->sensor_centre->get_distance(&distance);
+                                if (distance <= 50) {
+                                    M.speed(1.0); //drive forward
+                                } else {
+                                    M.speed(0.0); //stop
+                                }
                             } else {
                                 M.speed(0.0); //stop
-                            }
+                            }   
                             break;
                         case '6': //reverse
                             if (bhit=='1') {
@@ -87,4 +85,9 @@
                                 S = S + 0.5; //turn right
                             }
                             break;
+                    }
+                }
+            }
+        }
+    }
 }