TwinCAT Library in Simulink®
In Simulink®, TwinCAT-specific input and output function blocks can (not mandatory) be used to define the signals/buses connected to these function blocks as inputs or outputs in the subsequent TcCOM in TwinCAT. A common way is to use the standard input ports (In) and output ports (Out) of Simulink®. This is usually also the best practice way, unless the additional functions of the TwinCAT-specific input and output function blocks described below are required.
The TwinCAT-specific input and output function blocks can be found in the
Library Browser under Beckhoff TwinCAT Target.
If you use the input and output function blocks provided by Beckhoff, you will benefit from the following additional functionalities, compared to the standard Simulink® input and output ports:
- You can also define signals and buses from subsystems directly as inputs or outputs for TcCOM, without first transferring the signals/buses from the subsystem to the top system.
- You can (not mandatory) store an automatic mapping to other TcCOM or I/Os in the function block parameters, so that the mapping is executed directly and automatically when the TcCOM is instantiated.
- You can use initial values for inputs. To do this, set the Value of the Tc Module Inputs to any value.
When using automatic mapping, please note that if the TcCOM is instantiated more than once in TwinCAT, you will end up with a mapping conflict which you must resolve by manual mapping. This option is therefore not recommended for multiple instantiations.
In addition to TwinCAT-specific input and output function blocks, a TwinCAT Environment View Block is also provided. This can be used in the Simulink® environment to simply display TwinCAT and TE1400 versions on the system.
Example
A Simulink® model is created, which outputs two negated inputs. An input is placed in a subsystem, see figure below.
The inputs and outputs of the model are automatically mapped to digital inputs and outputs via the properties of the TC Modules Input and Output. The necessary tree items can be found in TwinCAT 3 by selecting the desired input or output and then copying the string in the Variable tab under Full Name.
A list of shortcuts for quick access can be found in the documentation of the Automation Interface > API > ITcSysManager > ITcSysmanager::LookupTreeItem.
When the Simulink® model described above is compiled and integrated into TwinCAT 3, a mapping to the corresponding inputs and outputs is automatically created. The automatically generated mappings are marked with a blue symbol to distinguish them from manual mapping, while manual mapping symbols appear white.