Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r2c08db070a6e09306caf461e7aceeb53097fd995 -re7e9ea67b63911dc9d8d46166fdd09e102111e3f --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 2c08db070a6e09306caf461e7aceeb53097fd995) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision e7e9ea67b63911dc9d8d46166fdd09e102111e3f) @@ -8,7 +8,7 @@ * @file DrainPump.c * * @author (last) Dara Navaei -* @date (last) 03-Nov-2022 +* @date (last) 06-Mar-2023 * * @author (original) Sean * @date (original) 08-Apr-2020 @@ -50,11 +50,11 @@ #define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the Drain Pump data is published on the CAN bus. -#define DRP_CONTROL_INTERVAL ( 200 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. +#define DRP_CONTROL_INTERVAL ( 1000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. #define DRP_CONTROL_MAX_ALLOWED_PPO_PSI 30.0F ///< Drain pump maximum allowed PPo pressure in psi. #define DRP_CONTROL_MAX_ALLOWED_PDR_PSI 40.0F ///< Drain pump maximum allowed PDr pressure in psi. -#define DRP_CONTROL_PSI_TO_DAC_P_TERM 0.2F ///< Drain pump psi to DAC conversion. -#define DRP_CONTROL_FLOW_TO_DAC_P_TERM 100.0F ///< Drain pump flow (L/min) to DAC conversion. +#define DRP_CONTROL_PSI_TO_DAC_P_ONLY_TERM 0.2F ///< Drain pump psi to DAC conversion. +#define DRP_CONTROL_FLOW_TO_DAC_P_ONLY_TERM 100.0F ///< Drain pump flow (L/min) to DAC conversion. #define DRP_CONTROL_PRES_TO_MAX_THRESHOLD_PSI 1.0F ///< Drain pump pressure to maximum pressure threshold in psi. #define DRP_CONTROL_MIN_DAC_CHANGE 1 ///< Drain pump minimum DAC change @@ -66,8 +66,8 @@ #define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.000005F ///< Toggle period to resolution in seconds. #define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4.0F ///< Rotational to toggle period conversion coefficient. -#define DRAIN_PUMP_P_COEFFICIENT 100.0F //0.5F ///< P term for drain pump delta pressure control. -#define DRAIN_PUMP_I_COEFFICIENT 1.0F ///< I term for drain pump delta pressure control. +#define DRAIN_PUMP_P_COEFFICIENT 20.0F ///< P term for drain pump delta pressure control. +#define DRAIN_PUMP_I_COEFFICIENT 80.0F ///< I term for drain pump delta pressure control. #define MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE 100 ///< Maximum allowed RPM out of range from target RPM in open loop. #define OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT ( 10 * MS_PER_SECOND ) ///< Open loop RPM out of range time out in ms. @@ -283,6 +283,8 @@ drainPumpControlModeSet = drainPumpControlMode; result = TRUE; isDrainPumpControlInFlowMode = TRUE; + + resetPIController( PI_CONTROLLER_ID_DRAIN_PUMP, DRAIN_PUMP_MIN_DAC ); } else { @@ -297,7 +299,9 @@ * The signalDrainPumpHardStop function stops the Drain pump immediately. * @details Inputs: none * @details Outputs: targetDrainPumpRPM, drainPumpState, drainPumpControlMode, - * hasClosedLoopBeenRequested, drainControlTimerCounter, drainPumpControlModeSet + * hasClosedLoopBeenRequested, drainControlTimerCounter, drainPumpControlModeSet, + * drainControlTimerCtr, pendingDrainPumpCmd, pendingDrainPumpCmdTarget, + * pendingDrainPumpCmdCountDown * @return none *************************************************************************/ void signalDrainPumpHardStop( void ) @@ -310,9 +314,9 @@ hasClosedLoopBeenRequested = FALSE; drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; drainPumpControlModeSet = drainPumpControlMode; - drainControlTimerCtr = 0; + drainControlTimerCtr = 0; pendingDrainPumpCmd = DRAIN_PUMP_OFF_STATE; - pendingDrainPumpCmdTarget = 0.0; + pendingDrainPumpCmdTarget = 0.0F; pendingDrainPumpCmdCountDown = 0; } @@ -434,8 +438,11 @@ /*********************************************************************//** * @brief * The execDrainPumpController function executes the drain pump controller. - * @details Inputs: drainPumpState - * @details Outputs: drainPumpState + * @details Inputs: drainPumpState, pendingDrainPumpCmdCountDown, + * pendingDrainPumpCmd + * @details Outputs: drainPumpState, pendingDrainPumpCmdCountDown, + * pendingDrainPumpCmd, targetDrainPumpOutletFlowLPM, drainPumpDAC, + * hasClosedLoopBeenRequested, drainPumpControlMode, drainPumpControlModeSet * @return none *************************************************************************/ void execDrainPumpController( void ) @@ -658,7 +665,7 @@ F32 drainPumpOutletPressurePSI = getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); F32 roPumpOutletPressurePSI = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); F32 targetROFlowLPM = getDrainPumpTargetOutletFlowLPM(); - F32 msrdROFlowLPM = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); + F32 msrdROFlowLPM = getMeasuredROFlowRateWithConcPumpsLPM(); F32 flowSubLPM = msrdROFlowLPM - targetROFlowLPM; if ( TRUE == isDrainPumpControlInFlowMode ) @@ -672,10 +679,11 @@ isDrainPumpControlInFlowMode = FALSE; } } - else if ( flowSubLPM > NEARLY_ZERO ) + else if ( flowSubLPM > 0.0F ) { // If measured flow if greater than the target flow, adjust the DAC to lower the flow rate - tempDACSet = (U32)( ( flowSubLPM * DRP_CONTROL_FLOW_TO_DAC_P_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); + tempDACSet = (U32)( ( flowSubLPM * DRP_CONTROL_FLOW_TO_DAC_P_ONLY_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); + tempDACSet = ( tempDACSet > drainPumpDACSet ? DRAIN_PUMP_MIN_DAC : tempDACSet ); drainPumpDACSet -= ( tempDACSet > 0.0F ? tempDACSet : DRP_CONTROL_MIN_DAC_CHANGE ); } else @@ -686,19 +694,20 @@ F32 ppoSubPSI = roPumpOutletPressurePSI - DRP_CONTROL_MAX_ALLOWED_PPO_PSI; F32 maxPresPSI = MAX( pdrSubPSI, ppoSubPSI ); - if ( ( pdrSubPSI > NEARLY_ZERO ) || ( ppoSubPSI > NEARLY_ZERO ) ) + if ( ( pdrSubPSI > 0.0F ) || ( ppoSubPSI > 0.0F ) ) { // If either of the pressure values are greater than the maximum pressure, recalculate the DAC by the maximum pressure difference // If the calculated DAC value turned out to be 0, set it to 1 so it changes at least by 1 DAC - tempDACSet = (U32)( ( maxPresPSI * DRP_CONTROL_PSI_TO_DAC_P_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); + tempDACSet = (U32)( ( maxPresPSI * DRP_CONTROL_PSI_TO_DAC_P_ONLY_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); + tempDACSet = ( tempDACSet > drainPumpDACSet ? DRAIN_PUMP_MIN_DAC : tempDACSet ); drainPumpDACSet -= ( tempDACSet > 0.0F ? tempDACSet : DRP_CONTROL_MIN_DAC_CHANGE ); } else if ( ( fabs(pdrSubPSI) > DRP_CONTROL_PRES_TO_MAX_THRESHOLD_PSI ) && ( fabs(ppoSubPSI) > DRP_CONTROL_PRES_TO_MAX_THRESHOLD_PSI ) ) { // If both of the DACs turned out to be less than their maximum pressure limits by more than the specified value, recalculate the // DAC. Using fabs for the subtraction means both pressure subtractions are negative so they are below their limits. // In the calculations use fabs for max pressure because it is negative so it will end of subtracting DAC but it should be adding - tempDACSet = (U32)( ( fabs(maxPresPSI) * DRP_CONTROL_PSI_TO_DAC_P_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); + tempDACSet = (U32)( ( fabs(maxPresPSI) * DRP_CONTROL_PSI_TO_DAC_P_ONLY_TERM ) + FLOAT_TO_INT_ROUNDUP_OFFSET ); drainPumpDACSet += ( tempDACSet > 0.0F ? tempDACSet : DRP_CONTROL_MIN_DAC_CHANGE ); } } @@ -935,17 +944,13 @@ { BOOL status = FALSE; - // Check if the requested drain pump RPM is within range - if ( ( value >= MIN_DRAIN_PUMP_RPM ) && ( value <= MAX_DRAIN_PUMP_RPM ) ) + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) { - // Check if the user is logged in - if ( TRUE == isTestingActivated() ) - { - drainPumpMeasuredRPM.ovData = value; - drainPumpMeasuredRPM.override = OVERRIDE_KEY; - drainPumpMeasuredRPM.ovInitData = drainPumpMeasuredRPM.data; - status = TRUE; - } + drainPumpMeasuredRPM.ovData = value; + drainPumpMeasuredRPM.override = OVERRIDE_KEY; + drainPumpMeasuredRPM.ovInitData = drainPumpMeasuredRPM.data; + status = TRUE; } return status;