Spring 2014, ECE 4180 project, Georgia Institute of Technolgoy. This is the human driver (RF controller) program for the Robotics Cat and Mouse program.

Dependencies:   ADXL345_I2C_NEST HMC6352 IMUfilter ITG3200_NEST USBHost mbed-rtos mbed

Fork of Project by Ganesh Subramaniam

Files at this revision

API Documentation at this revision

Comitter:
Strikewolf
Date:
Wed Apr 30 12:23:04 2014 +0000
Parent:
5:210cd333f770
Commit message:
Final product before demo

Changed in this revision

ADXL345_I2C.lib Show annotated file Show diff for this revision Revisions of this file
AI.cpp Show annotated file Show diff for this revision Revisions of this file
AIControl.h Show annotated file Show diff for this revision Revisions of this file
AIPosition.h Show annotated file Show diff for this revision Revisions of this file
GameCode.h Show annotated file Show diff for this revision Revisions of this file
ITG3200.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 210cd333f770 -r 3fb9f96765f6 ADXL345_I2C.lib
--- a/ADXL345_I2C.lib	Wed Apr 30 05:53:51 2014 +0000
+++ b/ADXL345_I2C.lib	Wed Apr 30 12:23:04 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/peterswanson87/code/ADXL345_I2C/#7e41b9136e7a
+http://mbed.org/users/Strikewolf/code/ADXL345_I2C_NEST/#7e41b9136e7a
diff -r 210cd333f770 -r 3fb9f96765f6 AI.cpp
--- a/AI.cpp	Wed Apr 30 05:53:51 2014 +0000
+++ b/AI.cpp	Wed Apr 30 12:23:04 2014 +0000
@@ -40,7 +40,9 @@
 
     // get away from user before starting game
     pc.printf("Getting head start (straight)...\n\r");
-    wait(5);
+    gyroDriveStraight(0.8, false, 5000);
+    //wait(5);
+    
     // gyroDriveStraight(0.7, false, 10000);
     // pc.printf("Getting head start (turn right)...\n\r");
     // centerTurnRight(90);
diff -r 210cd333f770 -r 3fb9f96765f6 AIControl.h
--- a/AIControl.h	Wed Apr 30 05:53:51 2014 +0000
+++ b/AIControl.h	Wed Apr 30 12:23:04 2014 +0000
@@ -76,11 +76,12 @@
 }
 
 //Turn left about the center
-void centerTurnLeft(int delta_degrees)
+void centerTurnLeft(bool gameRun)
 {
     //Reset the filter and re-init the IMU
     imuFilter.reset();
     rpy_init();
+    int delta_degrees = 0;
 
     //So there's this weird thing where the gyro treats left turns as POSITIVE degrees...
     float initial = toDegrees(imuFilter.getYaw());
@@ -91,20 +92,25 @@
     //Continue to turn to target
     while (!gameOver) {
         setTurnLeft(0.6);
+        if(gameRun) {
+            receivePosition(NULL);
+        }
         sample = toDegrees(imuFilter.getYaw());
         wait(0.02);
-        if(sample > target - 5)
+        if((sonar3.read()*100) > (SONAR_STOP+6))
             break;
     }
     stop();
 }
 
 //Turn right about the center
-void centerTurnRight(int delta_degrees)
+void centerTurnRight(bool gameRun)
 {
     //Reset the filter and re-init the IMU
     imuFilter.reset();
     rpy_init();
+    
+    int delta_degrees = 0;
 
     //So there's this weird thing where the gyro treats right turns as NEGATIVE degrees...
     float initial = toDegrees(imuFilter.getYaw());
@@ -116,15 +122,18 @@
     //Continue to turn to target
     while (!gameOver) {
         setTurnRight(0.6);
+        if(gameRun) {
+            receivePosition(NULL);
+        }
         sample = toDegrees(imuFilter.getYaw());
         wait(0.02);
-        if(sample < target)
+        if((sonar1.read()*100) > (SONAR_STOP+6))
             break;
     }
     stop();
 }
 
-void checkSonars()
+void checkSonars(bool gameRun)
 {
     //Collision Detection
     // read all sonar sensors
@@ -133,16 +142,16 @@
     float s3 = sonar3.read() * 100;
 
     // check if obstacle is near and adjust
-    pc.printf("%.2f, %.2f, %.2f, %f\n\r", s1, s2, s3, SONAR_STOP);
+    // pc.printf("%.2f, %.2f, %.2f, %f\n\r", s1, s2, s3, SONAR_STOP);
     if(s2 < SONAR_STOP) {
 
         if(s1 <= s3) {
-            centerTurnRight(90);
+            centerTurnRight(gameRun);
         } else {
-            centerTurnLeft(90);
+            centerTurnLeft(gameRun);
         }
-        imuFilter.reset();
-        rpy_init();
+        //imuFilter.reset();
+        //rpy_init();
     }
 }
 
@@ -162,7 +171,7 @@
     while (timer.read_ms() < ms) {
 
         timer.stop();
-        //checkSonars();
+        checkSonars(gameRun);
         if(gameRun) {
             receivePosition(NULL);
         }
@@ -170,14 +179,14 @@
 
         imuFilter.computeEuler();
         sample = toDegrees(imuFilter.getYaw());
-/*
+
         //Drift Correction
         sample = sample + float(timer.read_ms() / 800);
         // pc.printf("%f :::", sample);
 
         if (sample < 3) {
             // pc.printf("Steer Left\r\n");
-            leftMotorPWM = speed - 0.2;
+            leftMotorPWM = speed;
             rightMotorPWM = speed;
             leftMotor1 = 0;
             leftMotor2 = 1;
@@ -186,7 +195,7 @@
         } else if (sample > -3) {
             // pc.printf("Steer Right \r\n");
             leftMotorPWM = speed;
-            rightMotorPWM = speed - 0.18;
+            rightMotorPWM = speed - 0.2;
             leftMotor1 = 0;
             leftMotor2 = 1;
             rightMotor1 = 0;
@@ -194,7 +203,7 @@
         } else {
             // pc.printf("Straight\r\n");
             setMove(speed, false);
-        }*/
+        }
     }
     stop();
 }
diff -r 210cd333f770 -r 3fb9f96765f6 AIPosition.h
--- a/AIPosition.h	Wed Apr 30 05:53:51 2014 +0000
+++ b/AIPosition.h	Wed Apr 30 12:23:04 2014 +0000
@@ -48,8 +48,6 @@
     double g_temp = imuFilter.getYaw();
 
     // determine direction we are facing and add to that direction
-    //y_position += y_temp;
-    //x_position += y_temp * tan(g_temp);
     double dx = 0;
     double dy = 0;
     QUADRANT quadrant;
@@ -81,13 +79,10 @@
             break;
     }
 
+    // add to total position
     x_position += dx;
     y_position += dy;
 
-    // pc.printf("sin(g): %f, cos(g): %f\n\r", sin(g_temp), cos(g_temp));
-    // pc.printf("DEBUG: dx: %f, dy: %f, gyro: %f, quadrant: %d\n\r", dx, dy, toDegrees(g_temp), quadrant);
-    // pc.printf("x: %f, y: %f, dx: %f, dy:  %f, g: %f, q: %d\n\r", x_position, y_position, dx, dy, toDegrees(g_temp), quadrant);
-
     // check if human car is close enough to end game
     gameOver = isGameOver(x_hum, y_hum, x_position, y_position);
     if(gameOver) {
@@ -95,6 +90,10 @@
         xbee.putc('d');
         pc.printf("Game over sent!\n\r");
 
+        // sanity
+        for(int i = 0; i < 500; i++)
+            xbee.putc('d');
+                
         // go to end game routine
         endGame();
     }
@@ -122,17 +121,12 @@
 
 void receivePosition(void const *)
 {
+    // temp variables
     char buffer[SERIAL_BUFFER_SIZE];
     int index = 0;
     int xt = 0;
     int yt = 0;
 
-    // clear any garbage
-    // xbee.getc();
-    //xbee.getc();
-
-    // while(!gameOver) {
-
     // wait for start character
     while(xbee.readable() && xbee.getc() != 'x' && !gameOver);
 
diff -r 210cd333f770 -r 3fb9f96765f6 GameCode.h
--- a/GameCode.h	Wed Apr 30 05:53:51 2014 +0000
+++ b/GameCode.h	Wed Apr 30 12:23:04 2014 +0000
@@ -1,6 +1,7 @@
-#define THRESHOLD 500
+#define THRESHOLD 1000
 
 Serial pc(USBTX, USBRX);
+void stop();
 
 bool gameOver = false;
 
@@ -17,5 +18,6 @@
 void endGame()
 {
     pc.printf("GAME OVER\n\r");
+    stop();
     exit(1);
 }
\ No newline at end of file
diff -r 210cd333f770 -r 3fb9f96765f6 ITG3200.lib
--- a/ITG3200.lib	Wed Apr 30 05:53:51 2014 +0000
+++ b/ITG3200.lib	Wed Apr 30 12:23:04 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/aberk/code/ITG3200/#9e6042257318
+http://mbed.org/users/Strikewolf/code/ITG3200_NEST/#9e6042257318