Beckhoff#TwinCAT3 x TE1400 x Simulink Setup Guideline

This post I will explain how to link the TwinCAT3 System to the Simulink models and make simulations.This Road is a little long and I would like to remember all the things that I did before.

Please download the TE1400 Manual by the below link.It shoube be better to read this 🙁 and I will try to refer to all the installations within the Manual.

https://download.beckhoff.com/download/document/automation/twincat3/TE1400_TC3_Target_Matlab_EN.pdf

Project Link:

https://github.com/soup01Threes/TwinCAT3/blob/main/TwinCAT_Project_Link_With_Simulink.tnzip

And, It should be better to install this software in the VMWare.

What is TE1400 TwinCAT Target for MATLAB®/Simulink®?

The MATLAB and Simulink Coder® had an Auto-Code generator, we can use this generator to auto convert our model to C/C++ Code.And Beckhoff’s TE1400 is operating based on the code that generated this TE1400.

While we use TE1400 Target to generate our code from the model, a TcCOM(TwinCAT Object Model) is generated from it. This TcCOM3 object can be imported into your XAE.

Also, If necessary, while you start the runtime, the TcCOm models will be automatically run in Real-time and be a part of your machine.

What is MATLAB®/Simulink®?

Sure that you can search from Google.

https://jp.mathworks.com/products/simulink.html

When you use MATLAB® and Simulink® together, you combine textual and graphical programming to design your system in a simulation environment.

Directly use the thousands of algorithms that are already in MATLAB. Simply add your MATLAB code into a Simulink block or Stateflow® chart.

Use MATLAB to create input data sets to drive simulation. Run thousands of simulations in parallel. Then analyze and visualize the data in MATLAB.

Please refer to the above link to get more information.

Application Example

Rapid Control Prototyping

You can use Simulink to play the Real-time close loop control simulations with TwinCAT.

The Input/Output that is configured in the Simulink can be directly integrated into your TwinCAT Project.

We will call this as “Model in the loop Simulation”.

For Example:

https://stackoverflow.com/questions/34570215/how-to-model-for-loop-memory-things-in-matlab-simulink

Surely This Model in Simulink will be automatically generated as TcCOM modules and imported into your TwinCAT Project.

Real-time simulation of a machine / virtual commissioning

We can Generate the TcCOM modules from Simulink modules – And we can test that Model in Real-time.Thanks for this Technology, the program debug time,Commissioning time are decreased.

And we have 2 types of Configurations:SIL and HIL.

SiL(Software-in-the-loop)

This type of configuration is All the Remote IOs,PLC,Drives are in the virtual environment.

It is your first step of Virtual commissioning.

HiL(Hardware-in-the-loop)

Here is the next step – You will integrate some parts of Hardware inside your control loops.

For example: Drives,Remote IO.

Installation

Now I will explain how to install the TE1400 into your system.

TWINCAT3 C/C++

Engineering PC

Visual Studio

Reference to the installation manual, Visual Studio 2010(SP1),2012,2013,2015 or 2017 is supported.Please instal the above version.

Trips:Please Always Run as administrator for the installer.

And if you are using Visual Studio 2017,please check the box of “Desktop development withC++”.

Microsoft “Windows Driver Kit” version 7.1.0

If your TwinCAT3 Version is lower than 4024.0, please search in google and install it

Here is the link:

https://www.microsoft.com/en-us/download/details.aspx?id=11800

Unzip and run the installer as administrator.

Check the “Build Environments” and OK.

Set up the install path and please just let it in default.

Also,please copy the path to the notepad.

Agree the License and OK.

私のVMならたしかに5分くらいで終わるかな。

This installation takes about 5 mins in my VM.

Finished!

Modify the environment variables of windows.

Control Panel>System and Security>System>Advanced system settings

Advanced>Environment Variables。

System variables>New。

Variable Name:WindDDK7

Variable value:The path that you copied before in notepad.

Restart your PC.

TwinCAT 3 XAE

Install TwinCAT3 XAE into your Machine 😉

Sure, you need it!

Runtime PC

IPC or Embedded CX PC with Microsoft operating system based on “Windows NT kernel” (Win XP,Win 7 and corresponding embedded versions, Win 10)

TwinCAT3 XAR

Depends on the Version..

  • TwinCAT 3.0:32BitOS only
  • TwinCAT 3.1:32Bit/64BitOS Both OK。
    But you need to instal Driver sign if 64BitOS is used.

Driver sign

You can have a detailed explanation in the below link:

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_c/110691083.html&id=

Because I am using Visual Studio 2017, open the Developer Command Prompt inside the Visual studio 2017 folder.

Create the certification.

makecert -r -pe -ss PrivateCertStore -n CN=MyTestSigningCert MyTestSigningCert.cer

Now we can check if the certification is available or not.

Command prompt>mmc.

File>Add/Remove snap-in.

Certificates>Add.

Select My user account,Finish.

Press OK.

Save it.

Add the certification into your PC Environment Variables.

PC Environment Variables>User Variables>add the certification name that red-lined below.

Variable:TWINCATTESTCERTIFICATE

Value:CN=…

C++>Project>Properties

Check the Tc Sign setting into Configuration Properties>Tc Sign.

Change to TestMode

Run the Command prompt as Administrator and then execute the below command:

bcdedit /set testsigning yes

Restart your PC.

If the below text is shown in your Desktop, now your PC is in Test Mode.

MATLAB®/Simulink®

Version:

  • MATLAB®/Simulink®
    • From R2010a to R2019a
    • R2010b later is recommended.
  • Simulink Coder®

TE1400 Target

Download from the below link:

https://www.beckhoff.com/ja-jp/products/automation/twincat/te1xxx-twincat-3-engineering/te1400.html

After installation is finished, TE1400-TargetForMatlabSimulink is created.

Open the Matlab as Administrator.

Open the Folder.

Choose TE1400-TagertForMatlabSimulink Folder.

You can see the SetupTwinCatTarget.p inside the Folder.

Right click and Run.

If the Setup is OK, you can see the following messages in the Command Window.

License

TE1400 does not have the 7-days full functional trial license.

but you can use the demo license.

First Model

New>Model.

You can see the Model Edit Screen.

Click the Setting Button.

Click the Solver Tab.

Type:Fixed-step

Fixed-step size:0.01

Code Generation>Browse

Choose TwinCAT.tlc.

Check the Publish module inside TC Build and  TwinCAT RT(x86) and (x64),

Apply>OK.

Create a sample model.

Compile it.

If there is No Error, you are finished!

The tmc file is auto created also.

IMPORT to PLC

Next, Import the tmc into your PLC.

Open the TwinCAT XAE.

Create a new project.

C++>Add Existing Item.

Choose the C++ Project that you compiled in the Simulink.

Right Click the Project and Rebuild.

Build OK!

Then import the model that you compiled.

TcCOM Object>Reload System TMC Files。

TcCOM Objects>Add New Item.

TE1400 Module Vendor>Generated Modules>Choose the Model that you compiled>OK。

Choose the TcCOM Objects, Assign the task by Context>Task.

Use Build>Build Solution to compile your project and download to the runtime.

Click the Online button to monitor the current status.

you can see if you click In1, “0(False)” is displayed in the graph.

Press the write button. the graph will display 1(true).

You can also view the model in the Block Diagram.

Implementation

We monitored the signal in the previous parts.

Now we would like to link these signals to our PLC.

Click POUs>MAIN.

Define these Variables.

What is the the meaning of this –  binput1 AT %Q*:BOOL; ?

下のInformation Systemには説明があります:we can find more information in the below link:

https://infosys.beckhoff.com/english.php?content=../content/1033/tcplccontrol/html/TcPlcCtrl_ResGlobVar.htm&i=

The Reason that we need to define the local process IO:

If the code generator is configured appropriately with TwinCAT Target, a TwinCAT Object Model (TcCOM) is created with the input and output behavior of the Simulink model.

Build>Build Solution Again.

We would like to connect the In1,In2,Out1 of TcCOM to Untitled1 Instance’s In1,In2,Out1. 

Let’s assign the Input and output.

Click the In1 inside the TcCOM Objects.

Choose binput1>OK.

And do the same operation for the other parameters.

Build the Solution again after you assign all the pins.

テストtest

We can test the AND Gate very soon

Just turn on binput1.

Then turn on binput2.

We can see bOutput1 is True now.

Finally

TwinCAT3 AdsWarning 4115: system clock setup fail

If you can not Start the TwinCAT3 Runtime..

https://control.com/forums/threads/twincat-3-error-when-switched-to-run-mode.43467/
https://stackoverflow.com/questions/54264180/twincat3-adswarning-4115-system-clock-setup-fail

Summary:

  • Restart your Machine
  • Disable Hyper-V
  • Run as Administrator :win8settick.bat

Compiler is not match 

Please install the current version of Visual Studio.

x64 Publish procedure failed

While compiling the model in the Simulink, it just showed error and please send this report to Beckhoff Automation.

it said, ”You can try to build manually using the project file..”.

Let’s try it.

Insert that C++ Project and Compile it.

This time it shows “Either a certificate name or a certificate ID is expected”.

It seems like we do not have the Signtool!

それじゃ、Signtoolをダウンロードしインストールしましょう。ちなみに、先も書いていますが、64BitのOSだけSign認証が必要になります。

Please download the SignTool and install it.

Reference Link:

https://stackoverflow.com/questions/43636484/how-to-install-signtool-exe-for-vs-2017

Open Control Panel>Visual Studio>Change.

Check all the tools and install it.

Restart your PC.

Finished!

LINK

Beckhoff Information System

https://infosys.beckhoff.com/index_en.htm

Simulink

https://jp.mathworks.com/products/simulink.html

TWINCAT3 – Installation Manual

https://download.beckhoff.com/download/Document/automation/twincat3/TC3_Installation_EN.pdf

TC3 Target for Matlab®/Simulink® Manual

https://download.beckhoff.com/download/document/automation/twincat3/TE1400_TC3_Target_Matlab_EN.pdf

TwinCAT C/C++ Manual

Publish Procedure Failed – Simulink code generation with TwinCAT.tlc Target file

https://jp.mathworks.com/matlabcentral/answers/276156-publish-procedure-failed-simulink-code-generation-with-twincat-tlc-target-file

How to install SignTool.exe for Windows 10

https://stackoverflow.com/questions/31869552/how-to-install-signtool-exe-for-windows-10

How to install SignTool.exe for VS 2017?

https://stackoverflow.com/questions/43636484/how-to-install-signtool-exe-for-vs-2017

TwinCAT3 AdsWarning 4115: system clock setup fail

https://stackoverflow.com/questions/54264180/twincat3-adswarning-4115-system-clock-setup-fail

TwinCAT 3 Error When Switched to Run Mode.

https://control.com/forums/threads/twincat-3-error-when-switched-to-run-mode.43467/

The implementation and debugging of TwinCAT 3 C++ modules requires

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_c/110675211.html&id=121428688628873596

Windows Driver Kit Version 7.1.0

https://www.microsoft.com/en-us/download/details.aspx?id=11800

Driver signing

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_c/110691083.html&id=

How to sign X64 Driver Beckhoff TwinCat3

TE1400 Download

https://www.beckhoff.com/ja-jp/products/automation/twincat/te1xxx-twincat-3-engineering/te1400.html

Global Variables

https://infosys.beckhoff.com/english.php?content=../content/1033/tcplccontrol/html/TcPlcCtrl_ResGlobVar.htm&i=

Footer_Basic

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする