James Heavey / Mbed 2 deprecated 3875_DISSERTATION

Dependencies:   mbed 3875_Individualproject

Revision:
2:940e46e21353
Parent:
1:79219d0a33c8
Child:
3:a5e06482462e
diff -r 79219d0a33c8 -r 940e46e21353 main/main.cpp
--- a/main/main.cpp	Wed Feb 05 19:57:48 2020 +0000
+++ b/main/main.cpp	Thu Feb 13 15:28:21 2020 +0000
@@ -24,13 +24,13 @@
 void init();
 void calibrate();
 void follow_line( float speed );
-char junction_detect( unsigned int* sensor );
+char junction_detect();
 void turn_selector( char turn );
 void left();
 void right();
 void back();
-//void goal( char* simple_path );
-//char* simplify( char* path, int path_length );
+void goal();
+void simplify();
 
 // Constants
 
@@ -38,22 +38,27 @@
 const float B = 1/10000;     // 10000
 const float C = 1.5;    // 2/3
 
-// This bit is the main function and is the code that is run when the buggies are powered up
+const int sensor_threshold = 500;
+
+// Global Variables
+
+char path[100];
+int path_length = 0;
+unsigned int *sensor;  
+
+// Main
+
 int main()
 {
     init();
     calibrate();
     float speed = (pot_S*0.4)+0.1;   // have it so max is 0.5 and min is 0.1
-    unsigned int *sensor;  
     
     float proportional = 0.0;
     float prev_proportional = 0.0;
     float integral = 0.0;
     float derivative = 0.0;
     
-    char path[100];
-    int path_length = 0;
-    
     float dt = 1/50;           // updating 50 times a second
     
     while (1) {
@@ -85,10 +90,10 @@
         
         //follow_line(speed);
         
-        char turn = junction_detect(sensor);
+        char turn = junction_detect();
         turn_selector(turn);
         
-        if ( turn != 'S' ) {
+        if ( turn != 'S' ) {              // does need 'S', also may not need 'R' as that is not technically a junction
             path[path_length] = turn;
             path_length ++;
         }
@@ -138,7 +143,7 @@
 
 }
 
-char junction_detect( unsigned int* sensor ) 
+char junction_detect() 
 {
     // add a goal detector
     if ( sensor[0] < 500 && sensor[1] < 500 && sensor[2] < 500 && sensor[3] < 500 && sensor[4] < 500 ) {
@@ -178,7 +183,11 @@
     robot.spin_left(0.2);
     wait(0.32);                              // this wait could be replaced with while statements that wait for sensor3 to become untrigger then retriggered)
     /*while (sensor[3] > 500) {
+        robot.scan();
+        wait(0.1);
         while (sensor[3] < 500) {
+            robot.scan();
+            wait(0.1);
         }
     }*/
     //robot.scan();
@@ -192,6 +201,10 @@
     wait(0.2);
     robot.spin_right(0.2);
     wait(0.32);
+    /*while (sensor[1] > 500) {
+        while (sensor[1] < 500) {
+        }
+    }*/
     //robot.scan();
     //robot.follow_line();
 }
@@ -200,18 +213,28 @@
 {
     leds = 0b1111;
     robot.reverse(0.2);
-    wait(0.1);
+    wait(0.15);
     robot.spin_right(0.2);
     wait(0.6);
+    /*
+    while (sensor[1] < 500) {
+    }
+    */
 }
 
-void goal( char* simple_path )
+void goal()
 {
 
 }
 
-char* simplify( char* path, int path_length )
+void simplify()
 {
+    // check if the last one was a 'B'
+    // if it was, iterate over the last three turns and check the total angle change
+    // replace the three turns with the new single turn
     
-}
-    
\ No newline at end of file
+    if( path[path_length-1] == 'B' ) {
+        int angle_change;
+        
+    }
+}  
\ No newline at end of file