Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r9ee205a82fc3bb2b6cdf871a2ef506b7a6caf88f -rd0afb42f8728fd5ee05c90ec0e57e1f4eec4067b --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 9ee205a82fc3bb2b6cdf871a2ef506b7a6caf88f) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision d0afb42f8728fd5ee05c90ec0e57e1f4eec4067b) @@ -7,8 +7,8 @@ * * @file BloodFlow.c * -* @author (last) Varshini Nagabooshanam -* @date (last) 26-Jan-2026 +* @author (last) Jashwant Gantyada +* @date (last) 13-Mar-2026 * * @author (original) Sean Nash * @date (original) 24-Oct-2024 @@ -78,11 +78,10 @@ #define BP_RAMP_STEP_SPEED_RPM 50 ///< Blood pump ramp step size (in RPM). -#define BP_ML_PER_ROTOR_REV 13.75F ///< Blood pump volume (mL) per rotor revolution. -#define BP_FLOW_ALPHA_Y_INTERCEPT 1.00F ///< Y intercept used for alpha flow coefficient calculation. -#define BP_FLOW_WEAR_A_TERM 0.000000F ///< A term used for wear portion of alpha flow coefficient. -#define BP_FLOW_WEAR_B_TERM 0.000000F ///< B term used for wear portion of alpha flow coefficient. -#define BP_MAX_ROTOR_COUNT_FOR_WEAR 25000 ///< Maximum rotor count for determining wear of the cartridge (negligible affect beyond this threshold). +#define BP_ML_PER_ROTOR_REV 12.26F ///< Default blood pump volume (mL) per rotor revolution. +#define BP_FLOW_WEAR_A_TERM -0.00000034F ///< Default wear term alpha used in blood flow estimation. +#define BP_FLOW_WEAR_B_TERM 1500.0F ///< Default wear term beta (offset) used in blood flow estimation. +#define BP_MAX_ROTOR_COUNT_FOR_WEAR 26000 ///< Default maximum rotor count for determining wear of the cartridge. #define BP_MIN_ART_PRESSURE_MMHG -200.0F ///< Minimum arterial pressure factored into blood flow calculation. #define BP_RATE_FROM_RPM( rpm ) ( rpm / ( BP_GEAR_RATIO / BP_ML_PER_ROTOR_REV ) ) ///< Macro to estimate a flow rate (mL/min) from a given speed (RPM). @@ -147,11 +146,10 @@ static OVERRIDE_U32_T bloodPumpRotorCounter; ///< Running counter for blood pump rotor revolutions. static BOOL bpHomeRequested; ///< Flag indicating a home operation has been requested. static U32 bpHomeStartTime; ///< When did blood pump home command begin? (in ms). -static OVERRIDE_F32_T bpFlowAlphaYIntercept; ///< Blood flow estimation term for alpha Y intercept. static OVERRIDE_F32_T bpFlowWearATerm; ///< Blood flow estimation term for wear slope. static OVERRIDE_F32_T bpFlowWearBTerm; ///< Blood flow estimation term for wear offset. -static OVERRIDE_F32_T bpStrokeVolumeMlPerRev; - +static OVERRIDE_F32_T bpStrokeVolumeMlPerRev; ///< Blood flow estimation term for stroke volume (mL per rotor rev). +static OVERRIDE_U32_T bpMaxRotorCountForWear; ///< Maximum rotor count used for cartridge wear estimation. //static TD_PUMPS_CAL_RECORD_T bloodPumpCalRecord; ///< Blood pump calibration record. // ********** private function prototypes ********** @@ -170,6 +168,8 @@ static F32 getBPFlowAlphaYIntercept( void ); static F32 getBPFlowWearATerm( void ); static F32 getBPFlowWearBTerm( void ); +static F32 getBPStrokeVolume( void ); +static U32 getBPMaxRotorCountForWear( void ); static void resetBloodPumpRPMMovingAverage( void ); static void filterBloodPumpRPMReadings( F32 rpm ); static F32 calcBloodPumpTorque( void ); @@ -229,10 +229,6 @@ bloodPumpTorquemNm.ovData = 0.0F; bloodPumpTorquemNm.ovInitData = 0.0F; bloodPumpTorquemNm.override = OVERRIDE_RESET; - bpFlowAlphaYIntercept.data = BP_FLOW_ALPHA_Y_INTERCEPT; - bpFlowAlphaYIntercept.ovData = BP_FLOW_ALPHA_Y_INTERCEPT; - bpFlowAlphaYIntercept.ovInitData = BP_FLOW_ALPHA_Y_INTERCEPT; - bpFlowAlphaYIntercept.override = OVERRIDE_RESET; bpFlowWearATerm.data = BP_FLOW_WEAR_A_TERM; bpFlowWearATerm.ovData = BP_FLOW_WEAR_A_TERM; bpFlowWearATerm.ovInitData = BP_FLOW_WEAR_A_TERM; @@ -241,6 +237,14 @@ bpFlowWearBTerm.ovData = BP_FLOW_WEAR_B_TERM; bpFlowWearBTerm.ovInitData = BP_FLOW_WEAR_B_TERM; bpFlowWearBTerm.override = OVERRIDE_RESET; + bpStrokeVolumeMlPerRev.data = BP_ML_PER_ROTOR_REV; + bpStrokeVolumeMlPerRev.ovData = BP_ML_PER_ROTOR_REV; + bpStrokeVolumeMlPerRev.ovInitData = BP_ML_PER_ROTOR_REV; + bpStrokeVolumeMlPerRev.override = OVERRIDE_RESET; + bpMaxRotorCountForWear.data = BP_MAX_ROTOR_COUNT_FOR_WEAR; + bpMaxRotorCountForWear.ovData = BP_MAX_ROTOR_COUNT_FOR_WEAR; + bpMaxRotorCountForWear.ovInitData = BP_MAX_ROTOR_COUNT_FOR_WEAR; + bpMaxRotorCountForWear.override = OVERRIDE_RESET; // Initialize pump speed filter for ( i = 0; i < SIZE_OF_ROLLING_AVG; i++ ) @@ -250,7 +254,7 @@ resetBloodPumpRPMMovingAverage(); // Reset pump rotor count - resetBloodPumpRotorCount(); + //resetBloodPumpRotorCount(); // Initialize blood flow PI controller initializePIController( PI_CONTROLLER_ID_BLOOD_FLOW, 0.0F, @@ -358,22 +362,21 @@ /*********************************************************************//** * @brief * The calcBloodFlow function calculates an estimated blood flow rate from - * blood pump speed, arterial pressure and tubing wear (measured from count - * of rotor revolutions since cartridge install). - * @details \b Inputs: bloodPumpRotorCounter, arterial pressure + * blood pump speed and tubing wear (measured from count of rotor revolutions + * since cartridge install) using the simplified wear-only equation: + * Flow = [ Alpha * (RotorCnt + Beta) + 1 ] * RotorRPM * StrokeVolume. + * @details \b Inputs: bloodPumpRotorCounter, stroke volume and wear params * @details \b Outputs: none * @return calculated blood flow rate (mL/min) *************************************************************************/ static F32 calcBloodFlow( void ) { - F32 artPres = getLongFilteredArterialPressure(); - F32 artPresL= ( artPres > BP_MIN_ART_PRESSURE_MMHG ? artPres : BP_MIN_ART_PRESSURE_MMHG ); - F32 rotSpd = filteredBloodPumpSpeed / BP_GEAR_RATIO; - U32 r = getBloodPumpRotorCount(); - U32 rotCnt = CAP( r, BP_MAX_ROTOR_COUNT_FOR_WEAR ); - F32 wear = getBPFlowWearATerm() * (F32)rotCnt + getBPFlowWearBTerm(); - F32 alpha = wear * artPresL + getBPFlowAlphaYIntercept(); - F32 flow = BP_ML_PER_ROTOR_REV * rotSpd * alpha; + F32 rotSpd = filteredBloodPumpSpeed / BP_GEAR_RATIO; + U32 r = getBloodPumpRotorCount(); + U32 rotCnt = CAP( r, getBPMaxRotorCountForWear() ); + F32 alpha = ( getBPFlowWearATerm() * ( (F32)rotCnt + getBPFlowWearBTerm() ) ) + 1.0F; + F32 strokeVl = getBPStrokeVolume(); + F32 flow = alpha * rotSpd * strokeVl; return flow; } @@ -421,20 +424,21 @@ * @brief * The getBloodPumpRotorCount function returns the current count for the * blood pump rotor revolution counter. - * @details \b Inputs: bloodPumpRotorCounter - * @details \b Outputs: none - * @return bloodPumpRotorCounter + * @details \b Inputs: bloodPumpRotorCounter,getPeristalticPumpRotorRevs + * @details \b Outputs: bloodPumpRotorCounter + * @return h4RotorRevsCounter *************************************************************************/ static U32 getBloodPumpRotorCount( void ) { - U32 result = bloodPumpRotorCounter.data; + U32 h4RotorRevsCounter = getPeristalticPumpRotorRevs(); + bloodPumpRotorCounter.data = h4RotorRevsCounter; if ( OVERRIDE_KEY == bloodPumpRotorCounter.override ) { - result = bloodPumpRotorCounter.ovData; + h4RotorRevsCounter = bloodPumpRotorCounter.ovData; } - return result; + return h4RotorRevsCounter; } /*********************************************************************//** @@ -476,9 +480,9 @@ *************************************************************************/ void resetBloodPumpRotorCount( void ) { - bloodPumpRotorCounter.data = 0; +// bloodPumpRotorCounter.data = 0; -// if ( TRUE == getTestConfigStatus( TEST_CONFIG_USE_WORN_CARTRIDGE ) ) + // if ( TRUE == getTestConfigStatus( TEST_CONFIG_USE_WORN_CARTRIDGE ) ) { bloodPumpRotorCounter.data = BP_MAX_ROTOR_COUNT_FOR_WEAR; } @@ -829,21 +833,6 @@ /*********************************************************************//** * @brief - * The getBPFlowAlphaYIntercept function gets the blood pump flow alpha - * intercept for blood flow estimation. - * @details \b Inputs: bpFlowAlphaYIntercept - * @details \b Outputs: none - * @return the current blood flow alpha intercept term. - *************************************************************************/ -static F32 getBPFlowAlphaYIntercept( void ) -{ - F32 result = getF32OverrideValue( &bpFlowAlphaYIntercept ); - - return result; -} - -/*********************************************************************//** - * @brief * The getBPFlowWearATerm function gets the blood pump flow estimation * A term for wear. * @details \b Inputs: bpFlowWearATerm @@ -874,6 +863,36 @@ /*********************************************************************//** * @brief + * The getBPStrokeVolume function gets the blood pump stroke volume used + * for blood flow estimation (mL per rotor revolution). + * @details \b Inputs: bpStrokeVolumeMlPerRev + * @details \b Outputs: none + * @return the current stroke volume (mL per rotor rev). + *************************************************************************/ +static F32 getBPStrokeVolume( void ) +{ + F32 result = getF32OverrideValue( &bpStrokeVolumeMlPerRev ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getBPMaxRotorCountForWear function gets the maximum rotor count + * used for cartridge wear estimation. + * @details \b Inputs: bpMaxRotorCountForWear + * @details \b Outputs: none + * @return the maximum rotor count used for wear estimation. + *************************************************************************/ +static U32 getBPMaxRotorCountForWear( void ) +{ + U32 result = getU32OverrideValue( &bpMaxRotorCountForWear ); + + return result; +} + +/*********************************************************************//** + * @brief * The publishBloodFlowData function publishes blood flow data at the set * interval. * @details \b Message \b Sent: MSG_ID_TD_BLOOD_PUMP_DATA at set interval. @@ -1385,23 +1404,6 @@ /*********************************************************************//** * @brief - * The testBPFlowAlphaYInterceptOverride function overrides the Alpha Y - * intercept of the blood flow estimation equation. - * @details \b Inputs: none - * @details \b Outputs: bpFlowAlphaYIntercept - * @param message Override message from Dialin which includes the Alpha Y - * intercept value to override with. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testBPFlowAlphaYInterceptOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &bpFlowAlphaYIntercept ); - - return result; -} - -/*********************************************************************//** - * @brief * The testBPFlowWearATermOverride function overrides the wear A term of the * blood flow estimation equation. * @details \b Inputs: none