-
Notifications
You must be signed in to change notification settings - Fork 385
User_App_ROS_GazeboSimulationExample
2.2 Gazebo 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.4 Gazebo Setup on VM
- 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 Gazebo on the ROS side. The following figure illustrates the general schema of the application.
For simplicity, an existing Gazebo simulation is used to simulate the TurtleBot2 on the ROS side. The control signals are sent from Unity to ROS. Furthermore, the outcomes of ROS are captured by Unity for illustrative purposes.
-
/sensor_msgs/joy
-
/odom
-
/joint_states
-
/camera/rgb/image_raw/compressed
A joystick connected to Unity is used to control the TurtleBot2. Messages of the type /sensor_msgs/joy
are sent to the rosbridge_websocket
to be captured by ROS. The existing Gazebo simulation for TurtleBot2 requires messages of the type /geometry_msgs/twist
on the ROS side. Therefore, the captured /sensor_msgs/joy
messages are converted into /geometry_msgs/twist
messages. This is accomplished by the ROS node joy_to_twist
.
The Gazebo simulation publishes the topics /odom
, /joint_states
and /camera/rgb/image_raw/compressed
, which are captured by Unity using rosbridge_websocket
. Finally, the captured messages are linked to the URDF model in Unity.
- Import the Unity scene
GazeboSimulationScene.unity
from here and the required Unity scene will be complete and ready to use. - OR: Create the Unity scene from scratch by reproducing the steps shown in this video to learn more about particular components and how they interact.
- Make sure that you followed this tutorial. You should already have imported the URDF model to Unity.
- Make sure that you followed this and this tutorial.
- Place the folder
gazebo_simulation_scene
(from here) inside thesrc
folder of your workspace and rebuild your workspace. - In the directory
gazebo_simulation_scene/scripts
make the filejoy_to_twist.py
executable by running
chmod +x joy_to_twist.py
- Run the following command in your terminal:
$ roslaunch gazebo_simulation_scene gazebo_simulation_scene.launch
This will launch rosbridge_websocket
, file_server
, joy_to_twist
, rqt_graph
and a Gazebo simulation of the TurtleBot2 in the default turtlebot_world
As soon as all ROS nodes are launched, the robot in both simulations is ready to move.
- Make sure that the joystick is connected to Unity, which can be verified by checking the Unity console.
- When the
Play
button in pressed, the ROS terminal will show that a client has connected and subscribes to some topics:
[INFO] [1520503573.897354, 57.560000]: Client connected. 1 clients total.
[INFO] [1520503574.689767, 58.330000]: [Client 0] Subscribed to /camera/rgb/image_raw/compressed
[INFO] [1520503574.697262, 58.340000]: [Client 0] Subscribed to /joint_states
[INFO] [1520503574.736412, 58.380000]: [Client 0] Subscribed to /odom
- 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/sensor_msgs/joy
is published by Unity, whereas the topics/odom
,/joint_states
and/camera/rgb/image_raw/compressed
are subscribed by Unity usingrosbridge_websocket
. - Pressing the buttons of the controller will move the robot in Gazebo and in Unity. Furthermore, the camera image of the TurtleBot2 in Gazebo is projected onto a plane in Unity for illustrative purposes.
The whole process of preparation and execution can be seen in this video.
© Siemens AG, 2017-2018 Author: Verena Röhrl ([email protected])
-
- 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