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 pikaSome 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:
connectionsfield in thestep5_co-simulation/multimodel.jsonfile used by Maestro to set up the co-simulation given the FMUs and connections (see here). (Step 5 in the methodology)ModelDescription.xmlof the platform mapping FMU (see here). (Step 6 in the methodology)model.pyof the platform mapping FMU (see here). (Steps 6 and 7 in the methodology)ModelDescription.xmlof the d-model FMU (see here). (Step 8 in the methodology)ModelData structinsteps8-11_dmodelFMU/adapted_C/defs_fmi.hof the d-model FMU (see here). (Step 9 in the methodology)read_inputfunction in thesteps8-11_dmodelFMU/adapted_C/interface.hfile of the d-model FMU (see here). (Step 10 in the methodology)write_outputfunction in thesteps8-11_dmodelFMU/adapted_C/interface.hfile of the d-model FMU (see here). (Step 10 in the methodology)skeleton.cof the d-model FMU (see here). (Step 11 in the methodology)setStartValuesfunction in thesteps8-11_dmodelFMU/adapted_C/main.cfile of the d-model FMU (see here). (Step 11 in the methodology)model.pyof the controller FMU (see here). (Steps 12 and 13 in the methodology)ModelDescription.xmlof the controller FMU (also works for the outputs of the RabbitMQ FMU) (see here for the controllerFMU; RabbitMQ FMU requires the sameModelDescription.xmlin 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.jsonfile (co-simulation template) for the co-simulation and the distinctModelDescription.xmlfiles for each FMU. Use the feature 1 oftemplates/helper.pyto get the connections between FMUs. The features 2, 4, and 11 also help to set up theModelDescription.xmlfiles 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.pyto set up the platform mapping FMU. When everything is done, use the provided scripttemplates/steps6-7_mappingFMU/wrap_fmu.shto 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_Cfolder using the guidance provided to adapt themain.cfile. Update theModelDescription.xmlfile 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.pyto update the data struct. - Step 10 is provided in the interface.h template. Use the features 6 and 7 of the
templates/helper.pyto update the behavior of theinterface.hbased on your data. - Step 11 is provided in the d-model FMU template. Adapt the
skeleton.cusing the feature 8 of thetemplates/helper.pyand themain.cusing the feature 9 of thetemplates/helper.py. Be sure to have the modified structure in yourmain.cso the program is started using theinitand called using thetickfunction. - 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.pyto set up themodel.pyof 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.pyto set up theModelDescription.xmlfiles of the controller FMU and the RabbitMQ FMU (Note: RabbitMQ FMU requires that theModelDescription.xmlfile 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.
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," Robotics and Autonomous Systems, vol. 196, p. 105240, 2026. Available: https://www.sciencedirect.com/science/article/pii/S0921889025003379.
Bibtex:
@article{Gil&26,
title = {A model-based approach for co-simulation-driven digital twins in robotics},
journal = {Robotics and Autonomous Systems},
volume = {196},
pages = {105240},
year = {2026},
issn = {0921-8890},
doi = {10.1016/j.robot.2025.105240},
url = {https://www.sciencedirect.com/science/article/pii/S0921889025003379},
author = {Santiago Gil and Arjun Badyal and Alvaro Miyazawa and Peter Gorm Larsen and Ana Cavalcanti},
keywords = {Robotics, Co-simulation, Digital twin, Model-based engineering}
}