ParamManagerScripts/backend/script_groups/TwinCat/.example/SPEEDADJUST.EXP

30 lines
916 B
Plaintext

(* @PATH := '\/Functions_Collection' *)
(* @SYMFILEFLAGS := '0' *)
FUNCTION SpeedAdjust : REAL
VAR_INPUT
i_PrdTnkLvl : REAL ;
i_TrgTnkLvl : REAL ;
i_IstLvl : REAL ;
i_SpeedPerc : REAL ;
END_VAR
VAR
a : REAL ; (* Angolar Coefficient *)
b : REAL ; (* Constant *)
END_VAR
(* @END_DECLARATION := '0' *)
(* The following function calculates the percentage speed correction to get Product Tank target Level
the equation used is: y = a * PrdTankLvl + b ; that is a = - SpeedPerc / IstLvl; and b = 1 - TrgTnkLvl * a
the function yelds 1.0 at 50% of level; (1 - SpeedPerc) at 80% level; the maximum is (1 + SpeedPerc) *)
i_SpeedPerc := i_SpeedPerc / 100.0 ;
IF i_IstLvl>0 THEN
a := -i_SpeedPerc / i_IstLvl ;
b := 1 - (a * i_TrgTnkLvl) ;
SpeedAdjust := a * i_PrdTnkLvl + b ;
SpeedAdjust := LIMIT(1 - i_SpeedPerc,SpeedAdjust ,1 + i_SpeedPerc) ;
ELSE
SpeedAdjust := 0.0 ;
END_IF
END_FUNCTION