Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for...

23
Manual TC3 Interface for Matlab®/Simulink® TwinCAT 3 1.0 2017-08-17 TE1410 Version: Date: Order No.:

Transcript of Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for...

Page 1: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Manual

TC3 Interface for Matlab®/Simulink®

TwinCAT 3

1.02017-08-17TE1410

Version:Date:Order No.:

Page 2: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is
Page 3: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Table of contents

TC3 Interface for Matlab®/Simulink® 3Version: 1.0

Table of contents1 Foreword .................................................................................................................................................... 5

1.1 Notes on the documentation...........................................................................................................  51.2 Safety instructions ..........................................................................................................................  6

2 Overview..................................................................................................................................................... 7

3 Installation.................................................................................................................................................. 8

4 Licenses ..................................................................................................................................................... 9

5 TE1410 Simulink Library......................................................................................................................... 105.1 Asynchronous Blocks ...................................................................................................................  10

5.1.1 TC ADS Async Read........................................................................................................ 105.1.2 TC ADS Async Write........................................................................................................ 12

5.2 Synchronous Blocks .....................................................................................................................  145.2.1 TC ADS Symbol Interface................................................................................................ 145.2.2 TC ADS Module Interface ................................................................................................ 155.2.3 TC ADS Sync Read ......................................................................................................... 195.2.4 TC ADS Sync Write.......................................................................................................... 21

5.3 Utilities ..........................................................................................................................................  235.3.1 Sync Clock ....................................................................................................................... 23

Page 4: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Table of contents

TC3 Interface for Matlab®/Simulink®4 Version: 1.0

Page 5: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Foreword

TC3 Interface for Matlab®/Simulink® 5Version: 1.0

1 Foreword

1.1 Notes on the documentationThis description is only intended for the use of trained specialists in control and automation engineering whoare familiar with the applicable national standards.It is essential that the documentation and the following notes and explanations are followed when installingand commissioning the components. It is the duty of the technical personnel to use the documentation published at the respective time of eachinstallation and commissioning.

The responsible staff must ensure that the application or use of the products described satisfy all therequirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly underdevelopment.We reserve the right to revise and change the documentation at any time and without prior announcement.No claims for the modification of products that have already been supplied may be made on the basis of thedata, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE®, XFC® and XTS® are registeredtrademarks of and licensed by Beckhoff Automation GmbH.Other designations used in this publication may be trademarks whose use by third parties for their ownpurposes could violate the rights of the owners.

Patent Pending

The EtherCAT Technology is covered, including but not limited to the following patent applications andpatents:EP1590927, EP1789857, DE102004044764, DE102007017835with corresponding applications or registrations in various other countries.

The TwinCAT Technology is covered, including but not limited to the following patent applications andpatents:EP0851348, US6167425 with corresponding applications or registrations in various other countries.

EtherCAT® is registered trademark and patented technology, licensed by Beckhoff Automation GmbH,Germany

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.The reproduction, distribution and utilization of this document as well as the communication of its contents toothers without express authorization are prohibited.Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of apatent, utility model or design.

Page 6: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Foreword

TC3 Interface for Matlab®/Simulink®6 Version: 1.0

1.2 Safety instructions

Safety regulations

Please note the following safety instructions and explanations!Product-specific safety instructions can be found on following pages or in the areas mounting, wiring,commissioning etc.

Exclusion of liability

All the components are supplied in particular hardware and software configurations appropriate for theapplication. Modifications to hardware or software configurations other than those described in thedocumentation are not permitted, and nullify the liability of Beckhoff Automation GmbH & Co. KG.

Personnel qualification

This description is only intended for trained specialists in control, automation and drive engineering who arefamiliar with the applicable national standards.

Description of symbols

In this documentation the following symbols are used with an accompanying safety instruction or note. Thesafety instructions must be read carefully and followed without fail!

DANGER

Serious risk of injury!Failure to follow the safety instructions associated with this symbol directly endangers thelife and health of persons.

WARNING

Risk of injury!Failure to follow the safety instructions associated with this symbol endangers the life andhealth of persons.

CAUTION

Personal injuries!Failure to follow the safety instructions associated with this symbol can lead to injuries topersons.

Attention

Damage to the environment or devicesFailure to follow the instructions associated with this symbol can lead to damage to the en-vironment or equipment.

Note

Tip or pointerThis symbol indicates information that contributes to better understanding.

Page 7: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Overview

TC3 Interface for Matlab®/Simulink® 7Version: 1.0

2 OverviewTE1410 interface for MATLAB®/Simulink®

TE1410 interface for MATLAB®/Simulink® can be used for data exchange between TwinCAT3 andMATLAB®/Simulink®.

The data is exchanged via ADS using Simulink blocks, which are provided in a simulink library.

Webinars concerning TE1400 and TE1410

Date Topic Referent01.10.2013 TwinCAT 3 | Matlab®/Simulink®-integration: Introduction,

application examples, TC3 Interface for Matlab®/Simulink® (german)Dr. KnutGüttel

Overview of the Beckhoff webinars (german)

Page 8: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Installation

TC3 Interface for Matlab®/Simulink®8 Version: 1.0

3 InstallationSystem requirements

• MATLAB®/Simulink® R2010a or newer.• TwinCAT 3.0 or newer.

Installation instructions1. Run the TwinCAT 3 Setup2. Run the Setup "TE1410-InterfaceForMatlabSimulink"3. Start MATLAB® as administrator and execute "%TwinCAT3Dir%..\Functions\TE1410-

InterfaceForMatlabSimulink\SetupTE1410.p" in MATLAB®.

NOTE! When executing MATLAB® without Administrator permission, on a system with UserAccount Control (UAC) enabled, the MATLAB® path can't be saved durable. In this case"SetupTE1410.p" has to be executed after each restart of MATLAB®, otherwise some files cannot befound, which are necessary to generate TwinCAT modules.

Page 9: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

Licenses

TC3 Interface for Matlab®/Simulink® 9Version: 1.0

4 LicensesTo use the functions of the TE1410 interface for MATLAB®/Simulink®, a TE1410 license is required on thesystem on which MATLAB®/Simulink® is operated with the TE1410 Simulink function blocks. In addition, atleast a TwinCAT ADS installation is required on this computer, in order to make the ADS router available.

From this system, connections to various target platforms can then be established. No additional runtimelicenses are required for using the TE1410 on the target platforms.

Demo version

A 7-day trial license is not available for TE1410, since it is an engineering product. However, you can test theproduct with limited functionality (demo version). The limitations of the demo version are automaticallytriggered if no valid TE1410 license is found on the system. The functionality is limited to a total of 5 ADSvariables and 5 ADS function blocks per Simulink model.

Page 10: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®10 Version: 1.0

5 TE1410 Simulink LibraryAfter TE1410 - Interface for MATLAB®/Simulink® was installed successfully, the Simulink library browsercontains the entry Beckhoff / TwinCAT ADS:

5.1 Asynchronous BlocksTE1410 - Interface for MATLAB®/Simulink® was installed successfully, the Simulink library browser containsthe entry Beckhoff / TwinCAT ADS:

5.1.1 TC ADS Async ReadThe block "TC ADS Async Read" provides read access to TwinCAT ADS varaibles. You can find this blockbeneath the subfolder "Asynchronous" of the Beckhoff ADS Library inside the "Simulink Library Browser".

Page 11: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 11Version: 1.0

Block input ports

NetId The target AMS NetIdPort The target ADS PortIdxGrp The target ADS Index GroupIdxOffs The target ADS Index OffsetTrig Positive edge triggers the ADS request

Block output ports

Data The value, read from the ADS variableBusy Boolean flag signaling that the block is currently

waiting for an ADS responseErr Boolean flag signaling an actual ADS errorErrId The ADS error code

Block parameters

Page 12: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®12 Version: 1.0

Block sample time The Simulink block sample time, which is the ADSrequest interval (refered to the Simulink time but notto the real time)

Abort simulation on ADS error Stop simulation at the first ADS errorData type The data type of the Data output signal, which should

be the data type of the transmitted ADS variableData width The width of the Data output signal. Use values

greater than 1 to transmit arrays.ADS timeout Simulink will wait on a response of the last ADS

request until this timespan is exceeded (in each timestep)

Direct feed through Evaluate the input values in the output method of theblock. This ensures, that the values at the outputports in the current time step belong to the ADSparameters at the input ports of the same time step.Otherwise the output values belong to the input ADSparameters of the previous time step. Activating thisoption can significantly slow down the simulation.

Create signal labels Signal labels are created for the signal lines,connected to the output ports

Code generation

Code generation is supported only for the TwinCAT Target.

5.1.2 TC ADS Async WriteThe block "TC ADS Async Write" provides write access to TwinCAT ADS variables. You can find this blockbeneath the subfolder "Asynchronous" of the Beckhoff ADS Library inside the "Simulink Library Browser".

Block input ports

NetId The target AMS NetIdPort The target ADS PortIdxGrp The target ADS Index GroupIdxOffs The target ADS Index OffsetData The value to be written to the ADS variableTrig Positive edge triggers the ADS request

Block output ports

Busy Boolean flag signaling that the block is currentlywaiting for an ADS response

Err Boolean flag signaling an actual ADS errorErrId The ADS error code

Page 13: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 13Version: 1.0

Block parameters

Block sample time The Simulink block sample time, which is the ADSrequest interval (referred to the Simulink time but notto the real time)

Abort simulation on ADS error Stop simulation at the first ADS errorData type The data type of the Data input signal, which should

be the data type of the transmitted ADS variableData width The width of the Data input signal. Use values

greater than 1 to transmit arrays.ADS timeout Simulink will wait on a response of the last ADS

request until this time span is exceeded (in each timestep)

Direct feed through Evaluate the input values in the output method of theblock. This ensures, that the values at the outputports in the current time step belong to the ADSparameters at the input ports of the same time step.Otherwise the output values belong to the input ADSparameters of the previous time step. Activating thisoption can significantly slow down the simulation.

Create signal labels Signal labels are created for the signal lines,connected to the output ports

Code generation

Code generation is supported only for the TwinCAT Target.

Page 14: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®14 Version: 1.0

5.2 Synchronous BlocksTE1410 - Interface for MATLAB®/Simulink® was installed successfully, the Simulink library browser containsthe entry Beckhoff / TwinCAT ADS:

5.2.1 TC ADS Symbol InterfaceThe block "TC ADS Symbol Interface" provides synchronous read and write access to a TwinCAT ADSsymbols. You can find this block beneath the subfolder "Synchronous" of the Beckhoff ADS Library inside the"Simulink Library Browser".

Block input and output ports

The number of ports and the data types of the ports depend on the block configuration. There are no fix inputor output ports.

Page 15: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 15Version: 1.0

Block parameters

ADS symbolsDefine the input and output ports of the Simulink block. You can use the target browser to search for ADSsymbols and put the symbols to the symbol list of the desired transmit direction. This can be done via theappropriate buttons of the target browser or via Drag and Drop.

General Simulink block settings

Block sample time The Simulink block sample time,which is the ADS request interval(referred to the Simulink time butnot to the real time)

Code generation

Code generation from models using this block is supported for the TwinCAT Target. The generated TwinCATmodule gets additional Data Areas (Process Images), which contain the input and output variables of theSimulink block.

5.2.2 TC ADS Module InterfaceThe block "TC ADS Module Interface" provides synchronous read and write access to a special TwinCATmodule. You can find this block beneath the subfolder "Synchronous" of the Beckhoff ADS Library inside the"Simulink Library Browser".

Page 16: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®16 Version: 1.0

Block input and output ports

The number of ports and the data types of the ports depend on the block configuration. There are no fix inputor output ports.

Block parameters

Target moduleNetId The NetId of the target system,

where the interface moduleinstance is running.

OID The object ID of the moduleinstance.

Module settings

Module instance definition file Create or open a TMI (TwinCATmodule instance) file, containingthe interface module configuration.This file can be imported to theTwinCAT project.

Default module sample time The default sample time of theinterface module.

Module in-/outputs

Define the input and output ports of the Simulink block. These settings are saved to the selected TMI(TwinCAT module instance) file. The signals can be of any base type or a Simulink Bus Object, which isdefined in the MATLAB workspace.

General Simulink block settings

Page 17: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 17Version: 1.0

Block sample time The Simulink block sample time,which is the ADS request interval(referred to the Simulink time butnot to the real time)

Synchronisation

No synchronization /Synchronized data exchange

The real time span from the start ofthe simulation is transmitted fromthe interface module to Simulinkand can optionally be used to slowdown the simulation time to the realtime.

Provide TwinCAT time outputport

Provide the real time span from thestart of the simulation as an outputport.

Interface module configuration1. Open the TwinCAT project you want to connect to2. Create a new instance of the MatlabInterfaceModule at the TwinCAT projects node "System / TcCom

Objects" via its context menu item "Add new item..."

Page 18: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®18 Version: 1.0

3. Open the context menu of the newly created object node and Reload the TMI file. Open the TMI filethat was configured in the Simulink block configurator.

Page 19: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 19Version: 1.0

4. Link the process image variables of the interface module to the desired process images of otherTwinCAT modules (PLC, C++, MATLAB/Simulink, IOs). The objects input Data Area contains theSimulink block outputs and vice versa.

Code generation

Code generation from models using this block is supported for the TwinCAT Target. The generated TwinCATmodule gets additional Data Areas (Process Images), which have the same structures as the Data Areas ofthe interface module instance.

5.2.3 TC ADS Sync ReadThe block "TC ADS Sync Read" provides read access to TwinCAT ADS variables. You can find this blockbeneath the subfolder "Synchronous" of the Beckhoff ADS Library inside the "Simulink Library Browser".

Block input ports

NetId The target AMS NetIdPort The target ADS PortIdxGrp The target ADS Index GroupIdxOffs The target ADS Index Offset

Page 20: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®20 Version: 1.0

Block output ports

Data The value, read from the ADS variableErr Boolean flag signaling an actual ADS errorErrId The ADS error code

Block parameters

Page 21: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 21Version: 1.0

Block sample time The Simulink block sample time, which is the ADSrequest interval (referred to the Simulink time but notto the real time)

Abort simulation on ADS error Stop simulation at the first ADS errorData type The data type of the Data output signal, which should

be the data type of the transmitted ADS variableData width The width of the Data output signal. Use values

greater than 1 to transmit arrays.ADS timeout Simulink will wait on a response of the last ADS

request until this time span is exceeded (in each timestep)

Direct feed through Evaluate the input values in the output method of theblock. This ensures, that the values at the outputports in the current time step belong to the ADSparameters at the input ports of the same time step.Otherwise the output values belong to the input ADSparameters of the previous time step. Activating thisoption can significantly slow down the simulation.

Create signal labels Signal labels are created for the signal lines,connected to the output ports

Code generation

Code generation is not supported. The reason is, that synchronous ADS communication requires to wait forthe ADS responses. Due to nondeterministic ADS response times, this could lead to big jitter and cycle timeexceeding in real time applications. Use asynchronous ADS blocks for use in real time applications instead.

5.2.4 TC ADS Sync WriteThe block "TC ADS Sync Write" provides write access to TwinCAT ADS variables. You can find this blockbeneath the subfolder "Synchronous" of the Beckhoff ADS Library inside the "Simulink Library Browser".

Block input ports

NetId The target AMS NetIdPort The target ADS PortIdxGrp The target ADS Index GroupIdxOffs The target ADS Index OffsetData The value to be written to the ADS variable

Block output ports

Err Boolean flag signaling an actual ADS errorErrId The ADS error code

Page 22: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink®22 Version: 1.0

Block parameters

Block sample time The Simulink block sample time, which is the ADSrequest interval (referred to the Simulink time but notto the real time)

Abort simulation on ADS error Stop simulation at the first ADS errorData type The data type of the Data input signal, which should

be the data type of the transmitted ADS variableData width The width of the Data input signal. Use values

greater than 1 to transmit arrays.ADS timeout Simulink will wait on a response of the last ADS

request until this time span is exceeded (in each timestep)

Direct feed through Evaluate the input values in the output method of theblock. This ensures, that the values at the outputports in the current time step belong to the ADSparameters at the input ports of the same time step.Otherwise the output values belong to the input ADSparameters of the previous time step. Activating thisoption can significantly slow down the simulation.

Create signal labels Signal labels are created for the signal lines,connected to the output ports

Page 23: Manual TC3 Interface for Matlab®/Simulink® - Beckhoff · Foreword TC3 Interface for Matlab®/Simulink® Version: 1.05 1 Foreword 1.1Notes on the documentation This description is

TE1410 Simulink Library

TC3 Interface for Matlab®/Simulink® 23Version: 1.0

Code generation

Code generation is not supported. The reason is, that synchronous ADS communication requires to wait forthe ADS responses. Due to nondeterministic ADS response times, this could lead to big jitter and cycle timeexceedings in real time applications. Use asynchronous ADS blocks for use in real time applications instead.

5.3 Utilities

5.3.1 Sync ClockThe block "Sync Clock" can be used to slow down the simulation time to the system time. You can find thisblock beneath the subfolder "Utilities" of the Beckhoff ADS Library inside the "Simulink Library Browser".

Block parameters

Output port Activates an optional block output port, which can beused to monitor the deviation between the simulationand the system time.

Code generation

Code generation is supported for the TwinCAT Target but no code is generated for this block, because realtime modules do not require any system time synchronization.