Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -r03e051ef654a1bff100da02483645c4e9d0b7a30 -r7d4711edd7b40cd3e29f43e766f79a8a09586fe9 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 03e051ef654a1bff100da02483645c4e9d0b7a30) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 7d4711edd7b40cd3e29f43e766f79a8a09586fe9) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 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 +* @file PIControllers.c * -* @author (last) Quang Nguyen -* @date (last) 24-Aug-2020 +* @author (last) Dara Navaei +* @date (last) 11-Jan-2023 * -* @author (original) Sean -* @date (original) 04-Feb-2020 +* @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,5 +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 ); + + 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 ) + } + + } + else + { // Invalid controller given + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER, (U32)controllerID ) + } +} + /**@}*/