Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -r7104ce1a12799c5a3dff10c94cb191d409bc8244 -r7d4711edd7b40cd3e29f43e766f79a8a09586fe9 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 7104ce1a12799c5a3dff10c94cb191d409bc8244) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 7d4711edd7b40cd3e29f43e766f79a8a09586fe9) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2024 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 * * @author (last) Dara Navaei -* @date (last) 02-Nov-2021 +* @date (last) 11-Jan-2023 * * @author (original) Sean * @date (original) 04-Feb-2020 @@ -27,6 +27,8 @@ // ********** private definitions ********** +#define MAX_ILIMIT 1.0F ///< Controller max Ilimit/maxErrorSumStep. + /// Enumeration of PI controller direction. typedef enum controller_Directions { @@ -60,8 +62,8 @@ /// PI Controllers - initial configurations. static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = -{ // Kp Ki uMax uMin ref meas err esw esum ctrl Ilimit controller type - { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP +{ // Kp Ki uMax uMin ref meas err esw esum ctrl Ilimit controller type + { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_DRAIN_PUMP { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP_MAX_PRES }; @@ -166,8 +168,8 @@ // Calculate error signal if ( controller->direction == CONTROLLER_UNIDIRECTIONAL ) { - // To make sure that the outcome will be positive - controller->errorSignal = fabs( referenceSignal ) - ( referenceSignal < 0.0 ? ( measuredSignal * -1.0 ) : measuredSignal ); + // Control should always be positive + controller->errorSignal = fabs( referenceSignal ) - ( referenceSignal < 0.0F ? ( measuredSignal * -1.0F ) : measuredSignal ); } else { @@ -177,9 +179,9 @@ // Limit error sum step size if ( fabs( controller->errorSignal ) > controller->maxErrorSumStep ) { - if ( controller->errorSignal < 0.0 ) + if ( controller->errorSignal < 0.0F ) { - controller->errorSum += ( controller->maxErrorSumStep * -1.0 ); + controller->errorSum += ( controller->maxErrorSumStep * -1.0F ); } else { @@ -281,16 +283,37 @@ return output; } +/*********************************************************************//** + * @brief + * The getPIControllerSignals function returns the latest requested signal sample. + * @details Inputs: none + * @details Outputs: maxErrorSumStep of controller ID + * @param controllerID ID filter number + * @param stepLimit maximum step limit + * @return latest sample requested + *************************************************************************/ +void setPIControllerStepLimit( PI_CONTROLLER_ID_T controllerID, F32 stepLimit ) +{ + PI_CONTROLLER_T *controller; + if ( controllerID < NUM_OF_PI_CONTROLLERS_IDS ) + { + SET_CONTROLLER( controller, controllerID ); -/* - * reset needs to be called. - */ + if ( ( stepLimit > NEARLY_ZERO ) && ( stepLimit < MAX_ILIMIT ) ) + { + controller->maxErrorSumStep = stepLimit; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_STEP_LIMIT, (U32)stepLimit ) + } -void setPIControlerProfile( PI_CONTROLLER_ID_T controllerID, F32 initialControlSignal, PI_CONTROLLER_PROFILE_DATA_T profile) -{ - initializePIController(controllerID, initialControlSignal, - profile.Kp,profile.Ki,profile.uMin,profile.uMax); + } + else + { // Invalid controller given + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } } /**@}*/