Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r4d1a8ff389678d2f9a0bde6effba32d8c4ac5fb1 -r321e3603df2611c653e4bd330f640ab35822fd6d --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 4d1a8ff389678d2f9a0bde6effba32d8c4ac5fb1) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 321e3603df2611c653e4bd330f640ab35822fd6d) @@ -157,12 +157,6 @@ data.tempLastFill = getLastFillTemperature(); data.timereservoirFill = heatersTempCalc.timeReservoirFillMS; - // TODO remove - data.previousDrainFlow = reservoirPreviousStatus[ DG_RESERVOIR_1 ].previousDrainFlowML; - data.previousLoadCell = reservoirPreviousStatus[ DG_RESERVOIR_1 ].previousReservoirWeightG; - data.drainTime = reservoirWeightUnchangeStartTime[ DG_RESERVOIR_1 ]; - // TODO remove - broadcastData( MSG_ID_DG_RESERVOIRS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( RESERVOIR_DATA_T ) ); dataPublishCounter = 0; } @@ -686,12 +680,22 @@ F32 loadcellWeightML = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); U32 drainPumpFeedbackRPM = getDrainPumpMeasuredRPM(); + // Check if the drain pump is running, the drain pump usually starts with delay so it might take several + // milliseconds to see the RPM feedback is greater than 0. If the feedback is not greater than 0, checking + // for drain is not needed if ( drainPumpFeedbackRPM > 0 ) { + // Calculate the drain threshold that is needed for the target RPM. For instance, RPM = 500 / 2400 as reference = 0.20833 + // so the difference in between the current and previous load cell values must be less than this value to be considered + // as reaching towards the bottom of the reservoir. Otherwise, the drain pump must be easily able to drain more fluid + // than the threshold every 50 ms. F32 drainThresholdML = ( (F32)getDrainPumpTargetRPM() ) / MAX_DRAIN_RPM_MLP; + // Calculate the flow reservoirPreviousStatus[ reservoirId ].previousDrainFlowML = reservoirPreviousStatus[ reservoirId ].previousReservoirWeightG - loadcellWeightML; + // If the previous load cell is greater than the current load cell, it means the reservoir is draining and + // update the previous load cell value if ( reservoirPreviousStatus[ reservoirId ].previousReservoirWeightG > loadcellWeightML ) { reservoirPreviousStatus[ reservoirId ].previousReservoirWeightG = loadcellWeightML;