Desktop Robotti with RabbitMQ
Overview
This example demonstrates bidirectional communication between a mock physical twin and a digital twin of a mobile robot (Desktop Robotti). The communication is enabled by RabbitMQ Broker.
Example Structure
The mock physical twin of mobile robot is created using two python scripts
- data/drobotti_rmqfmu/rmq-publisher.py
- data/drobotti_rmqfmu/consume.py
The mock physical twin sends its physical location in (x,y) coordinates and expects a cartesian distance calculated from digital twin.
The rmq-publisher.py reads the recorded (x,y) physical coordinates of mobile robot. The recorded values are stored in a data file. These (x,y) values are published to RabbitMQ Broker. The published (x,y) values are consumed by the digital twin.
The consume.py subscribes to RabbitMQ Broker and waits for the calculated distance value from the digital twin.
The digital twin consists of a FMI-based co-simulation, where Maestro is used as co-orchestration engine. In this case, the co-simulation is created by using two FMUs - RMQ FMU (rabbitmq-vhost.fmu) and distance FMU (distance-from-zero.fmu). The RMQ FMU receives the (x,y) coordinates from rmq-publisher.py and sends calculated distance value to consume.py. The RMQ FMU uses RabbitMQ broker for communication with the mock mobile robot, i.e., rmq-publisher.py and consume.py. The distance FMU is responsible for calculating the distance between (0,0) and (x,y). The RMQ FMU and distance FMU exchange values during co-simulation.
Digital Twin Configuration
This example uses two models, one tool, one data, and two scripts to create mock physical twin. The specific assets used are:
Asset Type | Names of Assets | Visibility | Reuse in Other Examples |
---|---|---|---|
Models | distance-from-zero.fmu | Private | No |
rmq-vhost.fmu | Private | Yes | |
Tool | maestro-2.3.0-jar-with-dependencies.jar | Common | Yes |
Data | drobotti_playback_data.csv | private | No |
Mock PT | rmq-publisher.py | Private | No |
consume.py | Private | No |
This DT has many configuration files.
The coe.json
and multimodel.json
are two DT configuration files used for executing the digital twin.
You can change these two files to customize the DT to your needs.
The RabbitMQ access credentials need to be provided in multimodel.json
.
The rabbitMQ-credentials.json
provides RabbitMQ access credentials
for mock PT python scripts. Please add your credentials in both these files.
Lifecycle Phases
Lifecycle Phase | Completed Tasks |
---|---|
Create | Installs Java Development Kit for Maestro tool and pip packages for python scripts |
Execute | Runs both DT and mock PT |
Clean | Clears run logs and outputs |
Run the example
To run the example, change your present directory.
If required, change the execute permission of lifecycle scripts you need to execute, for example:
Now, run the following scripts:
Create
Installs Open Java Development Kit 17 in the workspace. Also install the required python pip packages for rmq-publisher.py and consume.py scripts.
Execute
Run the python scripts to start mock physical twin. Also run the the Digital Twin. Since this is a co-simulation based digital twin, the Maestro co-simulation tool executes co-simulation using the two FMU models.
Examine the results
The results can be found in the /workspace/examples/digital_twins/drobotti_rmqfmu directory.
Executing the DT will generate and launch a co-simulation (RMQFMU and distance FMU), and two python scripts. One to publish data that is read from a file. And one to consume what is sent by the distance FMU.
In this examples the DT will run for 10 seconds, with a stepsize of 100ms.
Thereafter it is possible to examine the logs produce in
/workspace/examples/digital_twins/drobotti_rmqfmu/target
.
The outputs for each FMU, xpos and ypos for the RMQFMU, and the distance for
the distance FMU are recorded in the outputs.csv
file.
Other logs can be examined for each FMU and the publisher scripts.
Note that, the RMQFMU only sends data, if the current input
is different to the previous one.
Terminate phase
Terminate to clean up the debug files and co-simulation output files.
References
The RabbitMQ FMU github repository contains complete documentation and source code of the rmq-vhost.fmu.
More information about the case study is available in: