Index: firmware/.launches/DG.launch =================================================================== diff -u -r5d8530d242d8065178eab9e3e5d8e4561b790e01 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/.launches/DG.launch (.../DG.launch) (revision 5d8530d242d8065178eab9e3e5d8e4561b790e01) +++ firmware/.launches/DG.launch (.../DG.launch) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -2,16 +2,20 @@ + + + + Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r0c1f66a170a3a0a4324fa1a3c3bfb4c7f77139b5 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 0c1f66a170a3a0a4324fa1a3c3bfb4c7f77139b5) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -53,25 +53,24 @@ #define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. #define ROP_RAMP_UP_CONTROL_INTERVAL ( 500 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. -#define ROP_P_COEFFICIENT 0.0020 ///< P term for RO pump pressure control. -#define ROP_I_COEFFICIENT 0.0015 ///< I term for RO pump pressure control. +#define ROP_RAMP_UP_P_COEFFICIENT 0.22 ///< P term for RO pump ramp up to flow control. +#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.25 ///< P term for RO pump flow control. +#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.25 ///< I term for RO pump flow control. +#define ROP_MAX_PRESSURE_P_COEFFICIENT 0.01 ///< P term for RO pump max pressure control. +#define ROP_MAX_PRESSURE_I_COEFFICIENT 0.01 ///< I term for RO pump max pressure control. -#define ROP_RAMP_UP_P_COEFFICIENT 0.0 ///< P term for RO pump flow control. -#define ROP_RAMP_UP_I_COEFFICIENT 0.1 ///< I term for RO pump flow control. #define ROP_FLOW_TARGET_TOLERANCE 0.03 ///< Tolerance in between the target flow rate and the actual flow rate in percentage. +#define ROP_RAMP_DOWN_DUTY_CYCLE_RATIO 0.03 ///< Pump ramp down duty cycle ratio when the pressure higher than max defined. #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define FLOW_SAMPLES_TO_AVERAGE ( 250 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 250 ms intervals. #define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -/// The time in counts to check the flow and make sure it is in range. -#define FLOW_VERIFICATION_COUNTER_TARGET ( 2 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) - #define RO_FLOW_ADC_TO_LPM_FACTOR 5555 ///< Conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). -#define ROP_FLOW_TO_PWM_SLOPE 0.5 ///< Slope of flow to PWM line equation. -#define ROP_FLOW_TO_PWM_INTERCEPT 0.28 ///< Intercept of flow to PWM line equation. +#define ROP_FLOW_TO_PWM_SLOPE 0.1 ///< Slope of flow to PWM line equation. +#define ROP_FLOW_TO_PWM_INTERCEPT 0.0 ///< Intercept of flow to PWM line equation. /// Initial conversion factor from target flow rate to PWM duty cycle estimate. #define ROP_FLOW_TO_PWM_DC(flow) ( ROP_FLOW_TO_PWM_SLOPE * flow + ROP_FLOW_TO_PWM_INTERCEPT ) @@ -88,79 +87,69 @@ #define MAX_ALLOWED_RAMP_UP_TIME ( 10 * MS_PER_SECOND ) ///< Maximum allowed ramp up time to a flow rate in ms. #define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< Conversion factor from target PSI to PWM duty cycle estimate. #define SAFETY_SHUTDOWN_TIMEOUT ( 3 * MS_PER_SECOND ) ///< RO pump safety shutdown activation timeout in ms. -#define ROP_FLOW_STABILIZE_TIME ( 3 * MS_PER_SECOND ) ///< Time required for RO flow to stabilize. -#define ROP_MAX_RAMP_UP_RETRY 5 ///< Maximum ramp up retires before alarm. /// Enumeration of RO pump states. typedef enum ROPump_States { - RO_PUMP_OFF_STATE = 0, ///< RO pump off state - RO_PUMP_CONTROL_SETUP_STATE, ///< RO pump control setup state - RO_PUMP_RAMP_UP_STATE, ///< RO pump ramp up to target flow rate state - RO_PUMP_VERIFY_FLOW_STATE, ///< RO pump maintain the flow rate for a set period of time - RO_PUMP_CONTROL_TO_TARGET_STATE, ///< RO pump control to target pressure state - RO_PUMP_OPEN_LOOP_STATE, ///< RO pump open loop state - NUM_OF_RO_PUMP_STATES ///< Number of RO pump states + RO_PUMP_OFF_STATE = 0, ///< RO pump off state. + RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE, ///< RO pump ramp up to target flow rate state. + RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE, ///< RO pump control to target flow state. + RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE, ///< RO pump control to max pressure state. + RO_PUMP_OPEN_LOOP_STATE, ///< RO pump open loop state. + NUM_OF_RO_PUMP_STATES ///< Number of RO pump states. } RO_PUMP_STATE_T; /// Enumeration of RO pump self-test states. typedef enum ROPump_Self_Test_States { - RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self-test start state - RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self-tests in progress state - RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self-tests completed state - NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self-test states + RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self-test start state. + RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self-tests in progress state. + RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self-tests completed state. + NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self-test states. } RO_PUMP_SELF_TEST_STATE_T; // ********** private data ********** -static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO pump controller state machine. -static U32 roPumpDataPublicationTimerCounter = 0; ///< used to schedule RO pump data publication to CAN bus. -static BOOL isROPumpOn = FALSE; ///< RO pump is currently running. -static F32 roPumpPWMDutyCyclePct = 0.0; ///< initial RO pump PWM duty cycle. -static F32 roPumpDutyCyclePctSet = 0.0; ///< currently set RO pump PWM duty cycle. -static PUMP_CONTROL_MODE_T roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested RO pump control mode. -static PUMP_CONTROL_MODE_T roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set RO pump control mode. +static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO pump controller state machine. +static U32 roPumpDataPublicationTimerCounter = 0; ///< used to schedule RO pump data publication to CAN bus. +static BOOL isROPumpOn = FALSE; ///< RO pump is currently running. +static F32 roPumpPWMDutyCyclePct = 0.0; ///< initial RO pump PWM duty cycle. +static F32 roPumpDutyCyclePctSet = 0.0; ///< currently set RO pump PWM duty cycle. +static PUMP_CONTROL_MODE_T roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested RO pump control mode. +static PUMP_CONTROL_MODE_T roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set RO pump control mode. -static F32 targetROPumpFlowRate = 0.0; ///< Target RO flow rate (in L/min). -static F32 targetROPumpPressure = 0; ///< Target RO pressure (in PSI). +static F32 targetROPumpFlowRate = 0.0; ///< Target RO flow rate (in L/min). +static F32 targetROPumpMaxPressure = 0.0; ///< Target RO max allowed pressure (in PSI). static OVERRIDE_U32_T roPumpDataPublishInterval = { RO_PUMP_DATA_PUB_INTERVAL, RO_PUMP_DATA_PUB_INTERVAL, - 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus. -static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in L/min). + 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus. +static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in L/min). -static U32 flowVerificationCounter = 0; ///< Counter to verify the flow is in range. -static U32 roControlTimerCounter = 0; ///< determines when to perform control on RO pump. -static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM. -static F32 roPumpFlowRateRunningSum = 0; ///< RO pump flow rate running sum. -static F32 roPumpPressureRunningSum = 0; ///< RO pump pressure running sum. +static U32 roControlTimerCounter = 0; ///< determines when to perform control on RO pump. +static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM. /* TODO These variables are used for POST. POST has not been implemented yet -static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< Current RO pump self test state. -static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for RO pump self test. +static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< Current RO pump self test state. +static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for RO pump self test. */ -static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. -static U32 flowFilterCounter = 0; ///< Flow filtering counter. -static U32 roPumpOnStartTime = 0; ///< Start time when RO pump turned on. -static BOOL setupROPumpControl = 0; ///< Flag to indicate if we need to setup RO pump control. -static U32 rampUpRetryCount = 0; ///< Number of ramp up retries. +static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. +static U32 flowFilterCounter = 0; ///< Flow filtering counter. // ********** private function prototypes ********** static RO_PUMP_STATE_T handleROPumpOffState( void ); -static RO_PUMP_STATE_T handleROPumpControlSetupState( void ); -static RO_PUMP_STATE_T handleROPumpRampUpState( void ); -static RO_PUMP_STATE_T handleROPumpVerifyFlowState( void ); -static RO_PUMP_STATE_T handleROPumpControlToTargetState( void ); +static RO_PUMP_STATE_T handleROPumpRampUpToTargetFlowState( void ); +static RO_PUMP_STATE_T handleROPumpControlToTargetFlowState( void ); +static RO_PUMP_STATE_T handleROPumpControlToMaxPressureState( void ); static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ); static void setROPumpTargetDutyCycle( F32 duty ); static void setROPumpControlSignalDutyCycle( F32 dutyCycle ); static void stopROPump( void ); static void publishROPumpData( void ); -static U32 getPublishROPumpDataInterval( void ); +static U32 getPublishROPumpDataInterval( void ); /*********************************************************************//** * @brief @@ -176,20 +165,22 @@ { stopROPump(); - // Initialize RO pump PI controller - initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE, ROP_P_COEFFICIENT, ROP_I_COEFFICIENT, + // Initialize RO pump PI controller to flow + initializePIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, MIN_RO_PUMP_DUTY_CYCLE, ROP_FLOW_CONTROL_P_COEFFICIENT, ROP_FLOW_CONTROL_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); - // Initialize the I controller during ramp up - initializePIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, MIN_RO_PUMP_DUTY_CYCLE, ROP_RAMP_UP_P_COEFFICIENT, ROP_RAMP_UP_I_COEFFICIENT, + // Initialize RO pump PI controller t maximum pressure + initializePIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, MIN_RO_PUMP_DUTY_CYCLE, ROP_MAX_PRESSURE_P_COEFFICIENT, ROP_MAX_PRESSURE_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); // Initialize the persistent alarm for flow out of upper and lower range initPersistentAlarm( ALARM_ID_FLOW_RATE_OUT_OF_UPPER_RANGE, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ); + initPersistentAlarm( ALARM_ID_FLOW_RATE_OUT_OF_LOWER_RANGE, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ); // Initialize the persistent alarm for max allowed pressure out of range - initPersistentAlarm( ALARM_ID_RO_PUMP_PRESSURE_OUT_OF_RANGE, MAX_PRESSURE_OUT_OF_RANGE_PERSISTENT_INTERVAL, MAX_PRESSURE_OUT_OF_RANGE_PERSISTENT_INTERVAL ); + initPersistentAlarm( ALARM_ID_RO_PUMP_PRESSURE_OUT_OF_RANGE, MAX_PRESSURE_OUT_OF_RANGE_PERSISTENT_INTERVAL, + MAX_PRESSURE_OUT_OF_RANGE_PERSISTENT_INTERVAL ); // Initialize the persistent alarm for ramp up to target flow timeout initPersistentAlarm( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, MAX_ALLOWED_RAMP_UP_TIME, MAX_ALLOWED_RAMP_UP_TIME ); @@ -200,13 +191,9 @@ // Initialize the variables roControlTimerCounter = 0; roPumpOpenLoopTargetDutyCycle = 0; - roPumpFlowRateRunningSum = 0; - roPumpPressureRunningSum = 0; measuredFlowReadingsSum = 0; flowFilterCounter = 0; - flowVerificationCounter = 0; roPumpDataPublicationTimerCounter = 0; - rampUpRetryCount = 0; roPumpState = RO_PUMP_OFF_STATE; roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; roPumpControlModeSet = roPumpControlMode; @@ -237,12 +224,13 @@ { // For now maximum allowed pressure is inserted into the target pressure override // if the target flow rate exceeded the max pressure, it will set the maximum pressure - targetROPumpPressure = maxPressure; - targetROPumpFlowRate = roFlowRate; - roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + targetROPumpMaxPressure = maxPressure; + targetROPumpFlowRate = roFlowRate; + roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + roPumpState = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the initial guess of the duty cycle - roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); - setupROPumpControl = TRUE; + roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); + roControlTimerCounter = 0; result = TRUE; } // Requested max pressure is out of range @@ -280,10 +268,9 @@ roPumpPWMDutyCyclePct = 0.0; roPumpOpenLoopTargetDutyCycle = 0.0; roControlTimerCounter = 0; - flowVerificationCounter = 0; isROPumpOn = FALSE; - targetROPumpPressure = 0; - resetPIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE ); + targetROPumpMaxPressure = 0; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, MIN_RO_PUMP_DUTY_CYCLE ); } /*********************************************************************//** @@ -331,7 +318,7 @@ // To monitor the flow, the control mode must be in closed loop and the pump should be control to target state, // meaning, it is controlling to a certain pressure - if ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && roPumpState == RO_PUMP_CONTROL_TO_TARGET_STATE ) + /*if ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && roPumpState == RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE ) { F32 const currentFlow = getMeasuredROFlowRate(); F32 const targetFlow = getTargetROPumpFlowRate(); @@ -357,7 +344,7 @@ { activateSafetyShutdown(); } - } + }*/ // Publish RO pump data on interval publishROPumpData(); @@ -378,22 +365,18 @@ roPumpState = handleROPumpOffState(); break; - case RO_PUMP_CONTROL_SETUP_STATE: - roPumpState = handleROPumpControlSetupState(); + case RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE: + roPumpState = handleROPumpRampUpToTargetFlowState(); break; - case RO_PUMP_RAMP_UP_STATE: - roPumpState = handleROPumpRampUpState(); + case RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE: + roPumpState = handleROPumpControlToTargetFlowState(); break; - case RO_PUMP_VERIFY_FLOW_STATE: - roPumpState = handleROPumpVerifyFlowState(); + case RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE: + roPumpState = handleROPumpControlToMaxPressureState(); break; - case RO_PUMP_CONTROL_TO_TARGET_STATE: - roPumpState = handleROPumpControlToTargetState(); - break; - case RO_PUMP_OPEN_LOOP_STATE: roPumpState = handleROPumpOpenLoopState(); break; @@ -439,80 +422,50 @@ * @brief * The handleROPumpOffState function handles the RO pump off state of the * controller state machine. - * @details Inputs: roPumpControlMode, roPumpPWMDutyCyclePctSet, roPumpOpenLoopTargetDutyCycle + * @details Inputs: roPumpControlMode, roPumpPWMDutyCyclePctSet, + * roPumpOpenLoopTargetDutyCycle * @details Outputs: roPumpPWMDutyCyclePct, setupROPumpControl, isROPumpOn * @return next state of the controller state machine *************************************************************************/ static RO_PUMP_STATE_T handleROPumpOffState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_OFF_STATE; + RO_PUMP_STATE_T state = RO_PUMP_OFF_STATE; // If there is a flow, transition to the PI controller to get the corresponding pressure of that flow if ( getTargetROPumpFlowRate() > 0 && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) { + roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; // Set pump to on isROPumpOn = TRUE; - result = RO_PUMP_CONTROL_SETUP_STATE; - setupROPumpControl = TRUE; + roPumpDutyCyclePctSet = ROP_FLOW_TO_PWM_DC( getTargetROPumpFlowRate() ); + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); + state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; } // If the target duty cycle is greater than zero (minimum is 10%) and the mode has been set to open // loop, set the duty cycle if ( roPumpOpenLoopTargetDutyCycle > 0 && roPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) { setROPumpControlSignalDutyCycle( roPumpOpenLoopTargetDutyCycle ); isROPumpOn = TRUE; - result = RO_PUMP_OPEN_LOOP_STATE; + state = RO_PUMP_OPEN_LOOP_STATE; } - return result; + return state; } /*********************************************************************//** * @brief - * The handleROPumpControlSetupState function handles the RO pump control - * setup state of the controller state machine. - * @details Inputs: setupROPumpControl, roPumpPWMDutyCyclePct - * @details Outputs: setup RO pump PI controller and wait for flow stabilize - * @return next state of the controller state machine - *************************************************************************/ -static RO_PUMP_STATE_T handleROPumpControlSetupState( void ) -{ - RO_PUMP_STATE_T result = RO_PUMP_CONTROL_SETUP_STATE; - - if ( TRUE == setupROPumpControl ) - { - roPumpControlModeSet = roPumpControlMode; - // Set initial PWM duty cycle - roPumpDutyCyclePctSet = roPumpPWMDutyCyclePct; - setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); - // Reset controller - resetPIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, roPumpDutyCyclePctSet ); - setupROPumpControl = FALSE; - roPumpOnStartTime = getMSTimerCount(); - } - - if ( TRUE == didTimeout( roPumpOnStartTime, ROP_FLOW_STABILIZE_TIME ) ) - { - rampUpRetryCount = 0; - result = RO_PUMP_RAMP_UP_STATE; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The handleROPumpRampUpState function handles the RO pump ramp up state - * of the controller state machine. + * The handleROPumpRampUpToTargetFlowState function handles the RO pump + * ramp up to flow state of the controller state machine. * @details Inputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet, * rampUp2FlowTimeoutCounter * @details Outputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet, * rampUp2FlowTimeoutCounter * @return next state of the controller state machine *************************************************************************/ -static RO_PUMP_STATE_T handleROPumpRampUpState( void ) +static RO_PUMP_STATE_T handleROPumpRampUpToTargetFlowState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_RAMP_UP_STATE; + RO_PUMP_STATE_T state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the current pressure from the sensor F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); @@ -523,14 +476,15 @@ BOOL isFlowOutOfRange = flowRateDeviation > ROP_FLOW_TARGET_TOLERANCE; // If the ramp up persistent alarm is active, turn off the pump and go to off state - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, isFlowOutOfRange ) ) + /*if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, isFlowOutOfRange ) ) { stopROPump(); result = RO_PUMP_OFF_STATE; SET_ALARM_WITH_2_F32_DATA( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, actualFlowRate, MAX_ALLOWED_RAMP_UP_TIME ); - } + }*/ // Control at set interval - else if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) + //else if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) + if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) { F32 targetPressure = getTargetROPumpPressure(); @@ -540,127 +494,115 @@ // be reset to the corresponding pressure of the target flow rate. if ( ( actualPressure > targetPressure ) || ( ( targetPressure - actualPressure ) < MAX_PRESSURE_TARGET_TOLERANCE ) ) { - result = RO_PUMP_CONTROL_TO_TARGET_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; } - // If the actual flow is still far from target flow, update the duty cycle using the I controller and stay in this state + // else if ( TRUE == isFlowOutOfRange ) { - roPumpDutyCyclePctSet = runPIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, targetFlowRate, actualFlowRate ); + roPumpDutyCyclePctSet += ( targetFlowRate - actualFlowRate ) * ROP_RAMP_UP_P_COEFFICIENT; + // If the duty cycle is out of the define range for the RO pump, set the boundaries + roPumpDutyCyclePctSet = roPumpDutyCyclePctSet < MIN_RO_PUMP_DUTY_CYCLE ? MIN_RO_PUMP_DUTY_CYCLE : roPumpDutyCyclePctSet; + roPumpDutyCyclePctSet = roPumpDutyCyclePctSet > MAX_RO_PUMP_DUTY_CYCLE ? MAX_RO_PUMP_DUTY_CYCLE : roPumpDutyCyclePctSet; + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); } // Reached to the target flow go to the next state else { - // Reset all the variables to prepare for transition - flowVerificationCounter = 0; - roPumpFlowRateRunningSum = 0; - roPumpPressureRunningSum = 0; - result = RO_PUMP_VERIFY_FLOW_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } roControlTimerCounter = 0; } - if ( TRUE == setupROPumpControl ) - { - resetPersistentAlarmTimer( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT ); - result = RO_PUMP_CONTROL_SETUP_STATE; - } - - return result; + return state; } /*********************************************************************//** * @brief - * The handleROPumpVerifyFlowState function handles the RO pump verify - * flow state of the RO pump controller state machine. - * @details Inputs: flowVerificationCounter, targetROPumpPressure, - * roPumpFlowRateRunningSum, roPumpFlowRateRunningSum - * @details Outputs: flowVerificationCounter, targetROPumpPressure, - * roPumpFlowRateRunningSum, roPumpFlowRateRunningSum + * The handleROPumpControlToTargetFlowState function handles the control to + * target flow state of the RO pump controller state machine. + * @details Inputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter, + * roPumpControlModeSet + * @details Outputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter * @return next state of the controller state machine *************************************************************************/ -static RO_PUMP_STATE_T handleROPumpVerifyFlowState( void ) +static RO_PUMP_STATE_T handleROPumpControlToTargetFlowState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_VERIFY_FLOW_STATE; + RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; - // Calculate the running sum of the flow rate and RO pump outlet pressure - roPumpFlowRateRunningSum = roPumpFlowRateRunningSum + (F32)getMeasuredROFlowRate(); - roPumpPressureRunningSum = roPumpPressureRunningSum + getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - - // Check if the time for flow verification has elapsed - if ( ++flowVerificationCounter >= FLOW_VERIFICATION_COUNTER_TARGET ) + // Control at set interval + if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) { + // Get the pressure to use it for setting the control + F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - // Calculate the average pressure and flow rate - F32 const targetFlowRate = getTargetROPumpFlowRate(); - F32 const avgFlowRate = roPumpFlowRateRunningSum / flowVerificationCounter; - F32 const flowRateDeviation = fabs( targetFlowRate - avgFlowRate ) / targetFlowRate; - if ( flowRateDeviation < ROP_FLOW_TARGET_TOLERANCE ) + if ( actualPressure >= targetROPumpMaxPressure ) { - F32 const avgPressure = roPumpPressureRunningSum / flowVerificationCounter; - // If the flow has been achieved without reaching the maximum pressure, set the new pressure - // otherwise, stay with the maximum allowed pressure as target pressure - if ( avgPressure < getTargetROPumpPressure() ) - { - targetROPumpPressure = avgPressure; - } - - // Set initial PWM duty cycle and reset controller - setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); - resetPIController( PI_CONTROLLER_ID_RO_PUMP, roPumpDutyCyclePctSet ); - result = RO_PUMP_CONTROL_TO_TARGET_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; } else { - if ( ++rampUpRetryCount > ROP_MAX_RAMP_UP_RETRY ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_RO_PUMP_TOO_MANY_RAMP_UP_RETRY, rampUpRetryCount, ROP_MAX_RAMP_UP_RETRY ); - } - result = RO_PUMP_RAMP_UP_STATE; + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); } - } - if ( TRUE == setupROPumpControl ) - { - result = RO_PUMP_CONTROL_SETUP_STATE; + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); + + roControlTimerCounter = 0; } - return result; + return state; } /*********************************************************************//** * @brief - * The handleROPumpControlToTargetState function handles the control to - * target state of the RO pump controller state machine. + * The handleROPumpControlToMaxPressureState function handles the control + * to max pressure state of the RO pump controller state machine. * @details Inputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter, * roPumpControlModeSet * @details Outputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter * @return next state of the controller state machine *************************************************************************/ -static RO_PUMP_STATE_T handleROPumpControlToTargetState( void ) +static RO_PUMP_STATE_T handleROPumpControlToMaxPressureState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_CONTROL_TO_TARGET_STATE; + RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; + // Get the pressure to use it for setting the control + F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + // Control at set interval - if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) + if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) { - // Get the pressure to use it for setting the control - F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + if ( actualPressure > targetROPumpMaxPressure ) + { + roPumpDutyCyclePctSet -= ROP_RAMP_DOWN_DUTY_CYCLE_RATIO; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); + } + else + { + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); + } - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP, getTargetROPumpPressure(), actualPressure ); setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); roControlTimerCounter = 0; } - if ( TRUE == setupROPumpControl ) + // Check if the actual pressure is out of tolerance from max pressure. + // If it is out, go back to ramp up state and to try to reach to target flow again + if ( ( targetROPumpMaxPressure - actualPressure ) > MAX_PRESSURE_TARGET_TOLERANCE ) { - result = RO_PUMP_CONTROL_SETUP_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; + + roControlTimerCounter = 0; } - return result; + return state; } /*********************************************************************//** @@ -785,7 +727,7 @@ *************************************************************************/ F32 getTargetROPumpPressure( void ) { - return targetROPumpPressure; + return targetROPumpMaxPressure; } /*********************************************************************//** @@ -834,8 +776,8 @@ if ( TRUE == isTestingActivated() ) { U32 intvl = value / TASK_PRIORITY_INTERVAL; - roPumpDataPublishInterval.ovData = intvl; - roPumpDataPublishInterval.override = OVERRIDE_KEY; + roPumpDataPublishInterval.ovData = intvl; + roPumpDataPublishInterval.override = OVERRIDE_KEY; result = TRUE; } @@ -906,7 +848,7 @@ // Make sure the requested pressure is in range if ( value >= MIN_ALLOWED_PRESSURE_PSI && value <= MAX_ALLOWED_PRESSURE_PSI ) { - targetROPumpPressure = value; + targetROPumpMaxPressure = value; result = TRUE; } } Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u -rd7024c2aa2768c24bab587d5db836f096d4a7989 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision d7024c2aa2768c24bab587d5db836f096d4a7989) +++ firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -31,17 +31,17 @@ */ // ********** public definitions ********** -#define MAX_RO_FLOWRATE_LPM 1.0 ///< Maximum target RO flow rate in L/min. +#define MAX_RO_FLOWRATE_LPM 1.4 ///< Maximum target RO flow rate in L/min. #define MIN_RO_FLOWRATE_LPM 0.2 ///< Minimum target RO flow rate in L/min. /// RO pump data struct. typedef struct { - F32 roPumpTgtPressure; ///< RO pump target pressure - F32 measROFlowRate; ///< RO flow rate measurement - F32 roPumpDutyCycle; ///< RO pump duty cycle - U32 roPumpState; ///< RO pump current state - F32 roPumpTgtFlowRate; ///< RO pump target flow rate + F32 roPumpTgtPressure; ///< RO pump target pressure. + F32 measROFlowRate; ///< RO flow rate measurement. + F32 roPumpDutyCycle; ///< RO pump duty cycle. + U32 roPumpState; ///< RO pump current state. + F32 roPumpTgtFlowRate; ///< RO pump target flow rate. } RO_PUMP_DATA_T; // ********** public function prototypes ********** Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r5d8530d242d8065178eab9e3e5d8e4561b790e01 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 5d8530d242d8065178eab9e3e5d8e4561b790e01) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -40,8 +40,8 @@ // General defines #define FLUSH_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Mode flush data publish interval in counts. -#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8 ///< RO pump target flow rate during flush/fill in L/min. TODO original flow was 0.8 -#define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. +#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8 ///< RO pump target flow rate during flush/fill in L/min. TODO original flow was 0.8 +#define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. #define DRAIN_PUMP_TARGET_RPM 1800 ///< Drain pump target RPM during drain. // Start state defines @@ -52,7 +52,7 @@ #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // Flush drain path state defines -#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * 60 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo original time is 2 minutes +#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * 60 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo original time is 2 minutes #define MIN_INLET_TEMPERATURE_C 15.0 ///< Minimum water inlet temperature in C. TODO original temperature was 25 C #define MIN_INLET_CONDUCTIVITY_US_PER_CM 0.0 ///< Minimum water inlet conductivity in uS/cm #define MAX_INLET_CONDUCTIVITY_US_PER_CM 2000.0 ///< Maximum water inlet conductivity in us/cm @@ -61,28 +61,31 @@ #define FLUSH_DIALYSATE_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. // Flush concentrate straws state defines -#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. TODO original time is 3 minutes +#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. TODO original time is 3 minutes -// Flush and drain R1 and R2 -#define RSRVRS_FULL_VOL_ML 1750.0 ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 +// Flush and drain R1 and R2 state defines +#define RSRVRS_FULL_VOL_ML 1650.0 ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 #define RSRVRS_PARTIAL_FILL_VOL_ML 500.0 ///< Reservoirs 1 & 2 partial volume in mL. #define RSRVRS_FULL_STABLE_TIME_COUNT ( ( 4 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Reservoirs 1 & 2 full stable time in counts. #define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. TODO original value was 5 mins #define RSRVRS_PARTIAL_FILL_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 partial fill up timeout in ms. #define RSRVRS_DRAIN_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. +// Flush circulation state defines +#define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. + // ********** private data ********** -static DG_FLUSH_STATE_T flushState = DG_FLUSH_STATE_START; ///< Currently active flush state. -static DG_FLUSH_STATE_T prevFlushState = DG_FLUSH_STATE_START; +static DG_FLUSH_STATE_T flushState = DG_FLUSH_STATE_START; ///< Current active flush state. +static DG_FLUSH_STATE_T prevFlushState = DG_FLUSH_STATE_START; ///< Previous flush state. static U32 rsrvrFillStableTimeCounter = 0; ///< Reservoirs fill stable time counter. -static U32 overallFlushElapsedTime = 0; -static U32 stateTimer = 0; -static ALARM_ID_T alarm; -static DG_RESERVOIR_STATUS_T rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 1 status. -static DG_RESERVOIR_STATUS_T rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 2 status. -static BOOL isThisInitialDrain = TRUE; +static U32 overallFlushElapsedTime = 0; ///< Overall flush mode elapsed time. +static U32 stateTimer = 0; ///< State timer. +static ALARM_ID_T alarm; ///< Alarm ID. +static DG_RESERVOIR_STATUS_T rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 1 status. +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. // ********** private function prototypes ********** @@ -109,14 +112,25 @@ /*********************************************************************//** * @brief * The initFlushMode function initializes flush mode module. - * @details Inputs: none - * @details Outputs: Initialized flush mode module + * @details Inputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, + * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, + * rsrvr1Status, rsrvr2Status + * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, + * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, + * rsrvr1Status, rsrvr2Status * @return none *************************************************************************/ void initFlushMode( void ) { - flushState = DG_FLUSH_STATE_START; - isThisInitialDrain = TRUE; + // 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; } /*********************************************************************//** @@ -140,8 +154,6 @@ *************************************************************************/ U32 execFlushMode( void ) { - //checkInletPressureFault(); TODO why do we need this? - // Execute current flush state switch ( flushState ) { @@ -199,6 +211,7 @@ break; } + // Publish the data publishFlushData(); return flushState; @@ -230,11 +243,22 @@ resetActuators(); // Transition to mode standby - requestNewOperationMode( DG_MODE_STAN ); + //requestNewOperationMode( DG_MODE_STAN ); + + requestNewOperationMode( DG_MODE_SOLO ); } // ********** private functions ********** +/*********************************************************************//** + * @brief + * The handleFlushModeStartState function handles the flush start state. + * If the sensors are in range, it transitions to the next state otherwise, + * it transitions to basic cancellation state. + * @details Inputs: stateTimer, rsrvr1Status + * @details Outputs: stateTimer, rsrvr1Status + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeStartState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_START; @@ -247,7 +271,7 @@ // Set all the actuators to reset and de-energized state resetActuators(); - if ( FALSE ) //TODO figure out the conductivity and pressure check + if ( FALSE ) //TODO figure out the conductivity and pressure range check { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } @@ -274,6 +298,15 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeDrainR1State function handles the drain reservoir 1. + * If the drain is completed within the defined time, it transitions to the + * next state, otherwise, it transitions to basic cancellation state. + * @details Inputs: stateTimer, rsrvr2Status, isThisInitialDrain + * @details Outputs: stateTimer, rsrvr2Status + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeDrainR1State( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_DRAIN_R1; @@ -284,8 +317,11 @@ } else if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) { - // Request a tare for reservoir 2 - tareReservoir(); + if ( TRUE == isThisInitialDrain ) + { + // Request a tare for reservoir 2 + tareReservoir(); + } // Set the actuators to drain R2 // NOTE: Drain pump is already on and VDr is already on drain state @@ -303,6 +339,15 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeDrainR2State function handles the drain reservoir 2. + * If the drain is completed within the defined time, it transitions to the + * next state, otherwise, it transitions to basic cancellation state. + * @details Inputs: stateTimer, rsrvr2Status, isThisInitialDrain + * @details Outputs: none + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeDrainR2State( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_DRAIN_R2; @@ -315,13 +360,27 @@ { signalDrainPumpHardStop(); - // Set the actuators to flush drain - setValveState( VPI, VALVE_STATE_OPEN ); - setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); + if ( TRUE == isThisInitialDrain ) + { + // Set the actuators to flush drain + setValveState( VPI, VALVE_STATE_OPEN ); + setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); - stateTimer = getMSTimerCount(); + state = DG_FLUSH_STATE_FLUSH_DRAIN; + } + else + { + signalDrainPumpHardStop(); + setValveState( VPI, VALVE_STATE_OPEN ); + setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); + setValveState( VRC, VALVE_STATE_RECIRC_C_TO_NC ); + setValveState( VDR, VALVE_STATE_RECIRC_C_TO_NC ); + setROPumpTargetFlowRate( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); - state = DG_FLUSH_STATE_FLUSH_DRAIN; + state = DG_FLUSH_STATE_FLUSH_CIRCULATION; + } + + stateTimer = getMSTimerCount(); } else if ( rsrvr2Status == DG_RESERVOIR_NOT_REACHED_TARGET ) { @@ -331,6 +390,14 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeFlushDrainState function handles the flush drain state. + * Once the flush drain time has elapsed, it transitions to the next state. + * @details Inputs: stateTimer + * @details Outputs: stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushDrainState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_DRAIN; @@ -352,6 +419,16 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeFlushDialysateState function handles the flush + * dialysate state. + * Once the flush dialysate time has elapsed, it transitions to the next + * state. + * @details Inputs: stateTimer + * @details Outputs: stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushDialysateState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_DIALYSATE; @@ -366,6 +443,16 @@ return state; } + +/*********************************************************************//** + * @brief + * The handleFlushModeFlushDialysateState function handles the flush + * dialysate state. Once the flush dialysate time has elapsed, it + * transitions to the next state. + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushConcentrateStrawsState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CONCENTRATE_STRAWS; @@ -386,6 +473,16 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeFlushR1ToR2State function handles the flush + * reservoir 1 to reservoir 2 state. If any of the reservoirs flush within + * the defined period of time, it transitions to the next state, otherwise, + * it transitions to water cancellation state. + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushR1ToR2State( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_R1_TO_R2; @@ -410,7 +507,7 @@ setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); stateTimer = getMSTimerCount(); - // Set both reservoirs status + // Set both reservoirs' status rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; @@ -428,6 +525,18 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeFlushR2AndDrainR1State function handles the flush + * reservoir 2 and drain reservoir 1 state. If reservoir 2 flushes within + * the defined period of time and reservoir 1 drains within the defined + * period of time, it transitions to the next state. If the flush times out, + * the function transitions to water cancellation state. If the drain times + * out the function transitions to basic cancellation state. + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushR2AndDrainR1State( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; @@ -466,7 +575,8 @@ stateTimer = getMSTimerCount(); isThisInitialDrain = FALSE; - state = DG_FLUSH_STATE_DRAIN_R2; + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + state = DG_FLUSH_STATE_DRAIN_R1; } // TODO add timeout } @@ -475,10 +585,25 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeFlushCirculationState function handles the flush + * circulation state. Once the flush circulation time has elapsed, it + * transitions to the next state. + * @details Inputs: none + * @details Outputs: none + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushCirculationState( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CIRCULATION; + if ( didTimeout( stateTimer, FLUSH_CIRCULATION_WAIT_TIME_MS ) ) + { + resetActuators(); + state = DG_FLUSH_STATE_COMPLETE; + } + return state; } @@ -496,10 +621,19 @@ return state; } +/*********************************************************************//** + * @brief + * The handleFlushModeComplete function handles the complete state. + * @details Inputs: none + * @details Outputs: none + * @return next state of the flush state machine + *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeComplete( void ) { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_COMPLETE; + stopDGFlush(); + return state; } @@ -537,11 +671,32 @@ stopTrimmerHeater(); } +/*********************************************************************//** + * @brief + * The setModeToFailed function sets the alarm that failed the flush mode. + * @details Inputs: alarm, prevHeatDisinfectState + * @details Outputs: none + * @return none + *************************************************************************/ static void setModeToFailed( void ) { SET_ALARM_WITH_1_U32_DATA( alarm, prevFlushState ) } +/*********************************************************************//** + * @brief + * The isRsrvrFull function checks whether the target reservoir is full or + * not. If the fill times out, the function sets the status to did not reach + * to target. + * @details Inputs: rsrvrFillStableTimeCounter, alarm, stateTimer, flushState, + * prevFlushState + * @details Outputs: rsrvrFillStableTimeCounter, alarm, stateTimer, + * prevFlushState + * @param r is DG_RESERVOIR_1 or DG_RESERVOIR_2 + * @param targetVol is the target fill volume + * @param timeout is the fill up time out that is checked against + * @return the status of the reservoirs during filling + *************************************************************************/ static DG_RESERVOIR_STATUS_T getRsrvrFillStatus( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout ) { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_BELOW_TARGET; @@ -570,13 +725,30 @@ else if ( didTimeout( stateTimer, timeout ) ) { // Failed to fill on time + prevFlushState = flushState; alarm = ALARM_ID_DG_RESERVOIR_FILL_TIMEOUT; status = DG_RESERVOIR_NOT_REACHED_TARGET; } return status; } +/*********************************************************************//** + * @brief + * The getRsrvrDrainStatus function returns the status of draining a + * reservoir. If the drain times out, it set the status to did not reach + * target. + * @details Inputs: rsrvrFillStableTimeCounter, alarm, stateTimer, + * flushState, prevFlushState + * @details Outputs: rsrvrFillStableTimeCounter, alarm, stateTimer, + * prevFlushState + * @param r is DG_RESERVOIR_1 or DG_RESERVOIR_2 + * @param drainSteadyStateTimeout which is the time the reservoir's level + * does not change and is steady state + * @param timeout which is the timeout that a reservoir must be drained by + * then + * @return the status of the reservoirs during draining + *************************************************************************/ static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ) { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; @@ -600,6 +772,14 @@ return status; } +/*********************************************************************//** + * @brief + * The publishFlushData function publishes the flush mode data at the set + * interval. + * @details Inputs: dataPublishCounter + * @details Outputs: dataPublishCounter + * @return: none + *************************************************************************/ static void publishFlushData( void ) { if ( ++dataPublishCounter > FLUSH_DATA_PUB_INTERVAL ) Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r5d8530d242d8065178eab9e3e5d8e4561b790e01 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 5d8530d242d8065178eab9e3e5d8e4561b790e01) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -236,7 +236,8 @@ BOOL result = FALSE; // If DG is in standby mode and the standby mode is in Idle state, request DG flush - if ( DG_MODE_STAN == getCurrentOperationMode() && DG_STANDBY_MODE_STATE_IDLE == standbyState ) + if ( ( DG_MODE_STAN == getCurrentOperationMode() || DG_MODE_SOLO == getCurrentOperationMode() ) && + DG_STANDBY_MODE_STATE_IDLE == standbyState ) { requestNewOperationMode( DG_MODE_FLUS ); Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -r64b37cc2955d04bbc77ea41940b1b1b30c06651b -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 64b37cc2955d04bbc77ea41940b1b1b30c06651b) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -60,12 +60,12 @@ /// PI Controllers - initial configurations. static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = -{ // Kp Ki uMax uMin ref meas err esw esum ctrl - { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP - { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_DRAIN_PUMP - { 0.0, 0.0, 1.39, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_PRIMARY_HEATER - { 0.0, 0.0, 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_TRIMMER_HEATER - { 0.0, 0.0, 0.99, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0, CONTROLLER_UNIDIRECTIONAL }, // I_CONTROLLER_ID_RO_PUMP_RAMP_UP +{ // Kp Ki uMax uMin ref meas err esw esum ctrl Ilimit controller type + { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP + { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_DRAIN_PUMP + { 0.0, 0.0, 1.39, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_PRIMARY_HEATER + { 0.0, 0.0, 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_TRIMMER_HEATER + { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP_MAX_PRES }; /*********************************************************************//** Index: firmware/App/Services/PIControllers.h =================================================================== diff -u -rfbc0a281b094ff309dcbf83db1878818a9b384f1 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision fbc0a281b094ff309dcbf83db1878818a9b384f1) +++ firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -33,11 +33,11 @@ /// Enumeration of PI controllers. typedef enum ControllerList { - PI_CONTROLLER_ID_RO_PUMP = 0, ///< RO Pump controller + PI_CONTROLLER_ID_RO_PUMP_FLOW = 0, ///< RO Pump controller to flow PI_CONTROLLER_ID_DRAIN_PUMP, ///< Drain Pump controller PI_CONTROLLER_ID_PRIMARY_HEATER, ///< Primary Heater controller PI_CONTROLLER_ID_TRIMMER_HEATER, ///< Trimmer Heater controller - I_CONTROLLER_ID_RO_PUMP_RAMP_UP, ///< RO Pump controller during ramp up time. + PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, ///< RO pump controller to maximum pressure NUM_OF_PI_CONTROLLERS_IDS ///< Number of PI controllers } PI_CONTROLLER_ID_T; Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r5d8530d242d8065178eab9e3e5d8e4561b790e01 -r45f4646609e6dd39691102e109d0b5c14f97e054 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 5d8530d242d8065178eab9e3e5d8e4561b790e01) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) @@ -78,7 +78,12 @@ *************************************************************************/ void initReservoirs( void ) { - setActiveReservoirCmd( DG_RESERVOIR_1 ); + activeReservoir.data = (U32)DG_RESERVOIR_1; + setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); + setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); + setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); + setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); + fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; }