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 synchronised axis groups. For more information about TwinCAT Motion please see the 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

As the NC-Task does not contain any axes by default. you need to add them, again by using the CreateChild() method - this time on a reference to the Axes 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)

Parameterize axes

Axes can be parameterized via their XML description. To get a sample XML description, you could add an axis manually in TwinCAT XAE and use the corresponding entry from the context menu or add the axis via Automation Interface and use the ITcSmTreeItem::ProduceXml() method to get 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 modify this XML description to your needs and then import it again via the method ITcSmTreeItem::ConsumeXml() 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)