Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r101c03d165ec613ba384bdad53100ba7bdda1e2c --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 101c03d165ec613ba384bdad53100ba7bdda1e2c) @@ -33,11 +33,11 @@ #define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Valves data publish interval. #define DATA_PUBLISH_COUNTER_START_COUNT 13 ///< Valves data publish start counter. -#define VALVE_TRANSITION_MIN_TGT_DELTA 10 ///< Minimum encoder position delta from target position to end transition state. -#define VALVE_HOME_MIN_POS_CHG 10 ///< Minimum encoder position change to indicate a home operation is still moving toward edge. -#define VALVE_HOME_BACK_OFF_EDGE 10 ///< Encoder counts to back off of detected edge position. +#define VALVE_TRANSITION_MIN_TGT_DELTA 3 ///< Minimum encoder position delta from target position to end transition state. +#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_ALLOWED_FAILED_VALVE_HOMINGS 3U ///< Maximum allowed failed valve home attempts -#define MAX_HOME_FULL_TRAVEL_DIFF 100U ///< Maximum allowed difference in full travel encoder counts between expected and measured during home operation. +#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 3000U ///< Valves transition time out in ms #define VALVE_FORCE_HOME TRUE ///< Force valve to home even if already homed @@ -147,6 +147,7 @@ { BOOL result = FALSE; +#ifndef TEST_NO_PINCH_VALVES if ( valve < NUM_OF_VALVES ) { VALVE_STATE_T currState = currentValveStates[ valve ].controlState; @@ -170,6 +171,7 @@ { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_VALVE8, (U32)valve ) } +#endif return result; } @@ -188,6 +190,7 @@ { BOOL result = FALSE; +#ifndef TEST_NO_PINCH_VALVES if ( ( valve < NUM_OF_VALVES ) && ( position < NUM_OF_VALVE_POSITIONS ) ) { currentValveStates[ valve ].pendingCommandedPosition = position; @@ -199,6 +202,7 @@ SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_PARAM, ( (U32)valve << SHIFT_16_BITS_FOR_WORD_SHIFT ) | (U32)position ) } +#endif return result; } @@ -250,7 +254,7 @@ currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); // execute valve state machine - switch( currentValveStates[ valve ].controlState ) + switch ( currentValveStates[ valve ].controlState ) { case VALVE_STATE_WAIT_FOR_POST: currentValveStates[ valve ].controlState = handleValvesWait4PostState( valve ); @@ -295,13 +299,17 @@ * @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 *************************************************************************/ -VALVE_STATE_T handleValvesWait4PostState( VALVE_T valve ) +static VALVE_STATE_T handleValvesWait4PostState( VALVE_T valve ) { +#ifndef TEST_PINCH_VALVES VALVE_STATE_T nextState = VALVE_STATE_WAIT_FOR_POST; +#else + VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_STARTED; +#endif if ( valve < NUM_OF_VALVES ) { -// if ( getCurrentOperationMode() != MODE_INIT ) + if ( getCurrentOperationMode() != MODE_INIT ) { nextState = VALVE_STATE_HOMING_NOT_STARTED; } @@ -324,19 +332,19 @@ * @param valve ID of valve for which to handle the Not Homed state * @return next state of the state machine for the given valve *************************************************************************/ -VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) +static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_STARTED; if ( valve < NUM_OF_VALVES ) { if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) { - U16 mag = ( 2 * ROTARY_VALVE_FULL_SWING_TRAVEL_COUNTS ); + U16 mag = ROTARY_VALVE_FULL_SWING_TRAVEL_COUNTS; // command valve to move to energized edge (end of travel) currentValveStates[ valve ].homingEdgeDetectionCounter = 0; - currentValveStates[ valve ].targetEncPosition = ROTARY_VALVE_FULL_SWING_TRAVEL_COUNTS; + currentValveStates[ valve ].targetEncPosition = mag; currentValveStates[ valve ].hasValveBeenHomed = FALSE; currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; setValveCmdChangePosition( valve, (U16)mag, MOTOR_DIR_FORWARD ); @@ -361,7 +369,7 @@ * @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 *************************************************************************/ -VALVE_STATE_T handleValvesFindEnergizedEdgeState( VALVE_T valve ) +static VALVE_STATE_T handleValvesFindEnergizedEdgeState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; @@ -372,14 +380,14 @@ // have we found foward edge of travel? if ( fabs( curPos - currentValveStates[ valve ].priorEncPosition ) < VALVE_HOME_MIN_POS_CHG ) { - U16 mag = ( 2 * ROTARY_VALVE_FULL_SWING_TRAVEL_COUNTS ); + U16 mag = ROTARY_VALVE_FULL_SWING_TRAVEL_COUNTS + VALVE_HOME_MIN_POS_CHG; // Record edge position currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ] = curPos - VALVE_HOME_BACK_OFF_EDGE; // command valve to move to de-energized edge (end of travel) currentValveStates[ valve ].homingEdgeDetectionCounter = 0; currentValveStates[ valve ].targetEncPosition = 0; - setValveCmdChangePosition( valve, (U16)mag, MOTOR_DIR_REVERSE ); + setValveCmdChangePosition( valve, mag, MOTOR_DIR_REVERSE ); nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; } } @@ -401,7 +409,7 @@ * @param valve ID of valve for which to handle the Find De-energized Edge state * @return next state of the state machine for the given valve *************************************************************************/ -VALVE_STATE_T handleValvesFindDeenergizedEdgeState( VALVE_T valve ) +static VALVE_STATE_T handleValvesFindDeenergizedEdgeState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; @@ -420,7 +428,7 @@ if ( expDelta <= MAX_HOME_FULL_TRAVEL_DIFF ) { // Record edge position - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = curPos + VALVE_HOME_BACK_OFF_EDGE; + currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = posC; // calculate and record middle position currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ] = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] + \ ( ( currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ] - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] ) / 2 ); @@ -466,7 +474,7 @@ * @param valve ID of valve for which to handle the Idle state * @return next state of the state machine for the given valve *************************************************************************/ -VALVE_STATE_T handleValvesIdleState( VALVE_T valve ) +static VALVE_STATE_T handleValvesIdleState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_IDLE; @@ -516,7 +524,7 @@ * @param valve ID of valve for which to handle the Transition state * @return next state of the state machine for the given valve *************************************************************************/ -VALVE_STATE_T handleValvesTransitionState( VALVE_T valve ) +static VALVE_STATE_T handleValvesTransitionState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_IN_TRANSITION;