Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r046ffdda014e511363b04ed523eb3399a3eb4ad0 -rc0b93a6de34d38d42e7a678b6ced59220e1d14da --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 046ffdda014e511363b04ed523eb3399a3eb4ad0) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision c0b93a6de34d38d42e7a678b6ced59220e1d14da) @@ -21,6 +21,7 @@ #include "Messaging.h" #include "OperationModes.h" #include "PersistentAlarm.h" +#include "PinchValve.h" #include "TaskGeneral.h" #include "Timers.h" #include "Valves.h" @@ -53,20 +54,19 @@ 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 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. +// 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. - BOOL hasValveBeenReset; ///< Valve homing has valve been reset. - S16 currentMaxEncPositionCnt; ///< Valve homing current maximum encoder position counts. - S16 previousMaxEncPositionCnt; ///< Valve homing previous maximum encoder position counts. +// 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 +89,23 @@ 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 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 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 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 checkValveInRange( VALVE_T valve, SW_FAULT_ID_T SWFault ); +//static BOOL hasEdgeBeenReached( VALVE_T valve ); +//static S16 convertCountToDivision8( S16 count ); static void publishValvesData( void ); /*********************************************************************//** @@ -118,7 +118,7 @@ void initValves( void ) { // Initialize driver - initRotaryValvesDriver(); + //initRotaryValvesDriver(); // Initialize controller variables memset( ¤tValveStates[0], 0, sizeof( currentValveStates ) ); @@ -153,24 +153,15 @@ BOOL homeValve( VALVE_T valve, BOOL force, BOOL cartridge ) { BOOL result = FALSE; - + //void)force; + //(void)cartridge; if ( valve < NUM_OF_VALVES ) { - VALVE_STATE_T currState = currentValveStates[ valve ].controlState; - - if ( ( VALVE_STATE_HOMING_NOT_STARTED == currState ) || ( VALVE_STATE_IDLE == currState ) ) + //result = homePinchValve( valve ); + if ( TRUE == result ) { - // If haven't already homed the valves, home the valves - if ( ( currentValveStates[ valve ].hasValveBeenHomed != TRUE ) || ( VALVE_FORCE_HOME == force ) ) - { - currentValveStates[ valve ].hasHomingBeenRequested = TRUE; - } - // Otherwise, go to position A (home position) - else - { - setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); - } - result = TRUE; + currentValveStates[valve].hasHomingBeenRequested = TRUE; + currentValveStates[valve].controlState = VALVE_STATE_IN_TRANSITION; } } else @@ -273,16 +264,16 @@ VALVE_T valve; // get latest valve readings from FPGA - readValves(); + //readValves(); for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { // Update valve encoder positions currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; - currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); + //currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); // Update valve max encoder positions currentValveStates[ valve ].previousMaxEncPositionCnt = currentValveStates[ valve ].currentMaxEncPositionCnt; - currentValveStates[ valve ].currentMaxEncPositionCnt = getValveMaximumEncoderPosition( valve ); + //currentValveStates[ valve ].currentMaxEncPositionCnt = getValveMaximumEncoderPosition( valve ); // execute valve state machine switch ( currentValveStates[ valve ].controlState ) @@ -332,33 +323,33 @@ publishValvesData(); } +///*********************************************************************//** +// * @brief +// * The execValvesSelfTest function executes the valves self-test. Calibration +// * factors are loaded from non-volatile memory and CRC checked. +// * @details \b Inputs: Calibration record stored in non-volatile memory. +// * @details \b Outputs: valvesCalibrationRecord +// * @return self-test result (pass/fail) +// *************************************************************************/ +//SELF_TEST_STATUS_T execValvesSelfTest( void ) +//{ +// BOOL calStatus = TRUE; /* TODO getNVRecord2Driver( GET_CAL_VALVES, (U08*)&valvesCalibrationRecord, sizeof( HD_VALVES_CAL_RECORD_T ), +// NUM_OF_CAL_DATA_HD_VALVES, ALARM_ID_NO_ALARM );*/ +// +// if ( TRUE == calStatus ) +// { +// valvesSelfTestResult = SELF_TEST_STATUS_PASSED; +// } +// else +// { +// valvesSelfTestResult = SELF_TEST_STATUS_FAILED; +// } +// +// return valvesSelfTestResult; +//} +// /*********************************************************************//** * @brief - * The execValvesSelfTest function executes the valves self-test. Calibration - * factors are loaded from non-volatile memory and CRC checked. - * @details \b Inputs: Calibration record stored in non-volatile memory. - * @details \b Outputs: valvesCalibrationRecord - * @return self-test result (pass/fail) - *************************************************************************/ -SELF_TEST_STATUS_T execValvesSelfTest( void ) -{ - BOOL calStatus = TRUE; /* TODO getNVRecord2Driver( GET_CAL_VALVES, (U08*)&valvesCalibrationRecord, sizeof( HD_VALVES_CAL_RECORD_T ), - NUM_OF_CAL_DATA_HD_VALVES, ALARM_ID_NO_ALARM );*/ - - if ( TRUE == calStatus ) - { - valvesSelfTestResult = SELF_TEST_STATUS_PASSED; - } - else - { - valvesSelfTestResult = SELF_TEST_STATUS_FAILED; - } - - return valvesSelfTestResult; -} - -/*********************************************************************//** - * @brief * The handleValvesWait4PostState function handles the Wait for POST state * of the state machine for a given valve. * @details \b Inputs: current operating mode @@ -394,7 +385,7 @@ VALVE_STATE_T nextState = VALVE_STATE_RESET_ENCODER; checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_RESET ); - resetValve( valve ); + //resetValve( valve ); return nextState; } @@ -413,7 +404,7 @@ VALVE_STATE_T nextState = VALVE_STATE_ENABLE_VALVE; checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_RESET_ENCODER ); - resetValveEncoder( valve ); + //resetValveEncoder( valve ); // Set the timer for the first debounce read currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); @@ -432,26 +423,26 @@ static VALVE_STATE_T handleValvesEnableValve( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_ENABLE_VALVE; - S16 valveEncPosistion = getValveEncoderPosition( valve ); + //S16 valveEncPosistion = getValveEncoderPosition( valve ); checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_ENABLE ); if ( FALSE == currentValveStates[ valve ].hasValveBeenReset ) { - enableValve( valve ); + //enableValve( valve ); currentValveStates[ valve ].hasValveBeenReset = TRUE; } else { - setValveZeroEncoderPosition( valve ); + //setValveZeroEncoderPosition( valve ); } - if ( valveEncPosistion >= ZERO_ENC_DEBOUNCE_THRESHOLD_CNT ) + //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 ) ) + //else if ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, ZERO_ENC_DEBOUNCE_TIMEOUT_MS ) ) { nextState = VALVE_STATE_HOMING_NOT_STARTED; } @@ -477,7 +468,7 @@ if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) { // Getting ready for homing enable the homing bit upon transitioning to homing not started - setValveHomingEnableDisable( valve, TRUE ); + //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 ) @@ -487,7 +478,7 @@ 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 ); + //setValveCmdChangePosition( valve, (U16)ROTARY_VALVE_INIT_ENERGIZED_COUNTS, MOTOR_DIR_FORWARD ); } return nextState; @@ -535,12 +526,10 @@ checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_FIND_DEENERGIZED_EDGE ); // Done with homing disable the homing bit - setValveHomingEnableDisable( valve, FALSE ); + //setValveHomingEnableDisable( valve, FALSE ); // TODO in the future this needs to be searched currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = VALVE_OFFEST_FROM_EDG_CNT; - // TODO in the future this needs to be searched - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_PARTIAL_CLOSE ] = POS_D_PARTIAL_CLOSE_FROM_ZERO_CNT; posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; @@ -577,7 +566,7 @@ if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) { // Homing has been requested, enable the homing bit. - setValveHomingEnableDisable( valve, TRUE ); + //setValveHomingEnableDisable( valve, TRUE ); // Transition to enable homing to set the encode to 0. nextState = VALVE_STATE_ENABLE_VALVE; } @@ -598,7 +587,7 @@ nextState = VALVE_STATE_IN_TRANSITION; // Command FPGA to move valve to commanded position - setValveCmdChangePosition( valve, (U16)( abs(mag) ), dir ); + //setValveCmdChangePosition( valve, (U16)( abs(mag) ), dir ); } } @@ -755,12 +744,11 @@ data.valveID = (U32)valve; data.state = (U32)currentValveStates[ valve ].controlState; data.currentPosID = (U32)currentValveStates[ valve ].currentPosition; - data.currentPos = getValveEncoderPosition( valve ); + //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.posD = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_PARTIAL_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 ) );