fdfdf
Dependencies: Motordriver mbed
Video of everything working: https://drive.google.com/a/usna.edu/file/d/0B6gx9qlkekGOSXVlQkN1RWpVcDg/view?usp=sharing
Updated Schematic
Diff: main.cpp
- Revision:
- 10:0ee2d6d8d965
- Parent:
- 9:fe3a1e9b08b7
- Child:
- 11:3953288dc1bd
--- a/main.cpp Wed Feb 04 18:21:16 2015 +0000 +++ b/main.cpp Wed Feb 04 20:50:29 2015 +0000 @@ -27,7 +27,7 @@ int t1, t2, //global variables for the echo pulse. c t3, t4; //timer within flip int jump = 0; //flag for wether or not car is jumping - + //Interrupt Service Routines//////////////// void driveforward() { @@ -63,7 +63,7 @@ trigger = 1; // begin pulse wait(.000015); // 15 us trigger = 0; // end pulse - wait(.01); //wait for return pulse + //wait(.001); //wait for return pulse dist+= (t2-t1)/58.0; //converts time to distance in cm } @@ -75,12 +75,18 @@ void flip() //all flip function stuff in here { t3 = t.read(); - if (t4 - t3 < 6) { //ensures that this can only run once every six seconds + if (t3 - t4 >= 3) { //ensures that this can only run once every six seconds + t3 = t.read(); + testled = 1; float PWM_wheel = 0.0; //initialize PWM speed for reactionwheel PWM_wheel = 0.20; //***control law here*** wheel.speed(PWM_wheel); //sets PWM for flywheel t4 = t.read(); - } + testled = 0; + } else + testled = 0; + + } //end flip function @@ -93,9 +99,9 @@ float PWM_drive = 0.0; //initialize PWM speed for drive wheels float range = 0.0; // variable to hold the range sensor value - + fwdled = 0; //intializes all LEDS to off - revled = 0; // + revled = 0; // testled = 0; // jumpled = 0; // @@ -111,7 +117,8 @@ wheel.speed(0.0); // reaction wheel is initially off drive.speed(0.0); //drive motor initially off - t1 = t2 = t3 = t4 = 0; //initialize all timers variables to 0 + t1 = t2 = t4 = 0; //initialize all timers variables to 0 + t3 = 10; t.start(); //start timer while(1) { @@ -119,9 +126,9 @@ range = read_ultrasonic(10); //read distance for average of 10 samples - if (range>6.0) { //when distance is greater than 6.0 cm it will do the flip function - flip(); - jumpled = 1; // lights LED 3 when in jump flag is true + if (range > 6.0) { //when distance is greater than 6.0 cm it will do the flip function + jumpled = 1; // lights LED 3 when in jump flag is true + flip(); } else { jumpled = 0; // if not in jump mode led is off }