Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -r9864b14f76782f1e68bf266dcd843451748715a0 -rd830f37cf6a42a16399c87985bd51dfd9312ced3 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 9864b14f76782f1e68bf266dcd843451748715a0) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision d830f37cf6a42a16399c87985bd51dfd9312ced3) @@ -1,17 +1,16 @@ -/************************************************************************** +/**********************************************************************//** * + * @file PIControllers.c + * * Copyright (c) 2019-2020 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 + * @brief PIControllers source file. * **************************************************************************/ @@ -28,35 +27,34 @@ typedef struct { // -- PI's parameters -- - F32 Kp; // Proportional Value - F32 Ki; // Integral Value - F32 uMax; // Maximum control signal - F32 uMin; // Minimum control signal + F32 Kp; /// Proportional Value + F32 Ki; /// Integral Value + F32 uMax; /// Maximum control signal + F32 uMin; /// Minimum control signal // -- 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; + 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; /// record for PI controller -#define SET_CONTROLLER( c, id ) ((c) = &piControllers[id]) +#define SET_CONTROLLER( c, id ) ((c) = &piControllers[id]) /// macro to set a local controller pointer to a given piController // ********** private data ********** -// PI Controllers -- definition - +/// 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_LOAD_CELL { 0.0, 0.0, 0.90, 0.10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // PI_CONTROLLER_ID_BLOOD_FLOW { 0.0, 0.0, 0.90, 0.10, 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 + * Initialize controller before operation. Make sure to call it before * first call to runController function. * * @param controllerID - ID filter number @@ -86,11 +84,15 @@ controller->uMax = controlMax; resetPIController( controllerID, initialControlSignal ); } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } } -/************************************************************************* +/*********************************************************************//** * @brief resetPIController - * Reset controller before new set point. Make sure to call it before first \n + * Reset controller before new set point. Make sure to call it before first * call to runController function. * * @param controllerID - ID filter number @@ -112,9 +114,13 @@ controller->errorSumBeforeWindUp = controller->errorSum; controller->measuredSignal = 0.0; } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } } -/************************************************************************* +/*********************************************************************//** * @brief runPIController * Call this function whenever a new measured signal sampled is acquired. * @@ -171,11 +177,15 @@ // } //#endif } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } return result; } -/************************************************************************* +/*********************************************************************//** * @brief getPIControllerSignals * Returns the latest requested signal sample. * @@ -228,10 +238,14 @@ break; default: - output = 0; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_SIGNAL, (U32)signalID ) break; } // end of switch } + else + { // invalid controller given + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } return output; }