-
Notifications
You must be signed in to change notification settings - Fork 395
User_App_ROS_UnitySimulationExample
2.3 Unity Simulation Example
Note: This tutorial assumes that you have completed the previous tutorials:
- 1.1 Unity3D on Windows
- 1.2 Ubuntu on Oracle VM
- 1.3 ROS on Ubuntu
- 1.5 TurtleBot2
- 2.1 Importing a URDF from ROS
This application of ROS# illustrates the communication between Unity and ROS in which the real time simulation takes place in Unity. The following figure illustrates the general schema of the application.

The control signals are sent from ROS to Unity. Consequently, the outcomes of Unity are captured by ROS to illustrate them using rviz as an example.
-
/sensor_msgs/joy -
/odom -
/joint_states -
/unity_image/compressed
The movement of the mouse cursor in Ubuntu is used to control the TurtleBot2 in Unity. Therefore, the ROS node mouse_to_joy.py maps the movement of the mouse cursor to messages of the type sensor_msgs/joy. These are sent to the rosbridge_websocket to be captured by Unity.
In Unity the robot will move according to the captured movement of the mouse cursor in Ubuntu and the topics /odom, /joint_states and /unity_image/compressed are published for further processing using ROS#.
- Make sure that you followed this tutorial. You should already have imported the URDF model to Unity.
- Import the Unity scene
UnitySimulationScene.unityfrom here and the required Unity scene will be complete and ready to use. - OR: Create the Unity scene from scratch by reproducing the following steps shown in this video to learn more about particular components and how they interact.
- Make sure that you followed this tutorial.
- Place the folder
unity_simulation_scene(from here) inside thesrcfolder of your workspace and rebuild your workspace. - Run the following command in your terminal:
$ roslaunch unity_simulation_scene unity_simulation_scene.launch
This will launch rosbridge_websocket, file_server, mouse_to_joy and rqt_graph.
As soon as all ROS nodes are launched, the robot in Unity is ready to move.
- When the
Playbutton in pressed and the mouse cursor in Ubuntu is moved the TurtleBot2 will move in Unity. - After clicking the refresh button in the
rqt_graph, a network similar to the following figure appears:
It can be seen here that the topic/joyis published by the ROS nodemouse_to_joyand it is sent to Unity usingrosbridge_websocket.
The topics /odom, /joint_states and /unity_image/compressed are published by Unity using ROS# for further processing.
This and the whole process of preparation and execution is demonstrated in this video.
© Siemens AG, 2017-2018 Author: Verena Röhrl (verena.roehrl@siemens.com)
-
- 1.3.1 R2D2 Setup
- 1.3.2 Gazebo Setup on VM
- 1.3.3 TurtleBot Setup (Optional for ROS2)
- 2.1 Quick Start
- 2.2 Transfer a URDF from ROS to Unity
- 2.3 Transfer a URDF from Unity to ROS
- 2.4 Unity Simulation Scene Example
- 2.5 Gazebo Simulation Scene Example
- 2.6 Fibonacci Action Client
- 2.7 Fibonacci Action Server
- 3.1 Import a URDF on Windows
- 3.2 Create, Modify and Export a URDF Model
- 3.3 Animate a Robot Model in Unity
- 4.1 Introduction to RosBridgeClient
- 4.2 Image Publication
- 4.3 URDF Transfer
- 4.4 Fibonacci Action Client/Server
- Message Handling: Readers & Writers
- Thread Safety for Message Reception
- File Server Package
- ROS-Unity Coordinate System Conversions
- Post Build Events
- Preprocessor Directives in ROS#
- Adding New Message Types
- RosBridgeClient Protocols
- RosBridgeClient Serializers
- Actions in ROS#
- Action Server State Machine Model
© Siemens AG, 2017-2025