/************************************************************************** * * Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPBoostDUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file BoostPump.c * * @author (last) Sean Nash * @date (last) 12-Nov-2024 * * @author (original) Sean Nash * @date (original) 12-Nov-2024 * ***************************************************************************/ //#include #include "BoostPump.h" #include "Flow.h" //#include "NVDataMgmt.h" #include "Messaging.h" #include "MessageSupport.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "PIControllers.h" #include "Pressure.h" #include "SafetyShutdown.h" #include "TaskGeneral.h" #include "Timers.h" #include "Utilities.h" /** * @addtogroup BoostPump * @{ */ // ********** private definitions ********** #define BOOST_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Boost Pump data is published on the CAN bus. #define BOOST_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Boost pump is controlled. #define BOOST_FLOW_CONTROL_P_COEFFICIENT 0.15F ///< P term for Boost pump flow control. #define BOOST_FLOW_CONTROL_I_COEFFICIENT 0.65F ///< I term for Boost pump flow control. #define BOOST_PRESSURE_CONTROL_P_COEFFICIENT 0.01F ///< P term for Boost pump pressure control. #define BOOST_PRESSURE_CONTROL_I_COEFFICIENT 0.01F ///< I term for Boost pump pressure control. #define BOOST_PWM_STEP_LIMIT 0.50F ///< Current maximum PWM step limit used in Boost Profiles. #define BOOST_RAMP_DOWN_DUTY_CYCLE_RATIO 0.03F ///< Pump ramp down duty cycle ratio when the pressure higher than max defined. #define BOOST_FLOW_TO_PWM_SLOPE 0.5F ///< Slope of flow to PWM line equation. #define BOOST_FLOW_TO_PWM_INTERCEPT 0.0F ///< Intercept of flow to PWM line equation. #define BOOST_PRESSURE_TO_PWM_SLOPE 0.5F ///< Slope of pressure to PWM line equation. #define BOOST_PRESSURE_TO_PWM_INTERCEPT 0.0F ///< Intercept of pressure to PWM line equation. #define DATA_PUBLISH_COUNTER_START_COUNT 10 ///< Data publish counter start count. #define BOOST_FLOW_TO_PWM(flow) ( BOOST_FLOW_TO_PWM_SLOPE * flow + BOOST_FLOW_TO_PWM_INTERCEPT ) ///< PWM line equation for flow. #define BOOST_PRESSURE_TO_PWM(pres) ( BOOST_PRESSURE_TO_PWM_SLOPE * pres + BOOST_PRESSURE_TO_PWM_INTERCEPT ) ///< PWM line equation for pressure. /// Enumeration of Boost pump states. typedef enum BoostPump_States { BOOST_PUMP_OFF_STATE = 0, ///< Boost pump off state. BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE, ///< Boost pump control to target flow state. BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE, ///< Boost pump control to max pressure state. BOOST_PUMP_OPEN_LOOP_STATE, ///< Boost pump open loop state. NUM_OF_Boost_PUMP_STATES ///< Number of Boost pump states. } BOOST_PUMP_STATE_T; // ********** private data ********** static BOOST_PUMP_STATE_T boostPumpState; ///< Current state of pump controller state machine. static PUMP_CONTROL_MODE_T boostPumpControlMode; ///< Requested pump control mode. static BOOL isBoostPumpOn; ///< Flag indicating whether pump is currently running. static BOOL stopPumpRequest; ///< Flag indicating pump stop is requested. static U32 boostPumpDataPublicationTimerCounter; ///< Used to schedule Boost pump data publication to CAN bus. static OVERRIDE_U32_T boostPumpDataPublishInterval; ///< Interval (in ms) at which to publish boost pump data to CAN bus. static U32 boostControlTimerCounter; ///< Determines when to perform control on Boost pump. static OVERRIDE_U32_T targetBoostPumpFlowRate; ///< Target Boost flow rate (in L/min). static OVERRIDE_F32_T targetBoostPumpPressure; ///< Target Boost max allowed pressure (in PSI). static F32 boostPumpDutyCyclePctSet; ///< Currently set Boost pump PWM duty cycle. static F32 boostPumpOpenLoopTargetDutyCycle; ///< Target Boost pump open loop PWM. // ********** private function prototypes ********** static BOOST_PUMP_STATE_T handleBoostPumpOffState( void ); static BOOST_PUMP_STATE_T handleBoostPumpControlToTargetFlowState( void ); static BOOST_PUMP_STATE_T handleBoostPumpControlToTargetPressureState( void ); static BOOST_PUMP_STATE_T handleBoostPumpOpenLoopState( void ); static F32 boostPumpPresToPWM( F32 targetPressure ); static F32 boostPumpFlowToPWM( U32 targetFlow ); static void stopBoostPump( void ); static void publishBoostPumpData( void ); /*********************************************************************//** * @brief * The initBoostPump function initializes the Boost Pump module. * @details \b Inputs: boostPumpState, boostPumpControlMode, isBoostPumpOn, stopPumpRequest, * boostControlTimerCounter, boostPumpDutyCyclePctSet, boostPumpOpenLoopTargetDutyCycle, boostPumpDataPublicationTimerCounter, * boostPumpDataPublishInterval, targetBoostPumpFlowRCLOSEDate, targetBoostPumpPressure * @details \b Outputs: Boost Pump controller unit initialized * @return none *************************************************************************/ void initBoostPump( void ) { initFluidPump(); // Initialize Boost pump PI controller to flow initializePIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, BOOST_FLOW_CONTROL_P_COEFFICIENT, BOOST_FLOW_CONTROL_I_COEFFICIENT, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); // Initialize Boost pump PI controller to target pressure initializePIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, BOOST_PRESSURE_CONTROL_P_COEFFICIENT, BOOST_PRESSURE_CONTROL_I_COEFFICIENT, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); boostPumpState = BOOST_PUMP_OFF_STATE; boostPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; isBoostPumpOn = FALSE; stopPumpRequest = FALSE; boostControlTimerCounter = 0; boostPumpDutyCyclePctSet = 0.0F; boostPumpOpenLoopTargetDutyCycle = 0.0F; boostPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; boostPumpDataPublishInterval.data = BOOST_DATA_PUB_INTERVAL; boostPumpDataPublishInterval.ovData = BOOST_CONTROL_INTERVAL; boostPumpDataPublishInterval.ovInitData = 0; boostPumpDataPublishInterval.override = OVERRIDE_RESET; targetBoostPumpFlowRate.data = 0; targetBoostPumpFlowRate.ovData = 0; targetBoostPumpFlowRate.ovInitData = 0; targetBoostPumpFlowRate.override = OVERRIDE_RESET; targetBoostPumpPressure.data = 0.0F; targetBoostPumpPressure.ovData = 0.0F; targetBoostPumpPressure.ovInitData = 0.0F; targetBoostPumpPressure.override = OVERRIDE_RESET; stopBoostPump(); } /*********************************************************************//** * @brief * The execBoostPumpController function executes the Boost pump controller. * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if pump is in an invalid state * @details \b Inputs: boostPumpState * @details \b Outputs: boostPumpState * @return none *************************************************************************/ void execBoostPumpController( void ) { // Update Boost pump feedback from FPGA readFluidPumps(); switch ( boostPumpState ) { case BOOST_PUMP_OFF_STATE: boostPumpState = handleBoostPumpOffState(); break; case BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE: boostPumpState = handleBoostPumpControlToTargetFlowState(); break; case BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE: boostPumpState = handleBoostPumpControlToTargetPressureState(); break; case BOOST_PUMP_OPEN_LOOP_STATE: boostPumpState = handleBoostPumpOpenLoopState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, SW_FAULT_ID_RO_INVALID_PUMP_DUTY_CYCLE_SELECTED, boostPumpState ) boostPumpState = BOOST_PUMP_OFF_STATE; break; } // Publish Boost pump data on interval publishBoostPumpData(); } /*********************************************************************//** * @brief * The handleBoostPumpOffState function handles the off state of the Boost pump * state machine. * @details \b Inputs: isBoostPumpOn, boostPumpControlMode, boostPumpOpenLoopTargetDutyCycle * @details \b Outputs: isBoostPumpOn, boostPumpDutyCyclePctSet * @return next state *************************************************************************/ static BOOST_PUMP_STATE_T handleBoostPumpOffState( void ) { BOOST_PUMP_STATE_T state = BOOST_PUMP_OFF_STATE; isBoostPumpOn = FALSE; // If there is a target pressure set, transition to the PI controller and control to pressure. if ( ( getTargetBoostPumpPressure() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { // Set pump to on isBoostPumpOn = TRUE; boostPumpDutyCyclePctSet = boostPumpPresToPWM( getTargetBoostPumpPressure() ); setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpDutyCyclePctSet ); state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } // If there is a target flow set, transition to the PI controller and control to flow else if ( ( getTargetBoostPumpFlowRateMLPM() > 0 ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { // Set pump to on isBoostPumpOn = TRUE; boostPumpDutyCyclePctSet = boostPumpFlowToPWM( getTargetBoostPumpFlowRateMLPM() ); setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpDutyCyclePctSet ); state = BOOST_PUMP_CONTROL_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 else if ( ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; isBoostPumpOn = TRUE; state = BOOST_PUMP_OPEN_LOOP_STATE; } return state; } /*********************************************************************//** * @brief * The handleBoostPumpOpenLoopState function handles the open loop control * state of the Boost pump state machine. * @details \b Inputs: stopPumpRequest, boostPumpControlMode, * boostPumpDutyCyclePctSet * @details \b Outputs: boostPumpState, stopPumpRequest * @return next state *************************************************************************/ static BOOST_PUMP_STATE_T handleBoostPumpOpenLoopState( void ) { BOOST_PUMP_STATE_T state = BOOST_PUMP_OPEN_LOOP_STATE; if ( TRUE == stopPumpRequest ) { stopPumpRequest = FALSE; state = BOOST_PUMP_OFF_STATE; } // If there is a target pressure set, transition to the PI controller and control to pressure. if ( ( getTargetBoostPumpPressure() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { // Transition to closed loop resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, boostPumpDutyCyclePctSet, 0.0F ); state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } // If there is a target flow set, transition to the PI controller and control to flow else if ( ( getTargetBoostPumpFlowRateMLPM() > 0 ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { ///transition to closed loop resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, boostPumpDutyCyclePctSet, 0.0F ); state = BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } return state; } /*********************************************************************//** * @brief * The handleBoostPumpControlToTargetFlowState function handles the control to * target flow state of the Boost pump controller state machine. * @details \b Inputs: boostPumpPWMDutyCyclePctSet, boostControlTimerCounter, boostPumpControlMode * @details \b Outputs: boostPumpPWMDutyCyclePctSet, boostControlTimerCounter * @return next state of the controller state machine *************************************************************************/ static BOOST_PUMP_STATE_T handleBoostPumpControlToTargetFlowState( void ) { BOOST_PUMP_STATE_T state = BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE; // Check if need to switch control modes if ( getTargetBoostPumpPressure() > 0.0F && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { // Transition to target pressure resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, boostPumpDutyCyclePctSet, 0 ); state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } else if ( boostPumpOpenLoopTargetDutyCycle > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; state = BOOST_PUMP_OPEN_LOOP_STATE; } // Control at set interval else if ( ( ++boostControlTimerCounter >= BOOST_CONTROL_INTERVAL ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { boostPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, getTargetBoostPumpFlowRateMLPM(), getFilteredFlow( P7_FLOW ) ); setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpDutyCyclePctSet ); boostControlTimerCounter = 0; } return state; } /*********************************************************************//** * @brief * The handleBoostPumpControlToTargetPressureState function handles the control * to target pressure state of the Boost pump controller state machine. * @details \b Inputs: boostPumpPWMDutyCyclePctSet, boostControlTimerCounter, boostPumpControlMode * @details \b Outputs: boostPumpPWMDutyCyclePctSet, boostControlTimerCounter * @return next state of the controller state machine *************************************************************************/ static BOOST_PUMP_STATE_T handleBoostPumpControlToTargetPressureState( void ) { BOOST_PUMP_STATE_T state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; if ( ( getTargetBoostPumpFlowRateMLPM() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { ///transition to target flow resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, boostPumpDutyCyclePctSet, 0.0F ); state = BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } else if ( boostPumpOpenLoopTargetDutyCycle > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; state = BOOST_PUMP_OPEN_LOOP_STATE; } // Control at set interval else if ( ( ++boostControlTimerCounter >= BOOST_CONTROL_INTERVAL ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { boostPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, getTargetBoostPumpPressure(), getFilteredPressure( M3_PRES ) ); setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpDutyCyclePctSet ); boostControlTimerCounter = 0; } return state; } /*********************************************************************//** * @brief * The setBoostPumpTargetFlowRateLPM function sets a new target flow rate for the * Boost pump. * @details \b Inputs: boostPumpOpenLoopTargetDutyCycle * @details \b Outputs: targetBoostPumpFlowRate, boostPumpControlMode, boostPumpDutyCyclePctSet, * boostControlTimerCounter, isBoostPumpOn * @param boostFlowRate which is target Boost flow rate in mL/min * @return TRUE if new target flow rate is set successfully, FALSE if not *************************************************************************/ BOOL setBoostPumpTargetFlowRateMLPM( U32 boostFlowRate ) { BOOL result = FALSE; // First of all, the flow rate must be in range if ( ( boostFlowRate <= MAX_BOOST_FLOWRATE_MLPM ) && ( boostFlowRate >= MIN_BOOST_FLOWRATE_MLPM ) ) { targetBoostPumpFlowRate.data = boostFlowRate; boostPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; // Get the initial guess of the duty cycle boostPumpDutyCyclePctSet = boostPumpFlowToPWM( getTargetBoostPumpFlowRateMLPM() ); boostControlTimerCounter = 0; isBoostPumpOn = TRUE; // Clear previous target data if ( getTargetBoostPumpPressure() > 0.0F ) { targetBoostPumpPressure.data = 0.0F; } if ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) { boostPumpOpenLoopTargetDutyCycle = 0.0F; } result = TRUE; } // Requested flow rate is out of range else { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_FLOW_RATE_SET, boostFlowRate ) } return result; } /*********************************************************************//** * @brief * The setBoostPumpTargetPressure function sets a new target pressure for the * Boost pump. * @details \b Inputs: boostPumpOpenLoopTargetDutyCycle, targetBoostPumpFlowRate * @details \b Outputs: boostPumpOpenLoopTargetDutyCycle, targetBoostPumpFlowRate, isBoostPumpOn, * boostControlTimerCounter, boostPumpDutyCyclePctSet, boostPumpControlMode, targetBoostPumpPressure * @param boostPressure which is target Boost pressure * @return TRUE if new target flow rate is set successfully, FALSE if not *************************************************************************/ BOOL setBoostPumpTargetPressure( F32 boostPressure ) { BOOL result = FALSE; // First of all, the pressure must be in range if ( ( boostPressure <= MAX_BOOST_PRESSURE_PSI ) && ( boostPressure >= MIN_BOOST_PRESSURE_PSI ) ) { targetBoostPumpPressure.data = boostPressure; boostPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; // Get the initial guess of the duty cycle boostPumpDutyCyclePctSet = boostPumpPresToPWM( getTargetBoostPumpPressure() ); boostControlTimerCounter = 0; isBoostPumpOn = TRUE; // Clear previous target data if ( getTargetBoostPumpFlowRateMLPM() > 0 ) { targetBoostPumpFlowRate.data = 0.0F; } if ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) { boostPumpOpenLoopTargetDutyCycle = 0.0F; } result = TRUE; } // Requested flow rate is out of range else { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_PRESSURE_SELECTED, boostPressure ) } return result; } /*********************************************************************//** * @brief * The setBoostPumpTargetDutyCycle function sets the duty cycle that the * pump should run. * @details \b Inputs: boostPumpOpenLoopTargetDutyCycle, boostPumpPWMDutyCyclePct, * targetBoostPumpPressure, targetBoostPumpFlowRate * @details \b Outputs: boostPumpOpenLoopTargetDutyCycle * boostPumpControlMode, targetBoostPumpFlowRate, targetBoostPumpPressure * @param duty which is the duty cycle * @return none *************************************************************************/ BOOL setBoostPumpTargetDutyCycle( F32 dutyCycle ) { BOOL status = FALSE; if ( ( dutyCycle >= MIN_FLUID_PUMP_DUTY_CYCLE_PCT ) && ( dutyCycle <= MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ) { boostPumpOpenLoopTargetDutyCycle = dutyCycle; boostPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; status = TRUE; // Set the new duty cycle of the pump setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); // Clear previous target data if ( getTargetBoostPumpFlowRateMLPM() > 0 ) { targetBoostPumpFlowRate.data = 0.0F; } if ( getTargetBoostPumpPressure() > 0.0F ) { targetBoostPumpPressure.data = 0.0F; } } else { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, SW_FAULT_ID_RO_INVALID_PUMP_DUTY_CYCLE_SELECTED, dutyCycle ) } return status; } /*********************************************************************//** * @brief * The getTargetBoostPumpPressure function gets the current target Boost pump * pressure. * @details \b Inputs: targetBoostPumpPressure * @details \b Outputs: none * @return the current target Boost pressure in PSI *************************************************************************/ F32 getTargetBoostPumpPressure( void ) { F32 pressure = getF32OverrideValue( &targetBoostPumpPressure ); return pressure; } /*********************************************************************//** * @brief * The getTargetBoostPumpFlowRateMLPM function gets the current target Boost pump * flow rate. * @details \b Inputs: targetBoostPumpFlowRate * @details \b Outputs: none * @return the current target Boost flow rate (in mL/min). *************************************************************************/ U32 getTargetBoostPumpFlowRateMLPM( void ) { U32 flowRate = getU32OverrideValue( &targetBoostPumpFlowRate ); return flowRate; } /*********************************************************************//** * @brief * The boostPumpPresToPWM function calculates the duty cycle for the given target * pressure. * @details \b Inputs: none * @details \b Outputs: dutyCyclePct * @param targetPressure target pressure value to control in PSI * @return the current target Boost pump PWM in a percentage. *************************************************************************/ static F32 boostPumpPresToPWM( F32 targetPressure ) { F32 dutyCyclePct = BOOST_PRESSURE_TO_PWM( targetPressure ); return dutyCyclePct; } /*********************************************************************//** * @brief * The boostPumpFlowToPWM function calculates the duty cycle for the given target * flow rate. * @details \b Inputs: none * @details \b Outputs: dutyCyclePct * @param targetFlow target flow value to control in in L/min * @return the current target Boost pump PWM in a percentage. *************************************************************************/ static F32 boostPumpFlowToPWM( U32 targetFlow ) { F32 dutyCyclePct = BOOST_FLOW_TO_PWM( targetFlow ); return dutyCyclePct; } /*********************************************************************//** * @brief * The signalBoostPumpStop function stops the P40 pump immediately and * resets all the variables associated with the P40 pump run. * @details \b Inputs: boostPumpState[] * @details \b Outputs: stopPumpRequest[] * @return none *************************************************************************/ void signalBoostPumpHardStop( void ) { if( targetBoostPumpFlowRate.data > 0.0F ) { targetBoostPumpFlowRate.data = 0.0F; resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, 0 ); } if( targetBoostPumpPressure.data > 0.0F ) { targetBoostPumpPressure.data = 0.0F; resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, 0 ); } boostPumpState = BOOST_PUMP_OFF_STATE; boostPumpDutyCyclePctSet = 0.0F; boostControlTimerCounter = 0; boostPumpOpenLoopTargetDutyCycle = 0.0F; stopBoostPump(); } /*********************************************************************//** * @brief * The stopBoostPump function sets the P40 pump duty cycle to zero. * @details Inputs: none * @details Outputs: isBoostPumpOn, boostPumpPWMDutyCyclePctSet * @return none *************************************************************************/ static void stopBoostPump( void ) { isBoostPumpOn = FALSE; boostPumpDutyCyclePctSet = 0.0F; // Set the new duty cycle of the pump setFluidPumpPWMDutyCycle( P40_PUMP, 0 ); } /*********************************************************************//** * @brief * The isBoostPumpRunning function returns the on/off status of P40 pump. * @details \b Inputs: isBoostPumpOn * @details \b Outputs: none * @return isBoostPumpOn the boolean flag that is TRUE if the pump is on and * FALSE if it is off *************************************************************************/ BOOL isBoostPumpRunning( void ) { return isBoostPumpOn; } /*********************************************************************//** * @brief * The publishBoostPumpData function publishes p40 pump data at the set interval. * @details \b Message \b Sent: MSG_ID_FP_BOOST_PUMP_DATA * @details \b Inputs: boostPumpDataPublicationTimerCounter * @details \b Outputs: boostPumpDataPublicationTimerCounter * @return none *************************************************************************/ static void publishBoostPumpData( void ) { // publish Boost pump data on interval if ( ++boostPumpDataPublicationTimerCounter >= getU32OverrideValue( &boostPumpDataPublishInterval ) ) { BOOST_PUMP_DATA_T pumpData; pumpData.p40PumpState = (U32)boostPumpState; pumpData.p40PumpDutyCycle = (U32)getFluidPumpPWMDutyCycle( P40_PUMP ); pumpData.p40PumpFBDutyCycle = (U32)getFluidPumpReadPWMDutyCycle( P40_PUMP ); pumpData.p40PumpSpeed = getFluidPumpRPM( P40_PUMP ); pumpData.p40TargetPressure = getTargetBoostPumpPressure(); pumpData.p40TargetFlow = getTargetBoostPumpFlowRateMLPM(); pumpData.p40TargetDutyCycle = boostPumpOpenLoopTargetDutyCycle; broadcastData( MSG_ID_FP_BOOST_PUMP_DATA, COMM_BUFFER_OUT_CAN_RO_BROADCAST, (U08*)&pumpData, sizeof( BOOST_PUMP_DATA_T ) ); boostPumpDataPublicationTimerCounter = 0; } } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testBoostPumpDataPublishIntervalOverride function overrides the Boost pump * data publish interval. * @details \b Inputs: boostPumpDataPublishInterval * @details \b Outputs: boostPumpDataPublishInterval * @param message Override message from Dialin which includes the value * that override boost pump data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testBoostPumpDataPublishIntervalOverride( MESSAGE_T *message ) { BOOL result = u32BroadcastIntervalOverride( message, &boostPumpDataPublishInterval, TASK_GENERAL_INTERVAL ); return result; } /*********************************************************************//** * @brief * The testBoostPumpTargetPressureOverride function overrides the Boost pump * data publish interval. * @details \b Inputs: targetBoostPumpPressure * @details \b Outputs: targetBoostPumpPressure * @param message Override message from Dialin which includes the value * that override target pressure * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testBoostPumpTargetPressureOverride( MESSAGE_T *message ) { BOOL result = f32Override( message, &targetBoostPumpPressure ); return result; } /*********************************************************************//** * @brief * The testBoostPumpTargetFlowOverride function overrides the Boost pump * target flow rate in ml/min. * @details \b Inputs: targetBoostPumpFlowRate * @details \b Outputs: targetBoostPumpFlowRate * @param message Override message from Dialin which includes the value * that override target flow * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testBoostPumpTargetFlowOverride( MESSAGE_T *message ) { BOOL result = u32Override( message, &targetBoostPumpFlowRate, MIN_BOOST_FLOWRATE_MLPM, MAX_BOOST_FLOWRATE_MLPM ); return result; } /**@}*/