Index: firmware/App/Services/StateServices/TubeSetAutoEject.c =================================================================== diff -u -racc8c3eb9d40711058bd214251d7554ab50b3836 -rb314f68347ca0720d370fd5ace385a2d8d92fabe --- firmware/App/Services/StateServices/TubeSetAutoEject.c (.../TubeSetAutoEject.c) (revision acc8c3eb9d40711058bd214251d7554ab50b3836) +++ firmware/App/Services/StateServices/TubeSetAutoEject.c (.../TubeSetAutoEject.c) (revision b314f68347ca0720d370fd5ace385a2d8d92fabe) @@ -15,6 +15,7 @@ * ***************************************************************************/ +#include "AlarmMgmtTD.h" #include "BloodFlow.h" #include "Ejector.h" #include "Messaging.h" @@ -37,6 +38,9 @@ ///< Blood pump flow rate (mL/min) for the ejecting operation #define AUTO_EJECT_BLOOD_FLOW_RATE_ML_MIN 100U +/// Blood pump torque threshold (mN.m) above which a tube-set jam is declared +#define BP_TORQUE_LIMIT_MNM 9999.0F // TODO: Replace with lab characterized value + // ********** private data ********** static BOOL autoEjectReqReceived; ///< Flag indicating that user confirmed to eject tubeset @@ -51,6 +55,7 @@ static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectHomingState( void ); static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectExtendingEjectorState( void ); static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectEjectingState( void ); +static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectBackOffState( void ); static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectRetractingEjectorState( void ); static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectCompleteState( void ); @@ -72,7 +77,7 @@ /*********************************************************************//** * @brief - * The execTubeSetEject function executes the Tube Set Eject + * The execTubeSetAutoEject function executes the Tube Set Eject * state machine. * @details \b Inputs: currentAutoEjectState * @details \b Outputs: currentAutoEjectState. Advances the @@ -99,6 +104,10 @@ currentAutoEjectState = handleAutoEjectEjectingState(); break; + case TUBE_SET_AUTO_EJECT_STATE_BACK_OFF: + currentAutoEjectState = handleAutoEjectBackOffState(); + break; + case TUBE_SET_AUTO_EJECT_STATE_RETRACTING_EJECTOR: currentAutoEjectState = handleAutoEjectRetractingEjectorState(); break; @@ -142,7 +151,7 @@ * The handleAutoEjectHomingState function handles the Homing state * of the Tube Set Eject state machine. * Homes the blood pump (H4) - * @details \b Inputs: autoEjectTimerCounter, isPeristalticPumpHome() + * @details \b Inputs: autoEjectTimerCounter * @details \b Outputs: autoEjectTimerCounter * @return next Auto-Eject state *************************************************************************/ @@ -176,7 +185,7 @@ * The handleAutoEjectExtendingEjectorState function handles the * Extending Ejector state of the Tube Set Eject Service * state machine. Extends the ejector pin (H5) to engage the tubeset. - * @details \b Inputs: autoEjectTimerCounter, getEjectorState() + * @details \b Inputs: autoEjectTimerCounter * @details \b Outputs: autoEjectTimerCounter * @return next Auto-Eject state *************************************************************************/ @@ -209,20 +218,30 @@ * of the Tube Set Eject state machine. Rotates the blood pump (H4) * forward at 100 mL/min with the ejector extended to push the tubeset * out of the rotor. - * @details \b Inputs: autoEjectTimerCounter, isPeristalticPumpHome() - * @details \b Outputs: autoEjectTimerCounter + * @details \b Inputs: autoEjectTimerCounter, bpLastHome + * @details \b Outputs: autoEjectTimerCounter, bpLastHome * @return next Auto-Eject state *************************************************************************/ static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectEjectingState( void ) { TUBE_SET_AUTO_EJECT_STATE_T state = TUBE_SET_AUTO_EJECT_STATE_EJECTING; BOOL bpCurrentHome = isPeristalticPumpHome(); + F32 bpTorque = getMeasuredBloodPumpTorque(); if ( ++autoEjectTimerCounter >= AUTO_EJECT_OPERATION_TIMEOUT_INTERVAL ) { signalBloodPumpHardStop(); SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_AUTO_LOAD_EJECT_BP_TIMEOUT, isPeristalticPumpHome(), autoEjectTimerCounter ); } + // Torque jam check. If measured torque exceeds the limit, the tubing set is likely jammed in the rotor. + else if ( bpTorque > BP_TORQUE_LIMIT_MNM ) + { + signalBloodPumpHardStop(); + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_TD_AUTO_LOAD_EJECT_BLOOD_TUBE_SET_FAILURE, bpTorque ); + setBloodPumpTargetFlowRate( AUTO_EJECT_BLOOD_FLOW_RATE_ML_MIN, MOTOR_DIR_REVERSE, PUMP_CONTROL_MODE_OPEN_LOOP ); + autoEjectTimerCounter = 0; + state = TUBE_SET_AUTO_EJECT_STATE_BACK_OFF; + } // BP home position check (rising edge: motor must leave home and return) else if ( ( TRUE == bpCurrentHome ) && ( FALSE == bpLastHome ) ) { @@ -243,10 +262,46 @@ /*********************************************************************//** * @brief + * The handleAutoEjectBackOffState function handles the Auto-Eject Back-Off + * state of Tube Set Eject state machine. + * @details \b Inputs: autoEjectTimerCounter + * @details \b Outputs: autoEjectTimerCounter + * @return next Auto-Eject state + *************************************************************************/ +static TUBE_SET_AUTO_EJECT_STATE_T handleAutoEjectBackOffState( void ) +{ + TUBE_SET_AUTO_EJECT_STATE_T state = TUBE_SET_AUTO_EJECT_STATE_BACK_OFF; + + if ( ++autoEjectTimerCounter >= AUTO_EJECT_OPERATION_TIMEOUT_INTERVAL ) + { + signalBloodPumpHardStop(); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_AUTO_LOAD_EJECT_BP_TIMEOUT, isPeristalticPumpHome(), autoEjectTimerCounter ); + } + else if ( TRUE == isPeristalticPumpHome() ) + { + signalBloodPumpHardStop(); + clearAlarmTD( ALARM_ID_TD_AUTO_LOAD_EJECT_BLOOD_TUBE_SET_FAILURE ); + + if ( FALSE == isAlarmActive( ALARM_ID_TD_AUTO_LOAD_EJECT_BLOOD_TUBE_SET_FAILURE ) ) + { + autoEjectTimerCounter = 0; + state = TUBE_SET_AUTO_EJECT_STATE_AWAIT_CONFIRMATION; + } + } + else + { + // No action required + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleAutoEjectRetractingEjectorState function handles the - * Retracting Ejector state of the Tube Set Eject state - * machine. Retracts the ejector pin (H5) after the tubeset has been ejected. - * @details \b Inputs: autoEjectTimerCounter, getEjectorState() + * Retracting Ejector state of the Tube Set Eject state machine. + * Retracts the ejector pin (H5) after the tubeset has been ejected. + * @details \b Inputs: autoEjectTimerCounter * @details \b Outputs: autoEjectTimerCounter * @return next Auto-Eject state *************************************************************************/ @@ -307,7 +362,7 @@ * The handleAutoEjectRequest function handles a UI request to remove the * disposable tubeset. * @details \b Message \b Sent: MSG_ID_TD_ADJUST_DISPOSABLES_REMOVAL_CONFIRM_RESPONSE - * @details \b Inputs: currentAutoEjectState, getCurrentOperationMode() + * @details \b Inputs: currentAutoEjectState * @details \b Outputs: autoEjectReqReceived * @param message UI message which includes the user confirmation to * eject the tubeset