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: StateMachine/StateMachine.cpp
- Revision:
- 74:d281aaef9766
- Parent:
- 73:f6f378311c8d
- Child:
- 76:c802e1da4179
--- a/StateMachine/StateMachine.cpp Mon Jul 30 16:48:48 2018 +0000 +++ b/StateMachine/StateMachine.cpp Tue Aug 14 21:06:48 2018 +0000 @@ -49,10 +49,6 @@ _max_recorded_depth_neutral = -99; //float to record max depth _max_recorded_depth_dive = -99; //float to record max depth - _neutral_sink_command_mm = -2.5; //defaults for neutral finding sub-FSM - _neutral_rise_command_mm = 2.0; - _neutral_pitch_command_mm = 0.5; - _max_recorded_auto_neutral_depth = -99; _debug_menu_on = false; //toggle between debug and simple menu screens @@ -80,7 +76,7 @@ printDebugMenu(); else printSimpleMenu(); - pc().printf("\r\n\nstate: SIT_IDLE\r\n"); + xbee().printf("\r\n\nstate: SIT_IDLE\r\n"); _isTimeoutRunning = true; // what is active? @@ -98,7 +94,7 @@ case CHECK_TUNING : // state used to check the tuning of the pressure vessel // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: CHECK_TUNING\r\n"); + xbee().printf("\r\n\nstate: CHECK_TUNING\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -113,13 +109,13 @@ // getSetPosition_mm is the commanded position in the LinearActuator class - pc().printf("CHECK_TUNING: BCE cmd: %3.1f (BCE current position: %3.1f)\r\n", bce().getSetPosition_mm(), bce().getPosition_mm()); - pc().printf("CHECK_TUNING: BATT cmd: %3.1f (BATT current position: %3.1f)\r\n", batt().getSetPosition_mm(), bce().getPosition_mm()); + xbee().printf("CHECK_TUNING: BCE cmd: %3.1f (BCE current position: %3.1f)\r\n", bce().getSetPosition_mm(), bce().getPosition_mm()); + xbee().printf("CHECK_TUNING: BATT cmd: %3.1f (BATT current position: %3.1f)\r\n", batt().getSetPosition_mm(), bce().getPosition_mm()); } // how exit? if (_fsm_timer > _timeout) { - pc().printf("CHECK_TUNING: timed out!\r\n"); + xbee().printf("CHECK_TUNING: timed out!\r\n"); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; @@ -129,16 +125,14 @@ // the inner loop position controls are maintaining the positions of the linear actuators //print status to screen continuously - pc().printf("CHECK_TUNING: BCE_position: %0.1f, BATT_position: %0.1f (BCE_cmd: %0.1f, BATT_cmd: %0.1f)(depth: %0.1f ft, pitch: %0.1f deg, heading: %0.1f) [%0.1f sec]\r",bce().getPosition_mm(),batt().getPosition_mm(),bce().getSetPosition_mm(),batt().getSetPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); - - checkMotorPositions(); + xbee().printf("CHECK_TUNING: BCE_position: %0.1f, BATT_position: %0.1f (BCE_cmd: %0.1f, BATT_cmd: %0.1f)(depth: %0.1f ft,pitch: %0.1f deg,heading: %0.1f) [%0.1f sec]\r",bce().getPosition_mm(),batt().getPosition_mm(),bce().getSetPosition_mm(),batt().getSetPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); break; case EMERGENCY_CLIMB : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: EMERGENCY_CLIMB\r\n"); + xbee().printf("\r\n\nstate: EMERGENCY_CLIMB\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -154,7 +148,7 @@ // how exit? if (_fsm_timer > _timeout) { - pc().printf("EC: timed out\r\n"); + xbee().printf("EC: timed out\r\n"); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; @@ -167,14 +161,14 @@ //WHAT IS ACTIVE? //print status to screen continuously - pc().printf("EC: depth: %3.1f, pitch: %0.1f deg [BCE:%0.1f (cmd: %0.1f) BMM:%0.1f (cmd: %0.1f)] [%0.1f sec]\r",depthLoop().getPosition(),pitchLoop().getPosition(),bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),_fsm_timer.read()); + xbee().printf("EC: depth: %3.1f, pitch: %0.1f deg [BCE:%0.1f (cmd: %0.1f) BMM:%0.1f (cmd: %0.1f)] [%0.1f sec]\r",depthLoop().getPosition(),pitchLoop().getPosition(),bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),_fsm_timer.read()); break; case FIND_NEUTRAL : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: FIND_NEUTRAL\r\n"); + xbee().printf("\r\n\nstate: FIND_NEUTRAL\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -182,8 +176,13 @@ // what needs to be started? bce().unpause(); batt().unpause(); - bce().setPosition_mm(_bceFloatPosition); - batt().setPosition_mm(_neutral_batt_pos_mm); //set battery to close-to-neutral setting from config file + + //start with a small offset from MANUAL neutral positions on the BCE only, BMM was pitching too much + float bce_find_neutral_mm = _neutral_bce_pos_mm + 10.0; + //float batt_find_neutral_mm = _neutral_batt_pos_mm + 10.0; + + bce().setPosition_mm(bce_find_neutral_mm); + batt().setPosition_mm(_neutral_batt_pos_mm); //set battery to the same neutral position //first iteration goes into Neutral Finding Sub-FSM //set the first state of the FSM, and start the sub-FSM @@ -199,7 +198,7 @@ // how exit? (exit with the timer, if timer still running continue processing sub FSM) if (_fsm_timer > _timeout) { - pc().printf("FN: timed out [time: %0.1f sec]\r\n", _fsm_timer.read()); + xbee().printf("FN: timed out [time: %0.1f sec]\r\n", _fsm_timer.read()); _state = EMERGENCY_CLIMB; //new behavior (if this times out it emergency surfaces) _fsm_timer.reset(); _isTimeoutRunning = false; @@ -213,7 +212,7 @@ //check if substate returned exit state, if so stop running the sub-FSM else if (runNeutralStateMachine() == NEUTRAL_EXIT) { //if successful, FIND_NEUTRAL then goes to RISE - pc().printf("*************************************** FIND_NEUTRAL sequence complete. Rising.\r\n\n"); + xbee().printf("*************************************** FIND_NEUTRAL sequence complete. Rising.\r\n\n"); _state = RISE; _isTimeoutRunning = false; } @@ -224,7 +223,7 @@ // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: DIVE\r\n"); + xbee().printf("\r\n\nstate: DIVE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -237,8 +236,11 @@ depthLoop().setCommand(_depth_command); pitchLoop().setCommand(_pitch_command); - pc().printf("DIVE: depth cmd: %3.1f\r\n",depthLoop().getCommand()); - pc().printf("DIVE: pitch cmd: %3.1f\r\n",pitchLoop().getCommand()); + headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) + + xbee().printf("DIVE: depth cmd: %3.1f\r\n",depthLoop().getCommand()); + xbee().printf("DIVE: pitch cmd: %3.1f\r\n",pitchLoop().getCommand()); + xbee().printf("DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); //reset max dive depth _max_recorded_depth_dive = -99; //float to record max depth @@ -246,36 +248,37 @@ // how exit? if (_fsm_timer.read() > _timeout) { - pc().printf("DIVE: timed out\r\n\n"); + xbee().printf("DIVE: timed out\r\n\n"); _state = RISE; //new behavior 11/17/2017 _fsm_timer.reset(); _isTimeoutRunning = false; } else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches - pc().printf("DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = RISE; _fsm_timer.reset(); _isTimeoutRunning = false; } // WHAT IS ACTIVE? - pc().printf("DIVE: bce pos: %3.1f mm, batt pos: %3.1f mm (depth: %3.1f ft) (pitch: %3.1f deg)[%0.2f sec] (CMD BCE: %0.1f BATT: %0.1f)\r", bce().getPosition_mm(), batt().getPosition_mm(), depthLoop().getPosition(), pitchLoop().getPosition(), _fsm_timer.read(),bce().getSetPosition_mm(),batt().getSetPosition_mm()); + xbee().printf("DIVE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors batt().setPosition_mm(pitchLoop().getOutput()); + // ACTIVE RUDDER CONTROL + rudder().setPosition_deg(headingLoop().getOutput()); + if (depthLoop().getPosition() > _max_recorded_depth_dive) { //debug _max_recorded_depth_dive = depthLoop().getPosition(); //new max depth recorded } - checkMotorPositions(); - break; case RISE : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: RISE\r\n"); + xbee().printf("\r\n\nstate: RISE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -287,14 +290,17 @@ // what are the commands? depthLoop().setCommand(-1.0); //make sure to get towards the surface (saw issues at LASR pool) pitchLoop().setCommand(-_pitch_command); - - pc().printf("RISE: depth cmd: %0.1f\r\n",depthLoop().getCommand()); - pc().printf("RISE: pitch cmd: %0.1f\r\n",pitchLoop().getCommand()); + + headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) + + xbee().printf("RISE: depth cmd: %3.1f\r\n",depthLoop().getCommand()); + xbee().printf("RISE: pitch cmd: %3.1f\r\n",pitchLoop().getCommand()); + xbee().printf("RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); } // how exit? if (_fsm_timer.read() > _timeout) { - pc().printf("RISE: timed out\r\n"); + xbee().printf("RISE: timed out\r\n"); _state = EMERGENCY_CLIMB; _fsm_timer.reset(); _isTimeoutRunning = false; @@ -303,18 +309,19 @@ //modified from (depthLoop().getPosition() < depthLoop().getCommand() + 0.5) //did not work correctly in bench test (stuck in rise state) else if (depthLoop().getPosition() < 0.5) { - pc().printf("RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; } // WHAT IS ACTIVE? - pc().printf("RISE: bce pos: %3.1f mm, batt pos: %3.1f mm (depthLoop POS: %3.1f ft) (pitch: %3.1f deg)[%0.2f sec] (CMD BCE: %0.1f BATT: %0.1f)\r", bce().getPosition_mm(), batt().getPosition_mm(), depthLoop().getPosition(), pitchLoop().getPosition(), _fsm_timer.read(),bce().getSetPosition_mm(),batt().getSetPosition_mm()); + xbee().printf("RISE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors batt().setPosition_mm(pitchLoop().getOutput()); - - checkMotorPositions(); + + // ACTIVE RUDDER CONTROL + rudder().setPosition_deg(headingLoop().getOutput()); break; @@ -322,7 +329,7 @@ case POSITION_DIVE : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: POSITION DIVE\r\n"); + xbee().printf("\r\n\nstate: POSITION DIVE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -334,15 +341,17 @@ // what are the commands? (using inner loops except for heading outer loop) // These actions happen ONCE in the POSITION_DIVE sequence - batt().setPosition_mm(_neutral_batt_pos_mm - _BMM_dive_offset); - bce().setPosition_mm(_neutral_bce_pos_mm- _BMM_dive_offset); - //rudder().setPosition_deg(_heading_command); + batt().setPosition_mm(_neutral_batt_pos_mm + _BMM_dive_offset); + bce().setPosition_mm(_neutral_bce_pos_mm - _BCE_dive_offset); + //DEPTH COMMAND + depthLoop().setCommand(_depth_command); + headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) - pc().printf("PD: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position - pc().printf("PD: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position - pc().printf("PD: heading cmd: %3.1f\r\n",headingLoop().getCommand()); + xbee().printf("POS DIVE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position + xbee().printf("POS DIVE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position + xbee().printf("POS DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); //reset max dive depth _max_recorded_depth_dive = -99; //float to record max depth @@ -351,7 +360,7 @@ // how exit? // timer runs out goes to POSITION_RISE if (_fsm_timer.read() > _timeout) { - pc().printf("PD: timed out\r\n\n"); + xbee().printf("POS DIVE timed out\r\n\n"); _state = POSITION_RISE; //new behavior 11/17/2017 _fsm_timer.reset(); _isTimeoutRunning = false; @@ -359,14 +368,14 @@ // when you reach the dive threshold, surface else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches - pc().printf("PD: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("POS DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = POSITION_RISE; _fsm_timer.reset(); _isTimeoutRunning = false; } // what is active? - pc().printf("PD: bce pos (cmd pos): %3.1f mm (%0.1f), batt pos: %3.1f mm (%0.1f), rudder: %f (depth: %3.1f ft, pitch: %3.1f, heading: %3.1f [cmd: %0.1f])[%0.2f sec] [imu heading: %0.1f] \r", bce().getPosition_mm(),bce().getSetPosition_mm(), batt().getPosition_mm(),batt().getSetPosition_mm(), rudder().getPosition_pwm(), depthLoop().getPosition(), pitchLoop().getPosition(), headingLoop().getPosition(), headingLoop().getOutput(), _fsm_timer.read(), imu().getHeading()); + xbee().printf("POS DIVE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); if (depthLoop().getPosition() > _max_recorded_depth_dive) { _max_recorded_depth_dive = depthLoop().getPosition(); //new max depth recorded when it is larger than previous values @@ -375,15 +384,13 @@ // ACTIVE RUDDER CONTROL rudder().setPosition_deg(headingLoop().getOutput()); - checkMotorPositions(); - break; case POSITION_RISE : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: POSITION RISE\r\n"); + xbee().printf("\r\n\nstate: POSITION RISE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -392,41 +399,36 @@ bce().unpause(); batt().unpause(); - // what are the commands? (using inner loops except for heading outer loop) - pc().printf("PR: <<DEBUG>> CMD BCE: %0.1f, CMD BMM: %0.1f)\r\n", _BCE_dive_offset, _BMM_dive_offset); - - batt().setPosition_mm(_neutral_batt_pos_mm + _BMM_dive_offset); //reversing the BCE and BATT positions + // what are the commands? (using inner loops except for heading outer loop) + batt().setPosition_mm(_neutral_batt_pos_mm - _BMM_dive_offset); //reversing the BCE and BATT positions bce().setPosition_mm(_neutral_bce_pos_mm + _BCE_dive_offset); //reversing the BCE and BATT positions - //rudder().setPosition_deg(_heading_command); //heading stays the same headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) - pc().printf("PR: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position - pc().printf("PR: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position - pc().printf("PR: heading cmd: %3.1f\r\n",headingLoop().getCommand()); + xbee().printf("POS RISE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position + xbee().printf("POS RISE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position + xbee().printf("POS RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); } // how exit? if (_fsm_timer.read() > _timeout) { - pc().printf("PR: timed out\r\n"); + xbee().printf("POS RISE: timed out\r\n"); _state = EMERGENCY_CLIMB; _fsm_timer.reset(); _isTimeoutRunning = false; } else if (depthLoop().getPosition() < 0.5) { - pc().printf("PR: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("POS RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; } // what is active? - pc().printf("PR: bce pos (cmd pos): %3.1f mm (%0.1f), batt pos: %3.1f mm (%0.1f), rudder: %0.1f (depth: %3.1f ft, pitch: %3.1f, heading: %3.1f [cmd: %0.1f])[%0.2f sec] [imu heading: %0.1f] \r", bce().getPosition_mm(),bce().getSetPosition_mm(), batt().getPosition_mm(),batt().getSetPosition_mm(), rudder().getPosition_pwm(), depthLoop().getPosition(), pitchLoop().getPosition(), headingLoop().getPosition(), headingLoop().getOutput(), _fsm_timer.read(), imu().getHeading()); + xbee().printf("POS RISE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); // ACTIVE RUDDER CONTROL rudder().setPosition_deg(headingLoop().getOutput()); - - checkMotorPositions(); break; // NEW DIVE AND RISE SEQUENCES @@ -434,7 +436,7 @@ case FLOAT_LEVEL : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: FLOAT_LEVEL\r\n"); + xbee().printf("\r\n\nstate: FLOAT_LEVEL\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -450,20 +452,20 @@ // how exit? if (_fsm_timer > _timeout) { - pc().printf("FL: timed out\r\n"); + xbee().printf("FL: timed out\r\n"); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; } else if (fabs(imu().getPitch() - pitchLoop().getCommand()) < fabs(_pitchTolerance)) { //current tolerance is 5 degrees - pc().printf("FL: pitch: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",imu().getPitch(), pitchLoop().getCommand(), _pitchTolerance); + xbee().printf("FL: pitch: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",imu().getPitch(), pitchLoop().getCommand(), _pitchTolerance); _state = FLOAT_BROADCAST; _fsm_timer.reset(); _isTimeoutRunning = false; } // what is active? - pc().printf("FL: pitchLoop output: %3.1f, batt pos: %3.1f, piston pos: %3.1f [%0.1f sec]\r", pitchLoop().getOutput(), batt().getPosition_mm(), bce().getPosition_mm(), _fsm_timer.read()); + xbee().printf("FL: pitchLoop output: %3.1f, batt pos: %3.1f, piston pos: %3.1f [%0.1f sec]\r", pitchLoop().getOutput(), batt().getPosition_mm(), bce().getPosition_mm(), _fsm_timer.read()); batt().setPosition_mm(pitchLoop().getOutput()); break; @@ -471,7 +473,7 @@ case FLOAT_BROADCAST : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: FLOAT_BROADCAST\r\n"); + xbee().printf("\r\n\nstate: FLOAT_BROADCAST\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -483,11 +485,14 @@ // what are the commands? bce().setPosition_mm(_bceFloatPosition); // 320.0 batt().setPosition_mm(_battFloatPosition); // 73.0 + + //set rudder to center + rudder().setPosition_deg(0.0); //set rudder to center, zero degrees } // how exit? if (_fsm_timer > _timeout) { - pc().printf("FB: timed out\r\n"); + xbee().printf("FB: timed out\r\n"); _state = SIT_IDLE; _fsm_timer.reset(); @@ -496,9 +501,11 @@ _isTimeoutRunning = false; } - else if ( (fabs(bce().getPosition_mm() - bce().getSetPosition_mm()) < bce().getDeadband()) and + + //fix on float_broadcast to account for BCE stopping early in current hardware + else if ( (fabs(bce().getPosition_mm() - bce().getSetPosition_mm()) < 4.0 ) and (fabs(batt().getPosition_mm() - batt().getSetPosition_mm()) < batt().getDeadband()) ) { - pc().printf("FB: position: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(), bce().getDeadband()); + xbee().printf("FB: position: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(), bce().getDeadband()); _state = SIT_IDLE; _fsm_timer.reset(); @@ -509,14 +516,14 @@ } // what is active? - pc().printf("FB: bce pos: %0.1f mm, batt pos: %0.1f mm, heading(IMU): %0.1f (depthLoop POS: %3.1f ft) [%0.1f sec] (CMD BCE: %0.1f BATT: %0.1f)\r", bce().getPosition_mm(), batt().getPosition_mm(), imu().getHeading(), depthLoop().getPosition(), _fsm_timer.read(), bce().getSetPosition_mm(),batt().getSetPosition_mm()); + xbee().printf("FB: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); break; case MULTI_DIVE : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: MULTI-DIVE\r\n"); + xbee().printf("\r\n\nstate: MULTI-DIVE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -532,38 +539,42 @@ // what are the commands? depthLoop().setCommand(sequence_depth_command); pitchLoop().setCommand(sequence_pitch_command); - pc().printf("MULTI-DIVE: depth cmd: %3.1f ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); + + + headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) + xbee().printf("MULTI-DIVE: depth cmd: %3.1f ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); //no max depth recording right now } // how exit? if (_fsm_timer > _timeout) { - pc().printf("\r\n\nMULTI-DIVE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); + xbee().printf("\r\n\nMULTI-DIVE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); _state = MULTI_RISE; //new behavior 11/17/2017 _fsm_timer.reset(); _isTimeoutRunning = false; } else if (depthLoop().getPosition() > depthLoop().getCommand()) { - pc().printf("MULTI-DIVE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("MULTI-DIVE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = MULTI_RISE; _fsm_timer.reset(); _isTimeoutRunning = false; } // WHAT IS ACTIVE? - pc().printf("MULTI-DIVE: bce pos: %3.1f mm, batt pos: %3.1f mm (depthLoop POS: %3.1f ft) [%0.1f sec]\r", bce().getPosition_mm(), batt().getPosition_mm(), depthLoop().getPosition(), _fsm_timer.read()); + xbee().printf("MD: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); bce().setPosition_mm(depthLoop().getOutput()); batt().setPosition_mm(pitchLoop().getOutput()); - checkMotorPositions(); + // ACTIVE RUDDER CONTROL + rudder().setPosition_deg(headingLoop().getOutput()); break; case MULTI_RISE : // start local state timer and init any other one-shot actions if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: MULTI-RISE\r\n"); + xbee().printf("\r\n\nstate: MULTI-RISE\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -582,12 +593,14 @@ // what are the commands? (send back to 0.5 feet, not surface) // 11/21/2017 depthLoop().setCommand(0.5); pitchLoop().setCommand(-sequence_pitch_command); - pc().printf("MULTI-RISE: depth cmd: 0.0 ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); + + headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) + xbee().printf("MULTI-RISE: depth cmd: 0.0 ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); } // how exit? if (_fsm_timer > _timeout) { - pc().printf("MULTI-RISE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); + xbee().printf("MULTI-RISE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); _state = EMERGENCY_CLIMB; _fsm_timer.reset(); _isTimeoutRunning = false; @@ -599,7 +612,7 @@ // sequenceController().loadSequence(); } else if (depthLoop().getPosition() < 0.5) { // depth is less than 0.5 (zero is surface level) - pc().printf("MULTI-RISE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); + xbee().printf("MULTI-RISE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); //going to next state _isTimeoutRunning = false; @@ -626,24 +639,25 @@ } // WHAT IS ACTIVE? - pc().printf("MULTI-RISE: bce pos: %3.1f mm, batt pos: %3.1f mm (depthLoop POS: %3.1f ft) [%0.1f sec]\r", bce().getPosition_mm(), batt().getPosition_mm(), depthLoop().getPosition(), _fsm_timer.read()); + xbee().printf("MR: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors batt().setPosition_mm(pitchLoop().getOutput()); - checkMotorPositions(); + // ACTIVE RUDDER CONTROL + rudder().setPosition_deg(headingLoop().getOutput()); break; case TX_MBED_LOG: if (!_isTimeoutRunning) { - pc().printf("\r\n\nstate: TX_MBED_LOG\r\n"); + xbee().printf("\r\n\nstate: TX_MBED_LOG\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; //mbedLogger().openFileForTransmit(); //starts _fp file pointer at the beginning of the file - pc().printf("TX_MBED_LOG set to zero\n\r"); + xbee().printf("TX_MBED_LOG set to zero\n\r"); //function to read the file and get number of lines (packets to transmit) _timeout = mbedLogger().getNumberOfPacketsInCurrentLog(); @@ -653,7 +667,7 @@ //TIMED OUT if (_fsm_timer.read() > _timeout) { - pc().printf("\r\nTX_MBED_LOG: timed out!\r\n"); + xbee().printf("\r\nTX_MBED_LOG: timed out!\r\n"); //STATE _state = SIT_IDLE; @@ -662,7 +676,7 @@ _isTimeoutRunning = false; //mbedLogger().closeLogFile(); - pc().printf("\r\n\nstate: TX_MBED_LOG (log filed closed)\r\n"); + xbee().printf("\r\n\nstate: TX_MBED_LOG (log filed closed)\r\n"); } //received end transmission packet (if this is true) @@ -677,7 +691,7 @@ //mbedLogger().closeLogFile(); - pc().printf("\r\n\nTX_MBED_LOG: Received end transmission packet.)\r\n"); + xbee().printf("\r\n\nTX_MBED_LOG: Received end transmission packet.)\r\n"); } //What is active? @@ -687,30 +701,30 @@ break; - case RECEIVE_SEQUENCE : - pc().printf("state: RECEIVE_SEQUENCE\r\n"); + case RX_SEQUENCE : + xbee().printf("state: RX_SEQUENCE\r\n"); if (!_isTimeoutRunning) { - pc().printf("RECEIVE_SEQUENCE _isTimeoutRunning\r\n"); + xbee().printf("RX_SEQUENCE _isTimeoutRunning\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; } if (_fsm_timer.read() > _timeout) { - pc().printf("RECEIVE_SEQUENCE: timed out!\r\n"); + xbee().printf("RX_SEQUENCE: timed out!\r\n"); _state = SIT_IDLE; _fsm_timer.reset(); _isTimeoutRunning = false; } // what is active? - pc().printf("Receive sequence active?\r\n"); + xbee().printf("Receive sequence active?\r\n"); break; default : - pc().printf("DEBUG: SIT_IDLE\r\n"); + xbee().printf("DEBUG: SIT_IDLE\r\n"); _state = SIT_IDLE; } @@ -727,72 +741,70 @@ // output the keyboard menu for user's reference void StateMachine::printSimpleMenu() { - pc().printf("\r\r\n\nSIMPLE KEYBOARD MENU (07/26/2018):\r\r\n"); //make sure depth sensor tares itself on startup - pc().printf(" Neutral Positions BCE: %0.1f BMM: %0.1f (LIMIT: BCE: %0.1f BATT: %0.1f)\r\n\n", _neutral_bce_pos_mm, _neutral_batt_pos_mm, bce().getTravelLimit(),batt().getTravelLimit()); - - pc().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); - pc().printf(" J to float level\r\n"); - pc().printf(" B to float at broadcast pitch\r\n"); - pc().printf(" E to initiate emergency climb\r\n"); - pc().printf(" P to print the current log file.\r\n"); - pc().printf(" G to transmit MBED log file (60 second timeout)\r\n"); - pc().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); + xbee().printf("\r\r\n\nSIMPLE KEYBOARD MENU (08/13/2018):\r\r\n"); //make sure depth sensor tares itself on startup + xbee().printf(" Neutral Positions BCE: %0.1f BMM: %0.1f (LIMIT: BCE: %0.1f BATT: %0.1f)\r\n\n", _neutral_bce_pos_mm, _neutral_batt_pos_mm, bce().getTravelLimit(),batt().getTravelLimit()); - pc().printf("Q to TYPE in the BMM offset: %0.1f (BMM Dive POS: %0.1f, Rise POS: %0.1f)\r\n",_BMM_dive_offset, _neutral_batt_pos_mm - _BMM_dive_offset, _neutral_batt_pos_mm + _BMM_dive_offset); - pc().printf("A to TYPE in the BCE offset: %0.1f (BCE Dive POS: %0.1f, Rise POS: %0.1f)\r\n",_BCE_dive_offset, _neutral_bce_pos_mm - _BCE_dive_offset, _neutral_bce_pos_mm + _BCE_dive_offset); - pc().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); - pc().printf("S to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); - pc().printf("T to TYPE in the timeout (default is 60 seconds): %d s\r\n",_timeout); + xbee().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); + xbee().printf(" J to float level\r\n"); + xbee().printf(" B to float at broadcast pitch\r\n"); + xbee().printf(" E to initiate emergency climb\r\n"); + xbee().printf(" P to print the current log file.\r\n"); + xbee().printf(" G to transmit MBED log file\r\n"); + xbee().printf(" I to receive multi-dive sequence file\r\n"); + xbee().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); - pc().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); - pc().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); + xbee().printf("Q to TYPE in the BMM offset: %0.1f (BMM Dive POS: %0.1f, Rise POS: %0.1f) (positive input offset = pitch down)\r\n",_BMM_dive_offset, _neutral_batt_pos_mm + _BMM_dive_offset, _neutral_batt_pos_mm - _BMM_dive_offset); + xbee().printf("A to TYPE in the BCE offset: %0.1f (BCE Dive POS: %0.1f, Rise POS: %0.1f) (positive input offset = dive)\r\n",_BCE_dive_offset, _neutral_bce_pos_mm - _BCE_dive_offset, _neutral_bce_pos_mm + _BCE_dive_offset); + xbee().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); + xbee().printf("S to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); + xbee().printf("T to TYPE in the timeout (default is 60 seconds): %d s\r\n",_timeout); - pc().printf(" '|' to tare the depth sensor (vertical bar)\r\n"); - - pc().printf(" ? to reset mbed\r\n"); - pc().printf(" * (asterisk) to go to DEBUG keyboard menu\r\n"); + xbee().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); + xbee().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); + xbee().printf(" ? to reset mbed\r\n"); + xbee().printf(" * (asterisk) to go to DEBUG keyboard menu\r\n"); } void StateMachine::printDebugMenu() { - pc().printf("\r\r\n\nDEBUG KEYBOARD MENU (07/26/2018):\r\r\n"); - pc().printf(" Y to go into CHECK NEUTRAL TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n"); - pc().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); - pc().printf(" N to find neutral\r\n"); - pc().printf(" M to initiate multi-dive cycle\r\n"); - pc().printf(" D to initiate dive cycle\r\n"); - pc().printf(" R to initiate rise\r\n"); - pc().printf(" J to float level\r\n"); - pc().printf(" B to float at broadcast pitch\r\n"); - pc().printf(" E to initiate emergency climb\r\n"); - pc().printf(" '|' to tare the depth sensor (vertical bar)\r\n"); - pc().printf(" Z to show FSM and sub-FSM states.\r\n"); - pc().printf(" P to print the current log file.\r\n"); - pc().printf(" X to print the list of log files.\r\n"); - pc().printf(" I to receive data.\r\n"); - pc().printf(" G to transmit MBED log file (60 second timeout)\r\n"); - pc().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); - pc().printf("; or : to TYPE in the BCE neutral position: %0.1f\r\n", _neutral_bce_pos_mm); - pc().printf("[ or { to TYPE in the BMM neutral position: %0.1f\r\n", _neutral_batt_pos_mm); - pc().printf("Q to TYPE in pitch setpoint: %0.1f (Current IMU pitch: %0.1f deg)\r\n",_pitch_command,imu().getPitch()); - pc().printf("A to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); - pc().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); - pc().printf("T to enter in the timeout (default is 60 seconds): %d s\r\n",_timeout); + xbee().printf("\r\r\n\nDEBUG KEYBOARD MENU (08/08/2018):\r\r\n"); + xbee().printf(" Y to go into CHECK NEUTRAL TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n"); + xbee().printf(" N to find neutral\r\n"); + xbee().printf(" M to initiate multi-dive cycle\r\n"); + xbee().printf(" D to initiate dive cycle\r\n"); + xbee().printf(" R to initiate rise\r\n"); + xbee().printf(" J to float level\r\n"); + xbee().printf(" B to float at broadcast pitch\r\n"); + xbee().printf(" E to initiate emergency climb\r\n"); + xbee().printf(" '}' to HOME the BCE (5 second delay)\r\n"); + xbee().printf(" '|' to HOME the BMM (5 second delay)\r\n"); + xbee().printf(" Z to show FSM and sub-FSM states.\r\n"); + xbee().printf(" P to print the current log file.\r\n"); + xbee().printf(" X to print the list of log files.\r\n"); + xbee().printf(" I to receive data.\r\n"); + xbee().printf(" G to transmit MBED log file (60 second timeout)\r\n"); + xbee().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); + xbee().printf("; or : to TYPE in the BCE neutral position: %0.1f\r\n", _neutral_bce_pos_mm); + xbee().printf("[ or { to TYPE in the BMM neutral position: %0.1f\r\n", _neutral_batt_pos_mm); + xbee().printf("Q to TYPE in pitch setpoint: %0.1f (Current IMU pitch: %0.1f deg)\r\n",_pitch_command,imu().getPitch()); + xbee().printf("A to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); + xbee().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); + xbee().printf("T to enter in the timeout (default is 60 seconds): %d s\r\n",_timeout); - pc().printf(" 1 BCE PID sub-menu (type in inputs)\r\n"); - pc().printf(" 2 BATT PID sub-menu (type in inputs)\r\n"); - pc().printf(" 3 Depth PID sub-menu (type in inputs)\r\n"); - pc().printf(" 4 Pitch PID sub-menu (type in inputs)\r\n"); - pc().printf(" 5 Rudder (servo) sub-menu\r\n"); - pc().printf(" 6 HEADING PID sub-menu (type in inputs)\r\n"); - pc().printf(" 7 MANUAL_TUNING sub-menu (does not have a timer!) *** MOTORS ARE ACTIVE ***\r\n"); - pc().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); + xbee().printf(" 1 BCE PID sub-menu (type in inputs)\r\n"); + xbee().printf(" 2 BATT PID sub-menu (type in inputs)\r\n"); + xbee().printf(" 3 Depth PID sub-menu (type in inputs)\r\n"); + xbee().printf(" 4 Pitch PID sub-menu (type in inputs)\r\n"); + xbee().printf(" 5 Rudder (servo) sub-menu\r\n"); + xbee().printf(" 6 HEADING PID sub-menu (type in inputs)\r\n"); + xbee().printf(" 7 MANUAL_TUNING sub-menu (does not have a timer!) *** MOTORS ARE ACTIVE *** (bce 200, bmm 40, rudder 1640)\r\n"); + xbee().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); - pc().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); - pc().printf(" ? to reset mbed\r\n"); - pc().printf(" * (asterisk) to go to SIMPLE keyboard menu\r\n"); + xbee().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); + xbee().printf(" ? to reset mbed\r\n"); + xbee().printf(" * (asterisk) to go to SIMPLE keyboard menu\r\n"); } -//FIND_NEUTRAL Sub-Finite State Machine (sub-FSM) +//FIND_NEUTRAL sub-Finite State Machine (sub-FSM) // Note: the sub-FSM only moves the pistons once at the start of each timer loop // (timer completes, moves piston, timer completes, moves piston, etc) int StateMachine::runNeutralStateMachine() { @@ -802,12 +814,12 @@ if (!_isSubStateTimerRunning) { _neutral_timer = _fsm_timer.read() + 5; //record the time when this block is first entered and add 5 seconds - pc().printf("\r\n\nNEUTRAL_SINKING: Next retraction at %0.1f sec [current time: %0.1f] (pitch: %0.1f) (getSetPosition: %0.1f)\r\n", _neutral_timer, _fsm_timer.read(), pitchLoop().getPosition(), bce().getSetPosition_mm()); + xbee().printf("\r\n\nNEUTRAL_SINKING: Next retraction at %0.1f sec [current time: %0.1f] (pitch: %0.1f) (BCE getSetPosition: %0.1f)\r\n", _neutral_timer, _fsm_timer.read(), pitchLoop().getPosition(), bce().getSetPosition_mm()); - // what are the commands? (BCE linear actuator active, no pitch movement) - bce().setPosition_mm(bce().getSetPosition_mm() - 2.5); //Troy: There is some strange error where this has to be a hardcoded number. + // what are the commands? (BCE linear actuator active, no BMM or pitch movement) + bce().setPosition_mm(bce().getSetPosition_mm() - 2.5); - pc().printf("NEUTRAL_SINKING: Retracting piston %0.1f mm [BCE CMD : %0.1f] [pitch cmd: %0.1f] (pitch: %0.1f)\r\n", _neutral_sink_command_mm, bce().getSetPosition_mm(), pitchLoop().getCommand(), pitchLoop().getPosition()); + xbee().printf("NEUTRAL_SINKING: Retracting piston 2.5 mm [BCE CMD : %0.1f] (pitch: %0.1f)\r\n", bce().getSetPosition_mm(), pitchLoop().getPosition()); _isSubStateTimerRunning = true; //disable this block after one iteration } @@ -815,10 +827,11 @@ // how exit? //once reached the travel limit, no need to keep trying, so exit if (bce().getPosition_mm() <= 0) { - pc().printf("\r\nDEBUG: BCE current position is %0.1f mm (NEXT SUBSTATE NEUTRAL EXIT)\r\n", bce().getPosition_mm()); + xbee().printf("\r\nDEBUG: BCE current position is %0.1f mm (NEXT SUBSTATE NEUTRAL EXIT)\r\n", bce().getPosition_mm()); _substate = NEUTRAL_EXIT; _isSubStateTimerRunning = false; // reset the sub state timer - } + } + //Troy: Pressure vessel went beyond set depth limit, goes to next state //once deeper than the commanded setpoint... else if (depthLoop().getPosition() > _depth_command) { _substate = NEUTRAL_SLOWLY_RISE; // next state @@ -828,31 +841,34 @@ // what is active? //once the 10 second timer is complete, reset the timeout so the state one-shot entry will move the setpoint if (_fsm_timer.read() >= _neutral_timer) { - pc().printf("\r\n\n NEUTRAL_SINKING TIMER COMPLETE! [current time: %0.1f]\r\n", _fsm_timer.read()); + xbee().printf("\r\n\n NEUTRAL_SINKING TIMER COMPLETE! [current time: %0.1f]\r\n", _fsm_timer.read()); _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again } // what is active? (only the buoyancy engine moved every 5 seconds at start) - pc().printf("BCE current pos: %0.1f mm (BCE setpoint: %0.1f mm) (current depth: %0.1f ft)\r", bce().getPosition_mm(),bce().getSetPosition_mm(),depthLoop().getPosition()); //debug + xbee().printf("BCE current pos: %0.1f mm (BCE setpoint: %0.1f mm) (current depth: %0.1f ft)\r", bce().getPosition_mm(),bce().getSetPosition_mm(),depthLoop().getPosition()); //debug - checkMotorPositions(); //failsafe + //the BCE moves every 5 seconds. No BMM or rudder movement. + break; case NEUTRAL_SLOWLY_RISE: if (!_isSubStateTimerRunning) { _neutral_timer = _fsm_timer.read()+ 5; //record the time when this block is first entered and add 5 seconds - pc().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Next extension at %0.1f sec) [current time: %0.1f]\r\n",_neutral_timer,_fsm_timer.read()); + xbee().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Next extension at %0.1f sec) [current time: %0.1f]\r\n",_neutral_timer,_fsm_timer.read()); // what are the commands? //move piston at start of sequence (default: extend 2.0 mm) - bce().setPosition_mm(bce().getSetPosition_mm() + 2.0); //no depth command + //Pressure vessel should slowly rise + bce().setPosition_mm(bce().getSetPosition_mm() + 2.0); //no depth command, only motor position + //Troy: I commented out this command, we're finding pitch in the next state. // it's okay to run the pitch outer loop now since we've already found pitch level in the previous state - pitchLoop().setCommand(0.0); + //pitchLoop().setCommand(0.0); - pc().printf("NEUTRAL_SLOWLY_RISE: Extending BCE piston %0.1f mm [BCE CMD : %0.1f] [pitch cmd: %0.1f]\r\n", _neutral_rise_command_mm, bce().getSetPosition_mm(), pitchLoop().getCommand()); + xbee().printf("NEUTRAL_SLOWLY_RISE: Extending BCE piston 2.0 mm [BCE CMD : %0.1f] (pitch: %0.1f)\r\n", bce().getSetPosition_mm(), pitchLoop().getPosition()); _isSubStateTimerRunning = true; //disable this block after one iteration } @@ -863,9 +879,10 @@ _substate = NEUTRAL_EXIT; _isSubStateTimerRunning = false; // reset the sub state timer } + //Troy: Depth rate will go negative as the pressure vessel starts rising //depth rate or sink rate < 0 ft/s, go to the next substate the next iteration else if (depthLoop().getVelocity() < 0) { //less than zero ft/s - pc().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Sink Rate < 0 ft/s [time: %0.1f]\r\n", _fsm_timer.read()); + xbee().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Sink Rate < 0 ft/s [time: %0.1f]\r\n", _fsm_timer.read()); _substate = NEUTRAL_CHECK_PITCH; _isSubStateTimerRunning = false; // reset the sub state timer } @@ -873,16 +890,14 @@ // what is active? //once 5 second timer complete, reset the timeout so the state one-shot entry will move the setpoint if (_fsm_timer.read() >= _neutral_timer) { - pc().printf("\r\n\n NEUTRAL_SLOWLY_RISE TIMER COMPLETE! [timer: %0.1f]\r\n", _fsm_timer.read()); + xbee().printf("\r\n\n NEUTRAL_SLOWLY_RISE TIMER COMPLETE! [timer: %0.1f]\r\n", _fsm_timer.read()); _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again } // what is active? (only the buoyancy engine moved every 5 seconds) - pc().printf("depthLoop getOutput: %0.1f\r", depthLoop().getOutput()); //debug - bce().setPosition_mm(depthLoop().getOutput()); + xbee().printf("depthLoop getOutput: %0.1f\r", depthLoop().getOutput()); //debug - checkMotorPositions(); //failsafe break; case NEUTRAL_CHECK_PITCH : // fall thru to next state is desired @@ -890,16 +905,16 @@ if (!_isSubStateTimerRunning) { _neutral_timer = _fsm_timer.read() + 10; // record time when this block is entered and add several seconds - pc().printf("\r\nNEUTRAL_CHECK_PITCH: Next move in %0.1f sec \r\n",_neutral_timer - _fsm_timer.read()); + xbee().printf("\r\nNEUTRAL_CHECK_PITCH: Next move in %0.1f sec \r\n",_neutral_timer - _fsm_timer.read()); // what are the commands? (default: retract or extend 0.5 mm) - if (pitchLoop().getPosition() > 2) { // nose is high + if (pitchLoop().getPosition() > 2) { // nose is high (extend batteries) batt().setPosition_mm(batt().getSetPosition_mm() + 0.5); // move battery forward (using setpoint from linear actuator) - pc().printf("\r\nNeutral Check Pitch: moving battery FWD in %0.1f mm increments\r\n\n", _neutral_pitch_command_mm); + xbee().printf("\r\nNeutral Check Pitch: moving battery FWD in 0.5 mm increments\r\n\n"); } - else if (pitchLoop().getPosition() < -2) { // nose is low + else if (pitchLoop().getPosition() < -2) { // nose is low (retract batteries) batt().setPosition_mm(batt().getSetPosition_mm() - 0.5); // move battery aft (using setpoint from linear actuator) - pc().printf("\r\nNeutral Check Pitch: moving battery AFT in %0.1f mm increments\r\n\n", _neutral_pitch_command_mm); + xbee().printf("\r\nNeutral Check Pitch: moving battery AFT in 0.5 mm increments\r\n\n"); } _isSubStateTimerRunning = true; //disable this block after one iteration @@ -909,7 +924,7 @@ //pitch angle and pitch rate within small tolerance //benchtop tests confirm angle needs to be around 2 degrees if ((fabs(pitchLoop().getPosition()) < 2.0) and (fabs(pitchLoop().getVelocity()) < 5.0)) { - pc().printf("Debug: Found Level (NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH)\r\n"); //debug + xbee().printf("Debug: Found Level (NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH)\r\n"); //debug // found level, but don't need to save anything this time if (depthLoop().getPosition() > _max_recorded_depth_neutral) { //debug @@ -931,14 +946,14 @@ configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm, _pitch_filter_freq, _pitch_deadband); //P,I,D,batt zeroOffset configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm, _depth_filter_freq, _depth_deadband); //P,I,D, bce zeroOffset - pc().printf("\r\n\n>>> Saving Positions: BCE: %0.1f mm, BATT: %0.1f <<<\r\n\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); + xbee().printf("\r\n\n>>> Saving Positions: BCE: %0.1f mm, BATT: %0.1f <<<\r\n\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); _substate = NEUTRAL_EXIT; _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again } else { - pc().printf("\r\nDid not find NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH, how did I get here?!\r\n"); + xbee().printf("\r\nDid not find NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH, how did I get here?!\r\n"); _substate = NEUTRAL_EXIT; } } @@ -946,21 +961,20 @@ // what is active? //once timer complete, reset the timeout so the state one-shot entry will move the setpoint if (_fsm_timer.read() >= _neutral_timer) { - pc().printf("\r\n\nlevel timer COMPLETE!"); - pc().printf("\r\n\n (BATT POS: %0.1f) moving 1 mm [timer: %0.1f]\r\n", batt().getPosition_mm(), _fsm_timer.read()); + xbee().printf("\r\n\nlevel timer COMPLETE!"); + xbee().printf("\r\n\n (BATT POS: %0.1f) moving 1 mm [timer: %0.1f]\r\n", batt().getPosition_mm(), _fsm_timer.read()); _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again } - - checkMotorPositions(); //failsafe + break; //this state could be removed, it is only used as a transition but is needed to stop entering this function case NEUTRAL_EXIT : - pc().printf("substate: NEUTRAL_EXIT\r\n"); + xbee().printf("substate: NEUTRAL_EXIT\r\n"); break; default : - pc().printf("how did we get to substate: default?\r\n"); //debug + xbee().printf("how did we get to substate: default?\r\n"); //debug //a default within the sub-state machine _substate = NEUTRAL_EXIT; break; @@ -968,7 +982,7 @@ // reset the sub-FSM if needed (useful if you need to redo the neutral-finding sequence) if (_substate == NEUTRAL_EXIT) { - pc().printf("******************************** EXITING sub-FSM! *******************************\r\n\n"); + xbee().printf("******************************** EXITING sub-FSM! *******************************\r\n\n"); //reset internal sub-state back to first entry conditions (first state is immediately sinking) _substate = NEUTRAL_SINKING; @@ -1011,9 +1025,9 @@ //TEST int _keyboard_state = 0; //made this a local variable because it was retaining the last keyboard state - if (pc().readable() && (_state == SIT_IDLE || _state == KEYBOARD)) { + if (xbee().readable() && (_state == SIT_IDLE || _state == KEYBOARD)) { // get the key - user_input = pc().getc(); + user_input = xbee().getc(); //record that the keyboard was used _state_array[_state_array_counter] = KEYBOARD; @@ -1026,25 +1040,30 @@ /***************************** COMMON COMMANDS *****************************/ if (user_input == 'W') { - pc().printf(">> Please enter the heading (deg).\r\n"); + xbee().printf(">> Please enter the heading (deg).\r\n"); _heading_command = getFloatUserInput(); } //////////////////// TEST // else if (user_input == 'l') { -// pc().printf("CUT OFF RUDDER SERVO????\n\r"); +// xbee().printf("CUT OFF RUDDER SERVO????\n\r"); // rudder().pwm_pulse_off(); // } //////////////////// TEST + else if (user_input == 'K') { + xbee().printf("(K) BLAST DATA AND EXIT! \n\r"); + mbedLogger().blastData(); + } + else if (user_input == 'U') { - pc().printf("(U) TRANSMIT MULTIPLE PACKETS \n\r"); + xbee().printf("(U) TRANSMIT MULTIPLE PACKETS \n\r"); mbedLogger().transmitMultiplePackets(); } else if (user_input == 'H') { - pc().printf("(H) BLAST DATA AND MULTIPLE PACKETS! \n\r"); + xbee().printf("(H) BLAST DATA AND MULTIPLE PACKETS! \n\r"); wait(1); mbedLogger().blastData(); @@ -1052,73 +1071,72 @@ } else if (user_input == 'G') { - pc().printf("(G) BLAST DATA TEST! \n\r"); + xbee().printf("(G) BLAST DATA TEST and use FSM! \n\r"); wait(1); mbedLogger().blastData(); _keyboard_state = TX_MBED_LOG; } + else if (user_input == 'I') { + xbee().printf("(I) Receive Multi-Dive Sequence! \n\r"); + mbedLogger().receiveSequenceFile(); //receive sequence.txt files + } + else if (user_input == '8') { keyboard_menu_STREAM_STATUS(); } - - else if (user_input == '|') { - pc().printf("taring depth sensor\r\n"); - pc().printf("Pre-tare: press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt()); - wait(0.1); - depth().tare(); // tares to ambient (do on surface) - pc().printf("Post-tare: press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt()); - } - + else if (user_input == '?') { - pc().printf("\n\n\n>>> Resetting MBED <<<\n\n\n"); + xbee().printf("\n\n\n>>> Resetting MBED <<<\n\n\n"); wait(0.5); mbed_reset(); } else if (user_input == 'T') { - pc().printf("Please enter the timeout (timer) value below: \n\r"); + xbee().printf("Please enter the timeout (timer) value below: \n\r"); _timeout = fabs(getFloatUserInput()); } else if (user_input == 'C' or user_input == 'c') { - pc().printf("\r\n\nCURRENT STATUS AND PARAMETERS:\r\n"); + xbee().printf("\r\n\nCURRENT STATUS AND PARAMETERS:\r\n"); - pc().printf("raw BCE pos: %d \r\n",adc().readCh0()); - pc().printf("raw BMM pos: %d \r\n",adc().readCh1()); - pc().printf("raw BCE current sense: %d \r\n",adc().readCh2()); - pc().printf("raw BMM current sense: %d \r\n",adc().readCh3()); - pc().printf("raw depth pressure: %d \r\n",adc().readCh4()); - pc().printf("raw vessel pressure %d (internal psi: %0.1f)\r\n", adc().readCh5(),sensors().getInternalPressurePSI()); - //pc().printf("raw vessel pressure: %d \r\n",adc().readCh5()); - pc().printf("raw board voltage: %d (%0.1f volts)\r\n",adc().readCh6(),sensors().getVoltageInput()); - pc().printf("raw board current: %d (%0.3f amps)\r\n",adc().readCh7(), sensors().getCurrentInput()); - pc().printf("raw BCE limit switch: %d \r\n",bce().getSwitch()); - pc().printf("raw BMM limit switch: %d \r\n",batt().getSwitch()); - pc().printf("calc vessel pressure: %f (counts: %d) \r\n",sensors().getInternalPressurePSI(),adc().readCh5()); + xbee().printf("raw BCE pos: %d \r\n",adc().readCh0()); + xbee().printf("raw BMM pos: %d \r\n",adc().readCh1()); + xbee().printf("raw BCE current sense: %d \r\n",adc().readCh2()); + xbee().printf("raw BMM current sense: %d \r\n",adc().readCh3()); + xbee().printf("raw depth pressure: %d \r\n",adc().readCh4()); + xbee().printf("raw vessel pressure %d (internal psi: %0.1f)\r\n", adc().readCh5(),sensors().getInternalPressurePSI()); + //xbee().printf("raw vessel pressure: %d \r\n",adc().readCh5()); + xbee().printf("raw board voltage: %d (%0.1f volts)\r\n",adc().readCh6(),sensors().getVoltageInput()); + xbee().printf("raw board current: %d (%0.3f amps)\r\n",adc().readCh7(), sensors().getCurrentInput()); + xbee().printf("raw BCE limit switch: %d \r\n",bce().getSwitch()); + xbee().printf("raw BMM limit switch: %d \r\n",batt().getSwitch()); + xbee().printf("calc vessel pressure: %f (counts: %d) \r\n",sensors().getInternalPressurePSI(),adc().readCh5()); // End of ADC Test - pc().printf("depth: %3.1f ft\r\n",depthLoop().getPosition()); - pc().printf("pitch: %3.1f deg\r\n",imu().getPitch()); - pc().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm()); - pc().printf("bce().getSetPosition_mm(): %3.1f\r\n",bce().getSetPosition_mm()); - pc().printf("batt().getPosition_mm(): %3.1f\r\n",batt().getPosition_mm()); - pc().printf("batt().getSetPosition_mm(): %3.1f\r\n",batt().getSetPosition_mm()); - pc().printf("depthLoop().getCommand(): %3.1f\r\n",depthLoop().getCommand()); - pc().printf("pitchLoop().getCommand(): %3.1f\r\n",pitchLoop().getCommand()); + xbee().printf("depth: %3.1f ft\r\n",depthLoop().getPosition()); + xbee().printf("pitch: %3.1f deg\r\n",imu().getPitch()); + xbee().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm()); + xbee().printf("bce().getSetPosition_mm(): %3.1f\r\n",bce().getSetPosition_mm()); + xbee().printf("batt().getPosition_mm(): %3.1f\r\n",batt().getPosition_mm()); + xbee().printf("batt().getSetPosition_mm(): %3.1f\r\n",batt().getSetPosition_mm()); + xbee().printf("depthLoop().getCommand(): %3.1f\r\n",depthLoop().getCommand()); + xbee().printf("pitchLoop().getCommand(): %3.1f\r\n",pitchLoop().getCommand()); - pc().printf("\r\nNeutral Buoyancy Positions: bce: %0.1f, batt: %0.1f\r\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); - pc().printf("depthLoop().getOutputOffset(): %0.1f\r\n",depthLoop().getOutputOffset()); - pc().printf("pitchLoop().getOutputOffset(): %0.1f\r\n",pitchLoop().getOutputOffset()); - pc().printf("Max recorded depth: neutral: %0.1f, dive: %0.1f, auto_neutral_depth: %0.1f\r\n\n",_max_recorded_depth_neutral, _max_recorded_depth_dive, _max_recorded_auto_neutral_depth); + xbee().printf("\r\nNeutral Buoyancy Positions: bce: %0.1f, batt: %0.1f\r\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); + xbee().printf("depthLoop().getOutputOffset(): %0.1f\r\n",depthLoop().getOutputOffset()); + xbee().printf("pitchLoop().getOutputOffset(): %0.1f\r\n",pitchLoop().getOutputOffset()); + xbee().printf("Max recorded depth: neutral: %0.1f, dive: %0.1f, auto_neutral_depth: %0.1f\r\n\n",_max_recorded_depth_neutral, _max_recorded_depth_dive, _max_recorded_auto_neutral_depth); - pc().printf("\r\n"); - pc().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %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 offset: %3i, limit %6.1f mm, slope %0.5f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); - pc().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, output 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, output offset: %6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset()); + xbee().printf("\r\n"); + xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, deadband: %0.1f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope(), bce().getDeadband()); + xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, deadband: %0.1f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope(), batt().getDeadband()); + xbee().printf("rudder min_pwm:%6.1f, center_pwm:%6.1f, max_pwm:%6.1f (min_deg:%6.1f max_deg:%6.1f)\r\n",rudder().getMinPWM(),rudder().getCenterPWM(),rudder().getMaxPWM(),rudder().getMinDeg(),rudder().getMaxDeg()); + xbee().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); + xbee().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); + xbee().printf("heading P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); } /***************************** COMMON COMMANDS *****************************/ @@ -1128,6 +1146,19 @@ if (user_input == 'D') { _keyboard_state = DIVE; } + + else if (user_input == '}') { + xbee().printf("HOMING the BCE (5 second delay)\r\n"); + wait(5); + bce().homePiston(); + } + + else if (user_input == '|') { + xbee().printf("HOMING the BMM (5 second delay)\r\n"); + wait(5); + batt().homePiston(); + } + else if (user_input == 'N') { _keyboard_state = FIND_NEUTRAL; } @@ -1145,7 +1176,7 @@ stateMachine().getDiveSequence(); //get first sequence on keyboard press _keyboard_state = currentStateStruct.state; - pc().printf("Starting Dive Sequence Controller! (state: %d)\r\n", _keyboard_state); //neutral sequence and dive cycles + xbee().printf("Starting Dive Sequence Controller! (state: %d)\r\n", _keyboard_state); //neutral sequence and dive cycles } else if (user_input == 'R') { _keyboard_state = RISE; @@ -1164,10 +1195,6 @@ _keyboard_state = CHECK_TUNING; } - else if (user_input == 'V') { - _keyboard_state = POSITION_DIVE; - } - // some debug tools below else if (user_input == 'P') { //Print current SD card log file @@ -1177,15 +1204,12 @@ else if (user_input == 'X') { mbedLogger().printMbedDirectory(); //print all log files to the screen } - else if (user_input == 'I') { - mbedLogger().receiveMissionDataWithTicker(); //receive sequence.txt files - } else if (user_input == '~') { - pc().printf("ERASING MBED LOG FILE\r\n"); + xbee().printf("ERASING MBED LOG FILE\r\n"); mbedLogger().eraseFile(); } else if (user_input == 'Z') { - pc().printf("FSG FSM States: \r\n"); + xbee().printf("FSG FSM States: \r\n"); string string_state; for (int i = 0; i < _state_array_counter; i++) { @@ -1209,10 +1233,10 @@ string_state = "MULTI_RISE"; else if (_state_array[i] == KEYBOARD) string_state = "KEYBOARD"; - pc().printf("State #%d: %d (%s)\r\n", i, _state_array[i], string_state.c_str()); + xbee().printf("State #%d: %d (%s)\r\n", i, _state_array[i], string_state.c_str()); } - pc().printf("\r\nNeutral sub-FSM States: \r\n"); + xbee().printf("\r\nNeutral sub-FSM States: \r\n"); string string_substate; for (int i = 0; i < _substate_array_counter; i++) { @@ -1226,26 +1250,26 @@ string_substate = "NEUTRAL_EXIT <-- "; else if (_substate_array[i] == EMERGENCY_CLIMB) string_substate = " -- > EMERGENCY_CLIMB <-- "; - pc().printf("Neutral Substate #%d: %d (%s)\r\n", i, _state_array[i], string_substate.c_str()); + xbee().printf("Neutral Substate #%d: %d (%s)\r\n", i, _state_array[i], string_substate.c_str()); } - pc().printf("\r\n"); //make space between printouts + xbee().printf("\r\n"); //make space between printouts } //BATTERY/PITCH else if (user_input == '[' or user_input == '{') { - pc().printf("Please TYPE in the new BATT neutral position.\n\r"); + xbee().printf("Please TYPE in the new BATT neutral position.\n\r"); _neutral_batt_pos_mm = getFloatUserInput(); pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // decrease the batt neutral setpoint - pc().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset()); + xbee().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset()); // save neutral pitch value to config file configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm, _pitch_filter_freq, _pitch_deadband); //P,I,D,batt zeroOffset } //BCE/DEPTH else if (user_input == ';' or user_input == ':') { - pc().printf("Please TYPE in the new BCE neutral position.\n\r"); + xbee().printf("Please TYPE in the new BCE neutral position.\n\r"); _neutral_bce_pos_mm = getFloatUserInput(); depthLoop().setOutputOffset(_neutral_bce_pos_mm); // decrease the bce neutral setpoint - pc().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset()); + xbee().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset()); // save neutral depth value to config file configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm, _depth_filter_freq, _depth_deadband); } @@ -1253,11 +1277,11 @@ // change settings //heading is in the common controls else if (user_input == 'Q') { - pc().printf(">> Please enter the desired PITCH (deg).\r\n"); + xbee().printf(">> Please enter the desired PITCH (deg).\r\n"); _pitch_command = getFloatUserInput(); } else if (user_input == 'A') { - pc().printf(">> Please enter the desired DEPTH (ft).\r\n"); + xbee().printf(">> Please enter the desired DEPTH (ft).\r\n"); _depth_command = getFloatUserInput(); } @@ -1293,8 +1317,8 @@ } else if (user_input == '*') { - pc().printf("SWITCHING TO SIMPLE MENU!\r\n"); - wait(2); + xbee().printf("SWITCHING TO SIMPLE MENU!\r\n"); + wait(1); _debug_menu_on = false; } } //end of debug menu @@ -1325,37 +1349,37 @@ mbedLogger().printCurrentLogFile(); //print the current log file to the screen } else if (user_input == '~') { - pc().printf("ERASING MBED LOG FILE\r\n"); + xbee().printf("ERASING MBED LOG FILE\r\n"); mbedLogger().eraseFile(); } //POSITION DIVE COMMANDS else if (user_input == 'Q') { - pc().printf(">> Please enter the desired BMM offset (mm).\r\n"); + xbee().printf(">> Please enter the desired BMM offset (mm).\r\n"); _BMM_dive_offset = getFloatUserInput(); } else if (user_input == 'A') { - pc().printf(">> Please enter the desired BCE offset (mm).\r\n"); + xbee().printf(">> Please enter the desired BCE offset (mm).\r\n"); _BCE_dive_offset = getFloatUserInput(); } else if (user_input == 'S') { - pc().printf(">> Please enter the desired DEPTH (ft).\r\n"); + xbee().printf(">> Please enter the desired DEPTH (ft).\r\n"); _depth_command = getFloatUserInput(); } //POSITION DIVE COMMANDS else if (user_input == '*') { - pc().printf("SWITCHING TO DEBUG MENU!\r\n"); + xbee().printf("SWITCHING TO DEBUG MENU!\r\n"); _debug_menu_on = true; - wait(2); + wait(1); } } /***************************** SIMPLE MENU *****************************/ //when you read the keyboard successfully, change the state _state = _keyboard_state; //set state at the end of this function - //pc().printf("\r\n\n ********* KEYBOARD STATE: %d *********\r\n\n", _state); + //xbee().printf("\r\n\n ********* KEYBOARD STATE: %d *********\r\n\n", _state); } } @@ -1363,11 +1387,11 @@ char STATUS_key; // show the menu - pc().printf("\r\n8: STATUS DEBUG MENU (EXIT WITH 'X' !)\r\n"); + xbee().printf("\r\n8: STATUS DEBUG MENU (EXIT WITH 'X' !)\r\n"); while (1) { - if (pc().readable()) { - STATUS_key = pc().getc(); //get each keystroke + if (xbee().readable()) { + STATUS_key = xbee().getc(); //get each keystroke } else { @@ -1375,20 +1399,20 @@ wait(1); -// pc().printf("BCE POS (CMD): %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rudder_servo_pwm: %0.1f \n[FILT/RAW 0(%d,%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getPosition_pwm(),adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7(), bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); - pc().printf("BCE POS: %0.1f (cmd %0.1f) BATT POS: %0.1f (cmd %0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rdr_pwm: %0.1f [FILT/RAW 0(%d,%d),1(%d,%d),2(%d,%d),3(%d,%d),4(%d,%d),5(%d,%d),6(%d,%d),7(%d,%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getPosition_pwm(),adc().readCh0(),adc().readRawCh0(),adc().readCh1(),adc().readRawCh1(),adc().readCh2(),adc().readRawCh2(),adc().readCh3(),adc().readRawCh3(),adc().readCh4(),adc().readRawCh4(),adc().readCh5(),adc().readRawCh5(),adc().readCh6(),adc().readRawCh6(),adc().readCh7(),adc().readRawCh7(),bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); +// xbee().printf("BCE POS (CMD): %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rudder_servo_pwm: %0.1f \n[FILT/RAW 0(%d,%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getSetPosition_pwm(),adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7(), bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); + xbee().printf("BCE POS: %0.1f (cmd %0.1f) BATT POS: %0.1f (cmd %0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rdr_pwm: %0.1f [FILT/RAW 0(%d,%d),1(%d,%d),2(%d,%d),3(%d,%d),4(%d,%d),5(%d,%d),6(%d,%d),7(%d,%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getSetPosition_pwm(),adc().readCh0(),adc().readRawCh0(),adc().readCh1(),adc().readRawCh1(),adc().readCh2(),adc().readRawCh2(),adc().readCh3(),adc().readRawCh3(),adc().readCh4(),adc().readRawCh4(),adc().readCh5(),adc().readRawCh5(),adc().readCh6(),adc().readRawCh6(),adc().readCh7(),adc().readRawCh7(),bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); continue; // didn't get a user input, so keep waiting for it } // process the keys if (STATUS_key == 'X') { - pc().printf("\r\nX: EXITING STATUS DEBUG MENU\r\n"); + xbee().printf("\r\nX: EXITING STATUS DEBUG MENU\r\n"); break; //exit the while loop } else { - pc().printf("\r\nThis key (%c) does nothing here. ", STATUS_key); + xbee().printf("\r\nThis key (%c) does nothing here. ", STATUS_key); } } } @@ -1404,21 +1428,18 @@ char RUDDER_PID_key; // print the menu - pc().printf("\r\nRUDDER (servo driver) settings (MENU)"); - pc().printf("\r\n(Adjust min/max/center PWM settings with the following keys: N and M and C"); - pc().printf("\r\n(Adjust DEGREE limit settings with the following keys: min = K, max = L"); - pc().printf("\r\n(Hit shift + X to exit w/o saving. Hit shift + S to save.\r\n"); - pc().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); + xbee().printf("\r\nRUDDER (servo driver) settings (MENU)"); + xbee().printf("\r\nAdjust min_pwm/max_pwm/center_pwm/min_deg/max_deg settings with the following keys: N, M, C, K, L"); + xbee().printf("\r\nHit shift + X to exit w/o saving. Hit shift + S to save.\r\n"); + xbee().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - RUDDER_PID_key = pc().getc(); + if (xbee().readable()) { + RUDDER_PID_key = xbee().getc(); } else { - wait(0.5); - pc().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); continue; // didn't get a user input, so keep waiting for it } @@ -1433,39 +1454,39 @@ // save rudder servo driver values for inner loop configFileIO().saveRudderData(rudder_min_deg, rudder_max_deg, rudder_ctr_pwm, rudder_min_pwm, rudder_max_pwm); - pc().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); + xbee().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); + xbee().printf("Adjust min_pwm/max_pwm/center_pwm/min_deg/max_deg settings with the following keys: N, M, C, K, L\r\n"); } else if (RUDDER_PID_key == 'X') { break; //exit the while loop } // MIN PWM else if (RUDDER_PID_key == 'N') { - pc().printf(">> Type in rudder_min_pwm with keyboard.\r\n"); + xbee().printf(">> Type in rudder_min_pwm with keyboard.\r\n"); rudder_min_pwm = getFloatUserInput(); } // MAX PWM else if (RUDDER_PID_key == 'M') { - pc().printf(">> Type in rudder_max_pwm with keyboard.\r\n"); + xbee().printf(">> Type in rudder_max_pwm with keyboard.\r\n"); rudder_max_pwm = getFloatUserInput(); } // CENTER PWM else if (RUDDER_PID_key == 'C') { - pc().printf(">> Type in rudder_ctr_pwm with keyboard.\r\n"); + xbee().printf(">> Type in rudder_ctr_pwm with keyboard.\r\n"); rudder_ctr_pwm = getFloatUserInput(); } // MIN DEG else if (RUDDER_PID_key == 'K') { - pc().printf(">> Type in rudder_min_deg with keyboard.\r\n"); + xbee().printf(">> Type in rudder_min_deg with keyboard.\r\n"); rudder_min_deg = getFloatUserInput(); } // MAX DEG else if (RUDDER_PID_key == 'L') { - pc().printf(">> Type in rudder_max_deg with keyboard.\r\n"); + xbee().printf(">> Type in rudder_max_deg with keyboard.\r\n"); rudder_max_deg = getFloatUserInput(); - } - + } else { - pc().printf("RUDDER SETUP: [%c] This key does nothing here. \r", RUDDER_PID_key); + xbee().printf("RUDDER SETUP: [%c] This key does nothing here. \r", RUDDER_PID_key); } } } @@ -1477,21 +1498,22 @@ void StateMachine::keyboard_menu_MANUAL_TUNING() { char TUNING_key; - // show the menu - pc().printf("\r\n7: MANUAL TUNING MENU (EXIT WITH 'X' !) (Pause and Unpause rudder ticker with P and U\n"); - pc().printf("\r\n(Adjust BCE and BATT positions in real-time. Timeout NOT running! (decrease/increase BCE with A/S, BATT with Q/W, RUDDER with E/R)\r\n"); - pc().printf("\r\nMANUAL_TUNING: BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(), imu().getHeading()); - //made these into internal parameters - float _tuning_bce_pos_mm = 300.0; //safe starting position - float _tuning_batt_pos_mm = 60.0; //safe starting position + float _tuning_bce_pos_mm = 200.0; //safe starting position + float _tuning_batt_pos_mm = 40.0; //safe starting position float _tuning_rudder_pos_deg = 0.0; //safe starting position + float _tuning_rudder_pwm = 1640.0; //immediately start at those positions bce().setPosition_mm(_tuning_bce_pos_mm); batt().setPosition_mm(_tuning_batt_pos_mm); rudder().setPosition_deg(_tuning_rudder_pos_deg); + // show the menu + xbee().printf("\r\n7: MANUAL TUNING MENU (EXIT WITH 'X' !) (Pause and Unpause rudder ticker with P and U\n"); + xbee().printf("\r\n(Adjust BCE and BATT positions in real-time. Timeout NOT running! (decrease/increase BCE with A/S, BATT with Q/W, RUDDER with E/R)\r\n"); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); + // what needs to be started? bce().unpause(); //this is now active batt().unpause(); //this is now active @@ -1500,12 +1522,12 @@ while (1) { wait(0.1); - if (pc().readable()) { - TUNING_key = pc().getc(); //get each keystroke + if (xbee().readable()) { + TUNING_key = xbee().getc(); //get each keystroke } else { - pc().printf("MT: POS (CMD) BCE %3.1f mm (%3.1f mm), BATT %3.1f mm (%3.1f mm) SERVO: %0.1f deg, (%0.1f pwm) PITCH: %0.1f,HEADING: %0.1f \r", bce().getPosition_mm(), bce().getSetPosition_mm(), batt().getPosition_mm(), batt().getSetPosition_mm(), rudder().getPosition_deg(), rudder().getPosition_pwm(),imu().getPitch(),imu().getHeading()); + //xbee().printf("MT: POS (CMD) BCE %3.1f mm (%3.1f mm), BATT %3.1f mm (%3.1f mm) SERVO: %0.1f deg, (%0.1f pwm) PITCH: %0.1f,HEADING: %0.1f \r", bce().getPosition_mm(), bce().getSetPosition_mm(), batt().getPosition_mm(), batt().getSetPosition_mm(), rudder().getSetPosition_deg(), rudder().getSetPosition_pwm(),imu().getPitch(),imu().getHeading()); continue; // didn't get a user input, so keep waiting for it } @@ -1523,58 +1545,70 @@ } //Buoyancy Engine - else if (TUNING_key == 'A') { + else if (TUNING_key == 'A' or TUNING_key == 'a') { _tuning_bce_pos_mm = _tuning_bce_pos_mm - 1.0; bce().setPosition_mm(_tuning_bce_pos_mm); //this variable is loaded from the file at initialization - pc().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } - else if (TUNING_key == 'S') { + else if (TUNING_key == 'S' or TUNING_key == 's') { _tuning_bce_pos_mm = _tuning_bce_pos_mm + 1.0; bce().setPosition_mm(_tuning_bce_pos_mm); //this variable is loaded from the file at initialization - pc().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } //BATTERY - else if (TUNING_key == 'Q') { + else if (TUNING_key == 'Q' or TUNING_key == 'q') { _tuning_batt_pos_mm = _tuning_batt_pos_mm - 1.0; batt().setPosition_mm(_tuning_batt_pos_mm); //this variable is loaded from the file at initialization - pc().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } - else if (TUNING_key == 'W') { + else if (TUNING_key == 'W' or TUNING_key == 'w') { _tuning_batt_pos_mm = _tuning_batt_pos_mm + 1.0; batt().setPosition_mm(_tuning_batt_pos_mm); //this variable is loaded from the file at initialization - pc().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } else if (TUNING_key == 'c' or TUNING_key == 'C') { - pc().printf("MANUAL_TUNING: (current stats) BCE pos: %3.1f mm (cmd: %3.1f mm), BATT pos: %3.1f mm (cmd: %3.1f mm) SERVO: %0.1f deg, %f pwm\r", bce().getPosition_mm(), bce().getSetPosition_mm(), batt().getPosition_mm(), batt().getSetPosition_mm(), rudder().getPosition_deg(), rudder().getPosition_pwm()); + xbee().printf("\r\nMT: (CURRENT POSITIONS) BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } //RUDER - else if (TUNING_key == 'E') { + else if (TUNING_key == 'R' or TUNING_key == 'r') { _tuning_rudder_pos_deg = _tuning_rudder_pos_deg - 0.5; rudder().setPosition_deg(_tuning_rudder_pos_deg); - pc().printf("MANUAL_TUNING: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getPosition_pwm(), rudder().getPosition_deg(), headingLoop().getPosition(), imu().getHeading()); + xbee().printf("MT: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getSetPosition_pwm(), rudder().getSetPosition_deg(), headingLoop().getPosition(), imu().getHeading()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } - else if (TUNING_key == 'R') { + else if (TUNING_key == 'E' or TUNING_key == 'e') { _tuning_rudder_pos_deg = _tuning_rudder_pos_deg + 0.5; rudder().setPosition_deg(_tuning_rudder_pos_deg); - pc().printf("MANUAL_TUNING: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getPosition_pwm(), rudder().getPosition_deg(), headingLoop().getPosition(), imu().getHeading()); + xbee().printf("MT: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getSetPosition_pwm(), rudder().getSetPosition_deg(), headingLoop().getPosition(), imu().getHeading()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } - else if (TUNING_key == 'P') { - rudder().pause(); + else if (TUNING_key == '-' or TUNING_key == '_') { + _tuning_rudder_pwm -= 10.0; + rudder().setPWM(_tuning_rudder_pwm); + xbee().printf("MT: (-) RUDDER CHANGE %0.1f pwm\n\r", rudder().getSetPosition_pwm()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } - - else if (TUNING_key == 'U') { - rudder().unpause(); + + else if (TUNING_key == '=' or TUNING_key == '+') { + _tuning_rudder_pwm += 10.0; + rudder().setPWM(_tuning_rudder_pwm); + xbee().printf("MT: (+) RUDDER CHANGE %0.1f pwm\n\r", rudder().getSetPosition_pwm()); + xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); } else { - pc().printf("\r\nMANUAL_TUNING: [%c] This key does nothing here. \r", TUNING_key); + xbee().printf("\r\nMANUAL_TUNING: [%c] This key does nothing here. \r", TUNING_key); } } } @@ -1583,11 +1617,11 @@ char TUNING_key; // show the menu - pc().printf("\r\n8: CHANNEL READINGS (EXIT WITH 'X' !)"); + xbee().printf("\r\n8: CHANNEL READINGS (EXIT WITH 'X' !)"); while (1) { - if (pc().readable()) { - TUNING_key = pc().getc(); //get each keystroke + if (xbee().readable()) { + TUNING_key = xbee().getc(); //get each keystroke } // process the keys @@ -1601,7 +1635,7 @@ else { wait(0.5); - pc().printf("0(%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)\r\n",adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7()); + xbee().printf("0(%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)\r\n",adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7()); continue; // didn't get a user input, so keep waiting for it } } @@ -1611,11 +1645,11 @@ // char TUNING_key; // // // show the menu -// pc().printf("\r\n9: BCE and BMM POSITION READINGS (EXIT WITH 'X' !)"); +// xbee().printf("\r\n9: BCE and BMM POSITION READINGS (EXIT WITH 'X' !)"); // // while (1) { -// if (pc().readable()) { -// TUNING_key = pc().getc(); //get each keystroke +// if (xbee().readable()) { +// TUNING_key = xbee().getc(); //get each keystroke // } // // // process the keys @@ -1635,7 +1669,7 @@ // unsigned int raw = adc().readCh5(); // vmeasured = ((float)raw)/4095.0*vref; // -// pc().printf("BCE POS(%d), BMM POS(%d), BCE CUR(%d), BMM CUR(%d), Depth Pressure (%d) << POS: BCE %0.2f, BATT %0.2f >>\r\n",adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),bce().getPosition_mm(),batt().getPosition_mm()); +// xbee().printf("BCE POS(%d), BMM POS(%d), BCE CUR(%d), BMM CUR(%d), Depth Pressure (%d) << POS: BCE %0.2f, BATT %0.2f >>\r\n",adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),bce().getPosition_mm(),batt().getPosition_mm()); // // continue; // didn't get a user input, so keep waiting for it // } @@ -1650,16 +1684,16 @@ float bce_KD = bce().getControllerD(); // load current global value // show the menu - pc().printf("\n\rBuoyancy Engine PID gain settings (MENU)"); - pc().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); - pc().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); - pc().printf("bce P: %3.3f, I: %3.3f, D %3.3f, zeroOffset %d, limit %3.0f mm, slope %3.3f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); + xbee().printf("\n\rBuoyancy Engine PID gain settings (MENU)"); + xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); + xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); + xbee().printf("bce P: %3.3f, I: %3.3f, D %3.3f, zeroOffset %d, limit %3.0f mm, slope %3.3f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - BCE_PID_key = pc().getc(); + if (xbee().readable()) { + BCE_PID_key = xbee().getc(); } else { continue; // didn't get a user input, so keep waiting for it @@ -1674,35 +1708,35 @@ // save to "BCE.TXT" file configFileIO().saveBCEData(bce_KP, bce_KI, bce_KD, 100, 6.0, 0.5); - pc().printf("bce P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); + xbee().printf("bce P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); } else if (BCE_PID_key == 'X') { break; //exit the while loop } else if (BCE_PID_key == 'P') { - pc().printf(">> Type in proportional gain with keyboard.\n\r"); + xbee().printf(">> Type in proportional gain with keyboard.\n\r"); bce_KP = getFloatUserInput(); } else if (BCE_PID_key == 'I') { - pc().printf(">> Type in integral gain with keyboard.\n\r"); + xbee().printf(">> Type in integral gain with keyboard.\n\r"); bce_KI = getFloatUserInput(); } else if (BCE_PID_key == 'D') { - pc().printf(">> Type in derivative gain with keyboard.\n\r"); + xbee().printf(">> Type in derivative gain with keyboard.\n\r"); bce_KD = getFloatUserInput(); } else if (BCE_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); + xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); float bce_freq = getFloatUserInput(); bce().setFilterFrequency(bce_freq); } else if (BCE_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); + xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); float bce_deadband = getFloatUserInput(); bce().setDeadband(bce_deadband); } else { - pc().printf("\n\rBCE: [%c] This key does nothing here. \r", BCE_PID_key); + xbee().printf("\n\rBCE: [%c] This key does nothing here. \r", BCE_PID_key); } } } @@ -1715,16 +1749,16 @@ float batt_KD = batt().getControllerD(); // load current global value // print the menu - pc().printf("\n\rBattery Motor PID gain settings (MENU)"); - pc().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); - pc().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); - pc().printf("batt P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); + xbee().printf("\n\rBattery Motor PID gain settings (MENU)"); + xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); + xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); + xbee().printf("batt P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - BMM_PID_key = pc().getc(); + if (xbee().readable()) { + BMM_PID_key = xbee().getc(); } else { continue; // didn't get a user input, so keep waiting for it @@ -1739,35 +1773,35 @@ // save to "BATT.TXT" file configFileIO().saveBattData(batt_KP, batt_KI, batt_KD, 100, 6.0, 0.5); - pc().printf("batt P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); + xbee().printf("batt P: %3.3f, I: %3.3f, D %3.3f, zero %d, limit %3.0f mm, slope %3.3f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); } else if (BMM_PID_key == 'X') { break; //exit the while loop } else if (BMM_PID_key == 'P') { - pc().printf(">> Type in proportional gain with keyboard.\n\r"); + xbee().printf(">> Type in proportional gain with keyboard.\n\r"); batt_KP = getFloatUserInput(); } else if (BMM_PID_key == 'I') { - pc().printf(">> Type in integral gain with keyboard.\n\r"); + xbee().printf(">> Type in integral gain with keyboard.\n\r"); batt_KI = getFloatUserInput(); } else if (BMM_PID_key == 'D') { - pc().printf(">> Type in derivative gain with keyboard.\n\r"); + xbee().printf(">> Type in derivative gain with keyboard.\n\r"); batt_KD = getFloatUserInput(); } else if (BMM_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); + xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); float batt_freq = getFloatUserInput(); batt().setFilterFrequency(batt_freq); } else if (BMM_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); + xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); float batt_deadband = getFloatUserInput(); batt().setDeadband(batt_deadband); } else { - pc().printf("\n\rBATT: [%c] This key does nothing here. \r", BMM_PID_key); + xbee().printf("\n\rBATT: [%c] This key does nothing here. \r", BMM_PID_key); } } } @@ -1782,16 +1816,16 @@ float depth_deadband = depthLoop().getDeadband(); // print the menu - pc().printf("\n\rDEPTH (Buoyancy Engine O.L.) PID gain settings (MENU)"); - pc().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); - pc().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); - pc().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); + xbee().printf("\n\rDEPTH (Buoyancy Engine O.L.) PID gain settings (MENU)"); + xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); + xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); + xbee().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - DEPTH_PID_key = pc().getc(); + if (xbee().readable()) { + DEPTH_PID_key = xbee().getc(); } else { continue; // didn't get a user input, so keep waiting for it @@ -1809,7 +1843,7 @@ // save to "DEPTH.TXT" file configFileIO().saveDepthData(depth_KP, depth_KI, depth_KD, _neutral_bce_pos_mm, depth_freq, depth_deadband); //P,I,D, bce zeroOffset - pc().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); + xbee().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); //set class variables that will be used in find neutral sequence _depth_KP = depthLoop().getControllerP(); // load current depth value @@ -1820,27 +1854,27 @@ break; //exit the while loop } else if (DEPTH_PID_key == 'P') { - pc().printf(">> Type in proportional gain with keyboard.\n\r"); + xbee().printf(">> Type in proportional gain with keyboard.\n\r"); depth_KP = getFloatUserInput(); } else if (DEPTH_PID_key == 'I') { - pc().printf(">> Type in integral gain with keyboard.\n\r"); + xbee().printf(">> Type in integral gain with keyboard.\n\r"); depth_KI = getFloatUserInput(); } else if (DEPTH_PID_key == 'D') { - pc().printf(">> Type in derivative gain with keyboard.\n\r"); + xbee().printf(">> Type in derivative gain with keyboard.\n\r"); depth_KD = getFloatUserInput(); } else if (DEPTH_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); + xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); depth_freq = getFloatUserInput(); } else if (DEPTH_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); + xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); depth_deadband = getFloatUserInput(); } else { - pc().printf("\n\rDEPTH: [%c] This key does nothing here. \r", DEPTH_PID_key); + xbee().printf("\n\rDEPTH: [%c] This key does nothing here. \r", DEPTH_PID_key); } } } @@ -1851,20 +1885,21 @@ float pitch_KP = pitchLoop().getControllerP(); // load current pitch value float pitch_KI = pitchLoop().getControllerI(); // load current pitch value float pitch_KD = pitchLoop().getControllerD(); // load current pitch value + float pitch_offset_deg = pitchLoop().getOutputOffset(); float pitch_freq = pitchLoop().getFilterFrequency(); float pitch_deadband = pitchLoop().getDeadband(); // print the menu - pc().printf("\n\rPITCH (Battery Motor O.L.) PID gain settings (MENU)"); - pc().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); - pc().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); - pc().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); + xbee().printf("\n\rPITCH (Battery Motor O.L.) PID gain settings (MENU)"); + xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); + xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); + xbee().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - PITCH_PID_key = pc().getc(); + if (xbee().readable()) { + PITCH_PID_key = xbee().getc(); } else { continue; // didn't get a user input, so keep waiting for it @@ -1882,7 +1917,7 @@ // save to "PITCH.TXT" file (doesn't modify neutral position) configFileIO().savePitchData(pitch_KP, pitch_KI, pitch_KD, _neutral_batt_pos_mm, pitch_freq, pitch_deadband); - pc().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); + xbee().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); _pitch_KP = pitchLoop().getControllerP(); // load current pitch value _pitch_KI = pitchLoop().getControllerI(); // load current pitch value @@ -1892,27 +1927,30 @@ break; //exit the while loop } else if (PITCH_PID_key == 'P') { - pc().printf(">> Type in proportional gain with keyboard.\n\r"); + xbee().printf(">> Type in proportional gain with keyboard.\n\r"); pitch_KP = getFloatUserInput(); } else if (PITCH_PID_key == 'I') { - pc().printf(">> Type in integral gain with keyboard.\n\r"); + xbee().printf(">> Type in integral gain with keyboard.\n\r"); pitch_KI = getFloatUserInput(); } else if (PITCH_PID_key == 'D') { - pc().printf(">> Type in derivative gain with keyboard.\n\r"); + xbee().printf(">> Type in derivative gain with keyboard.\n\r"); pitch_KD = getFloatUserInput(); } else if (PITCH_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); + xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); pitch_freq = getFloatUserInput(); } else if (PITCH_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); + xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); pitch_deadband = getFloatUserInput(); } + else if (PITCH_PID_key == 'O') { + pitch_offset_deg = getFloatUserInput(); + } else { - pc().printf("\n\rPITCH: [%c] This key does nothing here. \r", PITCH_PID_key); + xbee().printf("\n\rPITCH: [%c] This key does nothing here. \r", PITCH_PID_key); } } } @@ -1928,17 +1966,17 @@ float heading_deadband = headingLoop().getDeadband(); // print the menu - pc().printf("\n\rHEADING (rudder outer loop) PID gain settings (MENU)"); - pc().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); - pc().printf("\n\r Adjust zero offset with O (oh)"); - pc().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.\n\r"); - pc().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n\r\n", headingLoop().getControllerP(),headingLoop().getControllerI(),headingLoop().getControllerD(),headingLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); + xbee().printf("\n\rHEADING (rudder outer loop) PID gain settings (MENU)"); + xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); + xbee().printf("\n\r Adjust zero offset with O (oh)."); + xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.\n\r"); + xbee().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n\r\n", headingLoop().getControllerP(),headingLoop().getControllerI(),headingLoop().getControllerD(),headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); // handle the key presses while(1) { // get the user's keystroke from either of the two inputs - if (pc().readable()) { - HEADING_PID_key = pc().getc(); + if (xbee().readable()) { + HEADING_PID_key = xbee().getc(); } else { continue; // didn't get a user input, so keep waiting for it @@ -1951,10 +1989,12 @@ headingLoop().setControllerI(heading_KI); headingLoop().setControllerD(heading_KD); headingLoop().setOutputOffset(heading_offset_deg); - + headingLoop().setFilterFrequency(heading_freq); + headingLoop().setDeadband(heading_deadband); + // save pitch PID values for outer loop (must save neutral position also) - configFileIO().saveHeadingData(heading_KP, heading_KI, heading_KD, heading_offset_deg, 6.0, 0.5); //_neutral_heading_pos_deg); - pc().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm \r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset()); + configFileIO().saveHeadingData(heading_KP, heading_KI, heading_KD, heading_offset_deg, heading_freq, heading_deadband); //_neutral_heading_pos_deg); + xbee().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n\r\n", headingLoop().getControllerP(),headingLoop().getControllerI(),headingLoop().getControllerD(),headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); } else if (HEADING_PID_key == 'X') { break; //exit the while loop @@ -1970,33 +2010,18 @@ heading_KD = getFloatUserInput(); } else if (HEADING_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); + xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); heading_freq = getFloatUserInput(); } else if (HEADING_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); + xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); heading_deadband = getFloatUserInput(); } - -//heading offset else if (HEADING_PID_key == 'O') { heading_offset_deg = getFloatUserInput(); } -//heading offset - - else if (HEADING_PID_key == 'F') { - pc().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); - float heading_freq = getFloatUserInput(); - pitchLoop().setFilterFrequency(heading_freq); - } - else if (HEADING_PID_key == 'B') { - pc().printf(">> Type in DEADBAND with keyboard.\n\r"); - float heading_deadband = getFloatUserInput(); - pitchLoop().setDeadband(heading_deadband); - } - else { - pc().printf("HEADING SETUP: [%c] This key does nothing here. \r", HEADING_PID_key); + xbee().printf("HEADING SETUP: [%c] This key does nothing here. \r", HEADING_PID_key); } } } @@ -2047,7 +2072,7 @@ _neutral_batt_pos_mm = batt_pos_mm; _neutral_bce_pos_mm = bce_pos_mm; - pc().printf("Neutral Buoyancy Positions: batt: %0.1f, bce: %0.1f\r\n",_neutral_batt_pos_mm,_neutral_bce_pos_mm); + xbee().printf("Neutral Buoyancy Positions: batt: %0.1f, bce: %0.1f\r\n",_neutral_batt_pos_mm,_neutral_bce_pos_mm); } //process one state at a time @@ -2062,7 +2087,7 @@ } void StateMachine::printCurrentSdLog() { - pc().printf("SD card log work in progress\r\n"); + xbee().printf("SD card log work in progress\r\n"); //might be worth saving the last few logs to the MBED... } @@ -2073,21 +2098,21 @@ while(1) { bool valid_input = false; //flag for valid or invalid input - pc().printf("\n\rPlease enter your number below and press ENTER:\r\n"); + xbee().printf("\n\rPlease enter your number below and press ENTER:\r\n"); char user_string [80]; //variable to store input as a character array - pc().scanf("%s", user_string); //read formatted data from stdin - pc().printf("\n\n\ruser_string was <%s>\r\n", user_string); + xbee().scanf("%s", user_string); //read formatted data from stdin + xbee().printf("\n\n\ruser_string was <%s>\r\n", user_string); //check through the string for invalid characters (decimal values 43 through 57) for (int c = 0; c < strlen(user_string); c++) { - //pc().printf("character is [%c]\r\n", user_string[c]); //debug + //xbee().printf("character is [%c]\r\n", user_string[c]); //debug if (user_string[c] >= 43 and user_string[c] <= 57) { - //pc().printf("VALID CHARACTER!\r\n"); //debug + //xbee().printf("VALID CHARACTER!\r\n"); //debug ; } else { - pc().printf("INVALID INPUT!\r\n"); + xbee().printf("INVALID INPUT!\r\n"); break; } @@ -2098,7 +2123,7 @@ if (valid_input) { float_conversion = atof(user_string); - pc().printf("VALID INPUT! Your input was: %3.3f (PRESS \"S\" (shift + S) to save!)\r\n", float_conversion); + xbee().printf("VALID INPUT! Your input was: %3.3f (PRESS \"S\" (shift + S) to save!)\r\n", float_conversion); break; } } @@ -2106,18 +2131,6 @@ return float_conversion; } -//added because channel readings failed multiple times (if they fail, motors could break parts) -void StateMachine::checkMotorPositions() { - - /* 1. If channel readings fail, calculations will give negative positions - 2. If the potentiometers are reporting negative positions, send the system into float broadcast - 3. The motors will move in the correct direction and if something is wrong the will go to their full extension but be at the surface */ - - if (bce().getPosition_mm() < 0 or batt().getPosition_mm() < 0 ) { - //_state = FLOAT_BROADCAST; - } -} - float StateMachine::getTimerValue() { return _fsm_timer; } \ No newline at end of file