Quick start
Starting with a simple Simulink® model
- Feel free to use our built-in samples for first steps with the TwinCAT Target for Simulink®. The MATLAB® Command Window provides a list of available samples via
TwinCAT.ModuleGenerator.Samples.List
- 1. For example, select the
SimpleTemperatureController
and start the sample using the Start link in the Command Window. - In the following, the Quick start is executed along this sample.
- 2. Start at the beginning by selecting the button Open the model in the Live Script.
- For the further configuration steps in Simulink® you can simply click the next button in the Live Script.
Beginner video The following video (only available in English) can also be used as an introduction: TwinCAT Target for Simulink® |
The configuration steps in Simulink®
- 1. Select a fixed-step solver. To do this, go to the Configuration Parameters of the model.
- 2. Select the system target file to "TwinCatGrt.tlc".
Optional: Under Optimization, set the parameter Default parameter behavior to Tunable so that you can continue to change model parameters in TwinCAT. See also Parameterization of a module instance.
- 3. Save your changes in the Simulink® model.
- 4. Start code generation via the Simulink CoderTM App.
Insert TcCOM in TwinCAT
- 1. Open TwinCAT (TwinCAT XAE or TwinCAT in a Visual Studio environment).
- 2. Instantiate a new TcCOM object.
- 3. Select the desired object.
- 4. Create a cyclic task.
- 5. Assign the created task to your TcCOM instance.
Note that the cycle time of the task and the SampleTime in Simulink® (here 5 ms) match.
- 6. Activate the configuration.
Configure and link TcCOM instance
The data exchange of the TcCOM instance takes place via mappings of the process image. Simulink® inputs and Simulink® outputs are automatically mapped as inputs or outputs in the process image and can be linked to I/O or other objects.
In the Parameters (Init) area of the TcCOM instance, you can optionally configure the instance differently than specified when it was created from Simulink®.
For example, you can set the parameter Kp to "52" here. The TcCOM module would then use this value as the startup value for this instance.
Insert as PLC function block
The PLC library used in the following is only available if the following parameters are set in Simulink®:
If these options have not been set, this can be done subsequently without using Simulink® and the TwinCAT Target for Simulink®. See Create and install PLC library.
Brief overview of action steps PLC library/function block
- Create PLC in TwinCAT:
- Add PLC library:
- Select PLC library and view content:
- Use the function block from the library in the PLC:
Calling a TcCOM object also possible from the PLC In addition to the variant described here, you can also call an instance of a TcCOM from the PLC. See Applying the TcCOM Wrapper FB. |