Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r0eb08506bbe69f0cfc272e0a329591ffdeb3fc95 -rc0544e0ad0a0e83f247760f26205d79b64279ebe --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 0eb08506bbe69f0cfc272e0a329591ffdeb3fc95) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision c0544e0ad0a0e83f247760f26205d79b64279ebe) @@ -15,6 +15,8 @@ * ***************************************************************************/ +#include + #include "AlarmMgmtTD.h" #include "CpldInterface.h" #include "FpgaTD.h" @@ -35,7 +37,7 @@ #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_TRANSITION_MIN_TGT_DELTA 5 ///< 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_HOME_FULL_TRAVEL_DIFF 10U ///< Maximum allowed difference in full travel encoder counts between expected and measured during home operation. @@ -388,23 +390,13 @@ currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); } } - else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( FALSE == isPinchValveBusy( valve ) ) ) + else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == isPinchValveHomed( valve ) ) ) { 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; - } + currentValveStates[ valve ].hasValveBeenHomed = TRUE; + currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; + nextState = VALVE_STATE_IDLE; } else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) && @@ -478,7 +470,7 @@ else { currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; + // TODO - alarm nextState = VALVE_STATE_HOMING_NOT_HOMED; } } @@ -520,11 +512,7 @@ currentPosition = (S32)getPinchValvePosition( valve ); targetPosition = (S32)getPinchValveStoredPosition( valve, currentValveStates[ valve ].commandedPosition ); - positionDelta = currentPosition - targetPosition; - if ( positionDelta < 0 ) - { - positionDelta = -positionDelta; - } + positionDelta = abs( currentPosition - targetPosition ); if ( positionDelta <= VALVE_TRANSITION_MIN_TGT_DELTA ) { @@ -556,6 +544,7 @@ data.valveID = (U32)valve; data.state = (U32)currentValveStates[ valve ].controlState; data.currentPosID = (U32)currentValveStates[ valve ].currentPosition; + data.currentPos = (S16)getPinchValvePosition( valve ); data.cmdPos = currentValveStates[ valve ].commandedPosition; data.posA = (S16)getPinchValveStoredPosition( valve, VALVE_POSITION_A_INSERT_EJECT ); data.posB = (S16)getPinchValveStoredPosition( valve, VALVE_POSITION_B_OPEN ); @@ -614,8 +603,7 @@ 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 ) && - ( (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 ) ) { result = setValvePosition( (VALVE_T)payload.valve, (VALVE_POSITION_T)payload.pos ); }