/************************************************************************** * * Copyright (c) 2024-2026 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 PIDControllers.h * * @author (last) Michael Garthwaite * @date (last) 11-Sep-2025 * * @author (original) Vinayakam Mani * @date (original) 07-Oct-2024 * ***************************************************************************/ #ifndef __PID_CONTROLLERS_H__ #define __PID_CONTROLLERS_H__ #ifdef _TD_ #include "TDCommon.h" #endif #ifdef _DD_ #include "DDCommon.h" #endif /** * @defgroup PIDControllers PIDControllers * @brief PIDControllers common module. Provides PID controllers for various actuators. * * @addtogroup PIDControllers * @{ */ // ********** public definitions ********** /// Enumeration of PID controllers. typedef enum ControllerListPID { #ifdef _TD_ PID_CONTROLLER_ID_BLOOD_FLOW, ///< Blood pump controller to target flow rate #endif #ifdef _DD_ PID_CONTROLLER_ID_RO_PUMP_FLOW, ///< RO Pump controller to flow #endif NUM_OF_PID_CONTROLLERS_IDS ///< Number of PID controllers } PID_CONTROLLER_ID_T; /// Enumeration of PI controller signals. typedef enum ControllerSignalsPID { CONTROLLER_SIGNAL_PID_REFERENCE = 0, ///< Reference value CONTROLLER_SIGNAL_PID_MEASURED, ///< Measured value CONTROLLER_SIGNAL_PID_ERROR, ///< Error value CONTROLLER_SIGNAL_PID_ERROR_SUM, ///< Error sum before anti-windup CONTROLLER_SIGNAL_PID_ERROR_SUM_AFTER_WINDUP, ///< Error sum after anti-windup CONTROLLER_SIGNAL_PID_ERROR_PREVIOUS, ///< Previous error signal CONTROLLER_SIGNAL_PID_PROPORTIONAL_OUTPUT, ///< P portion of controller output signal CONTROLLER_SIGNAL_PID_INTEGRAL_OUTPUT, ///< I portion of controller output signal CONTROLLER_SIGNAL_PID_DERIVATIVE_OUTPUT, ///< D portion of controller output signal. CONTROLLER_SIGNAL_PID_FEEDFORWARD_OUTPUT, ///< Feed forward portion of controller output signal CONTROLLER_SIGNAL_PID_CONTROL, ///< Controller output signal NUM_OF_CONTROLLER_SIGNAL_PID ///< Number of PI controller signals } PID_CONTROLLER_SIGNALS_ID; /// Data structure for PI control profiles. typedef struct { F32 Kp; ///< Proportional Value F32 Ki; ///< Integral Value F32 Kd; ///< Derivative Value F32 uMin; ///< Minimum control signal F32 uMax; ///< Maximum control signal F32 maxErrorSumStep; ///< Maximum change in I (error sum) for a single control interval. U32 controlInterval; ///< Control interval value } PID_CONTROLLER_PROFILE_DATA_T; // ********** public function prototypes ********** void initializePIDController( PID_CONTROLLER_ID_T controllerID, F32 initialControlSignal, F32 kP, F32 kI, F32 kD, F32 controlMin, F32 controlMax, BOOL isFeedForwardEnabled, F32 feedFowardSignal ); void resetPIDController( PID_CONTROLLER_ID_T controllerID, F32 initialControlSignal, F32 feedFowardSignal ); F32 runPIDController( PID_CONTROLLER_ID_T controllerID, F32 referenceSignal, F32 measuredSignal ); F32 getPIDControllerSignals( PID_CONTROLLER_ID_T controllerID, PID_CONTROLLER_SIGNALS_ID signalID ); void setPIDControllerStepLimit( PID_CONTROLLER_ID_T controllerID, F32 stepLimit ); /**@}*/ #endif