Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -rcc398b14ccf518f350b57fb5cb8728e5c908bd1e -ra1b8dbb69c4bd2f0cc22e62bede7015c9307d378 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision cc398b14ccf518f350b57fb5cb8728e5c908bd1e) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a1b8dbb69c4bd2f0cc22e62bede7015c9307d378) @@ -7,8 +7,8 @@ * * @file ModeDrain.c * -* @author (last) Sean Nash -* @date (last) 19-Aug-2020 +* @author (last) Quang Nguyen +* @date (last) 24-Aug-2020 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -17,11 +17,12 @@ #include "ConductivitySensors.h" #include "DrainPump.h" -#include "LoadCell.h" #include "ModeDrain.h" #include "OperationModes.h" #include "Pressures.h" #include "Reservoirs.h" +#include "ROPump.h" +#include "TaskGeneral.h" #include "TemperatureSensors.h" #include "Valves.h" @@ -32,11 +33,15 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). +#define TARGET_DRAIN_PUMP_RPM 1800 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. +#define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. + // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. // ********** private function prototypes ********** @@ -45,9 +50,8 @@ /*********************************************************************//** * @brief * The initDrainMode function initializes the drain mode module. - * @details - * Inputs : none - * Outputs : drainState + * @details Inputs: none + * @details Outputs: drainState * @return none *************************************************************************/ void initDrainMode( void ) @@ -58,9 +62,8 @@ /*********************************************************************//** * @brief * The transitionToDrainMode function prepares for transition to drain mode. - * @details - * Inputs : none - * Outputs : Drain mode initialized + * @details Inputs: none + * @details Outputs: Drain mode initialized * @return none *************************************************************************/ void transitionToDrainMode( void ) @@ -70,15 +73,15 @@ // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setDrainPumpTargetSpeed( TARGET_DRAIN_PUMP_RPM ); + setDrainPumpTargetRPM( TARGET_DRAIN_PUMP_RPM ); + setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); } /*********************************************************************//** * @brief * The execDrainMode function executes the drain mode state machine. - * @details - * Inputs : drainState - * Outputs : Check water quality, drain mode state machine executed + * @details Inputs: drainState + * @details Outputs: Check water quality, drain mode state machine executed * @return current state. *************************************************************************/ U32 execDrainMode( void ) @@ -101,7 +104,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, 0, drainState ) // TODO - add s/w fault enum to 1st data param + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DRAIN_MODE_INVALID_EXEC_STATE, drainState ) drainState = DG_DRAIN_STATE_START; break; } @@ -112,26 +115,19 @@ /*********************************************************************//** * @brief * The handleDrainState function handles the drain state of the drain mode state machine. - * @details - * Inputs : none - * Outputs : Drain out from reservoir + * @details Inputs: none + * @details Outputs: Drain out from reservoir * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; - LOAD_CELL_ID_T drainWeightLoadCell = LOAD_CELL_A1; + DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); - // determine which load cell to use for drain volume - we want weight of inactive reservoir - if ( RESERVOIR_1 == getActiveReservoir() ) + // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to re-circ mode + if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGH_UNCHANGE_TIMEOUT ) ) { - drainWeightLoadCell = LOAD_CELL_B1; - } - - // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode - if ( getReservoirDrainVolumeTargetMl() >= getLoadCellFilteredWeight( drainWeightLoadCell ) ) - { - setDrainPumpTargetSpeed( 0 ); + setDrainPumpTargetRPM( 0 ); requestNewOperationMode( DG_MODE_CIRC ); } @@ -141,9 +137,8 @@ /*********************************************************************//** * @brief * The getCurrentDrainState function returns the current state of the drain mode. - * @details - * Inputs : drainState - * Outputs : none + * @details Inputs: drainState + * @details Outputs: none * @return the current state of drain mode. *************************************************************************/ DG_DRAIN_STATE_T getCurrentDrainState( void )