Sooner Competitive Robotics / Mbed 2 deprecated IEEE_14_Freescale

Dependencies:   mbed

Fork of IEEE_14_Freescale by IEEE 2014 Mbed

Revision:
7:3b2cf7efe5d1
Parent:
6:62d498ee97cf
Child:
9:aff48e331147
--- a/main.cpp	Mon Nov 18 23:45:12 2013 +0000
+++ b/main.cpp	Fri Nov 22 18:00:18 2013 +0000
@@ -14,55 +14,69 @@
     double targetAngle=0.0;
     while(1) {
         DBGPRINT("BB\n\r",1);
-        leds = leds^0x7;
+        leds = leds^0x7; // toggle the LEDs for each loop
         tmpchar = pc.getc();
         
+        // all of these movement commands are blocking, so they can't be easily stopped short of resetting the microcontroller
         switch(tmpchar){
-            case 'q':
+            case 'e': //drive in a smallish square
+                bot.driveForward(0,3000);
+                bot.driveForward(-90,0);
+                bot.driveForward(-90,3000);
+                bot.driveForward(-180,0);
+                bot.driveForward(-180,3000);
+                bot.driveForward(-270,0);
+                bot.driveForward(-270,3000);
+                bot.driveForward(0,0);
+                DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
+                break;
+            case 'q': //poll the encoders
                 constbuf = bot.bigenc.getVals();
                 DBGPRINT("\n\r%d\t%d\t%d\t%d\n\r",constbuf[0],constbuf[1],constbuf[2],constbuf[3]);
                 break;
-            case 'z':
+            case 'z': //set the current direction to "forward" for the following "go forward/reverse" commands
                 targetAngle = bot.gyro.getZDegrees();
                 break;
-            case 'w':
+            case 'w': // turn 90 degrees counter clockwise from the starting rotation
+                bot.driveForward(90,0);
+                DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
+                break;
+            case 'x': // turn 90 degrees clockwise from the starting rotation
                 bot.driveForward(-90,0);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'x':
-                bot.driveForward(90,0);
+            case 'a': // turn the opposite direction from the starting one
+                bot.driveForward(180,0);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'W':
+            case 'd': // turn back to starting rotation
+                bot.driveForward(0,0);
+                DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
+                break;
+            case 'W': // drive forward a small bit
                 bot.driveForward(targetAngle,1000);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'E':
+            case 'E': //drive forward five times as much
                 bot.driveForward(targetAngle,5000);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'X':
+            case 'X': // small reverse
                 bot.driveForward(targetAngle,-1000);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'C':
+            case 'C': // big reverse
                 bot.driveForward(targetAngle,-5000);
                 DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
                 break;
-            case 'a':
-                bot.driveForward(180,0);
-                DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
-                break;
-            case 'd':
-                bot.driveForward(0,0);
-                DBGPRINT("={%f,\t%f,\t%f}\n\r",bot.x,bot.y,bot.rot*180.0/3.14159);
-                break;
-            case 'p':
+            case 'p': // poll the gyro
                 DBGPRINT("%d\r\n",bot.gyro.getZ());
                 break;
-            case 'l':
+            case 'l': //calibrate the gyro ( caution, only use after resetting and before moving, otherwise will break any calibration)
                 bot.gyro.calibrate();
                 break;
+                
+                // these are all control system modifications which should be fairly well locked down at this point
             case 't':
                 bot.pfac*=2;
                 DBGPRINT("pfac = %f\r\n",bot.pfac);
@@ -119,9 +133,13 @@
                 bot.dfac/=1.05;
                 DBGPRINT("dfac = %f\r\n",bot.dfac);
                 break;
+                
+                // poll the compass ( currently gives bad values )
             case 'Q':
                 DBGPRINT("Compass vector = %d\t%d\t%d\r\n",bot.gyro.xmag,bot.gyro.ymag,bot.gyro.zmag);
                 break;
+                
+               // brake if we get an unknown command
             default:
                 bot.left.brake();
                 bot.right.brake();