Index: firmware/App/Common.h =================================================================== diff -u -r6311eb9b65fdeec7a285d25e07f3932ac0fb6cf1 -ra97e98d0f53f5825c5bc400f87f096f418e110cf --- firmware/App/Common.h (.../Common.h) (revision 6311eb9b65fdeec7a285d25e07f3932ac0fb6cf1) +++ firmware/App/Common.h (.../Common.h) (revision a97e98d0f53f5825c5bc400f87f096f418e110cf) @@ -107,7 +107,11 @@ #define MAKE_LONG_OF_WORDS(h, l) ((((U32)(h) << SHIFT_16_BITS_FOR_WORD_SHIFT) & MASK_OFF_LSW) | ((U32)(l) & MASK_OFF_MSW)) #define GET_TOGGLE(v, l, h) ((v) == (l) ? (h) : (l)) #define BIT_BY_POS(p) (1U << (p)) +#define CIRCULAR_INCREASE(i, i_max) (( (++i) == i_max) ? 0 : i ) +#define CIRCULAR_DECREASE(i, i_max) (( ((S16) --i) == -1) ? i_max-1 : i ) + + #define SET_ALARM_WITH_1_U32_DATA(a,d1) { \ ALARM_DATA_T dat1; \ dat1.dataType = ALARM_DATA_TYPE_U32; \ Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -rea6ff77291eee02f351953b76c6720cf860c8be7 -ra97e98d0f53f5825c5bc400f87f096f418e110cf --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision ea6ff77291eee02f351953b76c6720cf860c8be7) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision a97e98d0f53f5825c5bc400f87f096f418e110cf) @@ -1,205 +1,204 @@ -/************************************************************************** - * - * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file PIControllers.c - * - * @date 18-Dec-2019 - * @author L. Baloa - * - * @brief PIControllers service module. Creates a digital PI to be used as - * control loops - * - **************************************************************************/ - -#include "math.h" - -#include "PIControllers.h" - -// ********** private definitions ********** - -typedef struct { - // -- PI's parameters -- - F32 Kp; // Proportional Value - F32 Ki; // Integral Value - F32 uMax; // Maximum control signal - F32 uMin; // Minimum control signal - F32 iMax; // Maximum error sum - F32 iMin; // Minimum error sum - // -- PI's signals -- - F32 referenceSignal; // reference signal - F32 measuredSignal; // measured signal - F32 errorSignal; // reference - measured signal - F32 errorSumBeforeWindUp; // error signal before windup correction - F32 errorSum; // error integral after windup correction - F32 controlSignal; // actual control signal -} PI_CONTROLLER_T; - -#define SET_CONTROLLER( c, id ) ((c) = &piControllers[id]) - -// ********** private data ********** - -// PI Controllers -- definition - -static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = -{ // Kp Ki uMax uMin iMax iMin ref meas err esw esum ctrl - { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_LOAD_CELL - { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_BLOOD_FLOW - { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // PI_CONTROLLER_ID_DIALYSATE_FLOW -}; - -/************************************************************************* - * @brief initializePIController - * Initialize controller before operation. Make sure to call it before \n - * first call to runController function. - * - * @param controllerID - ID filter number - * @param initialControlSignal - Value of the output on the first iteration - * - * @return none - *************************************************************************/ -void initializePIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, - F32 kP, F32 kI, F32 controlMin, F32 controlMax, F32 iMin, F32 iMax ) -{ - PI_CONTROLLER_T *controller; - - if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) - { - SET_CONTROLLER( controller, controllerID ); - - controller->Kp = kP; - controller->Ki = kI; - controller->uMin = controlMin; - controller->uMax = controlMax; - controller->iMin = iMin; - controller->iMax = iMax; - resetPIController( controllerID, initialControlSignal ); - } -} - -/************************************************************************* - * @brief resetPIController - * Reset controller before new set point. Make sure to call it before first \n - * call to runController function. - * - * @param controllerID - ID filter number - * @param initialControlSignal - Value of the output on the first iteration - * - * @return none - *************************************************************************/ -void resetPIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal ) -{ - PI_CONTROLLER_T *controller; - - if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) - { - SET_CONTROLLER( controller, controllerID ); - controller->controlSignal = RANGE( initialControlSignal, controller->uMin, controller->uMax ); - controller->referenceSignal = 0.0; - controller->errorSignal = 0.0; - controller->errorSumBeforeWindUp = 0.0; - controller->errorSum = 0.0; - controller->measuredSignal = 0.0; - } -} - -/************************************************************************* - * @brief runPIController - * Call this function whenever a new measured signal sampled is acquired. - * - * @param controllerID - ID filter number - * @param referenceSignal - reference signal value - * @param measuredSignal - latest measured sample - * - * @return value of the control signal - *************************************************************************/ -F32 runPIController(PI_CONTROLLER_ID_T controllerID, F32 referenceSignal, F32 measuredSignal) -{ - PI_CONTROLLER_T *controller; - F32 result = 0.0; - - if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) - { - SET_CONTROLLER( controller, controllerID ); - - controller->referenceSignal = referenceSignal; - controller->measuredSignal = measuredSignal; - // calculate error signal - controller->errorSignal = fabs( referenceSignal ) - ( referenceSignal < 0.0 ? ( measuredSignal * -1.0 ) : measuredSignal ); - controller->errorSumBeforeWindUp += controller->errorSignal; - // anti-windup - controller->errorSum = RANGE( controller->errorSumBeforeWindUp, controller->iMin, controller->iMax ); - // calculate control signal - controller->controlSignal += ( controller->Kp * controller->errorSignal ) + ( controller->Ki * controller->errorSum ); - // limit control signal to valid range - controller->controlSignal = RANGE( controller->controlSignal, controller->uMin, controller->uMax ); - result = controller->controlSignal; - } - - return result; -} - -/************************************************************************* - * @brief getPIControllerSignals - * Returns the latest requested signal sample. - * - * @param controllerID - ID filter number - * @param signalID - signal sample ID request - * - * @return latest sample requested - *************************************************************************/ -F32 getPIControllerSignals( PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID ) -{ - PI_CONTROLLER_T *controller; - F32 output = 0.0; - - if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) - { - SET_CONTROLLER( controller, controllerID ); - - switch( signalID ) - { - case CONTROLLER_SIGNAL_REFERENCE: - output = controller->referenceSignal; - break; - - case CONTROLLER_SIGNAL_MEASURED: - output = controller->measuredSignal; - break; - - case CONTROLLER_SIGNAL_ERROR: - output = controller->errorSignal; - break; - - case CONTROLLER_SIGNAL_ERROR_SUM: - output = controller->errorSumBeforeWindUp; - break; - - case CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP: - output = controller->errorSum; - break; - - case CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT: - output = controller->Kp * controller->errorSignal; - break; - - case CONTROLLER_SIGNAL_INTEGRAL_OUTPUT: - output = controller->Ki * controller->errorSum; - break; - - case CONTROLLER_SIGNAL_CONTROL: - output = controller->controlSignal; - break; - - default: - output = 0; - break; - } // end of switch - } - - return output; -} - +/************************************************************************** + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file PIControllers.c + * + * @date 18-Dec-2019 + * @author L. Baloa + * + * @brief PIControllers service module. Creates a digital PI to be used as + * control loops + * + **************************************************************************/ + +#include "math.h" + +#include "PIControllers.h" + +// ********** private definitions ********** + +typedef struct { + // -- PI's parameters -- + F32 Kp; // Proportional Value + F32 Ki; // Integral Value + F32 uMax; // Maximum control signal + F32 uMin; // Minimum control signal + F32 iMax; // Maximum error sum + F32 iMin; // Minimum error sum + // -- PI's signals -- + F32 referenceSignal; // reference signal + F32 measuredSignal; // measured signal + F32 errorSignal; // reference - measured signal + F32 errorSumBeforeWindUp; // error signal before windup correction + F32 errorSum; // error integral after windup correction + F32 controlSignal; // actual control signal +} PI_CONTROLLER_T; + +#define SET_CONTROLLER( c, id ) ((c) = &piControllers[id]) + +// ********** private data ********** + +// PI Controllers -- definition + +static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = +{ // Kp Ki uMax uMin iMax iMin ref meas err esw esum ctrl + { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_LOAD_CELL + { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_BLOOD_FLOW + { 0.0, 0.0, 1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // PI_CONTROLLER_ID_DIALYSATE_FLOW +}; + +/************************************************************************* + * @brief initializePIController + * Initialize controller before operation. Make sure to call it before \n + * first call to runController function. + * + * @param controllerID - ID filter number + * @param initialControlSignal - Value of the output on the first iteration + * + * @return none + *************************************************************************/ +void initializePIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, + F32 kP, F32 kI, F32 controlMin, F32 controlMax, F32 iMin, F32 iMax ) +{ + PI_CONTROLLER_T *controller; + + if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) + { + SET_CONTROLLER( controller, controllerID ); + + controller->Kp = kP; + controller->Ki = kI; + controller->uMin = controlMin; + controller->uMax = controlMax; + controller->iMin = iMin; + controller->iMax = iMax; + resetPIController( controllerID, initialControlSignal ); + } +} + +/************************************************************************* + * @brief resetPIController + * Reset controller before new set point. Make sure to call it before first \n + * call to runController function. + * + * @param controllerID - ID filter number + * @param initialControlSignal - Value of the output on the first iteration + * + * @return none + *************************************************************************/ +void resetPIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal ) +{ + PI_CONTROLLER_T *controller; + + if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) + { + SET_CONTROLLER( controller, controllerID ); + controller->controlSignal = RANGE( initialControlSignal, controller->uMin, controller->uMax ); + controller->referenceSignal = 0.0; + controller->errorSignal = 0.0; + controller->errorSumBeforeWindUp = 0.0; + controller->errorSum = 0.0; + controller->measuredSignal = 0.0; + } +} + +/************************************************************************* + * @brief runPIController + * Call this function whenever a new measured signal sampled is acquired. + * + * @param controllerID - ID filter number + * @param referenceSignal - reference signal value + * @param measuredSignal - latest measured sample + * + * @return value of the control signal + *************************************************************************/ +F32 runPIController(PI_CONTROLLER_ID_T controllerID, F32 referenceSignal, F32 measuredSignal) +{ + PI_CONTROLLER_T *controller; + F32 result = 0.0; + + if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) + { + SET_CONTROLLER( controller, controllerID ); + + controller->referenceSignal = referenceSignal; + controller->measuredSignal = measuredSignal; + // calculate error signal + controller->errorSignal = fabs( referenceSignal ) - ( referenceSignal < 0.0 ? ( measuredSignal * -1.0 ) : measuredSignal ); + controller->errorSumBeforeWindUp += controller->errorSignal; + // anti-windup + controller->errorSum = RANGE( controller->errorSumBeforeWindUp, controller->iMin, controller->iMax ); + // calculate control signal + controller->controlSignal += ( controller->Kp * controller->errorSignal ) + ( controller->Ki * controller->errorSum ); + // limit control signal to valid range + controller->controlSignal = RANGE( controller->controlSignal, controller->uMin, controller->uMax ); + result = controller->controlSignal; + } + + return result; +} + +/************************************************************************* + * @brief getPIControllerSignals + * Returns the latest requested signal sample. + * + * @param controllerID - ID filter number + * @param signalID - signal sample ID request + * + * @return latest sample requested + *************************************************************************/ +F32 getPIControllerSignals( PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID ) +{ + PI_CONTROLLER_T *controller; + F32 output = 0.0; + + if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) + { + SET_CONTROLLER( controller, controllerID ); + + switch( signalID ) + { + case CONTROLLER_SIGNAL_REFERENCE: + output = controller->referenceSignal; + break; + + case CONTROLLER_SIGNAL_MEASURED: + output = controller->measuredSignal; + break; + + case CONTROLLER_SIGNAL_ERROR: + output = controller->errorSignal; + break; + + case CONTROLLER_SIGNAL_ERROR_SUM: + output = controller->errorSumBeforeWindUp; + break; + + case CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP: + output = controller->errorSum; + break; + + case CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT: + output = controller->Kp * controller->errorSignal; + break; + + case CONTROLLER_SIGNAL_INTEGRAL_OUTPUT: + output = controller->Ki * controller->errorSum; + break; + + case CONTROLLER_SIGNAL_CONTROL: + output = controller->controlSignal; + break; + + default: + output = 0; + break; + } // end of switch + } + + return output; +} Index: firmware/App/Services/PIControllers.c.old =================================================================== diff -u --- firmware/App/Services/PIControllers.c.old (revision 0) +++ firmware/App/Services/PIControllers.c.old (revision a97e98d0f53f5825c5bc400f87f096f418e110cf) @@ -0,0 +1,180 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file PIControllers.c + * + * @date 18-Dec-2019 + * @author L. Baloa + * + * @brief PIControllers service module. Creates a digital PI to be used as + * control loops + * + **************************************************************************/ +#include "PIControllers.h" + +// ********** private definitions ********** + +typedef struct { + // -- PI's parameters -- + F32 Kp; // Proportional Value + F32 Ki; // Integral Value + S32 uMax; // Maximum control signal + S32 uMin; // Minimum control signal + // -- PI's signals -- + BOOL firstIteration; // Mark true for the first iteration + S32 referenceSignal; // reference signal + S32 measuredSignal; // measured signal + S32 errorSignal; // reference - measured signal + S32 errorSumBeforeWindUp; // error signal before windup correction + S32 errorSum; // error integral after windup correction + S32 controlSignal; // actual control signal +} PI_CONTROLLER_T; + +// PI Controllers -- definition + +static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = +{ + + { /*Kp*/ 1.0, /*Ki*/ 1.0, /*uMax*/ 90, /*uMin*/ 0} // PI_CONTROLLER_ID_LOAD_CELL = 0 +}; + +static PI_CONTROLLER_T* m_controller; + +#define SET_CONTROLLER(id) (m_controller = &piControllers[id]) + +/************************************************************************* + * @brief initializeController + * Initialize controller before operation. Make sure to run it before + * first call to runController function. + * + * @param controllerID - ID filter number + * @param initialControlSignal - Value of the output on the first iteration + * + * @return none + *************************************************************************/ +void initializeController(PI_CONTROLLER_ID_T controllerID, U16 initialControlSignal) +{ + + SET_CONTROLLER(controllerID); + + m_controller->firstIteration = TRUE; + + m_controller->controlSignal = RANGE(initialControlSignal, + m_controller->uMin, + m_controller->uMax); +} + +/************************************************************************* + * @brief runController + * Call this function whenever a new measured signal sampled is acquired. + * + * @param controllerID - ID filter number + * @param referenceSignal - reference signal value + * @param measuredSignal - latest measured sample + * + * @return value of the control signal + *************************************************************************/ +S32 runController(PI_CONTROLLER_ID_T controllerID, S32 referenceSignal, S32 measuredSignal) +{ + + SET_CONTROLLER(controllerID); + + m_controller->referenceSignal = referenceSignal; + m_controller->measuredSignal = measuredSignal; + m_controller->errorSignal = referenceSignal - measuredSignal; + m_controller->errorSum += m_controller->errorSignal; + m_controller->errorSumBeforeWindUp = m_controller->errorSum; + + if( !m_controller->firstIteration || ( m_controller->controlSignal == 0 ) ) + { + S32 controlSignalBeforeWindup = (S32) (m_controller->Kp * m_controller->errorSignal + + m_controller->Ki * m_controller->errorSum); + + m_controller->controlSignal = RANGE(controlSignalBeforeWindup, m_controller->uMin, m_controller->uMax); + + S32 error = m_controller->controlSignal - controlSignalBeforeWindup; + + // Anti-wind up logic + + if ( error != 0 ) + { + // We have hit a max or min, need to compensate + m_controller->errorSum -= (S32)(error/m_controller->Ki); + } + } + else + { + m_controller->errorSum = (S32) ((m_controller->controlSignal - m_controller->Kp*m_controller->errorSignal)/(m_controller->Ki)); + } + + + return m_controller->controlSignal; +} + +/************************************************************************* + * @brief getController + * Returns the latest requested signal sample. + * + * @param controllerID - ID filter number + * @param signalID - signal sample ID request + * + * @return latest sample requested + *************************************************************************/ +S32 getControllerSignals(PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID) +{ + + SET_CONTROLLER(controllerID); + + S32 output; + + switch(signalID) { + + case CONTROLLER_SIGNAL_REFERENCE: + output = m_controller->referenceSignal; + break; + + case CONTROLLER_SIGNAL_MEASURED: + output = m_controller->measuredSignal; + break; + + case CONTROLLER_SIGNAL_ERROR: + output = m_controller->errorSignal; + break; + + case CONTROLLER_SIGNAL_ERROR_SUM: + output = m_controller->errorSumBeforeWindUp; + break; + + case CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP: + output = m_controller->errorSum; + break; + + case CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT: + output = (S32)(m_controller->Kp * m_controller->errorSignal); + break; + + case CONTROLLER_SIGNAL_INTEGRAL_OUTPUT: + output = (S32)(m_controller->Ki * m_controller->errorSum); + break; + + case CONTROLLER_SIGNAL_CONTROL_BEFORE_WINDUP: + output = (S32)(m_controller->Ki * m_controller->errorSumBeforeWindUp + + m_controller->Kp * m_controller->errorSignal); + break; + + case CONTROLLER_SIGNAL_CONTROL: + output = (S32)(m_controller->Ki * m_controller->errorSum + + m_controller->Kp * m_controller->errorSignal); + break; + + default: + output = 0; + break; + } // end of switch + + return output; +} Index: firmware/App/Services/PIControllers.h =================================================================== diff -u -rea6ff77291eee02f351953b76c6720cf860c8be7 -ra97e98d0f53f5825c5bc400f87f096f418e110cf --- firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision ea6ff77291eee02f351953b76c6720cf860c8be7) +++ firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision a97e98d0f53f5825c5bc400f87f096f418e110cf) @@ -1,54 +1,53 @@ -/************************************************************************** - * - * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file PIControllers.h - * - * @date 12-Dec-2019 - * @author L. Baloa - * - * @brief Header file for the PI controllers service (PIControllers.c). - * - **************************************************************************/ - -#ifndef __PICONTROLLERS_H__ -#define __PICONTROLLERS_H__ - -#include "Common.h" - -// ********** public definitions ********** - -typedef enum ControllerList -{ - PI_CONTROLLER_ID_LOAD_CELL = 0, - PI_CONTROLLER_ID_BLOOD_FLOW, - PI_CONTROLLER_ID_DIALYSATE_FLOW, - NUM_OF_PI_CONTROLLERS_IDS -} PI_CONTROLLER_ID_T; - -typedef enum ControllerSignals -{ - CONTROLLER_SIGNAL_REFERENCE = 0, - CONTROLLER_SIGNAL_MEASURED, - CONTROLLER_SIGNAL_ERROR, - CONTROLLER_SIGNAL_ERROR_SUM, - CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP, - CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT, - CONTROLLER_SIGNAL_INTEGRAL_OUTPUT, - CONTROLLER_SIGNAL_CONTROL, - NUM_OF_CONTROLLER_SIGNAL -} PI_CONTROLLER_SIGNALS_ID; - -// ********** public function prototypes ********** - -void initializePIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, - F32 kP, F32 kI, F32 controlMin, F32 controlMax, F32 iMin, F32 iMax ); -void resetPIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal ); -F32 runPIController( PI_CONTROLLER_ID_T controllerID, F32 referenceSignal, F32 measuredSignal ); -F32 getPIControllerSignals( PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID ); - -#endif - +/************************************************************************** + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file PIControllers.h + * + * @date 12-Dec-2019 + * @author L. Baloa + * + * @brief Header file for the PI controllers service (PIControllers.c). + * + **************************************************************************/ + +#ifndef __PICONTROLLERS_H__ +#define __PICONTROLLERS_H__ + +#include "Common.h" + +// ********** public definitions ********** + +typedef enum ControllerList +{ + PI_CONTROLLER_ID_LOAD_CELL = 0, + PI_CONTROLLER_ID_BLOOD_FLOW, + PI_CONTROLLER_ID_DIALYSATE_FLOW, + NUM_OF_PI_CONTROLLERS_IDS +} PI_CONTROLLER_ID_T; + +typedef enum ControllerSignals +{ + CONTROLLER_SIGNAL_REFERENCE = 0, + CONTROLLER_SIGNAL_MEASURED, + CONTROLLER_SIGNAL_ERROR, + CONTROLLER_SIGNAL_ERROR_SUM, + CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP, + CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT, + CONTROLLER_SIGNAL_INTEGRAL_OUTPUT, + CONTROLLER_SIGNAL_CONTROL, + NUM_OF_CONTROLLER_SIGNAL +} PI_CONTROLLER_SIGNALS_ID; + +// ********** public function prototypes ********** + +void initializePIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, + F32 kP, F32 kI, F32 controlMin, F32 controlMax, F32 iMin, F32 iMax ); +void resetPIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal ); +F32 runPIController( PI_CONTROLLER_ID_T controllerID, F32 referenceSignal, F32 measuredSignal ); +F32 getPIControllerSignals( PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID ); + +#endif Index: firmware/App/Services/PIControllers.h.old =================================================================== diff -u --- firmware/App/Services/PIControllers.h.old (revision 0) +++ firmware/App/Services/PIControllers.h.old (revision a97e98d0f53f5825c5bc400f87f096f418e110cf) @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file PIControllers.h + * + * @date 12-Dec-2019 + * @author L. Baloa + * + * @brief Header file for the PI controllers service (PIControllers.c). + * + **************************************************************************/ + +#ifndef __PICONTROLLERS_H__ +#define __PICONTROLLERS_H__ + + +#include "Common.h" + +typedef enum ControllerList +{ + PI_CONTROLLER_ID_LOAD_CELL = 0, + NUM_OF_PI_CONTROLLERS_IDS +} PI_CONTROLLER_ID_T; + +typedef enum ControllerSignals +{ + CONTROLLER_SIGNAL_REFERENCE = 0, + CONTROLLER_SIGNAL_MEASURED, + CONTROLLER_SIGNAL_ERROR, + CONTROLLER_SIGNAL_ERROR_SUM, + CONTROLLER_SIGNAL_ERROR_SUM_AFTER_WINDUP, + CONTROLLER_SIGNAL_PROPORTIONAL_OUTPUT, + CONTROLLER_SIGNAL_INTEGRAL_OUTPUT, + CONTROLLER_SIGNAL_CONTROL_BEFORE_WINDUP, + CONTROLLER_SIGNAL_CONTROL, + NUM_OF_CONTROLLER_SIGNAL +} PI_CONTROLLER_SIGNALS_ID; + + + + +// ********** public function prototypes ********** + +void initializeController(PI_CONTROLLER_ID_T controllerID, U16 initialControlSignal); +S32 runController(PI_CONTROLLER_ID_T controllerID, S32 referenceSignal, S32 measuredSignal); +S32 getControllerSignals(PI_CONTROLLER_ID_T controllerID, PI_CONTROLLER_SIGNALS_ID signalID); + + + +#endif