Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r3f7419dca9422a1e65ca166c250ae599634a2a90 -r370877da1639ae01135cf4c5f1e009e1517bbf03 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 3f7419dca9422a1e65ca166c250ae599634a2a90) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 370877da1639ae01135cf4c5f1e009e1517bbf03) @@ -44,9 +44,6 @@ #define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. #define DRAIN_PUMP_TARGET_RPM 1800 ///< Drain pump target RPM during drain. -// Start state defines - - // Drain R1 & R2 states defines #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. @@ -66,14 +63,13 @@ #define RSRVRS_FULL_VOL_ML 1650.0 ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 #define RSRVRS_PARTIAL_FILL_VOL_ML 500.0 ///< Reservoirs 1 & 2 partial volume in mL. #define RSRVRS_FULL_STABLE_TIME_COUNT ( ( 4 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Reservoirs 1 & 2 full stable time in counts. -#define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. TODO original value was 5 mins +#define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. TODO original value was 5 minutes #define RSRVRS_PARTIAL_FILL_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 partial fill up timeout in ms. -#define RSRVRS_DRAIN_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. +#define RSRVRS_DRAIN_TIMEOUT_MS ( 3 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. TODO original value was 2 minutes // Flush circulation state defines #define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. - // ********** private data ********** static DG_FLUSH_STATE_T flushState = DG_FLUSH_STATE_START; ///< Current active flush state. @@ -143,6 +139,9 @@ *************************************************************************/ void transitionToFlushMode( void ) { + // Reset all the actuators + resetActuators(); + initFlushMode(); } @@ -244,9 +243,7 @@ resetActuators(); // Transition to mode standby - //requestNewOperationMode( DG_MODE_STAN ); TODO which one should it transition to? - - requestNewOperationMode( DG_MODE_SOLO ); + requestNewOperationMode( DG_MODE_STAN ); } // ********** private functions ********** @@ -264,38 +261,26 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_START; - //TODO make sure the conductivities are in range - // Start overall flush timer overallFlushElapsedTime = getMSTimerCount(); - // Set all the actuators to reset and de-energized state - resetActuators(); + // Reset the load cells lowest weight prior to starting the run + resetReservoirsLowestWeight(); - if ( FALSE ) //TODO figure out the conductivity and pressure range check - { - state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; - } - else - { - // Reset the load cells lowest weight prior to starting the run - resetReservoirsLowestWeight(); + // Close VPi to prevent wasting water + setValveState( VPI, VALVE_STATE_CLOSED ); - // Close VPi to prevent wasting water - setValveState( VPI, VALVE_STATE_CLOSED ); + // Request a tare for reservoir 1 + tareReservoir(); - // Request a tare for reservoir 1 - tareReservoir(); + // Set the actuators to drain R1 + setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); + setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - // Set the actuators to drain R1 - setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); - setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); + stateTimer = getMSTimerCount(); + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + state = DG_FLUSH_STATE_DRAIN_R1; - stateTimer = getMSTimerCount(); - rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; - state = DG_FLUSH_STATE_DRAIN_R1; - } - return state; } @@ -312,11 +297,11 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_DRAIN_R1; - if ( rsrvr1Status == DG_RESERVOIR_ABOVE_TARGET ) + if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr1Status ) { rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } - else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { if ( TRUE == isThisInitialDrain ) { @@ -332,7 +317,7 @@ rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R2; } - else if ( rsrvr1Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } @@ -353,12 +338,13 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_DRAIN_R2; - if ( rsrvr2Status == DG_RESERVOIR_ABOVE_TARGET ) + if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr2Status ) { rsrvr2Status = getRsrvrDrainStatus( DG_RESERVOIR_2, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } - else if ( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { + // Done with draining signalDrainPumpHardStop(); if ( TRUE == isThisInitialDrain ) @@ -372,9 +358,9 @@ else { // Set the actuators to transition to flush circulation - signalDrainPumpHardStop(); setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); setValveState( VRC, VALVE_STATE_RECIRC_C_TO_NC ); setValveState( VDR, VALVE_STATE_RECIRC_C_TO_NC ); setROPumpTargetFlowRate( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); @@ -384,7 +370,7 @@ stateTimer = getMSTimerCount(); } - else if ( rsrvr2Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } @@ -489,17 +475,17 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_R1_TO_R2; - if ( rsrvr1Status == DG_RESERVOIR_BELOW_TARGET ) + if ( DG_RESERVOIR_BELOW_TARGET == rsrvr1Status ) { rsrvr1Status = getRsrvrFillStatus( DG_RESERVOIR_1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS ); } - else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { - if ( rsrvr2Status == DG_RESERVOIR_BELOW_TARGET ) + if ( DG_RESERVOIR_BELOW_TARGET == rsrvr2Status ) { rsrvr2Status = getRsrvrFillStatus( DG_RESERVOIR_2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_PARTIAL_FILL_TIMEOUT_MS ); } - else if ( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { // Set the actuators to flush R2 and drain R1 state setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); @@ -514,12 +500,12 @@ rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; } - else if ( rsrvr2Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { state = DG_FLUSH_STATE_CANCEL_WATER_PATH; } } - else if ( rsrvr1Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { state = DG_FLUSH_STATE_CANCEL_WATER_PATH; } @@ -544,45 +530,54 @@ DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; // If reservoir 1 is empty, turn off the drain pump - if ( rsrvr1Status == DG_RESERVOIR_ABOVE_TARGET ) + if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr1Status ) { rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } - else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { // Done with draining R1 signalDrainPumpHardStop(); } - else if ( rsrvr1Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + // Reservoir 1 drain time out + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } // First reservoir 2 must be completely full - if ( rsrvr2Status == DG_RESERVOIR_BELOW_TARGET ) + if ( DG_RESERVOIR_BELOW_TARGET == rsrvr2Status ) { rsrvr2Status = getRsrvrFillStatus( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS ); } - // Once R2 is full, R1 must be partially full - else if( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) + // Once reservoir 2 is full, reservoir 1 must be partially full + else if( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { rsrvr1Status = getRsrvrFillStatus( DG_RESERVOIR_1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_PARTIAL_FILL_TIMEOUT_MS ); // Once R1 is partially full, transition to the next state - if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { signalROPumpHardStop(); - setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); + setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); stateTimer = getMSTimerCount(); isThisInitialDrain = FALSE; rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R1; } - // TODO add timeout + // Check if reservoir 1 fill timed out + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) + { + state = DG_FLUSH_STATE_CANCEL_WATER_PATH; + } } - // TODO add timeout + // Check if reservoir 2 fill time out + else if( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) + { + state = DG_FLUSH_STATE_CANCEL_WATER_PATH; + } return state; } @@ -666,34 +661,34 @@ } // If reservoir 2 is empty, set to drain reservoir 1 - if ( rsrvr2Status == DG_RESERVOIR_ABOVE_TARGET ) + if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr2Status ) { // If the cancellation water path cannot be done, got to basic cancellation path rsrvr2Status = getRsrvrDrainStatus( DG_RESERVOIR_2, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); - if ( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) + if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { // Set the drain valve to reservoir 1 setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); } } - else if ( rsrvr2Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } // If reservoir 2 has already been drained and reservoir 1 is empty, reset and switch to complete - if ( ( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) && ( rsrvr1Status == DG_RESERVOIR_ABOVE_TARGET ) ) + if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) && ( DG_RESERVOIR_ABOVE_TARGET == rsrvr1Status ) ) { // If the cancellation water path cannot be done, got to basic cancellation path rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); - if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { setModeToFailed(); } } - else if ( rsrvr1Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } @@ -782,11 +777,11 @@ DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_BELOW_TARGET; F32 volume = 0.0; - if ( r == DG_RESERVOIR_1 ) + if ( DG_RESERVOIR_1 == r ) { volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); } - else if ( r == DG_RESERVOIR_2 ) + else if ( DG_RESERVOIR_2 == r ) { volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); }