added stuff

Dependencies:   FRDM-TFC

Fork of TFC-TEST_TXSTATE_TEAM6 by Cody Blakeney

Files at this revision

API Documentation at this revision

Comitter:
anthonylamme
Date:
Mon Apr 06 23:22:53 2015 +0000
Parent:
4:97014a4611c2
Commit message:
fixed errors

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 97014a4611c2 -r 0c142433cc51 main.cpp
--- a/main.cpp	Mon Apr 06 21:36:56 2015 +0000
+++ b/main.cpp	Mon Apr 06 23:22:53 2015 +0000
@@ -45,8 +45,8 @@
 int turnDir( int &, int &, int, int);
 int startstop(int);
 
-//void turnLeft(int &, int &, int, int);  needs to be finished
-//void turnRight(int &, int &, int, int);  needs to be finished
+void turnLeft(int &, int &, int, int);  //needs to be finished
+void turnRight(int &, int &, int, int);  //needs to be finished
  
 int main()
 {
@@ -111,41 +111,6 @@
                 break;                   
                     
             case 1: // moves servo and prints pot value.
-                
-                
-                if(TFC_Ticker[0]>=20)
-                {
-                    TFC_Ticker[0] = 0; //reset the Ticker
-                    //Every 20 mSeconds, update the Servos
-                    TFC_SetServo(0,TFC_ReadPot(0));
-                    TFC_SetServo(1,TFC_ReadPot(1));
-                    
-                  
-                }
-                
-                 if(TFC_PUSH_BUTTON_1_PRESSED)
-                   { 
-                   
-                    PC.printf("%f", TFC_ReadPot(0));
-                    }
-                
-                
-                //Let's put a pattern on the LEDs
-                if(TFC_Ticker[1] >= 125)
-                {
-                    TFC_Ticker[1] = 0;
-                    t++;
-                    if(t>4)
-                    {
-                        t=0;
-                    }           
-                    TFC_SetBatteryLED_Level(t);
-                }
-                
-              //  TFC_SetMotorPWM(0,0); //Make sure motors are off
-              //  TFC_HBRIDGE_DISABLE;
-            
-
                 break;
                 
             case 2 ://case 2 will run program after case 0
@@ -154,20 +119,20 @@
                 {
                     while(true)
                     {
-                        dark=FindBlack();//determines if its dark
-                        while(d==distance(a,b,black))//if straight line it just goes forward
+                        //dark=FindBlack();//determines if its dark
+                        while((d < (distance(a,b,black)*1.02))&&(d > (distance(a,b,black)*.98)))//if straight line it just goes forward
                         {
                             TFC_SetMotorPWM(.6,.6);
                         }
                         if(turnDir(a,b,black,d)==1)//straight line is broken determine direction if 1 go right
                         {
-                            turnRight();
+                            turnRight(a,b,black,d);
                         }
                         if(turnDir(a,b,black,d)==0)//straight line is broken determine direction if 0 go right
                         {
-                            turnLeft();
+                            turnLeft(a,b,black,d);
                         }
-                        if(FindBlack()==2000)//if white line then find black will return starting value because no black line
+                        /*if(FindBlack()>black)//if white line then find black will return starting value because no black line  // change to findblack()>black
                         {
                             TFC_SetMotorPWM(.6,.6);//go straight for given time
                             wait(0.146);
@@ -185,65 +150,18 @@
                             wait(0.143);
                             continue;
                         }
-                        if(startstop==1)// if start line is seen stop
+                        if(startstop()==1)// if start line is seen stop
                         {
                             TFC_SetMotorPWM(0,0);
                             TFC_HBRIDGE_DISABLE;
                             break;
                         }
+                        */
                     }       
                 }
                 break;
             
             case 3 :
-            
-         
-                //Demo Mode 3 will be in Freescale Garage Mode.  It will beam data from the Camera to the 
-                //Labview Application
-                
-                
-                if(TFC_Ticker[0]>50 && TFC_LineScanImageReady>0)
-                    {
-                     TFC_Ticker[0] = 0;
-                     TFC_LineScanImageReady=0;
-                    // PC.printf("\r\n");
-                    // PC.printf("L:");
-                     
-                        if(t==0)
-                            t=4;
-                        else
-                            t--;
-                        
-                         TFC_SetBatteryLED_Level(t);
-                        
-                         // camera 1
-                         
-                         if(TFC_PUSH_BUTTON_0_PRESSED)
-                    {          
-                               //Demo Mode 3 will be in Freescale Garage Mode.  It will beam data from the Camera to the 
-                //Labview Application
-
-                        
-                         // camera 1
-                         for(i=0;i<128;i++)
-                         {
-                               if(TFC_LineScanImage0[i]<=black)
-                               {
-                                   // zero is black
-                                   
-                                   data[i]=0;
-                                }
-                                else
-                                {
-                                    // one is white
-                                    data[i]=1;
-                                }
-                                PC.printf("%d", data[i]);
-                         }
-                         PC.printf("\r");
-                      }   
-                    }
-                 
                 break;
             }
     }
@@ -350,9 +268,8 @@
                     }
                     
              }
-     } 
-     
-/*void turnLeft(int &a, int &b,int black,int d)
+    } 
+ void turnLeft(int &a, int &b,int black,int d)
     {
         // waits for the amount of time it takes to reach the turn
         wait(.146);
@@ -362,44 +279,42 @@
               //   while the distance between the lines
               //   indicate the car is in a turn
                 
-        while(d > distance(a, b, black) )
-            {
-                setservo(-.214652);
-            }
+        while(((d < (distance(a, b, black)*1.27))&&(d!=distance(a,b,black)))||(b==128))
+        {
+            TFC_SetServo(0,-.214652);
+        }
+            // returns the wheels back to straight
             
-              // returns the wheels back to straight
-            
-         setservo(0,0.0);
-     }           
-                                      
-  */
-/* void turnRight(int &a, int &b,int black,int d)
+         TFC_SetServo(0,0.0);
+    }           
+void turnRight(int &a, int &b,int black,int d)
         {
             // waits for the amount of time it takes to reach the turn
             wait(.146);
-            while(d > distance(a, b, black) )
+            while(((d < (distance(a, b, black)*1.27))&&(d!=distance(a,b,black)))||(b==128))
             {
-                setservo(.2688640);
-        }*/
+                TFC_SetServo(0,.2688640);
+            }
+            TFC_SetServo(0,0.0);
+        }
 int startstop(int black)
     {
+        int data[128];
         int counter=0;
         
-        for(i=0;i<128;i++)
+        for(int i=0;i<128;i++)
         {
             if(TFC_LineScanImage0[i]<=black)
-            {
-                                   // zero is black                   
+            {                 // zero is black                   
                 data[i]=0;
                 counter++;
             }
             else
-            {
-                                    // one is white
+            {                    // one is white
                 data[i]=1;
             }
         }
-        if counter>6
+        if (counter>6)
         {
             return 1;
         }
@@ -409,4 +324,4 @@
         }
     }
             
-        
+     
\ No newline at end of file