• Stars
    star
    348
  • Rank 121,840 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unreal Engine Plugin to enable ROS Support

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.

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:

@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}
}

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 like MyUnrealProject/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 ROSIntegrationGameInstance in 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

    Create a new GameInstance

  • Open your new C++ class / Blueprint object and change the values of ROSBridgeSeverHost and ROSBridgeServerPort

    Change host and port to match your server

  • Open Project Settings > Maps and Modes, and set the GameInstance to match your new GameInstance object, not ROSIntegrationGameInstance

    Change host and port to match your server

  • 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 Plugins directory 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("std_msgs/String"));

// (Optional) Advertise the topic
ExampleTopic->Advertise();

// Publish a string to the topic
TSharedPtr<ROSMessages::std_msgs::String> StringMessage(new ROSMessages::std_msgs::String("This is an example"));
ExampleTopic->Publish(StringMessage);

C++ Topic Subscribe Example

#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("std_msgs/String"));

// Create a std::function callback object
std::function<void(TSharedPtr<FROSBaseMsg>)> SubscribeCallback = [](TSharedPtr<FROSBaseMsg> msg) -> void
{
    auto Concrete = StaticCastSharedPtr<ROSMessages::std_msgs::String>(msg);
    if (Concrete.IsValid())
    {
        UE_LOG(LogTemp, Log, TEXT("Incoming string was: %s"), (*(Concrete->_Data)));
    }
    return;
};

// Subscribe to the topic
ExampleTopic->Subscribe(SubscribeCallback);

Blueprint Topic Subscribe Example

  • Create a Blueprint based on Topic class.
  • Subscribe to a topic.
  • Define what happens when a message arrives.

Create Blueprint based on Topic class

  • Open Level Bluprint or any other you want to use the topic in.
  • Instantiate the blueprint via Construct Object from Class with a meaningful outer to define its lifetime and affiliation.

Use the bluprint topic instance

C++ Service Request example

@tsender provided some documentation on this topic here: #134 (comment)

Supported Message Types

Topic Message Type ROS to UE4 UE4 to ROS
std_msgs/Header āœ“ āœ“
std_msgs/String āœ“ āœ“
std_msgs/Bool āœ“ āœ“
std_msgs/Float32 āœ“ āœ“
std_msgs/Float32MultiArray āœ“ āœ“
std_msgs/MultiArrayDimension āœ“ āœ“
std_msgs/MultiArrayLayout āœ“ āœ“
std_msgs/UInt8MultiArray āœ“ āœ“
tf2_msgs/TFMessage āœ˜ āœ“
geometry_msgs/Point āœ“ āœ“
geometry_msgs/Pose āœ“ āœ“
geometry_msgs/PoseStamped āœ“ āœ“
geometry_msgs/PoseWithCovariance āœ“ āœ“
geometry_msgs/Quaternion āœ“ āœ“
geometry_msgs/Transform āœ“ āœ“
geometry_msgs/TransformStamped āœ“ āœ“
geometry_msgs/Twist āœ“ āœ“
geometry_msgs/TwistStamped āœ“ āœ“
geometry_msgs/TwistWithCovariance āœ“ āœ“
geometry_msgs/Vector3 āœ“ āœ“
grid_map_msgs/GridMap āœ“ āœ“
grid_map_msgs/GridMapInfo āœ“ āœ“
nav_msgs/Odometry āœ“ āœ“
nav_msgs/Path āœ“ āœ“
rosgraph_msgs/Clock āœ“ āœ“
sensor_msgs/CameraInfo āœ˜ āœ“
sensor_msgs/Image āœ“ āœ“
sensor_msgs/Imu āœ“ āœ“
sensor_msgs/JointState āœ“ āœ“
sensor_msgs/NavSatFix āœ“ āœ“
sensor_msgs/NavSatStatus āœ“ āœ“
sensor_msgs/PointCloud2 āœ“ āœ“
sensor_msgs/RegionOfInterest āœ“ āœ“
sensor_msgs/LaserScan āœ“ āœ“
actionlib_msgs/GoalID āœ“ āœ“
actionlib_msgs/GoalStatus āœ“ āœ“
actionlib_msgs/GoalStatusArray āœ“ āœ“
Service Message Type ROS to UE4 UE4 to ROS
rospy_tutorials/AddTwoIntsRequest āœ“ āœ“
rospy_tutorials/AddTwoIntsResponse āœ“ āœ“

Implementing New Message Types

To be able to send and receive message types with ROSIntegration we need two things: the message definition, as well as a converter of the data in that definition from and to BSON. For reference how to do that look into the message definitions in Source\ROSIntegration\Public, and the converters in Source\ROSIntegration\Private\Conversion\Messages. To avoid any memory leaks, please follow the same steps as done in this repo when implementing your overriden ConvertOutgoingMessage(TSharedPtr<FROSBaseMsg> BaseMsg, bson_t** message). It is also recommended that you make your custom converters user-friendly by creating helper functions like _bson_append_child_msg(...) and _bson_append_msg(...) as you see in most of our message converter header files. If you do create such helper functions, follow our convention to avoid any memory leaks.

If you need one of the standard message types provided by ROS, you should implement them inside the ROSIntegration's folder structure. Please keep to the naming convention of the ROS documentation for the message definition. If you want to implement your own messages you can do that in your own project. You only need to add something like the following to the Build.cs-file of your project:

string rosintegrationPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "../../Plugins/ROSIntegration/Source/ROSIntegration/Private"));
PrivateIncludePaths.AddRange(
    new string[] {
        rosintegrationPath,
        rosintegrationPath + "/rosbridge2cpp"
    }
);

Then you can create the message definition and the converter in your own projects source tree. You can just copy and paste the files of a similar standard message, but don't forget to replace the ROSINTEGRATION_API with your own API macro created by Unreal.

Overriding the rosbridge Connection Settings from Within the Level

You can now add a ROSBridgeParamOverride actor to a level, allowing you to use different rosbridge connection settings for that level only (compared to what is defined in the ROSIntegrationGameInstance settings).

When might this be useful? Say you have a powerful enough computer that can handle multiple independent UE4 simulations at the same time, and you want to run as many simulations as possible to collect data effeciently (perhaps you are training a reinforcement learning algorithm). If you create copies of your main level (saved with different names) and use different ROS topic names within each level, then you can launch each level in a new UE4 editor on the same computer. If using a single rosbridge node for all of these UE4 instances results in considerable delays, then you can then add the ROSBridgeParamOverride actor to each level so that each level uses its own rosbridge node.

FAQ

  • Question: My Topic/Service gets closed/unadvertised or my UE4 crashes around one minute after Begin Play. Answer: This might be a problem relating to the Garbage Collection of UE4. Please make sure that you declare your class member attributes as UPROPERTYs. See also: #32

More Repositories

1

iai_kinect2

Tools for using the Kinect One (Kinect v2) in ROS
C++
875
star
2

ROSIntegrationVision

Support for ROS-enabled RGBD data acquisition in Unreal Engine Projects
C++
62
star
3

pico_flexx_driver

ROS driver for the pmd CamBoard pico flexx
C++
50
star
4

snap_map_icp

Module for relocalizing a ROS-enabled robot based on it's base laser readings and matching them with the currently advertised /map topic.
C++
23
star
5

ros_emacs_utils

Emacs tools for ROS
Common Lisp
17
star
6

asimov

ROS Clojure Repository
Clojure
14
star
7

iai_maps

The semantic and ground lab and environment maps for projects in the IAI group in the University of Bremen
CMake
12
star
8

iai_robots

Repo holding descriptions and launch-files for robots in the iai lab.
CMake
10
star
9

knowrob_dev

Private development repository for the KnowRob knowledge base
Java
5
star
10

robot_scenarios_sim

Simulated Robot Scenarios for Testing various Robot Activities
Prolog
5
star
11

roslisp_tutorials

Common Lisp
4
star
12

knowrob_webtools

Collection of open-source modules and tools for building web-based robot apps based on the robot web tools (http://robotwebtools.org/)
JavaScript
4
star
13

unreal_interface

ROS package is intended to provide a low-level interface to interact with a UE4 world
C++
3
star
14

rosjava_jni

TBD
Java
3
star
15

iai_common_msgs

Holds various ROS message definitions used by the IAI group, UniversitƤt Bremen.
CMake
3
star
16

semrec

Semantic Hierarchy Recorder for (autonomous) hierarchical experiment data that is semantically annotated
C++
3
star
17

lisp_course_material

Emacs Lisp
2
star
18

ias_perception

Perception modules developed in the IAS group at TUM
C++
2
star
19

ConvertMeshToFBX

Python
2
star
20

rviz_plugin_moveit_collisionmap

RViz display plugin for moveit_msgs::CollisionMap messages
C++
2
star
21

UE4Bson

C
2
star
22

kiba_tutorials

C++
2
star
23

iai_gazebo_pkgs

Various gazebo plugins and configurations created by the IAI group, University Bremen, Germany.
C++
2
star
24

turtlebot_roomba

Launch files and drivers for using the turtlebot 1 robot with a Roomba 5xx base instead of an iRobot create.
Python
2
star
25

unreal_vision_bridge

Unreal to ROS bridge for UnrealVision / URoboVision
C++
2
star
26

longterm_fetch_and_place

Longterm Fetch and Place scenario
Common Lisp
2
star
27

UnrealUrdfExporter

C++
2
star
28

ias_perception_aux

Auxiliary packages for the ias_perception stack, containing perception modules developed by the IAS group at TUM
C++
2
star
29

iai_cad_tools

Tools for interacting with the IAI CAD model repository
Python
2
star
30

iai_table_robot_description

DEPRECATED: URDF description of the table-mounted UR5 robots in the lab of the IAI.
CMake
2
star
31

iai_control_pkgs

Collection of various robot control packages, written/maintained by the iai group at Universitaet Bremen.
C++
2
star
32

UnrealInterfaceObjectPlugin

Functionality specific to the unreal_interface ROS package
C++
1
star
33

iai-grasping-type-inference

Python
1
star
34

openEASE-flask

JavaScript
1
star
35

robot_wrist_ft_tools

Tools for dealing with force-torque sensors installed at robot wrists
Python
1
star
36

iai_tiago

CMake
1
star
37

iai_manual_tool_calib

A ROS utility to manually calibrate a tool with respect to the end-effector of a robot.
Python
1
star
38

iai_pr2

Installation, configuration, and launch files specific to IAI's PR2 robot.
Common Lisp
1
star
39

iai_photo

ROS Package for capturing images from a camera using llibgphoto2
C++
1
star
40

iai_shapelets

Python
1
star
41

iai_kmr_iiwa

Python
1
star
42

shopping_scenario

Shopping Scenario related repositories, holding code, models, and executives
Common Lisp
1
star
43

topic_relay

Tool for relaying information for specific topics between two different ROS masters
C++
1
star
44

narrative2vec

Python
1
star
45

UnrealApartment

1
star
46

saphari_final_review

Configurations, launch files, and source code for the final SAPHARI review.
Common Lisp
1
star
47

UAivatar

Avatar's Plugin for UE4
C++
1
star
48

iai_naive_kinematics_sim

naive, lightweight, and ROS-based robot kinematics simulation
C++
1
star
49

omni_teleop

Utility to teleoperator an omni-directional base in ROS.
C++
1
star
50

iai_perception

C++
1
star
51

iai_robot_drivers

Various robot driver packages forked and maintained by the IAI group, University Bremen, Germany.
C++
1
star
52

designator_integration

C++ and Lisp code for integrating designator communication (mainly serialization/deserialization) via ROS messages. Depends on designator_integration_msgs found in iai_common_msgs.
C++
1
star
53

grasping-learning-data-generator

Python
1
star
54

omni_pose_follower

Offers FollowJointTrajectoryAction and sends vel twist commands for an omni directional robot base
Python
1
star