Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -rba6530b83f85452382325b97eae02d9e7e5c1cb1 -r660a411129a92b9519b0cd34d41dba79953616e5 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision ba6530b83f85452382325b97eae02d9e7e5c1cb1) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 660a411129a92b9519b0cd34d41dba79953616e5) @@ -94,10 +94,8 @@ static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ); static VALVE_STATE_T handleValvesIdleState( VALVE_T valve ); static VALVE_STATE_T handleValvesTransitionState( VALVE_T valve ); -static S32 getValveActualEncoderPosition( VALVE_T valve ); -static S32 getValveCommandedEncoderPosition( VALVE_T valve ); -static S32 getValvePositionError( VALVE_T valve ); static BOOL isValveAtCommandedPosition( VALVE_T valve ); +static VALVE_POSITION_T getCurrentValveABCPosition( VALVE_T valve ); static void publishValvesData( void ); /*********************************************************************//** @@ -399,7 +397,7 @@ currentValveStates[ valve ].homingOperationActive = FALSE; currentValveStates[ valve ].hasValveBeenHomed = TRUE; currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; // TODO: Later + currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); nextState = VALVE_STATE_IDLE; } else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && @@ -449,7 +447,7 @@ } else { - if ( getValvePositionError( valve ) > 15 ) + if ( isValveAtCommandedPosition( valve ) != TRUE ) { setValvePosition( valve, currentValveStates[ valve ].commandedPosition ); } @@ -475,7 +473,7 @@ { if ( TRUE == isValveAtCommandedPosition( valve ) ) { - currentValveStates[ valve ].currentPosition = currentValveStates[ valve ].commandedPosition; + currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); nextState = VALVE_STATE_IDLE; } else @@ -514,16 +512,11 @@ *************************************************************************/ static BOOL isValveAtCommandedPosition( VALVE_T valve ) { - BOOL result = FALSE; - S32 currentPosition; - S32 targetPosition; - S32 positionDelta; + BOOL result = FALSE; + S32 currentPosition = getPinchValvePosition( valve ); + S32 targetPosition = getPinchValveStoredPosition( valve, currentValveStates[ valve ].commandedPosition ); + S32 positionDelta = abs( currentPosition - targetPosition ); - currentPosition = (S32)getPinchValvePosition( valve ); - targetPosition = (S32)getPinchValveStoredPosition( valve, currentValveStates[ valve ].commandedPosition ); - - positionDelta = abs( currentPosition - targetPosition ); - if ( positionDelta <= VALVE_TRANSITION_MIN_TGT_DELTA ) { result = TRUE; @@ -534,66 +527,36 @@ /*********************************************************************//** * @brief - * The getValveActualEncoderPosition function handles the current and target - * position - * @details \b Inputs: currentPosition, targetPosition, positionDelta - * @details \b Outputs: result - * @return none + * The getCurrentValveABCPosition function determines the current position + * (enum) for a given valve based on current encoder position. + * @details \b Inputs: currentValveStates[] + * @details \b Outputs: none + * @param valve ID of valve to get current position for + * @return Position of given valve (enum) *************************************************************************/ -static S32 getValveActualEncoderPosition( VALVE_T valve ) +static VALVE_POSITION_T getCurrentValveABCPosition( VALVE_T valve ) { - S32 result = 0; + VALVE_POSITION_T result = VALVE_POSITION_NOT_IN_POSITION; + VALVE_POSITION_T p; - if ( valve < NUM_OF_VALVES ) + for ( p = VALVE_POSITION_A_INSERT_EJECT; p < NUM_OF_VALVE_POSITIONS; p++ ) { - result = getPinchValvePosition( valve ); - } + S32 pos = getPinchValveStoredPosition( valve, p ); + S32 targetPosition = getPinchValveStoredPosition( valve, currentValveStates[ valve ].commandedPosition ); + S32 positionDelta = abs( pos - targetPosition ); - return result; -} - -/*********************************************************************//** - * @brief - * The getValveCommandedEncoderPosition function handles the current and target - * position - * @details \b Inputs: currentPosition, targetPosition, positionDelta - * @details \b Outputs: result - * @return none - *************************************************************************/ -static S32 getValveCommandedEncoderPosition( VALVE_T valve ) -{ - S32 result = 0; - - if ( valve < NUM_OF_VALVES ) - { - result = getPinchValveStoredPosition( valve, currentValveStates[ valve ].commandedPosition ); + if ( positionDelta <= VALVE_TRANSITION_MIN_TGT_DELTA ) + { + result = p; + break; + } } return result; } /*********************************************************************//** * @brief - * The getValvePositionError function handles the current and target - * position - * @details \b Inputs: currentPosition, targetPosition, positionDelta - * @details \b Outputs: result - * @return none - *************************************************************************/ -static S32 getValvePositionError( VALVE_T valve ) -{ - S32 result = 0; - - if ( valve < NUM_OF_VALVES ) - { - result = abs( getValveActualEncoderPosition( valve ) - getValveCommandedEncoderPosition( valve ) ); - } - - return result; -} - -/*********************************************************************//** - * @brief * The publishValvesData function constructs and sends the valves data * broadcast message. * @details \b Message \b Sent: MSG_ID_TD_VALVES_DATA Index: firmware/App/Drivers/PinchValve.h =================================================================== diff -u -rcff19e1c44fd570e139a2a3f49b5a05f0193367d -r660a411129a92b9519b0cd34d41dba79953616e5 --- firmware/App/Drivers/PinchValve.h (.../PinchValve.h) (revision cff19e1c44fd570e139a2a3f49b5a05f0193367d) +++ firmware/App/Drivers/PinchValve.h (.../PinchValve.h) (revision 660a411129a92b9519b0cd34d41dba79953616e5) @@ -54,23 +54,23 @@ // ********** public function prototypes ********** -void initPinchValveDriver( void ); ///< Initializes the pinch valve driver state, command data, and FPGA. -void execPinchValveFunction( void ); ///< Executes the pinch valve function state machine -void execPinchValveCommand( void ); ///< Executes the FPGA command state machine. +void initPinchValveDriver( void ); // Initializes the pinch valve driver state, command data, and FPGA. +void execPinchValveFunction( void ); // Executes the pinch valve function state machine +void execPinchValveCommand( void ); // Executes the FPGA command state machine. -BOOL homePinchValve( VALVE_T valve ); ///< Starts the homing sequence for the selected pinch valve. +BOOL homePinchValve( VALVE_T valve ); // Starts the homing sequence for the selected pinch valve. -BOOL setPinchValvePosition( VALVE_T valve, VALVE_POSITION_T position ); ///< Starts a movement request to the selected stored valve position -S32 getPinchValvePosition( VALVE_T valve ); ///< Returns the latest actual encoder position for the selected valve. +BOOL setPinchValvePosition( VALVE_T valve, VALVE_POSITION_T position ); // Starts a movement request to the selected stored valve position +S32 getPinchValvePosition( VALVE_T valve ); // Returns the latest actual encoder position for the selected valve. -void setPinchValveEnableReset( VALVE_T valve, BOOL enable, BOOL reset ); ///< Sets the enable and reset control for the selected pinch valve -U08 getPinchValveEnableReset( VALVE_T valve ); ///< Returns the last enable and reset value written for the selected valve. +void setPinchValveEnableReset( VALVE_T valve, BOOL enable, BOOL reset ); // Sets the enable and reset control for the selected pinch valve +U08 getPinchValveEnableReset( VALVE_T valve ); // Returns the last enable and reset value written for the selected valve. -BOOL isPinchValveBusy( VALVE_T valve ); ///< Returns TRUE when the selected valve is executing or waiting for a command. -BOOL isPinchValveHomed( VALVE_T valve ); ///< Returns TRUE when the selected valve is executing or waiting for a command +BOOL isPinchValveBusy( VALVE_T valve ); // Returns TRUE when the selected valve is executing or waiting for a command. +BOOL isPinchValveHomed( VALVE_T valve ); // Returns TRUE when the selected valve is executing or waiting for a command -S32 getPinchValveStoredPosition( VALVE_T valve, VALVE_POSITION_T position ); ///< Returns the stored encoder position for the selected valve position. -BOOL movePinchValveToStoredPosition( VALVE_T valve, VALVE_POSITION_T position ); ///< Starts movement to a previously stored valve position +S32 getPinchValveStoredPosition( VALVE_T valve, VALVE_POSITION_T position ); // Returns the stored encoder position for the selected valve position. +BOOL movePinchValveToStoredPosition( VALVE_T valve, VALVE_POSITION_T position ); // Starts movement to a previously stored valve position /**@}*/