NXP Group 13 / Mbed 2 deprecated Car3

Dependencies:   camera mbed tsi_sensor

Fork of Car2 by Zach Matthews

main.cpp

Committer:
zamatthews
Date:
2017-02-23
Revision:
3:dadfc15fc2d1
Parent:
2:0db7cc5ad6db
Child:
4:f4852befd69c

File content as of revision 3:dadfc15fc2d1:

#include "mbed.h"
#include "Servo.h"

//#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];

/*
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() {    
    //timer.start();
    motor.period_us(50);
    motor.write(0.50);
    DIR_R = 1;
    DIR_L = 0;
    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);
        */
        
        //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