cannon ball
Dependencies: SerialDriver Servo mbed-rtos mbed
Fork of Nucleo_ServoKnob by
Diff: main.cpp
- Revision:
- 2:a5e166306da7
- Parent:
- 1:dee6f3e0db9b
- Child:
- 3:bc919a54f665
--- a/main.cpp Tue Apr 07 19:46:52 2015 +0000 +++ b/main.cpp Tue Apr 07 21:45:10 2015 +0000 @@ -6,6 +6,7 @@ #include "mbed.h" #include "Servo.h" +#include "SerialDriver.h" /* --> myservo.calibrate(0.00095, 90.0); // Calibrate the servo Le 0.00095 est l'ecart max entre la valeur 1.5ms qui correspond a une angle de 90 degrés : Pour ce deplacer de 0 à 180 degré on set le range @@ -17,8 +18,8 @@ Servo steering(D5); Servo throttle(D6); -Serial usb(USBTX, USBRX); -//Serial usb(USBTX, USBRX, 1024, 512); +//Serial usb(USBTX, USBRX); +SerialDriver usb(USBTX, USBRX, 1024, 512); DigitalOut led(LED1); unsigned char steeringUSB = 95; @@ -26,7 +27,7 @@ unsigned int time_data_check = 0; unsigned int time_data_check_last = 0; -#define DEBUG 0 +#define DEBUG 1 #define signal 255 #define throttle_stop_ms 1.5 #define steering_right_deg 0 @@ -68,11 +69,11 @@ steeringUSB = usb.getc(); //writeSteering(steeringUSB); steering.position(steeringUSB - 95); - //usb.putc(steeringUSB); - // time_data_check_last = time_data_check; + usb.putc(steeringUSB); + //time_data_check_last = time_data_check; //time_data_check = timer.read_ms(); if (DEBUG) { - // wait_ms(2000); + //wait_ms(2000); led = false; } //} @@ -81,13 +82,12 @@ led = true; throttleUSB = usb.getc(); writeThrottle(throttleUSB); - //usb.putc(throttleUSB); - + + usb.putc(throttleUSB); + time_data_check_last = time_data_check; time_data_check = timer.read_ms(); - - if (DEBUG) { // wait_ms(2000); led = false; @@ -99,12 +99,13 @@ //emergencyCall(); if(DEBUG){ //wait_ms(2000); + } wait_ms(50); } void emergencyCall() { - int deltaTime = (DEBUG)? 10000 : 2000; + int deltaTime = 10000; //(DEBUG)? 10000 : 4000; if (time_data_check_last - time_data_check > deltaTime) { led = true; while (1) { @@ -116,6 +117,7 @@ if (usb.readable() && usb.getc()==255) { //Release signal led = false; wait_ms(1000); + time_data_check_last = timer.read_ms(); return; } }