Car 2: Electric Boogaloo
Fork of Car2 by
Code for an NXP Cup car using a linescan Camera
Diff: main.cpp
- Revision:
- 4:f4852befd69c
- Parent:
- 3:dadfc15fc2d1
- Child:
- 5:137dfb3e692f
--- a/main.cpp Thu Feb 23 20:59:25 2017 +0000 +++ b/main.cpp Thu Mar 02 21:39:22 2017 +0000 @@ -4,6 +4,9 @@ //#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 +#define STRAIGHT 0.00095f +#define FULLRIGHT 0.0013f +#define FULLLEFT 0.0006 //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; @@ -34,15 +37,33 @@ }//i for return frame; } +*/ -void turnWheels(int[][] frame){ +void setAccel(float turnAngle){//, float speed){ //ififififififif + turnAngle -= STRAIGHT; //this gets a value from -0.00035 and +0.00035 + turnAngle = abs(turnAngle); + float turnRatio = turnAngle/0.00035f; + float newSpeed = (0.9*(1-turnRatio)/4)+0.1; + motor.write(newSpeed); } -void setAccel(int[][] frame, float speed){ +void turnWheels(){//int[][] frame, float speed){ //ififififififif + for(float p=FULLLEFT; p<=FULLRIGHT; p += 0.00005f) { + servo.pulsewidth(p); + setAccel(p); + wait(.1); + }//for p increase + for(float p=FULLRIGHT; p>=FULLLEFT; p -= 0.00005f) { + servo.pulsewidth(p); + setAccel(p); + wait(.1); + }//for p decrease } + +/* int startFinish(int[][] frame){ //if start return 1; @@ -56,11 +77,11 @@ int main() { //timer.start(); motor.period_us(50); - motor.write(0.50); - DIR_R = 1; + //motor.write(0.25); + DIR_R = 1; //what purpose do these lines serve? DIR_L = 0; servo.period(0.020f); - servo.pulsewidth(0.0015f); + //servo.pulsewidth(STRAIGHT); while(1){ /* if(rotation){ @@ -73,19 +94,9 @@ //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 + turnWheels();//frame, speed); //includes setAccel(); + //setAccel(frame, speed); //} //end if(startFinish(frame)) }//while 1 }//main \ No newline at end of file