most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
Diff: main.cpp
- Revision:
- 74:d281aaef9766
- Parent:
- 73:f6f378311c8d
- Child:
- 75:92e79d23d29a
--- a/main.cpp Mon Jul 30 16:48:48 2018 +0000 +++ b/main.cpp Tue Aug 14 21:06:48 2018 +0000 @@ -1,10 +1,6 @@ #include "mbed.h" #include "StaticDefs.hpp" -#ifndef lround -#define lround(var) (long)(var+0.5f) -#endif - ////////////////////////////////////////////////////////////////// NEW TICKER Ticker systemTicker; bool setup_complete = false; @@ -56,7 +52,7 @@ file_opened = true; //stops it from continuing to open it - pc().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r"); + xbee().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r"); } //record to Mbed file system @@ -77,10 +73,10 @@ file_opened = false; - pc().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r"); + xbee().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r"); } } - } //END OF LOG LOOP + } //END OF LOG LOOP8 log_loop = false; // wait until the loop rate timer fires again } @@ -93,7 +89,7 @@ //only start these updates when everything is properly setup (through setup function) if (setup_complete) { - if ( (timer_counter % 1) == 0) { //this runs at 0.001 second intervals (1000 Hz) + if ( (timer_counter % 5) == 0) { //this runs at 0.005 second intervals (200 Hz) adc().update(); //every iteration of this the A/D converter runs //now this runs at 0.01 second intervals 03/12/2018 } @@ -103,7 +99,7 @@ } if ( (timer_counter % 20) == 0 ) { // 0.02 second intervals - //rudder().runServo(); + rudder().runServo(); } if ( (timer_counter % 50) == 0 ) { // 0.05 second intervals @@ -119,12 +115,18 @@ if ( (timer_counter % 1000) == 0) { // update at 1.0 second intervals //gui().updateGUI(); } + + if ( (timer_counter % 30000) == 0) { // update at 30.0 second intervals + //pc().printf("XB!\n"); + } } } void setup() { - pc().baud(57600); - pc().printf("\n\n\r FSG PCB Bench Test version 1.7C)\n\n\r"); + xbee().baud(115200); + xbee().printf("\n\n\r FSG PCB Bench Test version 1.8L 115200 BAUD)\n\n\r"); + + //pc().baud(57600); // start up the system timer //systemTimer().start(); @@ -135,7 +137,7 @@ // setup and run the rudder(servo) pwm signal (start the ticker) //rudder().init(); - pc().printf("Rudder servo initialized!\n\r"); + xbee().printf("Rudder servo initialized!\n\r"); // set up and start the imu. This polls in the background imu().initialize(); @@ -189,15 +191,15 @@ // show that the PID gains are loading from the file - pc().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); - pc().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); - pc().printf("rudder min pwm: %6.2f, max pwm: %6.2f, center pwm: %6.2f, min deg: %6.2f, max deg: %6.2f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); + xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); + xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); + xbee().printf("rudder min pwm: %6.2f, max pwm: %6.2f, center pwm: %6.2f, min deg: %6.2f, max deg: %6.2f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); - pc().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset()); - pc().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset()); - pc().printf("heading P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f deg (deadband: %0.1f)\r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(), headingLoop().getDeadband()); + xbee().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset()); + xbee().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset()); + xbee().printf("heading P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f deg (deadband: %0.1f)\r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(), headingLoop().getDeadband()); - pc().printf("\n\r"); + xbee().printf("\n\r"); //load sequence from file sequenceController().loadSequence(); @@ -221,9 +223,8 @@ systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval) unsigned int tNow = 0; - - //pc().baud(57600); - pc().printf("\n\n\r FSG PCB v1.8 (XBee) 07/12/2018 \n\n\r"); + + xbee().printf("\n\n\r FSG PCB v1.8D (XBee) 08/07/2018 \n\n\r"); systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval) @@ -233,7 +234,7 @@ ++tNow; //run finite state machine fast when transmitting data - if (current_state == TX_MBED_LOG or current_state == RECEIVE_SEQUENCE) { + if (current_state == TX_MBED_LOG or current_state == RX_SEQUENCE) { if ( (tNow % 100) == 0 ) { // 0.01 second intervals (100 Hz) fsm_loop = true; FSM(); @@ -258,10 +259,4 @@ } } } -} - - - - - - +} \ No newline at end of file