Create a simulator
PMP provides the ability to create a simulated system.
Simulation can be used to simulate the behavior of a physical controller and plants for testing and validation.
For instance, a customer can use a simulated system, which consist of a top-controller, a sub-controller and plant model that describes their system, to perform motion analysis before deploying it on physical hardware.
The simulator can run on a client PC processor or can be deployed on a remote simulation server.
This guide provides step-by-step instructions on how to create a local simulated system with a top-controller and a sub-controller.
During this guide you will learn how to:
Use a system description file to create a simulated system.
Monitor the value of a signal using the PMP API.
Dispose of a simulated system.
Prerequisites
Before continuing with the quick-start guide, please make sure that the following prerequisites are met:
PMP should be installed with Simulator and Tooling features.
Follow the Installation quick-start guide if this is not yet the case.
A Typical installation includes the required Simulator and Tooling features.
The create a simulator quick start project files should be available.
These files can be downloaded from Downloads.
System description file:
A system description file system.xml
, which describes the system properties and includes the controller’s description.
Controller description files:
A top-controller (Arcas) controller_arcas_5eg.xml
, which describes the controller’s main properties, such as templates, number of axes, processing blocks, updatables, and more.
A sub-controller (Arcas FPGA) controller_arcas_5eg_slave.xml
, which includes digital IOs.
System description
The System description file system.xml
defines the simulator properties and the simulated controllers that make up the simulated system.
The resulting system in visualized in Simulated system.
System description file
1
2
3
4
5
6
7
8
9
10
11
12
13 | <System>
<Properties>
<Property Name="SimulatorCpuUtilization" Value="Greedy" />
<Property Name="SimulatorRealTimeThreads" Value="2" />
<Property Name="SimulatorSpeedFactor" Value="1.0" />
<Property Name="SimulatorClientAddress" Value="localhost" />
</Properties>
<Controllers>
<Controller Description=".\controller_arcas_5eg.xml" HardwareSerialNumber="1" Id="1">
<Controller Description=".\controller_arcas_5eg_slave.xml" HardwareSerialNumber="2"/>
</Controller>
</Controllers>
</System>
|
Simulator creation
First, we create a PMP system that listens for available controllers on the specified IP address.
We will run the simulator on the local machine so the IP address should be localhost
.
Create a simulated system using the provided system.xml
.
Attention
Make sure to update the C:\your\path\to\
part of the absolute file paths to match your chosen locations.
Controllers are automatically discovered on a configurable discovery interval.
In addition, it is possible to force discovery between intervals using the Discover method.
Since the creation of the simulated Arcas controller can take some time, a loop is used to wait for the simulated Arcas to appear.
Top-controller state machine
The top-controller is governed by the Top-controller state machine.
Any controller, both physical and simulated, will automatically transition to the Config state.
The WaitState method can be used to wait for the transition to complete.
Note
Enumeration of the top- and sub-controllers can take some time depending on the complexity of the system and the amount of sub-controllers in the system.
Now that the system has been enumerated we can set the controller state to Run to enable periodic task running.
The WaitState method can be used to wait for the transition to complete.
Note
The Config to Run state transition can take some time depending on the complexity of the system and the amount of sub-controllers in the system.
Verification
By default, the sample frequency of the Arcas 5EG-1 is 2kHz.
To verify that the top-controller periodic tasks are enabled, monitor the incrementing of the SampleCount signal.
Note
The simulator is sample-accurate, but not time-accurate.
This means that all samples are calculated as if the sample frequency is 2kHz, however the exact SampleCount increment per second can deviate from 2,000 counts per second based on the available performance on the computer the simulator is running on.
Clean-up
Now that the verification is completed we can clean-up the simulator.
To stop the controller and disable periodic task running, set the controller state to Config.
To clean up the simulator, the following code can be used:
Note
Closing the test application does not destroy the simulator.
The simulator keeps running until it is explicitly destroyed.
See also
- Simulation
Explanation of a system simulation concept and its purpose in the motion software.
- System description
For more information on system descriptions.
- Configuration
For more information on controller configuration.