Simple movement via the PLC
After creating and configuring an NC axis, you can create a PLC project and move the axis via this.
DANGER | |
Risk of injury due to movement of axes! The commissioning results in a movement of axes.
|
WARNING | |
Incorrect axis position during initial commissioning Without referencing / calibrating the axis position, the displayed axis position may deviate from the actual axis position.
|
Creating a PLC project
- 1. Right click in the Solution Explorer on PLC > Add new Item...
- 2. Select the name and location in the dialog Add New Item.
- The PLC project was created.
Integrating a PLC library
The Tc2_MC2 library contains the PLCopen specified Motion Control function blocks. These can be used to manage NC axes and program movements.
- 1. Right click on References > Add library...
- 2. Select the library Tc2_MC2 and confirm with OK.
- The library is now added and can be viewed by double-clicking it.
Writing a PLC program
All necessary data types and function blocks for a simple PLC Motion program are contained in the library Tc2_MC2.
AXIS_REF
For each axis one instance of the data type AXIS_REF is required, which is the interface between PLC and NC. It contains all the information about the axis that is given to the MC function blocks as a reference.
MC_Power
The function block MC_Power is used to enable an axis and its directions of movement.
MC_Reset
The function block MC_Reset can be used to reset an error on an axis.
MC_MoveAbsolute
MC_MoveAbsolute is a simple Motion function block that can be used to position an axis to an absolute target position.
Simple programming
- 1. Open the
MAIN(PRG)
in the PLC project at POUs. - 2. Add the following declarations to
MAIN(PRG)
.
PROGRAM MAIN
VAR
axis : AXIS_REF;
fbPower : MC_Power;
fbStop : MC_Stop;
fbReset : MC_Reset;
fbMoveAbsolute : MC_MoveAbsolute;
enableAxis : BOOL;
executeStop : BOOL;
executeReset : BOOL;
executeMove : BOOL;
override : LREAL := 100;
position : LREAL := ???; // ToDo: set to a reachable position
velocity : LREAL := ???; // ToDo: set velocity for move absolute
END_VAR
- 3. Insert the following program code into
MAIN(PRG)
.
fbPower(
Axis := axis,
Enable := enableAxis,
Enable_Positive := enableAxis,
Enable_Negative := enableAxis,
Override := override,
BufferMode := ,
Options := ,
Status => ,
Busy => ,
Active => ,
Error => ,
ErrorID =>);
fbStop(
Axis := axis,
Execute := executeStop, // The command is executed with a positive edge.
Deceleration := , // If the value is ≤ 0, the deceleration
// parameterized with the last Move command is used.
Jerk := , // If the value is ≤ 0, the jerk parameterized
// with the last Move command is used.
Options := ,
Done => ,
Busy => ,
Active => ,
CommandAborted => ,
Error => ,
ErrorID => );
fbReset(
Axis := axis,
Execute := executeReset, // The command is executed with a positive edge.
Done => ,
Busy => ,
Error => ,
ErrorID => );
fbMoveAbsolute(
Axis := axis,
Execute := executeMove, // The command is executed with a positive edge.
Position := position,
Velocity := velocity,
Acceleration := , // If the value is 0, the standard acceleration from
// the axis configuration in the System Manager is used.
Deceleration := , // If the value is 0, the standard deceleration from
// the axis configuration in the System Manager is used.
Jerk := , // If the value is 0, the standard jerk from the axis
// configuration in the System Manager is applied.
BufferMode := MC_BufferMode.MC_Buffered,
Options := ,
Done => ,
Busy => ,
Active => ,
CommandAborted => ,
Error => ,
ErrorId => );
- 4. For the call from
fbMoveAbsolute
, adjust the target position and the dynamics according to your real axis. - 5. Build the PLC project.
- The
axis
instance of theAXIS_REF
should now be displayed among the PLC instances in the Solution Explorer. - 6. Link the PLC instance of
AXIS_REF
with the axis instance of the NC. - 7. Activate the TwinCAT project .
- 8. Log in the PLC and start it , see Activate TwinCAT project.
- 9. Check that the target position specified at
fbMoveAbsolute
can be approached safely with the specified dynamics. Adjust them as needed. - 10. If you are sure that there is no danger from the movement specified at
fbMoveAbsolute
, you can enable the controller for the axis by setting the variableenableAxis
online toTRUE
. - 11. If the controller enable was successful (
fbPower.Active = TRUE
), the motion command can then be activated withexecuteMove
. - Via
fbStop.Execute = TRUE
the motion command can be stopped prematurely if required. - An axis error can be reset via
fbReset.Execute := TRUE
.