NXP Group 13 / Mbed 2 deprecated Car3

Dependencies:   camera mbed tsi_sensor

Fork of Car2 by Zach Matthews

Committer:
zamatthews
Date:
Thu Feb 23 20:59:25 2017 +0000
Revision:
3:dadfc15fc2d1
Parent:
2:0db7cc5ad6db
Child:
4:f4852befd69c
added some commented framework for future functions -Levi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zamatthews 0:b761ef827157 1 #include "mbed.h"
zamatthews 2:0db7cc5ad6db 2 #include "Servo.h"
zamatthews 2:0db7cc5ad6db 3
zamatthews 3:dadfc15fc2d1 4 //#define CIRCUMFERENCE SOMEINT //circumference in some unit of measurement (inches perhaps?)
zamatthews 3:dadfc15fc2d1 5 //#define RESWIDTH 80 //resolution width/height. change these based on actual resolution
zamatthews 3:dadfc15fc2d1 6 //#define RESHEIGHT 60
zamatthews 3:dadfc15fc2d1 7
zamatthews 3:dadfc15fc2d1 8 //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?
zamatthews 3:dadfc15fc2d1 9 //Timer timer;
zamatthews 3:dadfc15fc2d1 10 //DigitalIn rotation(PXXX);
zamatthews 3:dadfc15fc2d1 11 //camera data pins used are (D0-D7): PTC7, PTC0, PTC3, PTC4, PTC5, PTC6, PTC10, PTC11
zamatthews 3:dadfc15fc2d1 12 //other camera pins: SCL->PTE5, SDA->PTE4, PCLK->PTE21, VSYNC->PTE30, H->PTE29
zamatthews 3:dadfc15fc2d1 13 PwmOut servo(PTE20);
zamatthews 3:dadfc15fc2d1 14 PwmOut motor(PTA5);
zamatthews 3:dadfc15fc2d1 15 DigitalOut DIR_L(PTD4);
zamatthews 3:dadfc15fc2d1 16 DigitalOut DIR_R(PTA4);
zamatthews 3:dadfc15fc2d1 17
zamatthews 3:dadfc15fc2d1 18 //int start = 0;
zamatthews 3:dadfc15fc2d1 19 //int end = 0;
zamatthews 3:dadfc15fc2d1 20 //int rotationTime = 0;
zamatthews 3:dadfc15fc2d1 21 //float speed = 0;
zamatthews 3:dadfc15fc2d1 22 //int startFinish = 0;
zamatthews 3:dadfc15fc2d1 23 //int frame[RESWIDTH][RESHEIGHT];
zamatthews 0:b761ef827157 24
zamatthews 3:dadfc15fc2d1 25 /*
zamatthews 3:dadfc15fc2d1 26 int frame(){ //triggered by interrupt from camera or request frame from camera?
zamatthews 3:dadfc15fc2d1 27 //get all the pixels
zamatthews 3:dadfc15fc2d1 28 int i = 0;
zamatthews 3:dadfc15fc2d1 29 int j = 0;
zamatthews 3:dadfc15fc2d1 30 for(i; i<RESWIDTH; i++){
zamatthews 3:dadfc15fc2d1 31 for(j; j<RESHEIGHT; j++){
zamatthews 3:dadfc15fc2d1 32 frame[i][j] = ???;
zamatthews 3:dadfc15fc2d1 33 }//j for
zamatthews 3:dadfc15fc2d1 34 }//i for
zamatthews 3:dadfc15fc2d1 35 return frame;
zamatthews 3:dadfc15fc2d1 36 }
zamatthews 3:dadfc15fc2d1 37
zamatthews 3:dadfc15fc2d1 38 void turnWheels(int[][] frame){
zamatthews 3:dadfc15fc2d1 39 //ififififififif
zamatthews 3:dadfc15fc2d1 40 }
zamatthews 3:dadfc15fc2d1 41
zamatthews 3:dadfc15fc2d1 42 void setAccel(int[][] frame, float speed){
zamatthews 3:dadfc15fc2d1 43 //ififififififif
zamatthews 3:dadfc15fc2d1 44 }
zamatthews 3:dadfc15fc2d1 45
zamatthews 3:dadfc15fc2d1 46 int startFinish(int[][] frame){
zamatthews 3:dadfc15fc2d1 47 //if start
zamatthews 3:dadfc15fc2d1 48 return 1;
zamatthews 3:dadfc15fc2d1 49 //if notFinished
zamatthews 3:dadfc15fc2d1 50 return 1;
zamatthews 3:dadfc15fc2d1 51 //if finished
zamatthews 3:dadfc15fc2d1 52 return 0;
zamatthews 3:dadfc15fc2d1 53 }
zamatthews 3:dadfc15fc2d1 54 */
zamatthews 2:0db7cc5ad6db 55
zamatthews 2:0db7cc5ad6db 56 int main() {
zamatthews 3:dadfc15fc2d1 57 //timer.start();
zamatthews 3:dadfc15fc2d1 58 motor.period_us(50);
zamatthews 3:dadfc15fc2d1 59 motor.write(0.50);
zamatthews 3:dadfc15fc2d1 60 DIR_R = 1;
zamatthews 2:0db7cc5ad6db 61 DIR_L = 0;
zamatthews 3:dadfc15fc2d1 62 servo.period(0.020f);
zamatthews 3:dadfc15fc2d1 63 servo.pulsewidth(0.0015f);
zamatthews 2:0db7cc5ad6db 64 while(1){
zamatthews 3:dadfc15fc2d1 65 /*
zamatthews 3:dadfc15fc2d1 66 if(rotation){
zamatthews 3:dadfc15fc2d1 67 end = time.read_ms();
zamatthews 3:dadfc15fc2d1 68 rotationTime = end-start;
zamatthews 3:dadfc15fc2d1 69 speed = CIRCUFERENCE / rotationTime; //inches/ms
zamatthews 3:dadfc15fc2d1 70 speed *= 56.8182 //convert to miles/hour
zamatthews 3:dadfc15fc2d1 71 start = timer.read_ms();
zamatthews 3:dadfc15fc2d1 72 }
zamatthews 3:dadfc15fc2d1 73 //camera.rise(&frame); //idea is that camera tells MCU that it's sending a frame
zamatthews 3:dadfc15fc2d1 74 //frame = frame();
zamatthews 3:dadfc15fc2d1 75 if(startFinish(frame)){; //frame returns the result
zamatthews 3:dadfc15fc2d1 76 turnWheels(frame);
zamatthews 3:dadfc15fc2d1 77 setAccel(frame, speed);
zamatthews 3:dadfc15fc2d1 78 */
zamatthews 2:0db7cc5ad6db 79
zamatthews 3:dadfc15fc2d1 80 //these will go to turnWheel() later
zamatthews 3:dadfc15fc2d1 81 for(float p=0.0001f; p<=0.0015f; p += 0.00005f) {
zamatthews 3:dadfc15fc2d1 82 servo.pulsewidth(p);
zamatthews 3:dadfc15fc2d1 83 wait(.05);
zamatthews 3:dadfc15fc2d1 84 }//for p increase
zamatthews 3:dadfc15fc2d1 85 for(float p=0.0015f; p>=0.0001f; p -= 0.00005f) {
zamatthews 3:dadfc15fc2d1 86 servo.pulsewidth(p);
zamatthews 3:dadfc15fc2d1 87 wait(.05);
zamatthews 3:dadfc15fc2d1 88 }//for p decrease
zamatthews 3:dadfc15fc2d1 89 //} //end if(startFinish(frame))
zamatthews 3:dadfc15fc2d1 90 }//while 1
zamatthews 3:dadfc15fc2d1 91 }//main