Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r5bd79f9cadaa4588be2797b7f68addd359a24f80 -rd0c2c5ec93f7fae9772c14e9aa0baec0b20ed5ce --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 5bd79f9cadaa4588be2797b7f68addd359a24f80) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision d0c2c5ec93f7fae9772c14e9aa0baec0b20ed5ce) @@ -35,7 +35,7 @@ #include "DialOutFlow.h" // ********** private definitions ********** -#define DIAL_OUT_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) // interval (ms/task time) at which the dialIn flow data is published on the CAN bus +#define DIAL_OUT_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) // interval (ms/task time) at which the dialout vol data is published on the CAN bus #define MAX_DIAL_OUT_FLOW_RATE 500 // mL/min #define MIN_DIAL_OUT_FLOW_RATE 100 // mL/min @@ -84,6 +84,16 @@ #define DIP_SPEED_ADC_TO_RPM_FACTOR 1.375 // conversion factor from ADC counts to RPM for dialIn pump motor #define DIP_CURRENT_ADC_TO_MA_FACTOR 2.65 // conversion factor from ADC counts to mA for dialIn pump motor +/*** test support declaration ***/ +DATA_DECL( U32, DialOutVolDataPub, DialOutVolDataPublishInterval, DIAL_OUT_FLOW_DATA_PUB_INTERVAL, DIAL_OUT_FLOW_DATA_PUB_INTERVAL ); // interval (in ms) at which to publish dialout vol data to CAN bus +DATA_DECL( F32, LoadCellVolumeInMl, loadCellVolumeInMl, 0.0, 0.0); +DATA_DECL( F32, TotalTargetDialOutVolInMl, totalTargetUFVolumeInMl, 0.0, 0.0 ); // target dialout UF vol +DATA_DECL( F32, TotalMeasuredUFVolumeInMl, totalMeasuredUFVolumeInMl, 0.0, 0.0 ); // measured dialout UF vol +DATA_DECL( F32, MeasuredDialOutPumpMCSpeed, dialOutPumpMCSpeedRPM, 0.0, 0.0 ); // measured dialOut pump motor controller speed +DATA_DECL( F32, MeasuredDialOutPumpMCCurrent, dialOutPumpMCCurrentmA, 0.0, 0.0 );// measured dialOut pump motor controller current +//TODO: DATA_DECL( F32, MeasuredDialOutPumpRotorSpeed, DialOutPumpRotorSpeedRPM, 0.0, 0.0 );// measured dialOut pump rotor speed +//TODO: DATA_DECL( F32, MeasuredDialOutPumpSpeed, DialOutPumpSpeedRPM, 0.0, 0.0 ); // measured dialOut pump motor speed + typedef enum DialOutFlow_Measured_Signals { DIALOUT_LOAD_CELL_WEIGHT = 0, @@ -97,33 +107,35 @@ volatile static DIALOUT_FLOW_STATE_T dialOutFlowState = DIALOUT_FLOW_STOP_STATE; // current state of dialOut flow state machine -static U32 dialOutFlowDataPublicationTimerCounter = 5; // used to schedule dialIn flow data publication to CAN bus +static U32 dialOutFlowDataPublicationTimerCounter = 5; // used to schedule dialout vol data publication to CAN bus // Rx values static volatile F32 rxTotalTargetVolumeInMl; static volatile U32 rxTargetTimeInSamples; static volatile F32 rxInitialTargetFlowRatePWM; static volatile F32 targetVolumeUFRatePerSample; -// Variables used in loop +// Broadcasting variables +DIALOUT_BROADCASTING_T dialOutBroadCastVariables; - // Controller key values -static F32 loadCellVolumeInMl; static F32 bagStartVolumeInMl; static F32 bagMeasuredUFVolumeInMl; static F32 accumulativeTotalUFVolumeInMl; -static volatile F32 totalMeasuredUFVolumeInMl; -static volatile F32 totalTargetUFVolumeInMl; +//TODO:delete static volatile F32 totalMeasuredUFVolumeInMl; +//TODO:delete static volatile F32 totalTargetUFVolumeInMl; static volatile F32 sentPWM; static volatile U32 targetVolumeTimer; -// Pump variables -static F32 dialOutPumpSpeedInRPM; -static F32 dialOutPumpCurrentInMA; +// publishData +static F32 pubDialOutPumpSpeedInRPM; +static F32 pubDialOutPumpCurrentInMA; +static F32 pubLoadCellVolumeInMl; +static F32 pubTargetTotalUFVolumeInMl; +static F32 pubMeasuredUFVolumeInMl; #ifdef DIALOUT_SIMULATOR @@ -199,7 +211,7 @@ else { // Reset total target volume - totalTargetUFVolumeInMl = 0.0; + totalTargetUFVolumeInMl.data = 0.0; accumulativeTotalUFVolumeInMl = 0.0; bagStartVolumeInMl = 0.0; sentPWM = 0.0; @@ -244,7 +256,7 @@ *************************************************************************/ static void updateTargetVolume( void ) { - totalTargetUFVolumeInMl += targetVolumeUFRatePerSample; + totalTargetUFVolumeInMl.data += targetVolumeUFRatePerSample; } /************************************************************************* @@ -275,7 +287,7 @@ else { - totalTargetUFVolumeInMl = 0.0; + totalTargetUFVolumeInMl.data = 0.0; simulator_inlet_flow_rate = (F32) rxFlowRateinMlPerMin; @@ -306,15 +318,18 @@ switch ( signal ) { case DIALOUT_LOAD_CELL_WEIGHT: - returnValue = 0.0; // TODO: getFPGALoadCellWeight(); + loadCellVolumeInMl.data = 0.0; // TODO: getFPGALoadCellWeight(); + returnValue = getLoadCellVolumeInMl(); break; case DIALOUT_MOTOR_SPEED: - returnValue = getIntADCReading( INT_ADC_DIAL_OUT_PUMP_SPEED ) * DIP_SPEED_ADC_TO_RPM_FACTOR; + dialOutPumpMCSpeedRPM.data = getIntADCReading( INT_ADC_DIAL_OUT_PUMP_SPEED ) * DIP_SPEED_ADC_TO_RPM_FACTOR; + returnValue = getMeasuredDialOutPumpMCCurrent(); break; case DIALOUT_MOTOR_CURRENT: - returnValue = getIntADCReading( INT_ADC_DIAL_OUT_PUMP_MOTOR_CURRENT ) * DIP_CURRENT_ADC_TO_MA_FACTOR; + dialOutPumpMCCurrentmA.data = getIntADCReading( INT_ADC_DIAL_OUT_PUMP_MOTOR_CURRENT )* DIP_CURRENT_ADC_TO_MA_FACTOR;; + returnValue = getMeasuredDialOutPumpMCSpeed(); break; default: @@ -329,27 +344,31 @@ /************************************************************************* * @brief execDialOutFlowMonitor - * The execDialOutFlowMonitor function executes the dialIn flow monitor. + * The execDialOutFlowMonitor function executes the dialout vol monitor. * @details * Inputs : none - * Outputs : measuredDialOutFlowRate, adcDialOutPumpMCSpeedRPM, adcDialOutPumpMCCurrentmA + * Outputs : measuredDialOutFlowRate, dialOutPumpMCSpeedRPM, dialOutPumpMCCurrentmA * @param none * @return none *************************************************************************/ void execDialOutFlowMonitor( void ) { - loadCellVolumeInMl = getMeasuredVariable( DIALOUT_LOAD_CELL_WEIGHT ); - dialOutPumpSpeedInRPM = getMeasuredVariable( DIALOUT_MOTOR_SPEED ); - dialOutPumpCurrentInMA = getMeasuredVariable( DIALOUT_MOTOR_CURRENT ); + pubLoadCellVolumeInMl = getMeasuredVariable( DIALOUT_LOAD_CELL_WEIGHT ); + pubDialOutPumpSpeedInRPM = getMeasuredVariable( DIALOUT_MOTOR_SPEED ); + pubDialOutPumpCurrentInMA = getMeasuredVariable( DIALOUT_MOTOR_CURRENT ); - // publish dialIn flow data on interval + // publish dialout vol data on interval - bagMeasuredUFVolumeInMl = loadCellVolumeInMl - bagStartVolumeInMl; - totalMeasuredUFVolumeInMl = bagMeasuredUFVolumeInMl + accumulativeTotalUFVolumeInMl; + bagMeasuredUFVolumeInMl = pubLoadCellVolumeInMl - bagStartVolumeInMl; - totalMeasuredUFVolumeInMl = UFSimulator(sentPWM); + totalMeasuredUFVolumeInMl.data = bagMeasuredUFVolumeInMl + accumulativeTotalUFVolumeInMl; + #ifdef DIALOUT_SIMULATOR + totalMeasuredUFVolumeInMl.data = UFSimulator(sentPWM); + #endif + pubMeasuredUFVolumeInMl = getTotalMeasuredUFVolumeInMl(); + publishDialOutFlowData(); } @@ -407,7 +426,7 @@ /************************************************************************* * @brief execDialOutFlowController - * The execDialOutFlowController function executes the dialIn flow controller. + * The execDialOutFlowController function executes the dialout vol controller. * @details * Inputs : dialOutPumpState * Outputs : dialOutPumpState @@ -454,6 +473,8 @@ stopDialOutPump(); + totalTargetUFVolumeInMl.data = 0.0; + return result; } @@ -469,7 +490,7 @@ *************************************************************************/ static DIALOUT_FLOW_STATE_T handleDialOutFlowPauseUFState( void ) { - sentPWM = runPIController( PI_CONTROLLER_ID_LOAD_CELL, totalTargetUFVolumeInMl, totalMeasuredUFVolumeInMl ); + sentPWM = runPIController( PI_CONTROLLER_ID_LOAD_CELL, totalTargetUFVolumeInMl.data, totalMeasuredUFVolumeInMl.data ); setControlSignalPWM( sentPWM ); @@ -490,7 +511,7 @@ { updateTargetVolume(); - sentPWM = runPIController( PI_CONTROLLER_ID_LOAD_CELL, totalTargetUFVolumeInMl, totalMeasuredUFVolumeInMl ); + sentPWM = runPIController( PI_CONTROLLER_ID_LOAD_CELL, totalTargetUFVolumeInMl.data, totalMeasuredUFVolumeInMl.data ); setControlSignalPWM( sentPWM ); @@ -544,26 +565,266 @@ /************************************************************************* * @brief publishDialOutFlowData - * The publishDialOutFlowData function publishes dialIn flow data at the set \n + * The publishDialOutFlowData function publishes dialout vol data at the set \n * interval. * @details * Inputs : target flow rate, measured flow rate, measured MC speed, \n * measured MC current - * Outputs : DialIn flow data is published to CAN bus. + * Outputs : dialout vol data is published to CAN bus. * @param none * @return none *************************************************************************/ static void publishDialOutFlowData( void ) { - S16 doFlowState = (S16) dialOutFlowState; - S16 doTotalTargetUFVolumeInMl = (S16) FLOAT_TO_INT_WITH_ROUND( totalTargetUFVolumeInMl ); - S16 doTotalMeasuredUFVolumeInMl = (S16) FLOAT_TO_INT_WITH_ROUND( totalMeasuredUFVolumeInMl ); - S16 doControlSignalPWM = (S16) FLOAT_TO_INT_WITH_ROUND( sentPWM * FRACTION_TO_PERCENT_FACTOR ); - - // publish dialIn flow data on interval + // publish dialout vol data on interval if ( ++dialOutFlowDataPublicationTimerCounter > DIAL_OUT_FLOW_DATA_PUB_INTERVAL ) { - broadcastDialOutFlowData( doFlowState, doTotalTargetUFVolumeInMl, doTotalMeasuredUFVolumeInMl, doControlSignalPWM ); + dialOutBroadCastVariables.flowState = (S16) dialOutFlowState; + dialOutBroadCastVariables.totalTargetVolMl = (S16) FLOAT_TO_INT_WITH_ROUND( pubTargetTotalUFVolumeInMl ); + dialOutBroadCastVariables.measuredVolMl = (S16) FLOAT_TO_INT_WITH_ROUND( pubMeasuredUFVolumeInMl ); + dialOutBroadCastVariables.pwmPCT = (S16) FLOAT_TO_INT_WITH_ROUND( sentPWM * FRACTION_TO_PERCENT_FACTOR ); + dialOutBroadCastVariables.motorCurrentMA = (S16) FLOAT_TO_INT_WITH_ROUND( pubDialOutPumpCurrentInMA); + dialOutBroadCastVariables.motorSpeedRPM = (S16) FLOAT_TO_INT_WITH_ROUND( pubDialOutPumpSpeedInRPM); + + broadcastDialOutFlowData( &dialOutBroadCastVariables); dialOutFlowDataPublicationTimerCounter = 0; } } + +/************************************************************************* + * GET SUPPORT FUNCTIONS + *************************************************************************/ + +/************************************************************************* + * @brief getPublishDialInFlowDataInterval + * The getPublishDialInFlowDataInterval function gets the dialIn flow data \n + * publication interval. + * @details + * Inputs : dialInFlowDataPublishInterval + * Outputs : none + * @param none + * @return the current dialIn flow data publication interval (in ms). + *************************************************************************/ +//TODO: DATA_GET( U32, getPublishDialInFlowDataInterval, dialInFlowDataPublishInterval ) + +/************************************************************************* + * @brief getLoadCellVolumeInMl + * The getLoadCellVolumeInMl function gets the load cell volume. + * @details + * Inputs : loadCellVolumeInMl + * Outputs : none + * @param none + * @return the current load cell volume in mL + *************************************************************************/ +DATA_GET( F32, getLoadCellVolumeInMl, loadCellVolumeInMl ) + +/************************************************************************* + * @brief getTotalTargetDialOutUFVolumeInMl + * The getTotalTargetDialOutUFVolumeInMl function gets the target UF volume. + * @details + * Inputs : totalTargetUFVolumeInMl + * Outputs : none + * @param none + * @return the current target UF volume in mL. + *************************************************************************/ +DATA_GET( F32, getTotalTargetDialOutUFVolumeInMl, totalTargetUFVolumeInMl ) + +/************************************************************************* + * @brief getTotalMeasuredUFVolumeInMl + * The getTotalMeasuredUFVolumeInMl function gets the measured UF volume. + * @details + * Inputs : totalMeasuredUFVolumeInMl + * Outputs : none + * @param none + * @return the current UF volume (in mL). + *************************************************************************/ +DATA_GET( F32, getTotalMeasuredUFVolumeInMl, totalMeasuredUFVolumeInMl ) + +/************************************************************************* + * @brief getMeasuredDialInPumpRotorSpeed + * The getMeasuredDialInPumpRotorSpeed function gets the measured dialIn flow \n + * rate. + * @details + * Inputs : dialInPumpRotorSpeedRPM + * Outputs : none + * @param none + * @return the current dialIn flow rate (in mL/min). + *************************************************************************/ +//TODO: DATA_GET( F32, getMeasuredDialInPumpRotorSpeed, dialInPumpRotorSpeedRPM ) + +/************************************************************************* + * @brief getMeasuredDialInPumpSpeed + * The getMeasuredDialInPumpSpeed function gets the measured dialIn flow \n + * rate. + * @details + * Inputs : dialInPumpSpeedRPM + * Outputs : none + * @param none + * @return the current dialIn flow rate (in mL/min). + *************************************************************************/ +//TODO: DATA_GET( F32, getMeasuredDialInPumpSpeed, dialInPumpSpeedRPM ) + +/************************************************************************* + * @brief getMeasuredDialOutPumpMCSpeed + * The getMeasuredDialOutPumpMCSpeed function gets the measured dialOut pump \n + * speed. + * @details + * Inputs : dialOutPumpMCSpeedRPM + * Outputs : none + * @param none + * @return the current dialOut pump speed (in RPM). + *************************************************************************/ +DATA_GET( F32, getMeasuredDialOutPumpMCSpeed, dialOutPumpMCSpeedRPM ) + +/************************************************************************* + * @brief getMeasuredDialOutPumpMCCurrent + * The getMeasuredDialOutPumpMCCurrent function gets the measured dialOut pump \n + * current. + * @details + * Inputs : dialOutPumpMCCurrentmA + * Outputs : none + * @param none + * @return the current dialOut pump current (in mA). + *************************************************************************/ +DATA_GET( F32, getMeasuredDialOutPumpMCCurrent, dialOutPumpMCCurrentmA) + + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/************************************************************************* + * @brief testSetDialOutVolDataPublishIntervalOverride + * The testSetDialOutVolDataPublishIntervalOverride function overrides the \n + * dialout vol data publish interval. + * @details + * Inputs : none + * Outputs : DialOutVolDataPublishInterval + * @param value : override dialout vol data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetDialOutVolDataPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_PRIORITY_INTERVAL; + + result = TRUE; + DialOutVolDataPublishInterval.ovData = intvl; + DialOutVolDataPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/************************************************************************* + * @brief testResetDialOutVolDataPublishIntervalOverride + * The testResetDialOutVolDataPublishIntervalOverride function resets the override \n + * of the dialout vol data publish interval. + * @details + * Inputs : none + * Outputs : DialOutVolDataPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetDialOutVolDataPublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + DialOutVolDataPublishInterval.override = OVERRIDE_RESET; + DialOutVolDataPublishInterval.ovData = DialOutVolDataPublishInterval.ovInitData; + } + + return result; +} + +/************************************************************************* + * @brief testSetTotalTargetDialOutVolInMlOverride and testResetTotalTargetDialOutVolInMlOverride + * The testSetTotalTargetDialOutVolInMlOverride function overrides the target \n + * dialout vol rate. \n + * The testResetTotalTargetDialOutVolInMlOverride function resets the override of the \n + * target dialout vol rate. + * @details + * Inputs : none + * Outputs : TotalTargetDialOutVolInMl + * @param value : override target dialout vol rate (in mL/min) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +DATA_OVERRIDE_FUNC( S32, testSetTotalTargetDialOutVolInMlOverride, testResetTotalTargetDialOutVolInMlOverride, totalTargetUFVolumeInMl ) + +/************************************************************************* + * @brief testSettotalMeasuredUFVolumeInMlOverride and testResettotalMeasuredUFVolumeInMlOverride + * The testResettotalMeasuredUFVolumeInMlOverride function overrides the measured \n + * dialout vol rate. \n + * The testResetOffButtonStateOverride function resets the override of the \n + * measured dialout vol rate. + * @details + * Inputs : none + * Outputs : totalMeasuredUFVolumeInMl + * @param value : override measured dialout vol rate (in mL/min) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +DATA_OVERRIDE_FUNC( F32, testSettotalMeasuredUFVolumeInMlOverride, testResettotalMeasuredUFVolumeInMlOverride, totalMeasuredUFVolumeInMl ) + +/************************************************************************* + * @brief testSetMeasuredDialOutPumpRotorSpeedOverride and testResetMeasuredDialOutPumpRotorSpeedOverride + * The testSetMeasuredDialOutPumpRotorSpeedOverride function overrides the measured \n + * dialIn pump rotor speed. \n + * The testResetMeasuredDialOutPumpRotorSpeedOverride function resets the override of the \n + * measured dialIn pump rotor speed. + * @details + * Inputs : none + * Outputs : DialOutPumpRotorSpeedRPM + * @param value : override measured dialIn pump rotor speed (in RPM) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +//TODO: DATA_OVERRIDE_FUNC( F32, testSetMeasuredDialOutPumpRotorSpeedOverride, testResetMeasuredDialOutPumpRotorSpeedOverride, DialOutPumpRotorSpeedRPM ) + +/************************************************************************* + * @brief testSetMeasuredDialOutPumpSpeedOverride and testResetMeasuredDialOutPumpSpeedOverride + * The testSetMeasuredDialOutPumpSpeedOverride function overrides the measured \n + * dialIn pump motor speed. \n + * The testResetMeasuredDialOutPumpSpeedOverride function resets the override of the \n + * measured dialIn pump motor speed. + * @details + * Inputs : none + * Outputs : DialOutPumpSpeedRPM + * @param value : override measured dialIn pump motor speed (in RPM) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +//TODO: DATA_OVERRIDE_FUNC( F32, testSetMeasuredDialOutPumpSpeedOverride, testResetMeasuredDialOutPumpSpeedOverride, DialOutPumpSpeedRPM ) + +/************************************************************************* + * @brief testSetMeasuredDialOutPumpMCSpeedOverride and testResetMeasuredDialOutPumpMCSpeedOverride + * The testSetMeasuredDialOutPumpMCSpeedOverride function overrides the measured \n + * dialIn pump motor speed. \n + * The testResetMeasuredDialOutPumpMCSpeedOverride function resets the override of the \n + * measured dialIn pump motor speed. + * @details + * Inputs : none + * Outputs : dialOutPumpMCSpeedRPM + * @param value : override measured dialIn pump speed (in RPM) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +DATA_OVERRIDE_FUNC( F32, testSetMeasuredDialOutPumpMCSpeedOverride, testResetMeasuredDialOutPumpMCSpeedOverride, dialOutPumpMCSpeedRPM ) + +/************************************************************************* + * @brief testSetMeasuredDialOutPumpMCCurrentOverride and testResetMeasuredDialOutPumpMCCurrentOverride + * The testSetMeasuredDialOutPumpMCCurrentOverride function overrides the measured \n + * dialIn pump motor current. \n + * The testResetMeasuredDialOutPumpMCCurrentOverride function resets the override of the \n + * measured dialIn pump motor current. + * @details + * Inputs : none + * Outputs : dialOutPumpMCCurrentmA + * @param value : override measured dialIn pump current (in mA) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +DATA_OVERRIDE_FUNC( F32, testSetMeasuredDialOutPumpMCCurrentOverride, testResetMeasuredDialOutPumpMCCurrentOverride, dialOutPumpMCCurrentmA ) +