ROSIntegration
Unreal Engine Plugin to enable ROS Support
Install / Use
/learn @code-iai/ROSIntegrationREADME
ROSIntegration Plugin for Unreal Engine 4
This plugin adds ROS support to your Unreal Engine Project. It is designed to be used on different common platforms. Currently, Windows and Linux are directly supported.
The connection to the ROS world will be accomplished through http://wiki.ros.org/rosbridge_suite and https://github.com/sanic/rosbridge2cpp
This plugin is currently mainly maintained for Unreal Engine 4. Even though functionality might work under UE5, we see UE4 as a first class citizen on our master branch.
Description
This Plugin contains the basic data structures to enable the user to communicate with a running roscore. Currently, ROS Topics and ROS Services are supported.
To boost the performance for big messages (Image Streams for example), this plugin utilizes http://bsonspec.org/ to transfer binary data in a compact manner.
The core communication library behind this plugin is https://github.com/sanic/rosbridge2cpp, which allows the core communication capabilities to be developed, tested and improved by people who are not necessarily using it with Unreal Engine.
ROS Functionality can be added to UObjects or AActors by using functions like Advertise/Subscribe/Publish on the ROS Wrapper classes or in the form specific Unreal ActorComponents. This currently includes an ActorComponent that can be added to AActors to easily publish their coordinates to TF. If you need Vision Support in your Unreal Project, you can also add the ROSIntegrationVision Plugin (https://github.com/code-iai/ROSIntegrationVision/) which is compatible with this Plugin.
Communication with ROS is achieved by communicating with rosbridge_suite (Unreal Engine <--> rosbridge <--> ROS Nodes). This plugin supports using both TCP and websocket protocols to communicate with rosbridge. The plugin also supports both ROS1 and ROS2 connections.
Citations
If you are using this Plugin in an academic context and you want to cite us, we would be happy if you could use the following reference:
<pre> @inproceedings{mania19scenarios, title = {A Framework for Self-Training Perceptual Agents in Simulated Photorealistic Environments}, author = {Patrick Mania and Michael Beetz}, year = {2019}, booktitle = {International Conference on Robotics and Automation (ICRA)}, address = {Montreal, Canada} } </pre>Dependencies of this Plugin
This Plugin utilizes BSON to achieve higher transferrates for binary data. It uses http://mongoc.org/libbson/ to encode and decode the whole ROS communication protocol. Since BSON is not included in Unreal Engine (yet), its code has to be added to this plugin. Currently, this plugin comes with a pre-compiled libbson for Windows x64 and Linux x64 which doesn't need any additional configuration.
To enable the communcation between Unreal and ROS, you will need a running ROSBridge (https://github.com/RobotWebTools/rosbridge_suite) with bson_mode. Note: Please use rosbridge with version=>0.8.0 to get full BSON support.
The recommended way to install rosbridge is from source (requires the rosauth package):
sudo apt-get install ros-ROS1_DISTRO-rosauth # Replace ROS1_DISTRO with the distro you are using
cd ~/ros_workspace/
source devel/setup.bash
cd src/
git clone -b ros1 https://github.com/RobotWebTools/rosbridge_suite.git
cd ..
catkin_make
source devel/setup.bash
Even though you could install rosbridge using apt via:
sudo apt-get install ros-ROS1_DISTRO-rosbridge-suite # Replace ROS1_DISTRO with the distro you are using
there have been numersous issues where these apt packages do not reflect the code in the ros1 branch. Hence, it is best to install from source. After installing rosbridge, you can enable the bson_mode like this:
roslaunch rosbridge_server rosbridge_tcp.launch bson_only_mode:=True
How to verify the rosbridge-UE4 connection: Make sure UE4 is configured to use the ROSIntegrationGameInstance (see below) and set the connection parameters. If UE4 and rosbridge are both running, then you should see the rosbridge node subscribe to two topics with the prefix /unreal_ros/. If you do NOT see this, then you likely have a problem with your rosbridge installation.
In our testing, we usually installed rosbridge on a Ubuntu Linux with ROS while the UE4 with ROSIntegration can be run on a Windows or Linux hosts. ROSBridge and UE4 with ROSIntegration don't need to be run on the same machine. So in order to run UE4 with ROSIntegration on Windows, you can either install a Linux Virtual Machine on your Windows Hosts or have a seperate, physical machine with Linux running in your network.
This plugin has previously been tested with Unreal Engine versions;
- 4.17.3
- 4.18.2
- 4.18.3
- 4.19.1, 4.19.2
- 4.20.3
- 4.23 (by Luigi Freda, fixed bugs with smart pointer management)
- 4.24
- 4.25
- 4.26
Please note that this list is a tracker of which UE4 versions have been previously tested. It is not guaranteed that the most recent version of ROSIntegration is working with all previous UE4 versions.
Usage
Setting up the plugin
-
Create a new C++ Unreal Project, or open your existing project. Please note that the Plugin might not get compiled automatically in BP-only Projects (see this Issue).
-
Add this repository to your
Plugins/Folder in your Unreal project (copy the folder in so your structure looks likeMyUnrealProject/Plugins/ROSIntegration/ROSIntegration.uplugin -
Activate the Plugin in your UE4 project by opening your project and go to Edit -> Plugins. Search for ROSIntegration in the "other" section and activate it.
-
Restart the editor and check that the code for the new plugin is built.
-
To specify your ROSBridge server, you have to create a custom GameInstance that inherits from
ROSIntegrationGameInstance -
Find
ROSIntegrationGameInstancein the Content browser (you might need to enable 'View Options' > 'Show Plugin Content' in the bottom right of the content browser). -
Right click and create a new C++ or Blueprint class based on
ROSIntegrationGameInstance
-
Open your new C++ class / Blueprint object and configure the rosbridge connection properties:
ROSBridgeServerProtocol: The communication protocol to use with rosbridge. Options are "tcp" or "ws".ROSBridgeServerHosts: A list of rosbridge server IP addresses. Each element pairs with the corresponding element inROSBridgeServerPorts.- Note 1: In an older version, this was just a single value
ROSBridgeServerHost. Now, you can connect to any number of rosbridge servers. - Note 2: If the number of elements in this array differs from the length of
ROSBridgeServerPorts, then the unpaired elements will be skipped. And if you remove all entries in this array, then the plugin will use a default value of "127.0.0.1".
- Note 1: In an older version, this was just a single value
ROSBridgeServerPortsA list of rosbridge server ports. Each element pairs with the corresponding element inROSBridgeServerHosts.- Note 1: In an older version, this was just a single value
ROSBridgeServerPort. Now, you can connect to any number of rosbridge servers. - Note 2: If the number of elements in this array differs from the length of
ROSBridgeServerHosts, then the unpaired elements will be skipped. And if you remove all entries in this array, then the plugin will use a default value of 9090.
- Note 1: In an older version, this was just a single value
ROSVersion: Indicate the ROS version that you are using. Only options are 1 or 2.
-
Open Project Settings > Maps and Modes, and set the GameInstance to match your new GameInstance object, not
ROSIntegrationGameInstance
-
Don't forget to save everything (Ctrl + Shift + S)
-
In some cases (for example on Linux), it might be necessary to call the Generate Project Files action on UE4 in order to fetch the new header files for the plugin. Reference: https://wiki.unrealengine.com/Generate_Visual_Studio_Project or https://wiki.unrealengine.com/Building_On_Linux#Generating_project_files_for_your_project
Build
- Run the following:
[Run UAT script] BuildPlugin -Plugin="[FULL PATH]/ROSIntegration.uplugin" -TargetPlatform=[Platform] -Package="[Desired Location]" -Rocket
UE may create a HostProject for the plugin, in which case, you'll find the plugin built inside HostProject/Plugins
- Link to
Pluginsdirectory of your project - Add plugin to
build.cs
[Public/Private]DependencyModuleNames.AddRange(new string[] { "ROSIntegration" });
- Add plugin to
uproject(may be performed via Editor GUI as well)
"Plugins": [
{
"Name": "ROSIntegration",
"Enabled": true
}
]
C++ Topic Publish Example
To get started, you can create a new C++ Actor and let it publish a message once at the BeginPlay Event. Add the following code into the BeginPlay() method of any actor that is put into to your world to see if the connection to ROS works:
#include "ROSIntegration/Classes/RI/Topic.h"
#include "ROSIntegration/Classes/ROSIntegrationGameInstance.h"
#include "ROSIntegration/Public/std_msgs/String.h"
// Initialize a topic
UTopic *ExampleTopic = NewObject<UTopic>(UTopic::StaticClass());
UROSIntegrationGameInstance* rosinst = Cast<UROSIntegrationGameInstance>(GetGameInstance());
ExampleTopic->Init(rosinst->ROSIntegrationCore, TEXT("/example_topic"), TEXT(
