This is the algorithm of one step of a PI-controller with feed-forward and limited output. The anti-windup measure (either back-calculation or clamped) is formulated straight-forward to avoid iteration. Therefore the code can be:
Integration is replaced by an explicit forward Euler.
Anti-Windup measure: A prediction of the output is calculated without limitation is calculated. If there is a difference between unlimited and limited result (i.e. protected variable cropped):
function piStep extends Modelica.Icons.Function; import MagLev.Types.AntiWindup; import Modelica.Constants.small; input Real u "Reference signal"; input Real u_m "Measured signal"; input Real kp "Parameter proportional gain"; input SI.Time Ti "Parameter integral time constant"; input SI.Time Ts "Sample period"; input Real kFF "Parameter proportional gain of feed-forward"; input Real ff "Feed-forward signal"; input AntiWindup antiWindup "Anti-Windup measure"; input Real yMin "Lower limit of output"; input Real yMax "Upper limit of output"; input Real pre_x "Previous state"; output Real x "State"; output Real y "Result"; end piStep;