-
Notifications
You must be signed in to change notification settings - Fork 373
User_App_ROS_UnitySimulationExample
Note: This tutorial assumes that you have completed tutorials:
ROS2 Humble - R2D2
Follow along with our tutorial video on YouTube for the complete tutorial.
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.
-
/joy
-
/odom
-
/joint_states
-
/camera/compressed
The movement of the mouse cursor in Ubuntu is used to control the R2D2 in Unity. Therefore, the ROS node mouse_to_joy2.py
maps the movement of the mouse cursor position in the respective window 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 and the topics /odom
, /joint_states
and /camera/compressed
are published for further processing using ROS#.
- Use
Unity Simulation Scene for ROS2
importable sample from Unity Package Manager to start. Although covered in the video, please note that meshes and textures of the robot are not included in this Unity project. Instead please import them yourself as described in Transfer URDF From ROS.
- Run the following command in your terminal:
# ROS2 Humble
ros2 launch unity_simulation_scene2 unity_simulation_scene.launch.py
This will launch rosbridge_websocket
, file_server2
(see File Server Package), mouse_to_joy2
.
As soon as all ROS nodes are launched, the robot in Unity is ready to move.
- When the
Play
button is pressed and the mouse cursor in Ubuntu is moved the R2D2 will move in Unity.
The topics /odom
, /joint_states
and /camera/compressed
are published by Unity using ROS# for further processing.
This and the whole process of preparation and execution is demonstrated in the video mentioned above.
ROS1 Noetic - TurtleBot2
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 TurtleBot 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#.
- Compose the Unity scene
UnitySimulationScene
by following this video for ROS1 Noetic. - You can use
Unity Simulation Scene
example for reference. Please note that meshes and textures of the robot are not included in this Unity project. Instead please import them yourself as described in Transfer URDF From ROS.
- Run the following command in your terminal:
# ROS1 Noetic
roslaunch unity_simulation_scene unity_simulation_scene.launch
This will launch rosbridge_websocket
, file_server
(see File Server Package), mouse_to_joy
and rqt_graph
.
As soon as all ROS nodes are launched, the robot in Unity is ready to move.
- When the
Play
button is pressed and the mouse cursor in Ubuntu is moved the TurtleBot will move in Unity. - After clicking the refresh button in the
rqt_graph
, a network similar to the following figure appears:
Above you can see that the topic/joy
is published by the ROS nodemouse_to_joy
and 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 the video mentioned above.
Next tutorial: Application examples without ROS communication
© Siemens AG, 2017-2024
-
- 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
- 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
- Action Server State Machine Model
© Siemens AG, 2017-2024