Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -r3f5b2cfad9edd2a67c0c6bbc9fd7f74021d566b8 -r66c62857a66b634a1174ec61d49a53b18dedef6d --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 3f5b2cfad9edd2a67c0c6bbc9fd7f74021d566b8) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 66c62857a66b634a1174ec61d49a53b18dedef6d) @@ -82,6 +82,8 @@ #define SYRINGE_PUMP_SYRINGE_DETECT_THRESHOLD_V 2.0F ///< Syringe pump syringe detected threshold (in V). #define SYRINGE_PUMP_HOME_DETECT_THRESHOLD_V 0.25F ///< Syringe pump home detected threshold (in V). #define SYRINGE_PUMP_PRIME_VOLUME_ML 0.353F ///< Target syringe prime volume (in mL). +#define SYRINGE_PUMP_PRELOAD_MARGIN_VOLUME_ML 1.0F ///< Target syringe preload margin volume (in mL). Total to deliver plus this give syringe load position. +#define SYRINGE_PUMP_PRELOAD_MAX_VOLUME_ML 10.0F ///< Target syringe preload max volume (in mL). Leave at home position above this value. #define SYRINGE_PUMP_MAX_VOL_ERROR_ML 0.1F ///< Maximum Heparin volume error (in mL). #define SYRINGE_PUMP_MAX_RATE_ERROR_ML_HR 0.1F ///< Maximum Heparin delivery rate error (in mL/hr). #define TEN_PCT_OVER_ALLOWANCE 1.1F ///< Allow 10 percent over target before alarming on over travel. @@ -162,6 +164,7 @@ SYRINGE_PUMP_INIT_STATE = 0, ///< Syringe pump initialize state SYRINGE_PUMP_OFF_STATE, ///< Syringe pump off state SYRINGE_PUMP_RETRACT_STATE, ///< Syringe pump retract state + SYRINGE_PUMP_PRELOAD_STATE, ///< Syringe pump preload state SYRINGE_PUMP_SEEK_STATE, ///< Syringe pump seek plunger state SYRINGE_PUMP_PRIME_STATE, ///< Syringe pump prime state SYRINGE_PUMP_HEP_BOLUS_STATE, ///< Syringe pump bolus delivery of Heparin state @@ -208,8 +211,10 @@ static U32 syringePumpSpeedCalcTimerCounter; ///< Used to calculate measured rate from change in position over time. static MOTOR_DIR_T syringePumpControllerMeasuredDirection; ///< Measured direction of syringe pump per controller. static MOTOR_DIR_T syringePumpEncoderMeasuredDirection; ///< Measured direction of syringe pump per encoder position relative to previous. +static F32 syringePumpVolumeRequired; ///< Volume required for complete therapy (in mL). static BOOL syringePumpRetractRequested; ///< Flag indicates a retract operation is requested. +static BOOL syringePumpPreloadRequested; ///< Flag indicates a plunger preload operation is requested. static BOOL syringePumpSeekRequested; ///< Flag indicates a plunger seek operation is requested. static BOOL syringePumpPrimeRequested; ///< Flag indicates a Heparin prime operation is requested. static BOOL syringePumpBolusRequested; ///< Flag indicates start or resume of a Heparin bolus operation is requested. @@ -220,6 +225,7 @@ static BOOL syringePumpPlungerFound; ///< Flag indicates plunger was found. static BOOL syringeVolumeAdequate; ///< Flag indicates whether Heparin volume is sufficient to complete treatment. static BOOL syringePumpPrimeCompleted; ///< Flag indicates prime operation was completed. +static BOOL syringePumpPreLoadCompleted; ///< Flag indicates preload operation was completed. static BOOL syringePumpDACVrefWriteInProgress; ///< Flag indicates DAC Vref write is in progress. static F32 syringePumpDACVref; ///< DAC Vref setting for force sensor. @@ -250,6 +256,7 @@ static SYRINGE_PUMP_STATE_T handleSyringePumpInitState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpOffState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpRetractState( void ); +static SYRINGE_PUMP_STATE_T handleSyringePumpPreLoadState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpSeekState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpPrimeState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpBolusState( void ); @@ -288,6 +295,7 @@ syringePumpVolumeStartPosition = 0; syringePumpHomePositionOffset = 0; syringePumpLastPosition = 0; + syringePumpVolumeRequired = 0.0; #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) @@ -306,6 +314,7 @@ syringePumpPlungerFound = FALSE; syringeVolumeAdequate = FALSE; syringePumpPrimeCompleted = FALSE; + syringePumpPreLoadCompleted = FALSE; syringePumpRampUpPct = 0.0; // Zero pump position counts buffer @@ -345,6 +354,7 @@ { syringePumpRetractRequested = FALSE; syringePumpSeekRequested = FALSE; + syringePumpPreloadRequested = FALSE; syringePumpPrimeRequested = FALSE; syringePumpBolusRequested = FALSE; syringePumpContinuousRequested = FALSE; @@ -471,7 +481,7 @@ * @brief * The stopSyringePump function requests syringe pump be stopped. * @details Inputs: none - * @details Outputs: syringePumpSetRate, syringePumpRetractRequested, syringePumpState + * @details Outputs: syringePumpSetRate, syringePumpState, heparinDeliveryState * @return TRUE if request accepted, FALSE if not *************************************************************************/ void stopSyringePump( void ) @@ -489,7 +499,7 @@ * @brief * The retractSyringePump function requests retract operation. * @details Inputs: syringePumpState - * @details Outputs: syringePumpSetRate, syringePumpRetractRequested + * @details Outputs: syringePumpSetRate, syringePumpRetractRequested, heparinDeliveryState * @return TRUE if request accepted, FALSE if not *************************************************************************/ BOOL retractSyringePump( void ) @@ -506,6 +516,29 @@ /*********************************************************************//** * @brief + * The preloadSyringePlunger function requests plunger preload operation. + * @details Inputs: syringePumpState + * @details Outputs: syringePumpSetRate, syringePumpPreloadRequested + * @return TRUE if request accepted, FALSE if not + *************************************************************************/ +BOOL preloadSyringePlunger( void ) +{ + if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + { + heparinDeliveryState = HEPARIN_STATE_STOPPED; + } + if ( ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) && + ( TRUE == syringePumpPositionKnown ) && ( heparinDeliveryState != HEPARIN_STATE_OFF ) ) + { + syringePumpSetRate = SYRINGE_PUMP_SEEK_RATE; + syringePumpPreloadRequested = TRUE; + } + + return syringePumpPreloadRequested; +} + +/*********************************************************************//** + * @brief * The seekSyringePlunger function requests plunger seek operation. * @details Inputs: syringePumpState * @details Outputs: syringePumpSetRate, syringePumpSeekRequested @@ -961,6 +994,19 @@ /*********************************************************************//** * @brief + * The isSyringePumpPreLoaded function determines whether the syringe pump + * is has been moved to preload position. + * @details Inputs: syringePumpPreLoadCompleted + * @details Outputs: none + * @return TRUE if syringe pump operation is in preload position, FALSE if not. + *************************************************************************/ +BOOL isSyringePumpPreLoaded( void ) +{ + return syringePumpPreLoadCompleted; +} + +/*********************************************************************//** + * @brief * The execSyringePumpMonitor function executes the syringe pump monitor. * @details Inputs: FPGA syringe pump readings * @details Outputs: Alarm(s) may be triggered @@ -1129,6 +1175,10 @@ syringePumpState = handleSyringePumpRetractState(); break; + case SYRINGE_PUMP_PRELOAD_STATE: + syringePumpState = handleSyringePumpPreLoadState(); + break; + case SYRINGE_PUMP_SEEK_STATE: syringePumpState = handleSyringePumpSeekState(); break; @@ -1252,6 +1302,10 @@ { result = SYRINGE_PUMP_RETRACT_STATE; } + else if ( TRUE == syringePumpPreloadRequested ) + { + result = SYRINGE_PUMP_PRELOAD_STATE; + } else if ( TRUE == syringePumpSeekRequested ) { result = SYRINGE_PUMP_SEEK_STATE; @@ -1342,6 +1396,8 @@ syringePumpPlungerFound = FALSE; syringeVolumeAdequate = FALSE; syringePumpPrimeCompleted = FALSE; + syringePumpPreLoadCompleted = FALSE; + syringePumpVolumeRequired = 0.0F; // Clear insufficient volume alarm condition in case we're retracting to allow user to resolve alarm clearAlarmCondition( ALARM_ID_HD_SYRINGE_PUMP_NOT_ENOUGH_HEPARIN_ALARM ); } @@ -1368,6 +1424,69 @@ /*********************************************************************//** * @brief + * The handleSyringePumpPreLoadState function handles the PreLoad plunger state + * of the syringe pump control state machine. Move to position that limits + * loadable Heparin volume to amount needed for treatment. + * @details Inputs: syringePumpMeasForce.data + * @details Outputs: syringePumpVolumeRequired, Syringe pump moved to preload position, alarm conditions checked + * @return next state + *************************************************************************/ +static SYRINGE_PUMP_STATE_T handleSyringePumpPreLoadState( void ) +{ + SYRINGE_PUMP_STATE_T result = SYRINGE_PUMP_PRELOAD_STATE; + BOOL stopPump = FALSE; + S32 pos = getSyringePumpPosition(); + F32 bolusVol = getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ); + F32 contRate = getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ); + U32 preStop = getTreatmentParameterU32( TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ); + U32 setTxDur = getTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_DURATION ); + F32 hepDurHr = ( (F32)( setTxDur - preStop ) / (F32)MIN_PER_HOUR ); + F32 txVolumeReq = SYRINGE_PUMP_PRIME_VOLUME_ML + bolusVol + ( hepDurHr * contRate ); + F32 syringeVol = ( SYRINGE_PUMP_EMPTY_POS - (F32)pos ) / SYRINGE_ENCODER_COUNTS_PER_ML; + + syringePumpVolumeRequired = txVolumeReq; + txVolumeReq = txVolumeReq + SYRINGE_PUMP_PRELOAD_MARGIN_VOLUME_ML; + + // Is syringe loaded? + if ( TRUE == isSyringeDetected() ) + { + activateAlarmNoData( ALARM_ID_HD_SYRINGE_DETECTED ); + stopPump = TRUE; + } + else + { + // Handle ramp up + rampSyringePump(); + } + + // Is plunger Heparin volume position detected? or volume requiring full syringe. + if ( ( syringeVol <= txVolumeReq ) || ( SYRINGE_PUMP_PRELOAD_MAX_VOLUME_ML < txVolumeReq ) ) + { + stopPump = TRUE; + syringePumpVolumeDelivered.data = 0.0; + syringePumpSafetyVolumeDelivered = 0.0; + syringePumpVolumeStartPosition = pos; + syringePumpPreLoadCompleted = TRUE; + } + + // Check max position > empty + 0.5 mL + stopPump = checkMaxTravel( stopPump, SYRINGE_PUMP_EMPTY_POS + SYRINGE_PUMP_EMPTY_POS_MARGIN ); + + // Check pump direction + stopPump = checkDirection( stopPump, MOTOR_DIR_FORWARD ); + + // If anything found that would require stopping the pump, stop pump and go to off state + if ( TRUE == stopPump ) + { + stopSyringePump(); + result = SYRINGE_PUMP_OFF_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The handleSyringePumpSeekState function handles the seek plunger state * of the syringe pump control state machine. * @details Inputs: syringePumpMeasForce.data @@ -1397,6 +1516,7 @@ syringePumpVolumeDelivered.data = 0.0; syringePumpSafetyVolumeDelivered = 0.0; syringePumpVolumeStartPosition = pos; + syringePumpPreLoadCompleted = FALSE; // Check estimated syringe volume needed for treatment vs. volume detected - if insufficient for treatment needs, alarm if ( syringeVol >= txVolume ) @@ -1458,6 +1578,7 @@ syringePumpVolumeDelivered.data = 0.0; syringePumpSafetyVolumeDelivered = 0.0; syringePumpVolumeStartPosition = syringePumpPosition.data; + syringePumpPreLoadCompleted = FALSE; } // Has syringe been removed? @@ -2011,6 +2132,7 @@ ( (U32)getSyringePumpADCReadCounter() ); volData.syringePumpVolumeDelivered = getSyringePumpVolumeDelivered(); + volData.syringePumpVolumeRequired = syringePumpVolumeRequired; broadcastData( MSG_ID_HD_SYRINGE_PUMP_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( SYRINGE_PUMP_DATA_PAYLOAD_T ) ); broadcastData( MSG_ID_HD_HEPARIN_DATA_BROADCAST, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&volData, sizeof( SYRINGE_PUMP_VOLUME_DATA_T ) ); Index: firmware/App/Modes/SelfTests.c =================================================================== diff -u -rb31eee6a3b7c95cf1392ad2cef7b7f9775fb7bd1 -r66c62857a66b634a1174ec61d49a53b18dedef6d --- firmware/App/Modes/SelfTests.c (.../SelfTests.c) (revision b31eee6a3b7c95cf1392ad2cef7b7f9775fb7bd1) +++ firmware/App/Modes/SelfTests.c (.../SelfTests.c) (revision 66c62857a66b634a1174ec61d49a53b18dedef6d) @@ -755,16 +755,26 @@ static NO_CART_SELF_TESTS_STATE_T handleNoCartSelfTestHomeSyringePumpState( void ) { NO_CART_SELF_TESTS_STATE_T state = NO_CART_SELF_TESTS_HOME_SYRINGE_PUMP_STATE; + BOOL syringeHome = isSyringePumpHome(); + BOOL syringeStopped = isSyringePumpStopped(); + BOOL syringePreload = isSyringePumpPreLoaded(); if ( TRUE == useHeparin ) { - if ( ( isSyringePumpHome() != TRUE ) && ( TRUE == isSyringePumpStopped() ) ) + if ( ( TRUE != syringeHome ) && ( TRUE == syringeStopped ) && ( FALSE == syringePreload ) ) { retractSyringePump(); } + else if ( ( TRUE == syringeHome ) && ( TRUE == syringeStopped ) && ( FALSE == syringePreload ) ) + { + preloadSyringePlunger(); + } + else if ( TRUE == syringePreload ) + { + state = NO_CART_SELF_TESTS_PUMPS_STATE; + } } - - if ( ( TRUE != useHeparin ) || ( TRUE == isSyringePumpHome() ) ) + else { state = NO_CART_SELF_TESTS_PUMPS_STATE; } @@ -1306,13 +1316,13 @@ } else { - if ( TRUE == isSyringePumpHome() ) + if ( TRUE == isSyringePumpPreLoaded() ) { seekSyringePlunger(); } else { - retractSyringePump(); + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, (U32)SW_FAULT_ID_HD_SYRINGE_NOT_PRELOADED ) } } }