Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r1d235091e158221f1fa8b1579140905a13249a54 -rdaf8d5b60c753becab80cbaf164aac0e49d533a2 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 1d235091e158221f1fa8b1579140905a13249a54) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision daf8d5b60c753becab80cbaf164aac0e49d533a2) @@ -84,19 +84,20 @@ static U32 drainPumpDataPublicationTimerCounter = 0; ///< used to schedule drain pump data publication to CAN bus static U32 drainPumpDAC = 0; ///< initial drain pump DAC value static U32 drainPumpDACSet = 0; ///< currently set drain pump DAC value -static PUMP_CONTROL_MODE_T drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; ///< requested drain pump control mode +static PUMP_CONTROL_MODE_T drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; ///< requested drain pump control mode +static PUMP_CONTROL_MODE_T drainPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set drain pump control mode static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, DRAIN_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus static OVERRIDE_U32_T targetDrainPumpSpeed = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI) -static OVERRIDE_U32_T targetDrainPumpDeltaPressure = { 0, 0, 0, 0 }; ///< Target delta pressure for the drain pump +static OVERRIDE_F32_T targetDrainPumpDeltaPressure = { 0.0, 0.0, 0.0, 0.0 }; ///< Target delta pressure for the drain pump static U32 drainControlTimerCounter = 0; ///< determines when to perform control on drain pump /* These variables are used for POST. POST will be implemented later static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState = DRAIN_PUMP_SELF_TEST_STATE_START; ///< current drain pump self test state -static U32 drainPumpSelfTestTimerCount = 0; ///< timer counter for drain pump self test +static U32 drainPumpSelfTestTimerCount = 0; ///< timer counter for drain pump self test */ // ********** private function prototypes ********** @@ -131,10 +132,10 @@ * The setDrainPumpTargetSpeed function sets a new target speed for the \n * drain pump. * @details - * Inputs : none - * Outputs : targetDrainPumpPressure - * @param rpm : new target drain pump speed (in RPM). - * @return TRUE if new target speed is set, FALSE if not + * Inputs: none + * Outputs: targetDrainPumpPressure + * @param: rpm : new target drain pump speed (in RPM). + * @return: TRUE if new target speed is set, FALSE if not *************************************************************************/ BOOL setDrainPumpTargetSpeed( U32 rpm ) { @@ -157,12 +158,12 @@ * The setDrainPumpTargetDeltaPressure function sets the target delta\n * pressure in between the PRd and PDr sensors * @details - * Inputs : targetDrainPumpDeltaP - * Outputs : targetDrainPumpDeltaP - * @param deltaP : new target drain pump delta pressure - * @return TRUE if new target speed is set, FALSE if not + * Inputs: targetDrainPumpDeltaP + * Outputs: targetDrainPumpDeltaP + * @param: deltaP : new target drain pump delta pressure + * @return: TRUE if new target speed is set, FALSE if not *************************************************************************/ -BOOL setDrainPumpTargetDeltaPressure ( U32 deltaP ) +BOOL setDrainPumpTargetDeltaPressure ( F32 deltaP ) { BOOL result = FALSE; @@ -177,9 +178,9 @@ * @brief * The signalDrainPumpHardStop function stops the Drain pump immediately. * @details - * Inputs : none - * Outputs : Drain pump stopped, set point reset, state changed to off - * @return none + * Inputs: none + * Outputs: Drain pump stopped, set point reset, state changed to off + * @return: none *************************************************************************/ void signalDrainPumpHardStop( void ) { @@ -194,9 +195,9 @@ * @brief * The execDrainPumpMonitor function executes the Drain Pump monitor. * @details - * Inputs : none - * Outputs : none - * @return none + * Inputs: none + * Outputs: none + * @return: none *************************************************************************/ void execDrainPumpMonitor( void ) { @@ -214,9 +215,9 @@ * @brief * The execDrainPumpController function executes the Drain Pump controller. * @details - * Inputs : drainPumpState - * Outputs : drainPumpState - * @return none + * Inputs: drainPumpState + * Outputs: drainPumpState + * @return: none *************************************************************************/ void execDrainPumpController( void ) { @@ -246,9 +247,9 @@ * The handleDrainPumpOffState function handles the drain pump off state \n * of the drain pump controller state machine. * @details - * Inputs : targetDrainPumpSpeed - * Outputs : drainPumpPWMDutyCyclePctSet - * @return next state + * Inputs: targetDrainPumpSpeed + * Outputs: drainPumpPWMDutyCyclePctSet + * @return: next state *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpOffState( void ) { @@ -262,15 +263,14 @@ setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - //setDrainPumpTargetSpeed( 1000 ); + setDrainPumpTargetSpeed( 1000 ); } #endif #endif // If the target drain pump speed was not 0 and the control mode // is open loop, set the drain pump to open loop - if ( getTargetDrainPumpSpeed() > 0 && - drainPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) + if ( getTargetDrainPumpSpeed() > 0 && drainPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) { // set drain pump enable pin SET_DRAIN_PUMP_ENABLE(); @@ -308,9 +308,9 @@ * The handleDrainPumpControlToTargetState function handles the "control to \n * target" state of the drain pump controller state machine. * @details - * Inputs : none - * Outputs : drainPumpState - * @return next state + * Inputs: none + * Outputs: drainPumpState + * @return: next state *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpControlToTargetState( void ) { @@ -321,10 +321,10 @@ { F32 inletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_INLET ); F32 outletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); - F32 pressureDiff = fabs( inletDrainPressure - outletDrainPressure ); + F32 pressureDiff = inletDrainPressure - outletDrainPressure; F32 rpm = runPIController( PI_CONTROLLER_ID_DRAIN_PUMP, targetDrainPumpDeltaPressure.data, pressureDiff ); - drainPumpDAC = (U32)(rpm * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); - setFPGADrainPumpSpeed( drainPumpDAC ); + drainPumpDACSet = (U32)(rpm * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); + setFPGADrainPumpSpeed( drainPumpDACSet ); drainControlTimerCounter = 0; } @@ -357,9 +357,9 @@ * The handleDrainPumpOpenLoopState function handles the open loop \n * state * @details - * Inputs : none - * Outputs : none - * @return next state + * Inputs: none + * Outputs: none + * @return: next state *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpOpenLoopState( void ) { @@ -370,9 +370,9 @@ * @brief * The stopDrainPump function sets the Drain pump DAC to zero. * @details - * Inputs : none - * Outputs : DAC zeroed - * @return none + * Inputs: none + * Outputs: DAC zeroed + * @return: none *************************************************************************/ static void stopDrainPump( void ) { @@ -387,9 +387,9 @@ * The getPublishDrainPumpDataInterval function gets the Drain pump data \n * publication interval. * @details - * Inputs : drainPumpDataPublishInterval - * Outputs : none - * @return the current Drain pump data publication interval (in ms). + * Inputs: drainPumpDataPublishInterval + * Outputs: none + * @return: the current Drain pump data publication interval (in ms). *************************************************************************/ U32 getPublishDrainPumpDataInterval( void ) { @@ -408,9 +408,9 @@ * The getTargetDrainPumpSpeed function gets the current target Drain pump \n * speed. * @details - * Inputs : targetDrainPumpSpeed + * Inputs: targetDrainPumpSpeed * Outputs : none - * @return the current target drain pump speed. + * @return: the current target drain pump speed. *************************************************************************/ U32 getTargetDrainPumpSpeed( void ) { @@ -429,9 +429,9 @@ * The publishDrainPumpData function publishes drain pump data at the set \n * interval. * @details - * Inputs : target speed - * Outputs : Drain pump data is published to CAN bus. - * @return none + * Inputs: target speed + * Outputs: Drain pump data is published to CAN bus. + * @return: none *************************************************************************/ static void publishDrainPumpData( void ) { @@ -453,9 +453,9 @@ * The execDrainPumpTest function executes the state machine for the Drain \n * Pump self test. * @details - * Inputs : none - * Outputs : none - * @return the current state of the Drain Pump self test. + * Inputs: none + * Outputs: none + * @return: the current state of the Drain Pump self test. *************************************************************************/ SELF_TEST_STATUS_T execDrainPumpTest( void ) { @@ -478,10 +478,10 @@ * The testSetDrainPumpDataPublishIntervalOverride function overrides the \n * drain pump data publish interval. * @details - * Inputs : none - * Outputs : drainPumpDataPublishInterval - * @param value : override RO pump data publish interval with (in ms) - * @return TRUE if override successful, FALSE if not + * Inputs: none + * Outputs: drainPumpDataPublishInterval + * @param: value : override RO pump data publish interval with (in ms) + * @return: TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetDrainPumpDataPublishIntervalOverride( U32 value ) { @@ -504,9 +504,9 @@ * The testResetDrainPumpDataPublishIntervalOverride function resets the override \n * of the drain pump data publish interval. * @details - * Inputs : none - * Outputs : drainPumpDataPublishInterval - * @return TRUE if override reset successful, FALSE if not + * Inputs: none + * Outputs: drainPumpDataPublishInterval + * @return: TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetDrainPumpDataPublishIntervalOverride( void ) { @@ -527,10 +527,10 @@ * The testSetTargetDrainPumpSpeedOverride function overrides the target \n * drain pump speed (in RPM). * @details - * Inputs : none - * Outputs : targetDrainPumpSpeed - * @param value : override target drain pump speed (in RPM) - * @return TRUE if override successful, FALSE if not + * Inputs: none + * Outputs: targetDrainPumpSpeed + * @param: value : override target drain pump speed (in RPM) + * @return: TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetTargetDrainPumpSpeedOverride( U32 value ) { @@ -552,9 +552,9 @@ * The testResetTargetDrainPumpSpeedOverride function resets the override of the \n * target drain pump speed (in RPM). * @details - * Inputs : none - * Outputs : targetDrainPumpSpeed - * @return TRUE if override reset successful, FALSE if not + * Inputs: none + * Outputs: targetDrainPumpSpeed + * @return: TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetTargetDrainPumpSpeedOverride( void ) { @@ -577,12 +577,12 @@ * The testSetTargetDrainPumpDeltaPressureOverride function overrides \n * the target drain pump delta pressure * @details - * Inputs : none - * Outputs : targetDrainPumpDeltaPressure - * @param value : override target drain pump delta pressure - * @return TRUE if override successful, FALSE if not + * Inputs: none + * Outputs: targetDrainPumpDeltaPressure + * @param: value : override target drain pump delta pressure + * @return: TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetDrainPumpDeltaPressureOverride( U32 value ) +BOOL testSetTargetDrainPumpDeltaPressureOverride( F32 value ) { BOOL result = FALSE; @@ -602,9 +602,9 @@ * The testResetTargetDrainPumpDeltaPressureOverride function resets the \n * override of the target drain pump delta pressure * @details - * Inputs : none - * Outputs : targetDrainPumpDeltaPressure - * @return TRUE if override reset successful, FALSE if not + * Inputs: none + * Outputs: targetDrainPumpDeltaPressure + * @return: TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetTargetDrainPumpDeltaPressureOverride( void ) { @@ -621,5 +621,3 @@ return result; } - -