Skip to content

ROS2

ROS2 for unity

Ros2ForUnity (R2FU) module is a communication solution that effectively connects Unity and the ROS2 ecosystem, maintaining a strong integration. Unlike other solutions, it doesn't rely on bridging communication but rather utilizes the ROS2 middleware stack (specifically the rcl layer and below), enabling the inclusion of ROS2 nodes within Unity simulations.

R2FU is used in AWSIM for many reasons. First of all, because it offers high-performance integration between Unity and ROS2, with improved throughput and lower latencies compared to bridging solutions. It provides real ROS2 functionality for simulation entities in Unity, supports standard and custom messages, and includes convenient abstractions and tools, all wrapped as a Unity asset. For a detailed description, please see README.

Warning

To avoid internal conflicts between the standalone libraries, and sourced ones, ROS2 instance shouldn't be sourced before running AWSIM or the Unity Editor.

Can't see topics

There are no errors but I can't see topics published by R2FU

  • Make sure your DDS (Localhost settings) config is correct.
  • Sometimes ROS2 daemon brakes up when changing network interfaces or ROS2 version.

Try to stop it forcefully (pkill -9 ros2_daemon) and restart (ros2 daemon start).

Awsim ROS2 node

AwsimRos2Node static class is a ROS2 node that can be commonly used in AWSIM. The design of AwsimRos2Node provides the following advantages.

  • Time sources used in ROS2 can be centrally managed, modified, and reflected.
  • A single node can be used to aggregate topics to be Pub/Subbed in AWSIM.
  • Ability to add and delete pub/subs on topics and services and retrieve times.

ROS2 node name and time source can be specified at initialization.

AwsimRos2Node.Initialize("AWSIM", TimeSourceType.Ros2);

Clock

ClockRos2Publisher allows the publication of the simulation time from the clock operating within AWSIM. The current time is retrived from a TimeSource object via the AwsimRos2Node. The AWSIM provides convenient method for selecting the appropriate time source type as well as the flexibility to implement custom TimeSources tailored to specific user requirements.

Timesource

List of Time Sources

Type TimeSouceType enum value Driven by Start Value Affected by Time Scale Remarks
Unity 0 UnityEngine.Time 0 yes
External 1 externally depends on external source no used by the scenario simulator v2
DotnetSystem 2 System.DateTime UNIX epoch yes starts with UNIX epoch time and progresses with System.DateTime scaled by AWSIM time scale
DotnetSimulation 3 System.DateTime 0 yes starts with zero value and progresses with System.DateTime scaled by AWSIM time scale
Ros2 4 ROS2.Clock UNIX epoch (by default) no uses ROS 2 time


Default message types

The basic ROS2 msgs types that are supported in AWSIM by default include:

In order for the message package to be used in Unity, its *.dll and *.so libraries must be generated using R2FU.

Custom message

If you want to generate a custom message to allow it to be used in AWSIM please read this tutorial.