Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -racebbc372d11f4f46a64eefc36ae784cbd08880d -rab304e2ca6e3e40ed8cb12650e9855ae0b9649d8 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision acebbc372d11f4f46a64eefc36ae784cbd08880d) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision ab304e2ca6e3e40ed8cb12650e9855ae0b9649d8) @@ -7,17 +7,15 @@ * * @file PIControllers.c * -* @author (last) Sean Nash -* @date (last) 04-Jun-2020 +* @author (last) Quang Nguyen +* @date (last) 24-Aug-2020 * * @author (original) Sean * @date (original) 04-Feb-2020 * ***************************************************************************/ -#ifndef _VECTORCAST_ - #include "math.h" -#endif +#include "math.h" #include "SystemCommMessages.h" #include "PIControllers.h" @@ -28,11 +26,8 @@ */ // ********** private definitions ********** - -/// minimum integral coefficient - cannot be zero. -#define MIN_KI NEARLY_ZERO - -/// record for PI controller. + +/// Record for PI controller. typedef struct { // -- PI's parameters -- F32 Kp; ///< Proportional Value. @@ -48,14 +43,14 @@ F32 controlSignal; ///< actual control signal. } PI_CONTROLLER_T; -#define SET_CONTROLLER( c, id ) ((c) = &piControllers[id]) ///< macro to set a local controller pointer to a given piController. +#define MIN_KI NEARLY_ZERO ///< minimum integral coefficient - cannot be zero. +#define SET_CONTROLLER( c, id ) ( (c) = &piControllers[ id ] ) ///< macro to set a local controller pointer to a given piController. // ********** private data ********** -/// PI Controllers -- initial configurations. +/// PI Controllers - initial configurations. static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = { // Kp Ki uMax uMin ref meas err esw esum ctrl - { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_RO_PUMP { 0.0, 0.0, 0.99, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // I_CONTROLLER_ID_RO_PUMP_RAMP_UP { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_DRAIN_PUMP @@ -65,16 +60,16 @@ /*********************************************************************//** * @brief - * Initialize controller before operation. Make sure to call it before - * first call to runController function. - * - * @param controllerID - ID filter number - * @param initialControlSignal - Value of the output on the first iteration - * @param kP - Coefficient for proportional. - * @param kI - Coefficient for integral. - * @param controlMin - Minimum control output. - * @param controlMax - Maximum control output. - * + * The initializePIController function initializes controller before operation. + * Make sure to call it before first call to runController function. + * Inputs : none + * Outputs : PI controllers module initialized + * @param controllerID ID filter number + * @param initialControlSignal Value of the output on the first iteration + * @param kP Coefficient for proportional + * @param kI Coefficient for integral + * @param controlMin Minimum control output + * @param controlMax Maximum control output * @return none *************************************************************************/ void initializePIController( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, @@ -107,12 +102,12 @@ /*********************************************************************//** * @brief - * Reset controller before new set point. Make sure to call it before first - * call to runController function. - * - * @param controllerID - ID filter number - * @param initialControlSignal - Value of the output on the first iteration - * + * The resetPIController functions resets controller before new set point. + * Make sure to call it before first call to runController function. + * Inputs : none + * Outputs : Reset a PI controller + * @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 ) @@ -137,12 +132,12 @@ /*********************************************************************//** * @brief - * 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 - * + * The runPIController functions executes a PI controller with a new sampled measured signal. + * Inputs : none + * Outputs : Feeds new signal to PI controller + * @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) @@ -185,11 +180,11 @@ /*********************************************************************//** * @brief - * Returns the latest requested signal sample. - * - * @param controllerID - ID filter number - * @param signalID - signal sample ID request - * + * The getPIControllerSignals function returns the latest requested signal sample. + * Inputs : none + * Outputs : none + * @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 )