Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r31af479fdd28f5bc5f0241de76f9b891d535feda -r01421bdf636834fad230d03258fc30ad2f839abf --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 31af479fdd28f5bc5f0241de76f9b891d535feda) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 01421bdf636834fad230d03258fc30ad2f839abf) @@ -47,26 +47,22 @@ #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 { VALVE_POSITION_T commandedPosition; ///< Valve commanded position enum. VALVE_POSITION_T currentPosition; ///< Valve current position enum. VALVE_POSITION_T pendingCommandedPosition; ///< Valve pending position enum. -// S16 currentEncPosition; ///< Valve current position in encoder counts. S16 priorEncPosition; ///< Valve prior position in encoder counts. BOOL hasTransitionBeenRequested; ///< Valve transition request flag. VALVE_STATE_T controlState; ///< Valve control state. U32 valveOpsStartTime; ///< Valve transition start time. -// S16 positionsABC[ NUM_OF_VALVE_POSITIONS ]; ///< Valve positions (in encoder counts) for positions A, B, and C. -// U32 overCurrentCounter; ///< Valve over current counter. -// U32 positionOutOfRangeCounter; ///< Valve position out of range counter. // Homing variables BOOL hasHomingBeenRequested; ///< Valve homing request flag. BOOL hasValveBeenHomed; ///< Valve homing completed flag. -// S16 currentMaxEncPositionCnt; ///< Valve homing current maximum encoder position counts. -// S16 previousMaxEncPositionCnt; ///< Valve homing previous maximum encoder position counts. } VALVE_STATUS_T; /// Payload record structure for pinch valve set position request @@ -89,23 +85,13 @@ static VALVE_STATUS_T currentValveStates[ NUM_OF_VALVES ]; ///< Current status of each valve. static U32 valvesDataPublicationTimerCounter; ///< Valves data broadcast timer counter. static OVERRIDE_U32_T valvesDataPublishInterval; ///< Valves data broadcast interval (in ms). -//static SELF_TEST_STATUS_T valvesSelfTestResult; ///< Valves self test result. -//static TD_VALVES_CAL_RECORD_T valvesCalibrationRecord; ///< Valves calibration record. // ********** private function prototypes ********** static VALVE_STATE_T handleValvesWait4PostState( VALVE_T valve ); -//static VALVE_STATE_T handleValvesResetValve( VALVE_T valve ); -//static VALVE_STATE_T handleValvesResetEncoder( VALVE_T valve ); -//static VALVE_STATE_T handleValvesEnableValve( VALVE_T valve ); static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ); -//static VALVE_STATE_T handleValvesFindEnergizedEdgeState( VALVE_T valve ); -//static VALVE_STATE_T handleValvesFindDeenergizedEdgeState( VALVE_T valve ); static VALVE_STATE_T handleValvesIdleState( VALVE_T valve ); static VALVE_STATE_T handleValvesTransitionState( VALVE_T valve ); -//static void checkValveInRange( VALVE_T valve, SW_FAULT_ID_T SWFault ); -//static BOOL hasEdgeBeenReached( VALVE_T valve ); -//static S16 convertCountToDivision8( S16 count ); static void publishValvesData( void ); /*********************************************************************//** @@ -117,6 +103,8 @@ *************************************************************************/ void initValves( void ) { + VALVE_T valve; + // Initialize Pinch Valve driver initPinchValveDriver(); @@ -128,6 +116,20 @@ valvesDataPublishInterval.ovInitData = 0; valvesDataPublishInterval.override = OVERRIDE_RESET; + for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) + { + currentValveStates[ valve ].commandedPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].pendingCommandedPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; + currentValveStates[ valve ].hasHomingBeenRequested = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + //currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].controlState = VALVE_STATE_WAIT_FOR_POST; + currentValveStates[ valve ].valveOpsStartTime = 0; + } + + #ifdef ASN_DEMO currentValveStates[ H1_VALV ].positionsABC[ VALVE_POSITION_C_CLOSE ] = ROTARY_VALVE_MICROSTEP_FRACTION; currentValveStates[ H1_VALV ].positionsABC[ VALVE_POSITION_B_OPEN ] = 1728; @@ -154,14 +156,24 @@ { BOOL result = FALSE; + ( void )cartridge; + if ( valve < NUM_OF_VALVES ) { - //result = homePinchValve( valve ); - if ( TRUE == result ) + if ( ( TRUE == force ) || ( FALSE == currentValveStates[ valve ].hasValveBeenHomed ) ) { - currentValveStates[valve].hasHomingBeenRequested = TRUE; - currentValveStates[valve].controlState = VALVE_STATE_IN_TRANSITION; + if ( ( FALSE == isPinchValveBusy( valve ) ) && ( FALSE == currentValveStates[ valve ].hasHomingBeenRequested ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = TRUE; + currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + result = TRUE; + } } + else + { + result = TRUE; + } } else { @@ -185,16 +197,20 @@ { BOOL result = FALSE; - if ( ( valve < NUM_OF_VALVES ) && ( position < NUM_OF_VALVE_POSITIONS ) ) + if ( ( valve < NUM_OF_VALVES ) && ( position > VALVE_POSITION_NOT_IN_POSITION ) && ( position < NUM_OF_VALVE_POSITIONS ) ) { - currentValveStates[ valve ].pendingCommandedPosition = position; - currentValveStates[ valve ].hasTransitionBeenRequested = TRUE; - result = TRUE; + if ( ( TRUE == currentValveStates[ valve ].hasValveBeenHomed ) && + ( FALSE == isPinchValveBusy( valve ) ) && + ( FALSE == currentValveStates[ valve ].hasTransitionBeenRequested ) ) + { + currentValveStates[ valve ].pendingCommandedPosition = position; + currentValveStates[ valve ].hasTransitionBeenRequested = TRUE; + result = TRUE; + } } else { - 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 ) + 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 ) } return result;