Skip to content

CORE Control


Create TwinCAT3 Project for CORE Module

Create TwinCAT 3 Project

  1. Select "New TwinCAT Project …" via the Start page.
  2. Alternatively, a new project can be created by clicking on FileNewProject (All existing project templates are displayed)
    Figure1 Figure 1. TwinCAT3 - New Project
  3. Select "TwinCAT XAE Project"; a suitable project name can optionally be entered.
  4. Click on "OK".
    Figure2
    Figure 2. TwinCAT3 - Project Configuration

Create TwinCAT3 C++ Module

  1. Right-click on "C++" and select "Add New Item..."
    • If the green C++ symbol is not listed, this means that either a target device doesn't support TwinCAT C++ or the current Visual Studio is not C++-capable.
      Figure3
      Figure 3. TwinCAT3 Project - Add C++ Project
  2. Select "TwinCAT Driver Project", optionally enter a related project name (e.g. CORE Controller) and click on "OK".
    Figure4
    Figure 4. TwinCAT3 Project - C++ Project Configuration
  3. Select "TwinCAT Module Class with Cyclic I/O" and click on "OK".
    Figure5
    Figure 5. TwinCAT3 Project - C++ Module Categories
  4. Enter a module name in the dialog window "TwinCAT Class Wizard" (E.g. CoreModule)
    Figure6
    Figure 6. TwinCAT3 Project - C++ Module Configuration

Create TwinCAT3 C++ Module Instance

  1. Right-click on the C++ project (in this case "Untitled1") and select "Add New Item...
    Figure7
    Figure 7. TwinCAT3 C++ Module - Add Module Instance
  2. Select a C++ module to create its instance
    Figure8
    Figure 8. TwinCAT3 C++ Module - Select Module for Instantiation
  3. The module already provides a simple I/O interface with default variables in each case:
    • Input area: Value, Status, Data
    • Output area: Value, Control, Data
      Figure9
      Figure 9. TwinCAT3 C++ Module - Default Data Variables
  4. The description of those variables is defined in
    • TwinCAT Module Configuration file (e.g. "CORE_Controller.tmc")
      Figure10
      Figure 10. TwinCAT3 C++ Module - Modify Data Variables
  5. Modify the list of variables as below to work with CORE module:
    • Input area: statusword, modeOpDisp, actPos, actVel, actTorq
    • Output area: controlword, modeOp, tarTorq
      Figure11
      Figure 11. TwinCAT3 C++ Module - Modify Data Variables

System Scanning & Mapping

  1. Scan devices

    • Right click on DeviceScan.
    • Then, every module will be displayed.
      Figure12
      Figure 12. TwinCAT3 Project - Scan for CORE Module

      Note: Before scanning, the ESI file for CORE module must be added to proper TwinCAT location. Also, the TwinCAT driver must be installed for Network Interface Card (NIC) Please refer to "Setting tips" section for guideline.

  2. Map data entries

    • Double click to each variable in CoreModuleLinked to ⇨ Select object link to ⇨ Click on OK.
      Figure13
      Figure 13. TwinCAT3 Project - Map Data Variables for CORE Module
    • Right click on Mapping ⇨ Generate Mapping
      Figure14
      Figure 14. TwinCAT3 Project - Generate Data Mapping

Implementing TwinCAT 3 C++ project

  1. Open "Module1.cpp" in this example
  2. The Module1::CycleUpdate() method is cyclically called
    • This is where the cyclic code is implemented.
      Figure15 Figure 15. TwinCAT3 C++ Module - Cyclic Function for Real-time Task

      Note: The drop-down menu at the top of the editor can be used for navigation through the Module class.

Compiling TwinCAT 3 C++ project

  1. Select the target platform according to which the compilation should be carried out
  2. Right-click on the TwinCAT 3 C++ project and select "Build" or "Rebuild"
  3. Compilation of the x64 driver generates the following output
    Figure16
    Figure 16. TwinCAT3 C++ Module - Build the C++ Source Code

Create a TwinCAT real-time task

  1. Open System ⇨ Right-click on Tasks ⇨ Select Add New Item...
    Figure17
    Figure 17. TwinCAT3 Project - Add Real-time Task
  2. Enter a unique name for the task (e.g. Task1)
    Figure18
    Figure 18. TwinCAT3 Project - Specify Task Name
  3. Configure the task
    • "Auto start" must be activated in order to automatically start a task that is cyclically executed.
    • "Cycle ticks" defines the timing of the clock in relation to the basic clock.
      Figure19
      Figure 19. TwinCAT3 Project - Real-time Task Configuration
  4. Assigning the task to C++ module
    • Select the C++ Module instance in the solution tree
    • Select the "Context" tab in the right-hand working area
    • Select the "Task 1" in the drop-down task menu
      Figure20
      Figure 20. TwinCAT3 Project - Assign Task to C++ Module

Enable TwinCAT 3 C++ Debugger

  • Select the "C++ Debugger" tab on the C++ node of the solution, switch on "Enable C++ Debugger"
    Figure21
    Figure 21. TwinCAT3 C++ Module - Enable Debugging Mode

Activating a TwinCAT 3 project

  1. Click on "Activate Configuration
    • All required files for the TwinCAT project are transferred to the target system
      Figure22
      Figure 22. TwinCAT3 Project - Activate System
  2. Confirm the activation of the new configuration
    Figure23
    Figure 23. TwinCAT3 Project - Confirm System Activation
  3. You will be offered the option to create a 7-day test license if needed. This can be repeated any number of times.
  4. TwinCAT 3 will ask whether the mode should be switched to Run Mode
    • Click on "OK" to switches TwinCAT to Run Mode
    • Click on "Cancel" to remain in Config Mode
      Figure24
      Figure 24. TwinCAT3 Project - Confirm System's Run Mode
  5. After switching to Run mode, the TwinCAT System Service symbol at the bottom in Visual Studio turns Green.
    Figure25
    Figure 25. TwinCAT3 Project - Run Mode Indication

References