Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r45f4646609e6dd39691102e109d0b5c14f97e054 -r3f7419dca9422a1e65ca166c250ae599634a2a90 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 3f7419dca9422a1e65ca166c250ae599634a2a90) @@ -48,7 +48,6 @@ // Drain R1 & R2 states defines -#define RSRVRS_DRAIN_TIME_OUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain time out in milliseconds. #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // Flush drain path state defines @@ -87,6 +86,7 @@ static DG_RESERVOIR_STATUS_T rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 2 status. static BOOL isThisInitialDrain = TRUE; ///< Initial drain boolean flag. static U32 dataPublishCounter = 0; ///< Flush data publish counter. +static BOOL hasWaterCancellationBeenSet = FALSE; ///< Water cancellation set/not set boolean flag. // ********** private function prototypes ********** @@ -114,23 +114,24 @@ * The initFlushMode function initializes flush mode module. * @details Inputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, - * rsrvr1Status, rsrvr2Status + * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, - * rsrvr1Status, rsrvr2Status + * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet * @return none *************************************************************************/ void initFlushMode( void ) { // Initialize the variables - flushState = DG_FLUSH_STATE_START; - prevFlushState = DG_FLUSH_STATE_START; - rsrvrFillStableTimeCounter = 0; - overallFlushElapsedTime = 0; - isThisInitialDrain = TRUE; - dataPublishCounter = 0; - rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; - rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; + flushState = DG_FLUSH_STATE_START; + prevFlushState = DG_FLUSH_STATE_START; + rsrvrFillStableTimeCounter = 0; + overallFlushElapsedTime = 0; + isThisInitialDrain = TRUE; + dataPublishCounter = 0; + rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; + rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; + hasWaterCancellationBeenSet = FALSE; } /*********************************************************************//** @@ -243,7 +244,7 @@ resetActuators(); // Transition to mode standby - //requestNewOperationMode( DG_MODE_STAN ); + //requestNewOperationMode( DG_MODE_STAN ); TODO which one should it transition to? requestNewOperationMode( DG_MODE_SOLO ); } @@ -313,7 +314,7 @@ if ( rsrvr1Status == DG_RESERVOIR_ABOVE_TARGET ) { - rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIME_OUT_MS ); + rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) { @@ -354,7 +355,7 @@ if ( rsrvr2Status == DG_RESERVOIR_ABOVE_TARGET ) { - rsrvr2Status = getRsrvrDrainStatus( DG_RESERVOIR_2, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIME_OUT_MS ); + rsrvr2Status = getRsrvrDrainStatus( DG_RESERVOIR_2, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } else if ( rsrvr2Status == DG_RESERVOIR_REACHED_TARGET ) { @@ -370,6 +371,7 @@ } else { + // Set the actuators to transition to flush circulation signalDrainPumpHardStop(); setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); @@ -544,7 +546,7 @@ // If reservoir 1 is empty, turn off the drain pump if ( rsrvr1Status == DG_RESERVOIR_ABOVE_TARGET ) { - rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIME_OUT_MS ); + rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_DRAIN_TIMEOUT_MS ); } else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) { @@ -607,17 +609,95 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeCancelBasicPathState function handles the flush + * cancel mode basic path state. The state sets the state + * to complete and raises an alarm. + * @details Inputs: none + * @details Outputs: none + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeCancelBasicPathState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; + // Once the fault alarm is raised, the DG Software will de-energize all the actuators + setModeToFailed(); + return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeCancelWaterPathState function handles the flush mode + * cancel water path state. The state drains the 2 reservoirs. If the drain + * times out, it transitions to basic cancellation path. + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeCancelWaterPathState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_CANCEL_WATER_PATH; + if ( FALSE == hasWaterCancellationBeenSet ) + { + // Stop all the actuators first then decide who should run next + resetActuators(); + + // The fluid is hot so this is a mix drain. Set the VPd to direct the cold inlet fluid to drain + setValveState( VPI, VALVE_STATE_OPEN ); + setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); + + // Set both reservoirs to be considered as full + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; + + // Water cancellation path was set + hasWaterCancellationBeenSet = TRUE; + + // The drain is set to start from reservoir 2 since all the actuators have been de-energized + // Start the drain pump + setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); + + // Start the timer for drain timeout + stateTimer = getMSTimerCount(); + } + + // If reservoir 2 is empty, set to drain reservoir 1 + if ( rsrvr2Status == DG_RESERVOIR_ABOVE_TARGET ) + { + // 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 ) + { + // Set the drain valve to reservoir 1 + setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); + } + } + else if ( rsrvr2Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + { + 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 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 ) + { + setModeToFailed(); + } + } + else if ( rsrvr1Status == DG_RESERVOIR_NOT_REACHED_TARGET ) + { + state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; + } + return state; }