Creating and handling Motion projects

This chapter explains in-depth how to create and handle Motion projects. The following list shows all chapters in this article:

General information about TwinCAT Motion

TwinCAT 3 Motion consists of the following three components: NC I, NC PTP and CNC. It is therefore an assembly of function groups used for the control and regulation of axes or of synchronized axis groups. Further information about TwinCAT Motion can be found in TwinCAT 3 Motion documentation.

Creating and handling Motion projects 1:

Creating a NC-Task

The first step to create a TwinCAT 3 Motion project is to create a so-called NC-Task. In TwinCAT Automation Interface, you can create this task simply by calling the method ITcSmTreeItem::CreateChild() and using the SubType parameter 1, as the following code snippet shows.

Code Snippet (C#):

ITcSmTreeItem ncConfig = systemManager.LookupTreeItem("TINC");
ncConfig.CreateChild("NC-Task", 1);

Code Snippet (Powershell):

$ncConfig = $systemManager.LookupTreeItem("TINC")
$ncConfig.CreateChild("NC-Task", 1)

Creating axes

Since an NC task does not contain any axes by default, you must add them, again using the CreateChild() method, only this time on a reference to an axis node below the NC task.

Code snippet (C#):

ITcSmTreeItem axes = systemManager.LookupTreeItem("TINC^NC-Task^Axes");
axes.CreateChild("Axis 1", 1);

Code snippet (PowerShell):

$axes = $systemManager.LookupTreeItem("TINC^NC-Task^Axes")
$axes.CreateChild("Axis 1", 1)

Parameterizing axes

Axes can be parameterized via their XML description. To obtain an exemplary XML description, you can add an axis manually in TwinCAT XAE and use the corresponding entry in the context menu or add the axis via the Automation Interface and use the ITcSmTreeItem::ProduceXml() method to obtain it.

Creating and handling Motion projects 2:

Code snippet (C#):

ITcSmTreeItem axis = systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1");
string xmlDescription = axis.ProduceXml();

Code snippet (PowerShell):

$axis = $systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1")
$xmlDescription = $axis.ProduceXml()

You can adapt this XML description according to your needs and then import it again using the ITcSmTreeItem::ConsumeXml() method to parameterize your axis.

Code snippet (C#):

ITcSmTreeItem axis = systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1");
axis.ConsumeXml(xmlDescription);

Code snippet (PowerShell):

$axis = $systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1")
$axis.ConsumeXml($xmlDescription)