Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r27f3db92495948d4c1192421c1b0c20338c4a034 -re440fa19012fb060ae96bc91b4e1b8f60bb08723 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 27f3db92495948d4c1192421c1b0c20338c4a034) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision e440fa19012fb060ae96bc91b4e1b8f60bb08723) @@ -169,14 +169,15 @@ { VALVE_POSITION_T commandedPosition; ///< Valve commanded position enum VALVE_POSITION_T currentPosition; ///< Valve current position enum - S16 currentPositionInCounts; ///< Valve current position in counts + S16 currentPositionInCounts; ///< Valve current position in counts TODO remove + OVERRIDE_S32_T currentPositionInCounts2; ///< Valve current position in counts S16 targetPositionInCounts; ///< Valve target position in counts BOOL hasTransitionBeenRequested; ///< Valve transition request flag VALVE_STATE_T execState; ///< Valve execution state U32 transitionStartTime; ///< Valve transition start time S16 positions[ NUM_OF_VALVE_POSITIONS ]; ///< Valve positions array (Pos A, Pos B, Pos C) VALVE_MODE_T controlMode; ///< Valve control mode (PID, bypass, disable) - F32 current; ///< Valve current + OVERRIDE_F32_T current; ///< Valve current U32 overCurrentCounter; ///< Valve over current counter U32 positionOutOfRangeCounter; ///< Valve position out of range counter U32 dataPublishCounter; ///< Valve data publish counter @@ -276,6 +277,10 @@ for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { valvesStatus[ valve ].execState = VALVE_STATE_WAIT_FOR_POST; + valvesStatus[ valve ].current.data = 0.0; + valvesStatus[ valve ].current.ovData = 0.0; + valvesStatus[ valve ].current.ovInitData = 0.0; + valvesStatus[ valve ].current.override = 0; } // Close air trap valve @@ -363,6 +368,26 @@ /*********************************************************************//** * @brief + * The getValveCurrent function returns the current of a valve. + * @details Inputs: none + * @details Outputs: valvesStatus + * @param valve that the current is requested + * @return returns the current of the valve in float + *************************************************************************/ +F32 getValveCurrent( VALVE_T valve ) +{ + F32 current = valvesStatus[ valve ].current.data; + + if ( OVERRIDE_KEY == valvesStatus[ valve ].current.override ) + { + current = valvesStatus[ valve ].current.ovData; + } + + return current; +} + +/*********************************************************************//** + * @brief * The setValveBloodTrap function set the blood trap valve to open or close * position. * @details Inputs: valveAirTrapStatus @@ -1080,22 +1105,22 @@ U16 currentInADC = 0; currentInADC = getFPGAValveDialyzerInletCurrentCounts(); - valvesStatus[ VDI ].current = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; + valvesStatus[ VDI ].current.data = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveDialyzerOutletCurrentCounts(); - valvesStatus[ VDO ].current = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; + valvesStatus[ VDO ].current.data = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveBloodArterialCurrentCounts(); - valvesStatus[ VBA ].current = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; + valvesStatus[ VBA ].current.data = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveBloodVenousCurrentCounts(); - valvesStatus[ VBV ].current = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; + valvesStatus[ VBV ].current.data = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; // Check the current of all the valves for ( valve = VDI; valve < NUM_OF_VALVES; valve++) { // Absolute value is used to cover both positive and negative values - F32 current = fabs( valvesStatus[ valve ].current ); + F32 current = fabs( getValveCurrent( valve ) ); if ( current > VALVES_CURRENT_THRESHOLD_AMPS ) { @@ -1109,8 +1134,7 @@ #endif } // If the current is below the threshold again and the counter for the time is greater than - else if ( current < VALVES_CURRENT_THRESHOLD_AMPS && - valvesStatus[ valve ].overCurrentCounter > 0 ) + else if ( ( current < VALVES_CURRENT_THRESHOLD_AMPS ) && ( valvesStatus[ valve ].overCurrentCounter > 0 ) ) { valvesStatus[ valve ].overCurrentCounter = 0; } @@ -1224,7 +1248,7 @@ valveData.currentPosID = (U32)valvesStatus[ valve ].currentPosition; valveData.currentPos = valvesStatus[ valve ].currentPositionInCounts; valveData.nextPos = valvesStatus[ valve ].targetPositionInCounts; - valveData.current = valvesStatus[ valve ].current; + valveData.current = getValveCurrent( valve ); valveData.posC = valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ]; valveData.posA = valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ]; valveData.posB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; @@ -1460,7 +1484,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { // Get the current position of the valve as the initial position valvesPositionOverride[ valve ].ovInitData = (U32)valvesStatus[ valve ].currentPosition; @@ -1479,14 +1503,14 @@ * of the valves publish interval. * @details Inputs: valvesDataPublishInterval * @details Outputs: valvesDataPublishInterval - * @param valve that its data publish will be overridden + * @param valve that its position override will be reset * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetValvesPositionOverride( U32 valve ) { BOOL result = FALSE; - if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { valvesPositionOverride[ valve ].override = OVERRIDE_RESET; valvesPositionOverride[ valve ].ovData = valvesPositionOverride[ valve ].ovInitData; @@ -1514,13 +1538,13 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { BOOL homingStatus = valvesStatus[ valve ].hasValveBeenHomed; // The PWM should be in range and also the valve direction should be legal and the valve must have been homed // Prior to running this command - if ( pwm <= VALVE_MAX_ALLOWED_PWM_PERCENT && direction < NUM_OF_VALVE_DIRECTION && homingStatus ) + if ( ( pwm <= VALVE_MAX_ALLOWED_PWM_PERCENT ) && ( direction < NUM_OF_VALVE_DIRECTION ) && ( TRUE == homingStatus ) ) { valvesStatus[ (VALVE_T)valve ].bypassModeStatus.commandedPWMInPercent = (U16)pwm; valvesStatus[ (VALVE_T)valve ].bypassModeStatus.direction = (VALVE_DIRECTION_T)direction; @@ -1543,15 +1567,15 @@ * control mode. * @details Inputs: valvesStatus * @details Outputs: valvesStatus - * @param valve that its data publish will be overridden + * @param valve that its PWM override will be reset * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetValvePWMOverride( U32 valve ) { BOOL result = FALSE; // Check if the valve is in the range of the valves available - if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { // Turn off the bypass mode request and the change request valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasBypassModeBeenRequeseted = FALSE; @@ -1562,6 +1586,73 @@ return result; } + +/*********************************************************************//** + * @brief + * The testSetValvesPositionCountOverride function overrides the valves + * position in counts. + * @details Inputs: valvesPositionOverride, valvesStatus + * @details Outputs: valvesPositionOverride + * @param valve to override its position + * @param position of the valve that will be overridden + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetValvesPositionCountOverride( U32 valve, U32 count ) +{ + +} + +BOOL testResetValvesPositionCountOverride( U32 valve ) +{ + +} + +/*********************************************************************//** + * @brief + * The testSetValvesPositionOverride function overrides the valves position. + * @details Inputs: valvesStatus + * @details Outputs: valvesStatus + * @param valve to override its position + * @param current of the valve that will be overridden + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetValvesCurrentOverride( U32 valve, F32 current ) +{ + BOOL result = FALSE; + + // Check if the valve is in the range of the valves available + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) + { + valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_RESET; + valvesStatus[ (VALVE_T)valve ].current.ovData = current; + valvesStatus[ (VALVE_T)valve ].current.ovInitData = valvesStatus[ (VALVE_T)valve ].current.data; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetValvesCurrentOverride function resets the override + * of the valves' current. + * @details Inputs: valvesStatus + * @details Outputs: valvesStatus + * @param valve that its current override will be reset + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetValvesCurrentOverride( U32 valve ) +{ + BOOL result = FALSE; + + if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) + { + valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_RESET; + valvesStatus[ (VALVE_T)valve ].current.ovData = valvesStatus[ (VALVE_T)valve ].current.ovInitData; + } + + return result; +} + #endif /**@}*/