Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r04a86b2e8ae3f5643f72de134882948f3c59f1d6 -rd305dff19b8ce0fdd0d0f848a579da3d95bf4e31 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 04a86b2e8ae3f5643f72de134882948f3c59f1d6) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision d305dff19b8ce0fdd0d0f848a579da3d95bf4e31) @@ -56,7 +56,7 @@ // ********** private data ********** static RO_PUMP_STATE_T roPumpState; ///< Current state of pump controller state machine. -static PUMP_CONTROL_MODE_T roPumpControlMode; ///< Requested pump control mode. +//static PUMP_CONTROL_MODE_T roPumpControlMode; ///< Requested pump control mode. static BOOL isROPumpOn; ///< Flag indicating whether pump is currently running. static BOOL stopPumpRequest; ///< Flag indicating pump stop is requested. static U32 roPumpDataPublicationTimerCounter; ///< Used to schedule RO pump data publication to CAN bus. @@ -101,7 +101,7 @@ MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); roPumpState = RO_PUMP_OFF_STATE; - roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; +// roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; isROPumpOn = FALSE; stopPumpRequest = FALSE; roControlTimerCounter = 0; @@ -183,7 +183,7 @@ isROPumpOn = FALSE; // If there is a target flow set, transition to the PI controller and control to flow - if ( targetROPumpFlowRate.data > 0 ) + if ( getTargetROPumpFlowRateMLPM() > 0 ) { // Set pump to on isROPumpOn = TRUE; @@ -193,7 +193,7 @@ state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } // If there is a target pressure set, transition to the PI controller and control to pressure. - else if ( targetROPumpPressure.data > 0.0F ) + else if ( getTargetROPumpPressure() > 0.0F ) { // Set pump to on isROPumpOn = TRUE; @@ -204,7 +204,7 @@ } // 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 - else if ( roPumpOpenLoopTargetDutyCycle.data > 0.0F ) + else if ( getTargetROPumpDutyCyclePCT() > 0.0F ) { roPumpDutyCyclePctSet = getTargetROPumpDutyCyclePCT(); setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); @@ -234,19 +234,23 @@ signalROPumpHardStop(); } // If there is a target flow set, transition to the PI controller and control to flow - else if ( targetROPumpFlowRate.data > 0 ) + if ( getTargetROPumpFlowRateMLPM() > 0 ) { ///transition to closed loop resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpDutyCyclePCT(), 0 ); state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } // If there is a target pressure set, transition to the PI controller and control to pressure. - else if ( targetROPumpPressure.data > 0.0F ) + else if ( getTargetROPumpPressure() > 0.0F ) { //transition to closed loop resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, getTargetROPumpDutyCyclePCT(), 0 ); state = RO_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } + else if ( (F32)getTargetROPumpDutyCyclePCT() == 0.0F ) + { + signalROPumpHardStop(); + } return state; } @@ -263,29 +267,24 @@ { RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; - if ( TRUE == stopPumpRequest ) - { - stopPumpRequest = FALSE; - signalROPumpHardStop(); - } // Check if need to switch control modes - else if ( targetROPumpPressure.data > 0.0F ) + if ( getTargetROPumpPressure() > 0.0F ) { // Transition to target pressure resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, roPumpDutyCyclePctSet, 0 ); state = RO_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } - else if ( roPumpOpenLoopTargetDutyCycle.data > 0.0F ) + else if ( getTargetROPumpDutyCyclePCT() > 0.0F ) { roPumpDutyCyclePctSet = getTargetROPumpDutyCyclePCT(); setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); state = RO_PUMP_OPEN_LOOP_STATE; } // Control at set interval or shut off -// else if ( (F32)getTargetROPumpFlowRateMLPM() == 0.0F ) -// { -// signalROPumpHardStop(); -// } + else if ( (F32)getTargetROPumpFlowRateMLPM() == 0.0F ) + { + signalROPumpHardStop(); + } else if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) { roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, (F32)getTargetROPumpFlowRateMLPM(), getFilteredFlow( P16_FLOW ) ); @@ -308,28 +307,23 @@ { RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; - if ( TRUE == stopPumpRequest ) - { - stopPumpRequest = FALSE; - signalROPumpHardStop(); - } // Check if we are changing control - else if ( targetROPumpFlowRate.data > 0 ) + if ( getTargetROPumpFlowRateMLPM() > 0 ) { resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet, 0 ); state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } - else if ( roPumpOpenLoopTargetDutyCycle.data > 0.0F ) + else if ( getTargetROPumpDutyCyclePCT() > 0.0F ) { setFluidPumpPctToPWMDutyCycle( P12_PUMP, getTargetROPumpDutyCyclePCT() ); roPumpDutyCyclePctSet = getTargetROPumpDutyCyclePCT(); state = RO_PUMP_OPEN_LOOP_STATE; } // Control at set interval or shut off -// else if ( getTargetROPumpPressure() == 0.0F ) -// { -// signalROPumpHardStop(); -// } + else if ( getTargetROPumpPressure() == 0.0F ) + { + signalROPumpHardStop(); + } else if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) { roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, getTargetROPumpPressure(), getFilteredPressure( P17_PRES ) ); @@ -357,39 +351,6 @@ // First of all, the flow rate must be in range if ( ( roFlowRate <= MAX_RO_FLOWRATE_MLPM ) && ( roFlowRate >= MIN_RO_FLOWRATE_MLPM ) ) { - // Backup the initial data and Set the pressure and duty cycle to zero - if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) - { - if ( targetROPumpFlowRate.ovInitData == 0 ) - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - } - - if ( targetROPumpPressure.data > 0.0 ) - { - if ( targetROPumpPressure.override != OVERRIDE_RESET ) - { - targetROPumpPressure.data = 0.0; - } - else - { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.data = 0.0; - } - } - if ( roPumpOpenLoopTargetDutyCycle.data > 0.0 ) - { - if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) - { - roPumpOpenLoopTargetDutyCycle.data = 0.0; - } - else - { - roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; - roPumpOpenLoopTargetDutyCycle.data = 0.0; - } - } - } targetROPumpFlowRate.data = roFlowRate; // Get the initial guess of the duty cycle roPumpDutyCyclePctSet = roPumpFlowToPWM( getTargetROPumpFlowRateMLPM() ); @@ -423,50 +384,13 @@ // First of all, the pressure must be in range if ( ( roPressure <= MAX_RO_PRESSURE_PSI ) && ( roPressure >= MIN_RO_PRESSURE_PSI ) ) { - // Backup the initial data and Set the flow rate and duty cycle to zero - if ( targetROPumpPressure.override != OVERRIDE_RESET ) - { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - if ( targetROPumpFlowRate.data > 0 ) - { - if ( targetROPumpFlowRate.ovInitData == 0 ) - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.data = 0; - } - else - { - targetROPumpFlowRate.data = 0; - } - } - if ( roPumpOpenLoopTargetDutyCycle.data > 0.0 ) - { - if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0.0 ) - { - roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; - roPumpOpenLoopTargetDutyCycle.data = 0.0; - } - else - { - roPumpOpenLoopTargetDutyCycle.data = 0.0; - } - } - } targetROPumpPressure.data = roPressure; // Get the initial guess of the duty cycle roPumpDutyCyclePctSet = roPumpPresToPWM( getTargetROPumpPressure() ); roControlTimerCounter = 0; isROPumpOn = TRUE; result = TRUE; } - else if ( roPressure == 0.0F ) - { - result = TRUE; - if ( ( targetROPumpFlowRate.data == 0 ) && ( roPumpOpenLoopTargetDutyCycle.data == 0.0 ) ) - { - stopPumpRequest = TRUE; - } - } // Requested flow rate is out of range else { @@ -493,51 +417,22 @@ if ( ( dutyCycle >= MIN_FLUID_PUMP_DUTY_CYCLE_PCT ) && ( dutyCycle <= MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ) { - // Backup the initial data and Set the pressure and flow rate to zero - if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) + // Set the new duty cycle of the pump + roPumpOpenLoopTargetDutyCycle.data = dutyCycle; + result = TRUE; + // stop RO Pump if duty cycle is set to zero + if ( dutyCycle == 0.0 ) { - if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) + if ( ( targetROPumpFlowRate.data == 0 ) && ( targetROPumpPressure.data == 0.0 ) ) { - roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + signalROPumpHardStop(); } - if ( targetROPumpFlowRate.data > 0 ) - { - if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) - { - targetROPumpFlowRate.data = 0; - } - else - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.data = 0; - } - } - if ( targetROPumpPressure.data > 0.0 ) - { - if ( targetROPumpPressure.override != OVERRIDE_RESET ) - { - targetROPumpPressure.data = 0.0; - } - else - { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.data = 0.0; - } - } } - // Set the new duty cycle of the pump - roPumpOpenLoopTargetDutyCycle.data = dutyCycle; - result = TRUE; - setFluidPumpPctToPWMDutyCycle( P12_PUMP, getTargetROPumpDutyCyclePCT() ); - } - else if ( dutyCycle == 0.0F ) - { - result = TRUE; - if ( ( targetROPumpFlowRate.data == 0 ) && ( targetROPumpPressure.data == 0.0 ) ) + else { - stopPumpRequest = TRUE; + setFluidPumpPctToPWMDutyCycle( P12_PUMP, getTargetROPumpDutyCyclePCT() ); } - } + } else { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, SW_FAULT_ID_FP_INVALID_PUMP_DUTY_CYCLE_SELECTED, dutyCycle ) @@ -664,6 +559,7 @@ roPumpDutyCyclePctSet = 0.0F; roControlTimerCounter = 0; roPumpOpenLoopTargetDutyCycle.data = 0.0F; + stopROPump(); } @@ -761,33 +657,64 @@ { TEST_OVERRIDE_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverridePayloadFromMessage( message, &payload ); - - if ( ovType == OVERRIDE_RESET_OVERRIDE ) +// BOOL result = FALSE; + // reset target pressure override + if ( ( ovType == OVERRIDE_RESET_OVERRIDE ) && ( targetROPumpPressure.override != OVERRIDE_RESET ) ) { // Restore previous flow, duty cycle and pressure values targetROPumpPressure.data = targetROPumpPressure.ovInitData; targetROPumpPressure.ovInitData = 0.0; - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) // isTargetDutyCycleActive + targetROPumpPressure.ovData = targetROPumpPressure.ovInitData; + targetROPumpPressure.override = OVERRIDE_RESET; + if ( targetROPumpFlowRate.override == OVERRIDE_RESET && targetROPumpFlowRate.ovInitData != 0 ) { + targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; + } + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0 ) + { roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; } - else + } + // set target pressure override + else if ( ovType == OVERRIDE_OVERRIDE ) + { + targetROPumpPressure.ovData = payload.state.f32; + targetROPumpPressure.override = OVERRIDE_KEY; + if ( targetROPumpPressure.ovInitData == 0 ) { - roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovData; + targetROPumpPressure.ovInitData = targetROPumpPressure.data; } - if ( targetROPumpFlowRate.override == OVERRIDE_RESET ) // isTargetFlowActive + if ( roPumpOpenLoopTargetDutyCycle.data > 0 ) { - targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; + if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) + { + roPumpOpenLoopTargetDutyCycle.ovData = 0; + roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; + roPumpOpenLoopTargetDutyCycle.data = 0; + } + else if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) + { + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + roPumpOpenLoopTargetDutyCycle.data = 0; + } } - else + if ( targetROPumpFlowRate.data > 0.0 ) { - targetROPumpFlowRate.data = targetROPumpFlowRate.ovData; + if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) + { + targetROPumpFlowRate.ovData = 0.0; + targetROPumpFlowRate.override = OVERRIDE_RESET; + targetROPumpFlowRate.data = 0; + } + else if ( targetROPumpFlowRate.ovInitData == 0 ) + { + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; + targetROPumpFlowRate.data = 0.0; + } } } + BOOL result = setROPumpTargetPressure(getTargetROPumpPressure()); - BOOL result = f32Override( message, &targetROPumpPressure ); - setROPumpTargetPressure(getTargetROPumpPressure()); - return result; } @@ -805,33 +732,63 @@ { TEST_OVERRIDE_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverridePayloadFromMessage( message, &payload ); - - if ( ovType == OVERRIDE_RESET_OVERRIDE ) + // reset target flow rate override + if ( ( ovType == OVERRIDE_RESET_OVERRIDE ) && ( targetROPumpFlowRate.override != OVERRIDE_RESET ) ) { // Restore previous flow, duty cycle and pressure values targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; targetROPumpFlowRate.ovInitData = 0; - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) // isTargetDutyCycleActive + targetROPumpFlowRate.ovData = targetROPumpFlowRate.ovInitData; + targetROPumpFlowRate.override = OVERRIDE_RESET; + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0 ) { roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; } - else + if ( targetROPumpPressure.override == OVERRIDE_RESET && targetROPumpPressure.ovInitData != 0 ) { - roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovData; + targetROPumpPressure.data = targetROPumpPressure.ovInitData; } - if ( targetROPumpPressure.override == OVERRIDE_RESET ) // isTargetPressureActive + } + // set target flow rate override + else if ( ovType == OVERRIDE_OVERRIDE ) + { + targetROPumpFlowRate.ovData = payload.state.u32; + targetROPumpFlowRate.override = OVERRIDE_KEY; + if ( targetROPumpFlowRate.ovInitData == 0 ) { - targetROPumpPressure.data = targetROPumpPressure.ovInitData; + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; } - else + if ( roPumpOpenLoopTargetDutyCycle.data > 0 ) { - targetROPumpPressure.data = targetROPumpPressure.ovData; + if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) + { + roPumpOpenLoopTargetDutyCycle.ovData = 0; + roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; + roPumpOpenLoopTargetDutyCycle.data = 0; + } + else if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) + { + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + roPumpOpenLoopTargetDutyCycle.data = 0; + } } + if ( targetROPumpPressure.data > 0.0 ) + { + if ( targetROPumpPressure.override != OVERRIDE_RESET ) + { + targetROPumpPressure.ovData = 0.0; + targetROPumpPressure.override = OVERRIDE_RESET; + targetROPumpPressure.data = 0; + } + else if ( targetROPumpPressure.ovInitData == 0 ) + { + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.data = 0.0; + } + } } + BOOL result = setROPumpTargetFlowRateMLPM(getTargetROPumpFlowRateMLPM()); - BOOL result = u32Override( message, &targetROPumpFlowRate, MIN_RO_FLOWRATE_MLPM, MAX_RO_FLOWRATE_MLPM ); - setROPumpTargetFlowRateMLPM(getTargetROPumpFlowRateMLPM()); - return result; } @@ -849,33 +806,63 @@ { TEST_OVERRIDE_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverridePayloadFromMessage( message, &payload ); - - if ( ovType == OVERRIDE_RESET_OVERRIDE ) + // reset target duty cycle override + if ( ( ovType == OVERRIDE_RESET_OVERRIDE ) && ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) ) { // Restore previous flow, duty cycle and pressure values roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0; - if ( targetROPumpFlowRate.override == OVERRIDE_RESET ) // isTargetFlowActive + roPumpOpenLoopTargetDutyCycle.ovData = roPumpOpenLoopTargetDutyCycle.ovInitData; + roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; + if ( targetROPumpFlowRate.override == OVERRIDE_RESET && targetROPumpFlowRate.ovInitData != 0 ) { targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; } - else + if ( targetROPumpPressure.override == OVERRIDE_RESET && targetROPumpPressure.ovInitData != 0 ) { - targetROPumpFlowRate.data = targetROPumpFlowRate.ovData; + targetROPumpPressure.data = targetROPumpPressure.ovInitData; } - if ( targetROPumpPressure.override == OVERRIDE_RESET ) // isTargetPressureActive + } + // set target duty cycle override + else if ( ovType == OVERRIDE_OVERRIDE ) + { + roPumpOpenLoopTargetDutyCycle.ovData = payload.state.f32; + roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_KEY; + if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) { - targetROPumpPressure.data = targetROPumpPressure.ovInitData; + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; } - else + if ( targetROPumpFlowRate.data > 0 ) { - targetROPumpPressure.data = targetROPumpPressure.ovData; + if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) + { + targetROPumpFlowRate.ovData = 0; + targetROPumpFlowRate.override = OVERRIDE_RESET; + targetROPumpFlowRate.data = 0; + } + else if ( targetROPumpFlowRate.ovInitData == 0 ) + { + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; + targetROPumpFlowRate.data = 0; + } } + if ( targetROPumpPressure.data > 0.0 ) + { + if ( targetROPumpPressure.override != OVERRIDE_RESET ) + { + targetROPumpPressure.ovData = 0.0; + targetROPumpPressure.override = OVERRIDE_RESET; + targetROPumpPressure.data = 0; + } + else if ( targetROPumpPressure.ovInitData == 0 ) + { + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.data = 0.0; + } + } } + BOOL result = setROPumpTargetDutyCycle(getTargetROPumpDutyCyclePCT()); - BOOL result = f32Override( message, &roPumpOpenLoopTargetDutyCycle ); - setROPumpTargetDutyCycle(getTargetROPumpDutyCyclePCT()); - return result; }