# DataBridge Plugin (CPP) One way to extend the 3D application functionality is to use data from other sources (sensors, cameras, IoT devices, etc.) to simulate changes in the 3D application environment or scenario, or send data generated by the 3D application to other applications. Sorry, your browser does not support embedded videos. Such changes make the simulation more credible and serve to fulfill a number of goals: | Interoperability | Integration of the 3D application with enterprise software, ML pipelines, robotics systems, or scientific tools | |---|---| | Real-Time Control | Control of the 3D environment by external logic (Python, REST). The ability to modify Variables on-the-fly. This can be useful for testing, debugging, or creating custom behaviors during flight. | | Data-Driven Visualization | Live visualization of remote data sources in the 3D application (e.g. IoT telemetry, simulation output) | | Rapid Prototyping | Engineers or researchers can tweak control logic in Python without rebuilding the entire 3D application | | Inspection and Monitoring | Users can inspect and monitor the current values of Variables in real-time, which helps them understand what values the simulator is using at any given moment. | | Filtering and Searching | Users can search for specific Variables and view their corresponding values, making it easier to understand which variables are relevant for a particular task (e.g., controlling a specific aircraft system). | | Scripting and Automation | Users can write custom scripts to automate interactions with the simulation environment. For example, users can set up a script that adjusts the aircraft�s speed or control surfaces based on specific conditions or triggers. | | Debugging and Development | Developers use the tool to debug aircraft models and plugins by ensuring that Variables are correctly set and manipulated during the simulation. | To address this scope of tasks and provide interaction based on the exchange of dynamic data that describes the state of the simulation, the *DataBridge* plugin was created. - The ***DataBridge*** plugin provides a simple universal API that allows establishing communication and exchanging data between the UNIGINE application and any client application over the network. - Data exchange is fast and secure, the communication between applications is performed over RUDP. - You can run multiple UNIGINE application instances and/or Python application instances and synchronize the values by name across them all. - In terms of *DataBridge*, the basic data exchange unit is Variable � a key-value pair that represents a particular piece of data, such as an aircraft's altitude, engine throttle setting, or current wind speed and direction. Variables can have different types � bool, int, float, string, blob. - Data is sent to the 3D application during runtime enabling it to work as part of a larger software ecosystem. ### See also - sample in [C++ SIM Samples](../../../sdk/api_samples/sim_cpp/index.md) set illustrating how to set up the interaction of a UNIGINE application with a Python script via *DataBridge* - sample in [C# SIM Samples](../../../sdk/api_samples/sim_cs/index.md) set illustrating how to set up the interaction of a UNIGINE application with a Python script via *DataBridge* Plugin - *[DataBridge Plugin](../../../api/library/plugins/databridge/index.md)* classes ## Use Cases Using *DataBridge*, you can run scientific calculations, machine learning models, or simulation control logic in a third-party application and feed the data to a UNIGINE application. Or you can use external Python scripts to control the mission logic in a robotics simulator running inside UNIGINE. The plugin�s areas of application include the following: - **Digital Twins** ![](../../../learn/01_introduction/digital_twins.jpg) - Python feeds real-time data from sensors into a 3D scene - UNIGINE visualizes changes in temperature, humidity, or machinery state - **VR Training Simulators** | ![](../../../learn/01_introduction/training3.jpg) | ![](../../../learn/01_introduction/training1.jpg) | |---|---| - C++/C#/Python/REST API controls training flow, scenarios, and tracks trainee performance - UNIGINE renders interactive training scenes - **Robotics & AI** | ![](../../../start/what_is_inside/path.png) | ![](../../../learn/01_introduction/ai_learning2.jpg) | |---|---| - Python for running AI agents (e.g., using PyTorch) - UNIGINE for simulating robot environments ## Using DataBridge Plugin A UNIGINE application with *DataBridge* acts as a server. Python scripts and/or applications (both C++ and C#, language doesn�t matter), which are called Clients, connect to this server. If you have several UNIGINE applications, identify which of them is going to be the host. It doesn't affect anything except it's being a server for all other connecting apps. Data exchange is performed via UNIGINE **RUDP** � Reliable User Data Protocol. The Client sends data to the Server, and the Server sends this data to all Clients. All packets are delivered to the recipient in the exact order they were sent. The more detailed information on addressing modes is provided [here](../../../code/plugins/syncker/index.md#addressing_modes). In addition to the RUDP-based data exchange, the DataBridge plugin can expose a lightweight **[HTTP](#http)** interface for reading and updating Variables at runtime (REST API). ### Launching DataBridge Plugin > **Notice:** DataBridge Plugin requires **Python 3.12+**. To **add the plugin to a new project**, start by [creating a project](../../../sdk/projects/index_cpp.md#creation) from a template. In the project creation dialog, open *Advanced Settings > Plugins*, enable the *DataBridge* plugin, click *Add*, then select *Create New Project*. ![](add_plugin.png) For **existing projects**, in the SDK Browser, open the *My Projects* tab, and click the three-dot menu on the project card. Select *Configure*, then click *Plugins*, enable the required plugin, click *Add*, and finish with *Configure Project*. ![](../../../sdk/projects/other_actions.png) To use *DataBridge Plugin*, specify the `extern_plugin` command line option on the application start-up: ```bash main_x64 -extern_plugin "UnigineDataBridge" ``` ### Accessing Plugin Methods In your UNIGINE application logic, get access to the plugin methods. Add the logic that processes the received data (variables). Two ways of interaction with API are available, you can select whichever is more convenient for you: | Traditional approach with explicit method calls and manual pointer management | Concise approach with references for cleaner syntax | |---|---| | ```cpp auto *manager = Plugins::DataBridge::Manager::get(); // 1. Set and get value using DataBridge::Manager variable full path // set new value to a variable, if variable doesn't exist it will be created manager->setVariableInt32("UNIGINE_TESTS/int", 1); // get Int value from manager by variable path "UNIGINE_TESTS/int" int ivalue = manager->getVariableInt32("UNIGINE_TESTS/int"); Log::message("UNIGINE_TESTS/int = %d\n", ivalue); // 2. Set and get value directly to variable // get variable from manager by path, if variable doesn't exist it will be created DBVariable *var = manager->getVariable("UNIGINE_TESTS/float"); // set new float value to variable var->setFloat32(15.0f); // get float value float fvalue = var->getFloat32(); Log::message("UNIGINE_TESTS/float = %f\n", var->getFloat32()); Log::message("fvalue = %f\n", fvalue); DBVariable *var_array = manager->getVariable("UNIGINE_TESTS/array"); for (int i = 0; i < 10; i++) { // add child or get already existing DBVariable *child = var_array->addChild(String::itoa(i)); child->setInt32(i); } for (int i = 0; i < var_array->getNumChildren(); i++) { DBVariable *child = var_array->getChild(i); int val = child->getInt32(); Log::message("Index %d Path: %s \t Value: %d\n", i, child->getPath().get(), val); }; ``` | ```cpp auto &DATA = *Plugins::DataBridge::Manager::get(); // 1. Set and get value using DataBridge::Manager variable full path // set new value to a variable, if variable doesn't exist it will be created DATA["UNIGINE_TESTS/int"] = 1; // get Int value from manager by variable path "UNIGINE_TESTS/int" // conversion operator to int will be called int ivalue = DATA["UNIGINE_TESTS/int"]; Log::message("UNIGINE_TESTS/int = %d\n", ivalue); // 2. Set and get value directly to variable // get variable from manager by path, if variable doesn't exist it will be created DBVariable &var = DATA["UNIGINE_TESTS/float"]; // set new float value to variable var = 15.0f; // get float value float fvalue = var; // here we need to use explicit conversion or getter with variable type Log::message("UNIGINE_TESTS/float = %f %f\n", static_cast(var), var.getFloat32()); Log::message("fvalue = %f\n", fvalue); DBVariable &var_array = DATA["UNIGINE_TESTS/array"]; for (int i = 0; i < 10; i++) { // get child or create if it doesn't exist yet DBVariable &child = var_array[String::itoa(i)]; child = i; } for (int i = 0; i < var_array.getNumChildren(); i++) { DBVariable &child = var_array[i]; int val = child; Log::message("Index %d Path: %s \t Value: %d\n", i, child.getPath().get(), val); }; ``` | ### Initializing the Network The network for *DataBridge* can be initialized in either of the following ways: - [Using startup arguments](#init_startup_arguments) - [Via configuration file](#init_config) - [In code](#init_code) #### Using Startup Arguments The network may be initialized using the startup arguments. | databridge_server | | |---|---| | **Description:** Initializes the *DataBridge* network. If this startup argument is not specified, the application is initialized as the Server by default. ```bash -databridge_server 1 ``` | **Arguments:** - ***1*** - initialize the application as the Server (by default) - ***0*** (or any other digit) - initialize the application as a Client | | addressing_mode | | | **Description:** Sets the [addressing mode](../../../code/plugins/syncker/index.md#addressing_modes) to be used by *DataBridge*. If not specified on startup, the network won't be initialized, and initialization via the configuration file will be required. ```bash -addressing_mode broadcast ``` | **Arguments:** - ***unicast*** - one-to-one addressing mode: hosts have different IP-addresses (some may be the same) and different ports (by default) - ***multicast*** - one-to-many addressing mode: hosts have different IP-addresses, but a single port - ***broadcast*** - one-to-all addressing mode: hosts have different IP-addresses, but a single port | | server_address | | | **Description:** Sets the address of the Server computer. If the key is not specified, *DataBridge* will try to determine the value automatically. ```bash -server_address "xxx.xxx.xxx.xxx" ``` | **Arguments:** Server's address in the *xxx.xxx.xxx.xxx* format | | multicast_address | | | **Description:** Sets a *multicast* address that is used by the *Server* computer to send messages to *Client* over the network. ```bash -multicast_address "xxx.xxx.xxx.xxx" ``` | **Arguments:** *Multicast* address in the *xxx.xxx.xxx.xxx* format `239.0.0.1` by default | | broadcast_address | | | **Description:** Sets a broadcast address of the *Server* computer that is used to broadcast messages to *Client* over the network. If the key is not specified, *DataBridge* shall try to determine the value automatically. ```bash -broadcast_address "xxx.xxx.xxx.xxx" ``` | **Arguments:** *Broadcast* address in the *xxx.xxx.xxx.xxx* format | | udp_port | | | **Description:** Sets the *UDP* port to be used to send and receive messages for *DataBridge*. ```bash -udp_port 8890 ``` | **Arguments:** *UDP* port number `8890` by default | | client_udp_port | | | **Description:** Sets a UDP port to be used by *Client*. 0 � means any unused port available. ```bash -client_udp_port 0 ``` | **Arguments:** *UDP* port number `0` by default | #### Via Configuration File To initialize the network via the configuration file, the path to the config should be specified in the start-up argument. For example: ```bash -extern_plugin UnigineDataBridge -databridge_config db_client.xml ``` Parameter names in the configuration file are identical to the start-up arguments. The `addressing_mode` parameter has the identical behavior: if it's incorrect or missing, the network won't be initialized. Here's an example configuration file for the Client: ```xml ``` > **Warning:** If the configuration file is not found by the specified way, the plugin will run without the network being initialized. #### Via Code To initialize the network via the API, add the following into your code: For Server: ```cpp Unigine::Plugins::DataBridge::Manager *manager = Plugins::DataBridge::Manager::get(); if (manager) { Unigine::Plugins::DataBridge::NetworkManager *network = manager->getNetworkManager(); if (network && !network->isInitialized()) { Unigine::Plugins::DataBridge::Server *server = network->initServerUnicast(1234); } } ``` For Client: ```cpp Unigine::Plugins::DataBridge::Manager *manager = Plugins::DataBridge::Manager::get(); if (manager) { Unigine::Plugins::DataBridge::NetworkManager *network = manager->getNetworkManager(); if (network && !network->isInitialized()) { Unigine::Plugins::DataBridge::Client *client = network->initClientUnicast(1234, 0); } } ``` ### HTTP REST API The DataBridge plugin can expose a lightweight HTTP interface for reading and updating Variables at runtime (REST API). This interface is primarily intended for configuration, debugging, and integration with external tools. An example illustrating how to obtain and change the DataBridge parameters via HTTP requests is accessible via the *Web Dash* button in the sample. #### Enabling the HTTP Server To start the HTTP server, use one of the following options: - Specify the port via a command-line argument when launching the application: ```text -databridge_http_port 8080 ``` You can use any available port. - Add an **http_port** entry to the [configuration file](#init_config), following the same pattern as other port settings. Here's an example configuration file for the Server: ```xml ``` #### Available Commands The following HTTP commands are supported: | **GET /get?path=** | Reads a Variable value by its **path**. Example: ```text GET /get?path=aircraft/altitude ``` | |---|---| | **GET /set?path=&value=[&type=]** | Writes a Variable value by its **path**. The **type** parameter is optional. - If the Variable does not exist, it is created with the **string** type. - If **type** is omitted, the server attempts to convert **value** to the current type of the Variable. - If **type** is provided and differs from the current Variable type, the Variable type may be overwritten. > **Warning:** This can break compatibility with clients that rely on the original type and may lead to unexpected behavior. Avoid changing types of existing Variables unless you fully control all clients and their expectations. Examples: ```text GET /set?path=weather/wind_speed&value=10.0 ``` ```text GET /set?path=weather/wind_dir&value=270&type=int ``` | | **GET /list** | Lists all available Variables. | ### DataBridge UI You can [enable the *DataBridgeUI*](../../../api/library/plugins/databridge/class.databridgeui_cpp.md) window to visualize the list of all variables available in your application along with their types and current values. ![](databridgeui.png)