Fa2018-es200-1121-project2-herndon-toss
/
herndon-threaded
Threaded version of Herndon cover toss
Revision 6:f76e93f043e2, committed 2018-11-05
- Comitter:
- nhersom
- Date:
- Mon Nov 05 12:53:56 2018 +0000
- Parent:
- 5:226dfa7d6308
- Commit message:
- Final code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 23 01:00:41 2018 +0000 +++ b/main.cpp Mon Nov 05 12:53:56 2018 +0000 @@ -23,12 +23,11 @@ //DigitalIn sw1 (p16) ; not sure why this is here - maybe broken pin // You guys are supposed to include at least a few EXTERNAL leds. -DigitalOut heartbeat_led(LED1); // indicates heartbeat -DigitalOut aiming_led(LED2); // indicates aiming state -DigitalOut firing_led(LED3); // indicates firing -DigitalOut recycle_led(LED4); // indicates recycling +DigitalOut heartbeat_led(p5); // indicates heartbeat +DigitalOut aiming_led(p6); // indicates aiming state +DigitalOut firing_led(p7); // indicates firing +DigitalOut recycle_led(p8); // indicates recycling -DigitalOut LEDs[5]={p25, p26, p27, p28, p29}; // possible LEDs that can be lit // Herndon wiggling thread stuff @@ -82,19 +81,19 @@ pc.printf("main() entering aiming mode, turn dial to aim cover\r\n"); aiming_led.write(1); while(!launch_sw3.read()){ - LEDs[0] = 1; + printf("traverse_pot.read()"); pc.printf("main() aiming, dial at %f, servo at %f\r\n",traverse_pot.read(),traverse_servo.read()); traverse_servo.write(traverse_pot.read()); + ThisThread::sleep_for(200); } aiming_led.write(0); // firing state firing_led.write(1); - LEDs[1] = 1; pc.printf("main() thread entering cover launch sequence\r\n"); pc.printf("main() thread motor launch cover\r\n"); - launch_motor.speed(1.0); + launch_motor.speed(-1.0); ThisThread::sleep_for(400); pc.printf("main() thread motor off\r\n"); launch_motor.speed(0.0); @@ -107,23 +106,17 @@ // recovery state recycle_led.write(1); - LEDs[3] = 1; pc.printf("main() thread recycling catapult back to battery\r\n"); pc.printf("main() thread motor reversing back to battery \r\n"); - launch_motor.speed(-0.25); + launch_motor.speed(0.25); ThisThread::sleep_for(600); pc.printf("main() thread motor off\r\n"); launch_motor.speed(0.0); ThisThread::sleep_for(1000); pc.printf("main() thread back in battery\r\n"); recycle_led.write(0); - }// while(1) - LEDs[0] = 0; - LEDs[1] = 0; - LEDs[2] = 0; - LEDs[3] = 0; - LEDs[4] = 0; + } // main() @@ -155,8 +148,9 @@ x = 1.0; xinc = -0.1; // switch to moving left pc.printf("herndon_thread hit right end, now moving left\r\n"); + } // hit the right end - LEDs[4] = 1; + else if (x < 0.0) { x = 0.0; xinc = 0.1; // switch to moving right @@ -189,7 +183,6 @@ // heartbeat_thread loop here while(1) { - LEDs[2] = 1; heartbeat_led = !heartbeat_led; ThisThread::sleep_for(500); } // while(1)