Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r986abcfcf047822cad1a10c1ee0924a80dd5f512 -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 986abcfcf047822cad1a10c1ee0924a80dd5f512) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -47,7 +47,7 @@ #define MIN_DRAIN_INLET_PSI_EMPTY -3.0 ///< Minimum drain inlet pressure (in PSI) to indicate reservoir is empty while drain pump on. #define RESERVOIR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the reservoir data is published on the CAN bus. #define MAX_REDUNDANT_LOAD_CELL_DIFF 50.0 ///< Maximum difference in redundant load cells when determining if fill completed. -#define DRAIN_THRESHOLD_ML 30.0 ///< Drain threshold in milliliters. +#define DRAIN_THRESHOLD_ML 1.0 ///< Drain threshold in milliliters. #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. // ********** private data ********** @@ -87,7 +87,7 @@ static DG_HEATING_CAL_RECORD_T heatingConstsCalRecord; ///< DG heating calibration record. static F32 targetFillFlowRateLPM; ///< Target fill flow rate in L/min. static BOOL isThisTheFirstCycle = TRUE; ///< Boolean flag to indicate whether this is the first cycle. -static F32 previousReservoiWeight[ NUM_OF_DG_RESERVOIRS ]; ///< Previous reservoir weight. +static F32 previousReservoirWeight[ NUM_OF_DG_RESERVOIRS ]; ///< Previous reservoir weight. /*********************************************************************//** * @brief @@ -107,7 +107,7 @@ isThisTheFirstCycle = TRUE; dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - memset( &previousReservoiWeight, 0.0, sizeof( F32 ) * NUM_OF_DG_RESERVOIRS ); + memset( &previousReservoirWeight, 0.0, sizeof( F32 ) * NUM_OF_DG_RESERVOIRS ); } /*********************************************************************//** @@ -430,18 +430,6 @@ /*********************************************************************//** * @brief - * The tareReservoir function sets the tare load cell variable to TRUE. - * @details Inputs: none - * @details Outputs: none - * @return none - *************************************************************************/ -void tareReservoir( void ) -{ - tareLoadCellRequest = TRUE; -} - -/*********************************************************************//** - * @brief * The getInactiveReservoir function gets the inactive reservoir. * @details Inputs: activeReservoir * @details Outputs: none @@ -683,10 +671,16 @@ F32 loadcellWeightML = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); U32 targetDrainVolML = getU32OverrideValue( &drainVolumeTargetMl ); - F32 drainFlowML = loadcellWeightML - previousReservoiWeight[ reservoirId ]; + F32 drainFlowML = loadcellWeightML - previousReservoirWeight[ reservoirId ]; - previousReservoiWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + // Update the structure with the current weight as the previous + previousReservoirWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + // If the flow is less than the threshold and the time has not been set, set the timer + // If the flow is greater than the threshold and timer has been set, 0 it because the flow is out of range and we are not + // ready to consider this the end of the reservoir flow + // If the wait for drain to steady has elapsed and the drain pump inlet pressure sensor is indicating and increased vacuum, + // signal the drain is complete if ( ( drainFlowML <= DRAIN_THRESHOLD_ML ) && ( 0 == reservoirWeightUnchangeStartTime[ reservoirId ] ) ) { reservoirWeightUnchangeStartTime[ reservoirId ] = getMSTimerCount(); @@ -695,12 +689,9 @@ { reservoirWeightUnchangeStartTime[ reservoirId ] = 0; } - // If the goal is to tare the load cell, then the target drain should be reached and timing out on the - // reservoir weight is not enough else if ( ( TRUE == didTimeout( reservoirWeightUnchangeStartTime[ reservoirId ], timeout ) && - ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) || ( FALSE == tareLoadCellRequest ) ) + ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) ) { - reservoirWeightUnchangeStartTime[ reservoirId ] = 0; result = TRUE; } @@ -745,7 +736,25 @@ return tareLoadCellRequest; } +/*********************************************************************//** + * @brief + * The initDrainParameters function initializes the drain parameters. + * @details Inputs: none + * @details Outputs: reservoirWeightUnchangeStartTime, previousReservoirWeight + * associatedLoadCell + * @param reservoirId the ID of the reservoir that it drain parameters have + * to be initialized + * @return none + *************************************************************************/ +void initDrainParameters( DG_RESERVOIR_ID_T reservoirId ) +{ + // Set the start time to 0 for the next drain and update the current load cell reading to the previous value + reservoirWeightUnchangeStartTime[ reservoirId ] = 0; + previousReservoirWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/