FUNCTION_BLOCK FB40 TITLE ='Positioning and ramp generator for slitting' AUTHOR : Tuomo FAMILY : Slitting NAME : Slitting VERSION : '1.0' //reversed VAR_INPUT Encoder : DINT ; SetPoint : REAL ; Enable : BOOL ; JogFWD : BOOL ; JogBWD : BOOL ; Cycle : INT ; END_VAR VAR_OUTPUT ActValue : REAL ; Speed : INT ; OnPos : BOOL ; Release : BOOL ; END_VAR VAR Line : ARRAY [0 .. 2 ] OF STRUCT MaxSpeed : REAL := 1.000000e+002; ManSpeed : REAL := 3.000000e+001; MinSpeed : REAL := 1.000000e+001; Accuracy : REAL := 5.000000e-001; Accelerate : REAL := 6.000000e-001; SlowCurve : REAL := 3.000000e+002; SlowLine : REAL := 3.000000e+001; END_STRUCT ; Wheel : REAL := 3.141590e+002; //Wheel perimeter Pulses : REAL := 1.250000e+003; //Amount pulses of encoder Difference : REAL ; //Length to go AbsValue : REAL ; //Length to go (absolut value) Memory : REAL ; END_VAR VAR_TEMP Maksimi : REAL ; Kiihdytys1 : REAL ; Kiihdytys2 : REAL ; Kerroin : REAL ; Nopeus : REAL ; OhjeArvo : REAL ; END_VAR Line[0]:=Line["Order".Line]; IF "Order".Line = 2 AND "Main".Control.LinePot = 1 THEN Line[0].MaxSpeed:="Main".LinePot; END_IF; IF "Order".Line = 1 THEN ActValue:=Wheel / Pulses * DINT_TO_REAL(Encoder) / 4.000000e+000; ELSE ActValue:=Wheel / Pulses * DINT_TO_REAL(Encoder) / 4.000000e+003; END_IF; Difference:=SetPoint - ActValue; AbsValue:=ABS(Difference); IF Line[0].Accuracy >= AbsValue THEN OnPos:=true; ELSE OnPos:=false; END_IF; Kiihdytys1:=(2.764800e+001 / Line[0].Accelerate) * INT_TO_REAL(Cycle); Kiihdytys2:=(2.764800e+001 / Line[1].Accelerate) * INT_TO_REAL(Cycle); IF (NOT JogFWD AND Enable) AND (NOT JogBWD) THEN Kerroin:=2.764800e+004/SQRT(Line[0].SlowCurve); IF AbsValue > Line[0].SlowLine THEN Nopeus:= SQRT(AbsValue) * Kerroin; ELSE Nopeus:=SQRT(Line[0].SlowLine) * Kerroin / Line[0].SlowLine * AbsValue; END_IF; IF Difference > 0.0 THEN Maksimi:=Line[0].MaxSpeed * 2.764800e+002; ELSE Maksimi:=Line[0].MinSpeed * 2.764800e+002; END_IF; IF Nopeus > Maksimi THEN Nopeus:=Maksimi; END_IF; IF Nopeus > Memory THEN Memory:=Memory + Kiihdytys1; IF Memory > Nopeus THEN Memory:=Nopeus; END_IF; ELSE Memory:=Nopeus; END_IF; IF Difference > 0.0 THEN OhjeArvo:=Memory; ELSE OhjeArvo:=-Memory; END_IF; ELSE Nopeus:=0.0; IF JogFWD THEN Nopeus:=Line[0].ManSpeed * 2.764800e+002; END_IF; IF JogBWD THEN Nopeus:=Line[0].ManSpeed * -2.764800e+002; END_IF; IF Nopeus > Memory THEN Memory:=Memory + Kiihdytys2; IF Memory > Nopeus THEN Memory:=Nopeus; END_IF; ELSE Memory:=Memory - Kiihdytys2; IF Memory < Nopeus THEN Memory:=Nopeus; END_IF; END_IF; OhjeArvo:=Memory; END_IF; IF Memory = 0.0 THEN Release:=false; ELSE Release:=true; END_IF; Speed:=REAL_TO_INT(OhjeArvo); END_FUNCTION_BLOCK