(*Einmaliges INIT*)
axis1Ref := ADR(gAxis01);
PROGRAM _CYCLIC
(* TODO : Add your code here *)
CASE state OF
STATE_READY: (*STATE_READY *)
IF (power) THEN
state:=STATE_POWER;
power:=FALSE;
END_IF
STATE_POWER: (*State wird zu Beginn angefahren und schaltet Regelung ein*)
MC_Power_0.Enable:=TRUE;
IF (MC_Power_0.Status <> 0) THEN
state:=STATE_HOME
(* Store ErrorID in a variable,
ErrorID is reset on falling edge of 'Enable' *)
ELSIF (MC_Power_0.Error) THEN
axis1ErrorID:=MC_Power_0.ErrorID;
(*Reset 'Enable' before going to STATE_ERROR*)
MC_Power_0.Enable:=FALSE;
state:=STATE_ERROR;
END_IF
STATE_HOME: (*State führt eine Refernz fahrt des Antriebs durch*)
MC_Home_0.Execute:=TRUE;
MC_Home_0.Position:=0;
MC_Home_0.HomingMode:=mcHOME_DIRECT;
IF (MC_Home_0.Done) THEN
MC_Home_0.Execute:=FALSE;
state:=STATE_MOVE_VELOCITY;
ELSIF (MC_Home_0.Error) THEN
(*Store ErrorID in a variable,
ErrorID is reset on falling edge of "Execute"*)
axis1ErrorID:=MC_Home_0.ErrorID;
(*Reset "Execute" before going to STATE_ERROR*)
MC_Home_0.Execute:=FALSE;
state:=STATE_ERROR;
END_IF
STATE_MOVE_VELOCITY: (*Starte eine Beweugung*)
MC_MoveVelocity_0.Execute:=TRUE;
MC_MoveVelocity_0.Velocity:=5000;
MC_MoveVelocity_0.Acceleration:=50000;
MC_MoveVelocity_0.Deceleration:=50000;
MC_MoveVelocity_0.Direction:=mcPOSITIVE_DIR;
IF (MC_MoveVelocity_0.InVelocity) THEN
MC_MoveVelocity_0.Execute:=FALSE;
state:=STATE_STOP;
ELSIF (MC_MoveVelocity_0.Error) THEN
(*Store ErrorID in a variable,
ErrorID is reset on falling edge of 'Execute'*)
axis1ErrorID:=MC_MoveVelocity_0.ErrorID;
MC_MoveVelocity_0.Execute:=FALSE; (*Reset before STATE_ERROR*)
state:=STATE_ERROR;
END_IF
STATE_STOP: (*Stoppe den Antreib*)
IF Taster1=TRUE THEN (*Nur wenn Taster betätigt, dann stoppen*)
MC_Stop_0.Execute:=TRUE;
MC_Stop_0.Deceleration:=0; (*0=use limit value*)
IF ((stop=FALSE) AND (MC_Stop_0.Done)) THEN
MC_Stop_0.Execute:=0;
state:=STATE_MOVE_VELOCITY;
ELSIF (MC_Stop_0.Error) THEN
(*Store ErrorID in a variable,
ErrorID is reset on falling edge of ‚Execute"*)
axis1ErrorID:=MC_Stop_0.ErrorID;
MC_Stop_0.Execute:=FALSE;
state:=STATE_ERROR;
END_IF
END_IF
END_CASE
(* Function Block calls *)
MC_Power_0(Axis:= axis1Ref);
MC_Home_0(Axis:= axis1Ref);
MC_MoveVelocity_0(Axis:=axis1Ref);
MC_Stop_0(Axis:=axis1Ref);
END_PROGRAM