Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r01421bdf636834fad230d03258fc30ad2f839abf -r8fc5ef2c8ca8e8438b1eaf388b6b9ee5190ae76b --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 01421bdf636834fad230d03258fc30ad2f839abf) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 8fc5ef2c8ca8e8438b1eaf388b6b9ee5190ae76b) @@ -39,17 +39,15 @@ #define VALVE_HOME_MIN_POS_CHG 3 ///< Minimum encoder position change to indicate a home operation is still moving toward edge. #define VALVE_HOME_BACK_OFF_EDGE 3 ///< Encoder counts to back off of detected edge position. #define MAX_HOME_FULL_TRAVEL_DIFF 10U ///< Maximum allowed difference in full travel encoder counts between expected and measured during home operation. -#define VALVE_TRANSITION_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Valves transition time out in ms. +#define VALVE_TRANSITION_TIMEOUT_MS ( 30 * MS_PER_SECOND ) ///< Valves transition time out in ms. #define HOMING_EDGE_DETECTION_TIMEOUT_MS ( 0.5 * MS_PER_SECOND ) ///< Valves homing edge detection timeout in milliseconds. #define VALVE_FORCE_HOME TRUE ///< Force valve to home even if already homed. #define ZERO_ENC_DEBOUNCE_THRESHOLD_CNT 5 ///< Valves zero encoder debounce threshold count. #define ZERO_ENC_DEBOUNCE_TIMEOUT_MS ( 0.25 * MS_PER_SECOND ) ///< Valves zero encoder debounce timeout in milliseconds. #define VALVE_OFFEST_FROM_EDG_CNT 296 ///< Valves offset from the edge. #define POS_C_FROM_ZERO_CNT VALVE_OFFEST_FROM_EDG_CNT ///< Position C from zero position in counts. #define POS_D_PARTIAL_CLOSE_FROM_ZERO_CNT ( POS_C_FROM_ZERO_CNT + 32 ) ///< Position D partial close from zero position in counts. -#define VALVE_TRANSITION_TIMEOUT_MS ( 30 * MS_PER_SECOND ) ///< Maximum controller wait time for a home or position operation. - /// Valve status structure typedef struct { @@ -63,6 +61,7 @@ // Homing variables BOOL hasHomingBeenRequested; ///< Valve homing request flag. BOOL hasValveBeenHomed; ///< Valve homing completed flag. + BOOL homingOperationActive; } VALVE_STATUS_T; /// Payload record structure for pinch valve set position request @@ -124,7 +123,7 @@ currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; currentValveStates[ valve ].hasHomingBeenRequested = FALSE; currentValveStates[ valve ].hasValveBeenHomed = FALSE; - //currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].homingOperationActive = FALSE; currentValveStates[ valve ].controlState = VALVE_STATE_WAIT_FOR_POST; currentValveStates[ valve ].valveOpsStartTime = 0; } @@ -252,7 +251,7 @@ *************************************************************************/ VALVE_STATE_T getValveState( VALVE_T valve ) { - VALVE_STATE_T result = VALVE_STATE_HOMING_NOT_STARTED; + VALVE_STATE_T result = VALVE_STATE_WAIT_FOR_POST; if ( valve < NUM_OF_VALVES ) { @@ -278,49 +277,22 @@ { VALVE_T valve; - // get latest valve readings from FPGA - //readValves(); +// execPinchValveCommand(); +// execPinchValveFunction(); for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { - // Update valve encoder positions - currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; - //currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); - // Update valve max encoder positions - currentValveStates[ valve ].previousMaxEncPositionCnt = currentValveStates[ valve ].currentMaxEncPositionCnt; - //currentValveStates[ valve ].currentMaxEncPositionCnt = getValveMaximumEncoderPosition( valve ); - // execute valve state machine switch ( currentValveStates[ valve ].controlState ) { case VALVE_STATE_WAIT_FOR_POST: currentValveStates[ valve ].controlState = handleValvesWait4PostState( valve ); break; - case VALVE_STATE_RESET_VALVE: - currentValveStates[ valve ].controlState = handleValvesResetValve( valve ); - break; - - case VALVE_STATE_RESET_ENCODER: - currentValveStates[ valve ].controlState = handleValvesResetEncoder( valve ); - break; - - case VALVE_STATE_ENABLE_VALVE: - currentValveStates[ valve ].controlState = handleValvesEnableValve( valve ); - break; - - case VALVE_STATE_HOMING_NOT_STARTED: + case VALVE_STATE_HOMING_NOT_HOMED: currentValveStates[ valve ].controlState = handleValvesNotHomedState( valve ); break; - case VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE: - currentValveStates[ valve ].controlState = handleValvesFindEnergizedEdgeState( valve ); - break; - - case VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE: - currentValveStates[ valve ].controlState = handleValvesFindDeenergizedEdgeState( valve ); - break; - case VALVE_STATE_IDLE: currentValveStates[ valve ].controlState = handleValvesIdleState( valve ); break; @@ -331,6 +303,9 @@ default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_STATE, (U32)currentValveStates[ valve ].controlState ) + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].controlState = VALVE_STATE_HOMING_NOT_HOMED; break; } } @@ -376,97 +351,19 @@ { VALVE_STATE_T nextState = VALVE_STATE_WAIT_FOR_POST; - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_WAIT_FOR_POST_STATE ); - - if ( getCurrentOperationMode() != MODE_INIT ) + if ( valve < NUM_OF_VALVES ) { - nextState = VALVE_STATE_RESET_VALVE; + if ( MODE_INIT != getCurrentOperationMode() ) + { + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } } return nextState; } /*********************************************************************//** * @brief - * The handleValvesResetValve function handles the reset valve of the state - * machine for a given valve. - * @details \b Inputs: current operating mode - * @details \b Outputs: none - * @param valve ID of valve for which to handle the Wait for POST state - * @return next state of the state machine for the given valve - *************************************************************************/ -static VALVE_STATE_T handleValvesResetValve( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_RESET_ENCODER; - - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_RESET ); - //resetValve( valve ); - - return nextState; -} - -/*********************************************************************//** - * @brief - * The handleValvesResetEncoder function handles the reset encoder of the state - * machine for a given valve. - * @details \b Inputs: current operating mode - * @details \b Outputs: none - * @param valve ID of valve for which to handle the Wait for POST state - * @return next state of the state machine for the given valve - *************************************************************************/ -static VALVE_STATE_T handleValvesResetEncoder( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_ENABLE_VALVE; - - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_RESET_ENCODER ); - //resetValveEncoder( valve ); - // Set the timer for the first debounce read - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - - return nextState; -} - -/*********************************************************************//** - * @brief - * The handleValvesEnableValve function handles the enable valve of the state - * machine for a given valve. - * @details \b Inputs: currentValveStates[] - * @details \b Outputs: currentValveStates[] - * @param valve ID of valve for which to handle the Wait for POST state - * @return next state of the state machine for the given valve - *************************************************************************/ -static VALVE_STATE_T handleValvesEnableValve( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_ENABLE_VALVE; - //S16 valveEncPosistion = getValveEncoderPosition( valve ); - - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_ENABLE ); - - if ( FALSE == currentValveStates[ valve ].hasValveBeenReset ) - { - //enableValve( valve ); - currentValveStates[ valve ].hasValveBeenReset = TRUE; - } - else - { - //setValveZeroEncoderPosition( valve ); - } - - //if ( valveEncPosistion >= ZERO_ENC_DEBOUNCE_THRESHOLD_CNT ) - { - // Keep reseting the debounce timer until the encoder count is less than the encoder count is less than the number - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - } - //else if ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, ZERO_ENC_DEBOUNCE_TIMEOUT_MS ) ) - { - nextState = VALVE_STATE_HOMING_NOT_STARTED; - } - - return nextState; -} - -/*********************************************************************//** - * @brief * The handleValvesNotHomedState function handles the Not Homed state * of the state machine for a given valve. * @details \b Inputs: currentValveStates[] @@ -476,94 +373,27 @@ *************************************************************************/ static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) { - VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_STARTED; + VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_NOT_HOMED ); - if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) { - // Getting ready for homing enable the homing bit upon transitioning to homing not started - //setValveHomingEnableDisable( valve, TRUE ); - - // TODO figure out the new valve homing failure alarm - // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_HOMING_FAILED, (U32)valve, (U32)currentValveStates[ valve ].proposedEnergizedPos ) - - // Command valve to move to energized edge (end of travel) - currentValveStates[ valve ].valveOpsStartTime = 0; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - nextState = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; - //setValveCmdChangePosition( valve, (U16)ROTARY_VALVE_INIT_ENERGIZED_COUNTS, MOTOR_DIR_FORWARD ); + if ( TRUE == homePinchValve( valve ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].homingOperationActive = TRUE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + nextState = VALVE_STATE_IN_TRANSITION; + } } return nextState; } -/*********************************************************************//** - * @brief - * The handleValvesFindEnergizedEdgeState function handles the find energized - * edge state of the state machine for a given valve. - * @details \b Inputs: currentValveStates[] - * @details \b Outputs: currentValveStates[] - * @param valve ID of valve for which to handle the Find Energized Edge state - * @return next state of the state machine for the given valve - *************************************************************************/ -static VALVE_STATE_T handleValvesFindEnergizedEdgeState( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_FIND_ENERGIZED_EDGE ); - - if ( TRUE == hasEdgeBeenReached( valve ) ) - { - nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; - } - - return nextState; -} - /*********************************************************************//** * @brief - * The handleValvesFindDeenergizedEdgeState function handles the find Deenergized - * edge state of the state machine for a given valve. - * @details \b Inputs: currentValveStates[] - * @details \b Outputs: currentValveStates[] - * @param valve ID of valve for which to handle the find deenergized edge state - * @return next state of the state machine for the given valve - *************************************************************************/ -static VALVE_STATE_T handleValvesFindDeenergizedEdgeState( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; - S16 posB = 0; - S16 posC = 0; - S16 posA = 0; - - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_FIND_DEENERGIZED_EDGE ); - - // Done with homing disable the homing bit - //setValveHomingEnableDisable( valve, FALSE ); - - // TODO in the future this needs to be searched - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = VALVE_OFFEST_FROM_EDG_CNT; - - posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; - posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; - posA = posC + ( ( posB - posC ) / 2 ); - posA = convertCountToDivision8( posA ); - - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ] = posA; - currentValveStates[ valve ].hasValveBeenHomed = TRUE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_B_OPEN; - currentValveStates[ valve ].pendingCommandedPosition = VALVE_POSITION_A_INSERT_EJECT; - currentValveStates[ valve ].hasTransitionBeenRequested = TRUE; - currentValveStates[ valve ].hasHomingBeenRequested = FALSE; - nextState = VALVE_STATE_IDLE; - - return nextState; -} - -/*********************************************************************//** - * @brief * The handleValvesIdleState function handles the Idle state of the state * machine for a given valve. * @details \b Inputs: currentValveStates[] @@ -575,34 +405,28 @@ { VALVE_STATE_T nextState = VALVE_STATE_IDLE; - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_IDLE ); - - // handle a home request if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) { - // Homing has been requested, enable the homing bit. - //setValveHomingEnableDisable( valve, TRUE ); - // Transition to enable homing to set the encode to 0. - nextState = VALVE_STATE_ENABLE_VALVE; + if ( TRUE == homePinchValve( valve ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].homingOperationActive = TRUE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + nextState = VALVE_STATE_IN_TRANSITION; + } } - // handle a position change request else if ( TRUE == currentValveStates[ valve ].hasTransitionBeenRequested ) { - currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; - if ( currentValveStates[ valve ].currentPosition != currentValveStates[ valve ].pendingCommandedPosition ) + if ( TRUE == movePinchValveToStoredPosition( valve, currentValveStates[ valve ].pendingCommandedPosition ) ) { - S16 curPos = currentValveStates[ valve ].currentEncPosition; - S16 tgtPos = currentValveStates[ valve ].positionsABC[ currentValveStates[ valve ].pendingCommandedPosition ]; - S16 mag = tgtPos - curPos; // calculate magnitude of position change - MOTOR_DIR_T dir = ( mag < 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); // determine direction of position change - - // Set commanded position and transition start time stamp - currentValveStates[ valve ].commandedPosition = currentValveStates[ valve ].pendingCommandedPosition; - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - nextState = VALVE_STATE_IN_TRANSITION; - - // Command FPGA to move valve to commanded position - //setValveCmdChangePosition( valve, (U16)( abs(mag) ), dir ); + currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; + currentValveStates[ valve ].commandedPosition = currentValveStates[ valve ].pendingCommandedPosition; + currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + nextState = VALVE_STATE_IN_TRANSITION; } } @@ -621,124 +445,61 @@ static VALVE_STATE_T handleValvesTransitionState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_IN_TRANSITION; - S16 curPos = currentValveStates[ valve ].currentEncPosition; - S16 tgtPos = currentValveStates[ valve ].positionsABC[ currentValveStates[ valve ].commandedPosition ]; - S16 delta = tgtPos - curPos; - checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_IN_TRANSITION ); - - // have we completed the transition? - if ( abs( delta ) < VALVE_TRANSITION_MIN_TGT_DELTA ) + if ( FALSE == isPinchValveBusy( valve ) ) { - currentValveStates[ valve ].currentPosition = currentValveStates[ valve ].commandedPosition; - nextState = VALVE_STATE_IDLE; + if ( TRUE == currentValveStates[ valve ].homingOperationActive ) + { + currentValveStates[ valve ].homingOperationActive = FALSE; + + if ( TRUE == isPinchValveHomed( valve ) ) + { + currentValveStates[ valve ].hasValveBeenHomed = TRUE; + currentValveStates[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_A_INSERT_EJECT; + nextState = VALVE_STATE_IDLE; + } + else + { + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } + } + else + { + currentValveStates[ valve ].currentPosition = currentValveStates[ valve ].commandedPosition; + nextState = VALVE_STATE_IDLE; + } } - // is transition taking too long? else if ( ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) && - ( getCPLDACPowerLossDetected() != TRUE ) ) + ( TRUE != getCPLDACPowerLossDetected() ) ) { - // Go back to Idle state and set the valve position to not in position because it was not able to get to the target position currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - nextState = VALVE_STATE_IDLE; - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)abs( delta ) ); - // If the valve's commanded position is C, activate safety shutdown + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) + if ( VALVE_POSITION_C_CLOSE == currentValveStates[ valve ].commandedPosition ) { activateSafetyShutdown(); } - } - return nextState; -} - -/*********************************************************************//** - * @brief - * The checkValveInRange function checks whether the selected valve is in range - * and if not it will trigger the provided software fault. - * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given valve is invalid. - * @details \b Inputs: none - * @details \b Outputs: none - * @param valve the valve check whether it is in range - * @param SWFault the provided software fault to trigger - * @return none - *************************************************************************/ -static void checkValveInRange( VALVE_T valve, SW_FAULT_ID_T SWFault ) -{ - if ( valve >= NUM_OF_VALVES ) - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, (U32)SWFault, (U32)valve ) - } -} - -/*********************************************************************//** - * @brief - * The hasEdgeBeenReached function checks whether the valve has reached to - * its edge or not. - * @details \b Inputs: currentValveStates[] - * @details \b Outputs: currentValveStates[] - * @param valve ID of valve for which to check its edge - * @return TRUE if the edge has been reached otherwise, FALSE - *************************************************************************/ -static BOOL hasEdgeBeenReached( VALVE_T valve ) -{ - BOOL status = FALSE; - S16 previousMaxEnc = currentValveStates[ valve ].previousMaxEncPositionCnt; - S16 currentMaxEnc = currentValveStates[ valve ].currentMaxEncPositionCnt; - - checkValveInRange( valve, SW_FAULT_ID_VALVES_INVALID_VALVE_FINDING_EDGE ); - - if ( abs( currentMaxEnc - previousMaxEnc ) < VALVE_HOME_MIN_POS_CHG ) - { - if ( 0 == currentValveStates[ valve ].valveOpsStartTime ) + if ( TRUE == currentValveStates[ valve ].homingOperationActive ) { - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + nextState = VALVE_STATE_HOMING_NOT_HOMED; } - else if ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, HOMING_EDGE_DETECTION_TIMEOUT_MS ) ) + else { - status = TRUE; - currentMaxEnc = convertCountToDivision8( currentMaxEnc ); - currentMaxEnc -= VALVE_OFFEST_FROM_EDG_CNT; - - currentValveStates[ valve ].valveOpsStartTime = 0; - - if ( VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE == currentValveStates[ valve ].controlState ) - { - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ] = currentMaxEnc; - } - // TODO uncomment the deenergized edge - //else if ( VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE == currentValveStates[ valve ].controlStat ) - //{ - // currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = currentMaxEnc - //} + nextState = VALVE_STATE_IDLE; } } - else - { - currentValveStates[ valve ].valveOpsStartTime = 0; - } - return status; + return nextState; } /*********************************************************************//** * @brief - * The convertCountToDivision8 function converts the provided data to be in - * division of 8. - * @details \b Inputs: none - * @details \b Outputs: none - * @param count the value to be converted to the division of 8 - * @return the converted value - *************************************************************************/ -static S16 convertCountToDivision8( S16 count ) -{ - S16 convCount = ( count >> 3 ) << 3; - - return convCount; -} - -/*********************************************************************//** - * @brief * The publishValvesData function constructs and sends the valves data * broadcast message. * @details \b Message \b Sent: MSG_ID_TD_VALVES_DATA @@ -759,11 +520,10 @@ data.valveID = (U32)valve; data.state = (U32)currentValveStates[ valve ].controlState; data.currentPosID = (U32)currentValveStates[ valve ].currentPosition; - //data.currentPos = getValveEncoderPosition( valve ); data.cmdPos = currentValveStates[ valve ].commandedPosition; - data.posA = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ]; - data.posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; - data.posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; +// data.posA = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ]; +// data.posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; +// data.posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; data.maxHomingPos = currentValveStates[ valve ].currentMaxEncPositionCnt; broadcastData( MSG_ID_TD_VALVES_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( TD_VALVE_DATA_T ) ); @@ -819,7 +579,8 @@ VALVE_PINCH_SET_CMD_PAYLOAD_T payload; memcpy( &payload, message->payload, sizeof(VALVE_PINCH_SET_CMD_PAYLOAD_T) ); - if ( ( (VALVE_T)payload.valve < NUM_OF_VALVES ) && ( (VALVE_POSITION_T)payload.pos < NUM_OF_VALVE_POSITIONS ) ) + if ( ( (VALVE_T)payload.valve < NUM_OF_VALVES ) && ( (VALVE_POSITION_T)payload.pos < NUM_OF_VALVE_POSITIONS ) && + ( (VALVE_POSITION_T)payload.pos < NUM_OF_VALVE_POSITIONS ) ) ) { result = setValvePosition( (VALVE_T)payload.valve, (VALVE_POSITION_T)payload.pos ); } Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -rc0b93a6de34d38d42e7a678b6ced59220e1d14da -r8fc5ef2c8ca8e8438b1eaf388b6b9ee5190ae76b --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision c0b93a6de34d38d42e7a678b6ced59220e1d14da) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision 8fc5ef2c8ca8e8438b1eaf388b6b9ee5190ae76b) @@ -53,12 +53,7 @@ typedef enum Valve_Control_States { VALVE_STATE_WAIT_FOR_POST = 0, ///< Valve state wait for POST. -// VALVE_STATE_RESET_VALVE, ///< Valve state reset valve. -// VALVE_STATE_RESET_ENCODER, ///< Valve state reset encoder. -// VALVE_STATE_ENABLE_VALVE, ///< Valve state enable valve. - VALVE_STATE_HOMING_NOT_HOMED, ///< Valve state homing not started. -// VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE, ///< Valve state homing find energized edge. -// VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE, ///< Valve state homing find de-energized edge. + VALVE_STATE_HOMING_NOT_HOMED, ///< Valve state homing not started. VALVE_STATE_IDLE, ///< Valve state idle. VALVE_STATE_IN_TRANSITION, ///< Valve state in transition. NUM_OF_VALVE_STATES, ///< Number of valve exec states.