This repository contains the templates for the technique to create Digital Twin implementations of robotic platforms using co-simulation and RoboStar technologies associated to this publication.
We also provide examples for the instantiation of the templates for the Universal Robots UR5e (see here) and the UR3e (see here). The UR5e belongs to a manufacturing cell, the Flex-cell, which has been used as a case study for Digital Twins in robotics. For these examples, we provide the implementations for simulation using CoppeliaSim and for real robots using the URInterface, which is based on the Universal Robots RTDE.
- Installation.
- External resources.
- Implementation of examples.
- Templates.
- FMI3 support.
- Cite this work.
- Java and Python must be installed.
- Clone this repository.
git clone https://github.com/INTO-CPS-Association/DigitalTwins_RoboSim.git
- Install CoppeliaSim: https://www.coppeliarobotics.com/
- Install ZeroMQ to communicate remotely with CoppeliaSim and the URInterface to communicate with the UR5e/UR3e:
python3 -m pip install coppeliasim-zmqremoteapi-client zmq urinterface
- Install the additional dependencies for running and testing the examples and components - Robotics Toolbox Python, pickle, FMPy, mqtt, and pika (AMQP):
python3 -m pip install roboticstoolbox-python pickle fmpy paho-mqtt pika
Some of the tools this approach relies on include:
We provide the implementation of three examples below, with the general methodology outlined in the following Templates section of this readme.
- UR3e
- UR5e
- Mobile Robot (this one has additional dependencies for ROS2 and Gazebo)
We provide templates based on the provided methodology in our paper (see Cite this work) in the templates folder.
The script templates/helper.py
provides a set of miscellaneous functions that help with automatically printing some portions of code to set up the templates based on the particular RoboSim models and variables names. These portions of code are printed to the terminal and must be copied and pasted to the corresponding files.
To use this script, update the RoboSim module name in robosim_module_name = "name"
; update the dictionary vars
with your Input Events, Operations, and Arguments for Input Events and Operations accordingly; define which of the Input Events are to be provided by the controller FMU in vars_controller
; and define which variables of the robotic platform you want to log in vars_log_pmFMU
(these are not necessarily part of the RoboSim module but observations you can get from the robotic platform - either real or simulated).
The script provides 11 functions that provide some portions of code for the following files or sections in the templates:
connections
field in thestep5_co-simulation/multimodel.json
file used by Maestro to set up the co-simulation given the FMUs and connections (see here). (Step 5 in the methodology)ModelDescription.xml
of the platform mapping FMU (see here). (Step 6 in the methodology)model.py
of the platform mapping FMU (see here). (Steps 6 and 7 in the methodology)ModelDescription.xml
of the d-model FMU (see here). (Step 8 in the methodology)ModelData struct
insteps8-11_dmodelFMU/adapted_C/defs_fmi.h
of the d-model FMU (see here). (Step 9 in the methodology)read_input
function in thesteps8-11_dmodelFMU/adapted_C/interface.h
file of the d-model FMU (see here). (Step 10 in the methodology)write_output
function in thesteps8-11_dmodelFMU/adapted_C/interface.h
file of the d-model FMU (see here). (Step 10 in the methodology)skeleton.c
of the d-model FMU (see here). (Step 11 in the methodology)setStartValues
function in thesteps8-11_dmodelFMU/adapted_C/main.c
file of the d-model FMU (see here). (Step 11 in the methodology)model.py
of the controller FMU (see here). (Steps 12 and 13 in the methodology)ModelDescription.xml
of the controller FMU (also works for the outputs of the RabbitMQ FMU) (see here for the controllerFMU; RabbitMQ FMU requires the sameModelDescription.xml
in two places, here and here). (Step 13 in the methodology)
- Steps 1 and 2 are case-specific. Refer to the examples provided in UR5e/UR3e/MobileRobot for further guidance.
- Step 3 refers to the platform mapping interface, whose template is provided in mapping template. Here, the user is expected create the mapping given the robotic platform and the communication interface and libraries required. For exemplification, refer to mapping UR5e to see the instantiation of the mapping template for the UR5e with two different interfaces, the CoppeliaSim Remote API and the URInterface.
- Step 4 is case-specific; be sure the simulation or real robotic platform is running and enabled for remote connection based on the communication interface provided in Step 3. Refer to the examples provided in UR5e/UR3e/MobileRobot for further guidance.
- Step 5 is defined in the
co-simulation/multimodel.json
file (co-simulation template) for the co-simulation and the distinctModelDescription.xml
files for each FMU. Use the feature 1 oftemplates/helper.py
to get the connections between FMUs. The features 2, 4, and 11 also help to set up theModelDescription.xml
files that are used for the FMUs used in the co-simulation. For exemplification, refer to co-simulation UR5e to see the implementation of the co-simulation for the UR5e. - Steps 6 and 7 are provided in the mapping FMU template. Use the features 2 and 3 of the
templates/helper.py
to set up the platform mapping FMU. When everything is done, use the provided scripttemplates/steps6-7_mappingFMU/wrap_fmu.sh
to wrap the platform mapping FMU with extension.fmu
, including the worked-out Step 3. For exemplification, refer to mapping FMU UR5e to see the instantiation of the mapping FMU template for the UR5e. - Step 8 is provided in the d-model FMU template. Adapt the automatically generated C code in the
templates/steps8-11_dmodelFMU/adapted_C
folder using the guidance provided to adapt themain.c
file. Update theModelDescription.xml
file using the feature 4 of thetemplates/helper.py
. For exemplification, refer to d-model FMU to see the instantiation of the d-model FMU template for the UR5e. - Step 9 is provided in the defs_fmi.h template. Use the feature 5 of the
templates/helper.py
to update the data struct. - Step 10 is provided in the interface.h template. Use the features 6 and 7 of the
templates/helper.py
to update the behavior of theinterface.h
based on your data. - Step 11 is provided in the d-model FMU template. Adapt the
skeleton.c
using the feature 8 of thetemplates/helper.py
and themain.c
using the feature 9 of thetemplates/helper.py
. Be sure to have the modified structure in yourmain.c
so the program is started using theinit
and called using thetick
function. - Steps 12 and 13 are provided in the templates for the controller and RabbitMQ FMU. The logic is to be stored in the
templates/steps12-13_controller/controllerFMU/resources/model.py
(see here) for the controller FMU (use the feature 10 of thetemplates/helper.py
to set up themodel.py
of the controller FMU) and in thetemplates/steps12-13_controller/publisher_rmq.py
(see here) for the RabbitMQ FMU. Use the feature 11 of thetemplates/helper.py
to set up theModelDescription.xml
files of the controller FMU and the RabbitMQ FMU (Note: RabbitMQ FMU requires that theModelDescription.xml
file is also stored in its resources folderrmqfmu/resources/
). For exemplification, refer to controller UR5e to see the instantiation of the controller FMU and RabbitMQ FMU templates for the UR5e.
After these steps have been worked out, the co-simulation can be executed using the script templates/step5_co-simulation/cosimulation_execution.sh
. For exemplification, refer to co-simulation UR5e to see the implementation of the co-simulation for the UR5e.
The execution of the resulting co-simulation artifacts can also be done through the TwinManager. See the UR5e implementation with the TwinManager.
The artifacts of this co-simulation framework have been extended to support FMI3. The underlying technologies use beta versions, therefore, expect to encounter some bugs when running FMI3 co-simulations. The artifacts are available for the UR5e example. More information is in the fmi3 folder.
(preprint) When citing the tool, please cite the following paper:
GIL, SANTIAGO and Badyal, Arjun and Miyazawa, Alvaro and Larsen, Peter Gorm and Cavalcanti, Ana, A Model-Based Approach for Co-Simulation-Driven Digital Twins in Robotics. Available at SSRN: https://ssrn.com/abstract=5050127 or http://dx.doi.org/10.2139/ssrn.5050127
Bibtex:
@article{Gil_robotics2024,
author = {Gil, Santiago and Badyal, Arjun and Miyazawa, Alvaro and Larsen, Peter Gorm and Cavalcanti, Ana},
title = {A Model-Based Approach for Co-Simulation-Driven Digital Twins in Robotics},
year = {2024},
doi = {10.2139/ssrn.5050127},
url = {http://dx.doi.org/10.2139/ssrn.5050127}
}