Car 2: Electric Boogaloo

Dependencies:   camera mbed

Fork of Car2 by NXP Group 13

Code for an NXP Cup car using a linescan Camera

Revision:
3:dadfc15fc2d1
Parent:
2:0db7cc5ad6db
Child:
4:f4852befd69c
--- a/main.cpp	Mon Feb 20 02:42:27 2017 +0000
+++ b/main.cpp	Thu Feb 23 20:59:25 2017 +0000
@@ -1,44 +1,91 @@
 #include "mbed.h"
 #include "Servo.h"
 
-//Servo myServo(PTD4);
-//
-//int main(){
-//    while(1){  
-//        for(float p=0; p<1.0; p += 0.1) {
-//            myServo = p;
-//            wait(0.2);
-//        }
-//    }
-//}
-    
+//#define CIRCUMFERENCE SOMEINT //circumference in some unit of measurement (inches perhaps?)
+//#define RESWIDTH 80  //resolution width/height. change these based on actual resolution
+//#define RESHEIGHT 60
+
+//InterruptIn camera(PXXX); //can set up to get a frame from the camera whenever is sends one? does the camera even have a pin for this?
+//Timer timer;
+//DigitalIn rotation(PXXX);
+//camera data pins used are (D0-D7): PTC7, PTC0, PTC3, PTC4, PTC5, PTC6, PTC10, PTC11
+//other camera pins: SCL->PTE5, SDA->PTE4, PCLK->PTE21, VSYNC->PTE30, H->PTE29
+PwmOut servo(PTE20);
+PwmOut motor(PTA5);
+DigitalOut DIR_L(PTD4);
+DigitalOut DIR_R(PTA4);
+
+//int start = 0;
+//int end = 0;
+//int rotationTime = 0;
+//float speed = 0;
+//int startFinish = 0;
+//int frame[RESWIDTH][RESHEIGHT];
 
- 
-PwmOut servo(PTD4);
-PwmOut leftMotor(PTA12);
-PwmOut rightMotor(PTA4);
-DigitalOut DIR_L(PTC4);
-DigitalOut DIR_R(PTC5);
+/*
+int frame(){ //triggered by interrupt from camera or request frame from camera?
+    //get all the pixels
+    int i = 0;
+    int j = 0;
+    for(i; i<RESWIDTH; i++){
+        for(j; j<RESHEIGHT; j++){
+            frame[i][j] = ???;
+        }//j for
+    }//i for
+    return frame;
+}
+
+void turnWheels(int[][] frame){
+    //ififififififif
+}
+
+void setAccel(int[][] frame, float speed){
+    //ififififififif
+}
+
+int startFinish(int[][] frame){
+    //if start
+    return 1;
+    //if notFinished
+    return 1;
+    //if finished
+    return 0;
+}
+*/
  
 int main() {    
-    leftMotor.period_us(50);
-    rightMotor.period_us(50);
-    leftMotor.write(0.25);
-    rightMotor.write(0.25);
+    //timer.start();
+    motor.period_us(50);
+    motor.write(0.50);
+    DIR_R = 1;
     DIR_L = 0;
-    DIR_R = 1;
+    servo.period(0.020f);
+    servo.pulsewidth(0.0015f);
     while(1){
+        /*
+        if(rotation){
+            end = time.read_ms();
+            rotationTime = end-start;
+            speed = CIRCUFERENCE / rotationTime; //inches/ms
+            speed *= 56.8182 //convert to miles/hour
+            start = timer.read_ms(); 
+        }
+        //camera.rise(&frame); //idea is that camera tells MCU that it's sending a frame
+        //frame = frame();
+        if(startFinish(frame)){; //frame returns the result 
+            turnWheels(frame);
+            setAccel(frame, speed);
+        */
         
-        //for(float p=0.0001f; p<=0.0015f; p += 0.00005f) {
-//            //servo.period(0.020f);
-//            servo.pulsewidth(p);
-//            wait(0.05);
-//        }
-//        for(float p=0.0015f; p>=0.0001f; p -= 0.00005f) {
-//            //servo.period(0.020f); 
-//            servo.pulsewidth(p);
-//            wait(0.05);
-//        }
-        
-    }
-}
\ No newline at end of file
+        //these will go to turnWheel() later
+        for(float p=0.0001f; p<=0.0015f; p += 0.00005f) {
+            servo.pulsewidth(p);
+            wait(.05);
+        }//for p increase
+        for(float p=0.0015f; p>=0.0001f; p -= 0.00005f) {
+            servo.pulsewidth(p);
+            wait(.05);
+        }//for p decrease
+        //} //end if(startFinish(frame))        
+    }//while 1
+}//main
\ No newline at end of file