大家誰(shuí)用codesys做過PID控制,可以共同討論一下(* PD controller *)
FUNCTION_BLOCK PID_FIXCYCLE
VAR_INPUT
ACTUAL :REAL; (* actual value, process variable *)
SET_POINT:REAL; (* desired value, set point *)
KP:REAL; (* proportionality const. (P)*)
TN:REAL; (* reset time (I) in sec *)
TV:REAL; (* rate time, derivative time (D) in sec*)
Y_MANUAL:REAL; (* Y is set to this value as long as MANUAL=TRUE *)
Y_OFFSET:REAL; (* offset for manipulated variable *)
Y_MIN:REAL; (* minimum value for manipulated variable *)
Y_MAX:REAL; (* maximum value for manipulated variable *)
MANUAL:BOOL; (* TRUE: manual: Y is not influenced by controller,
FALSE: controller determines Y *)
RESET:BOOL; (* reset: set Y output to Y_OFFSET and reset integral part *)
CYCLE:REAL; (* time in s between two calls *)
END_VAR
VAR_OUTPUT
Y:REAL; (* manipulated variable, set value*)
LIMITS_ACTIVE:BOOL:=FALSE; (* true set value would exceed limits Y_MIN, Y_MAX *)
OVERFLOW:BOOL:=FALSE; (* overflow in integral part *)
END_VAR
VAR
I: INTEGRAL;
D: DERIVATIVE;
TMDIFF: DWORD;
ERROR: REAL;
INIT: BOOL:=TRUE;
Y_ADDOFFSET: REAL;
KPcopy:REAL;
TNcopy:REAL;
TVcopy:REAL;
END_VAR