Note
Prerequisites – The following is required for this tutorial
- The performance of Unity as a simulatorin the ROS environment should be tested in this thesis work. While testing the performance of the simulator, its ability to adapt to different scenarios and applications should be rated. For that purpose, benchmarks were created.
- Getting a Unity Project with ROS2 support¶ Navigate to /UnityRos2/Assets and run python3 starteditor.py. This script sets environment variables and starts the Unity Editor. This is only way to start the Editor with ROS2 support at the moment. Opening the project through Unity Hub is not supported yet.
ROS# is a set of open source software libraries and tools in C# for communicating with ROS from. NET applications, in particular Unity. Here are some showcases illustrating what can be done with ROS#. Community provided a variety of other application examples for ROS# here. With the chosen setup, Unity showed systematic and nonsystematic errors in the end-position of predefined paths. A SLAM case study presented the possibility to use Unity in combination with SLAM algorithms on ROS. It was possible to implement other algorithms and simulate required sensors for data acquisition in Unity.
- Unity3D last stable version
- Docker and docker-compose
- ROS2 dependencies
- Сloned this repository unity_ros2.
The goal of this tutorial is to get the turtlebot3 sample scene up and running and to explore some of the features in unity_ros2.
Getting a Unity Project with ROS2 support¶
Navigate to ~/UnityRos2/Assets
and run python3start_editor.py
. This script sets environment variables and starts the Unity Editor. Don’t use sudo. This is only way to start the Editor with ROS2 support at the moment. Opening the project through Unity Hub is not supported yet.
Unity should now look similar to the image above. (Depending on your layout settings for Unity).Double click on Turtlebot3NavigationDemo located under Assets/Scenes
in the Project window.
Press the Play button to start the simulation.
If everything is working, there should be no error messages in the Console.
To teleop the turtlebot3 with your keyboard (wasd or arrows), navigate to Inspector window then click Add Component. Find Unity Input Teleop and select it. Then navigate to Game window and press navigation buttons.
If everything is fine TurtleBot3 must move.
Running navigation2 for turtlebot3¶
The easiest way (in my opinion…) to test the navigation2 stack with turtlebot3 and unity_ros2 is to use our precompiled docker image from DockerHub. Navigate to ~/UnityRos2/docker/turtlebot3_navigation
folder and run docker-composeup
command to start docker building. The first time it’s will take about an hour
Navigation2 stack starting automatically. You should eventually see something like this in the terminal window.
For next time to launch the container use docker-composeup--build
command.
Sending navigation goals from Unity¶
Ros Unity Linux
For send navigation2 goal position navigate to Inspector window then click Add Component. Find Move Base Goal Publisher and select it.
Now that everything is up and running, we should be able to send some navigation goals to the robot.Start by selecting a NavigationGoal in the Hierarch window in Unity, then enter some goal position and press Send Navigation Goal in the Inspector window.
That’s all for this tutorial. Good luck and have fun!
Challenge
The importance of simulation for the development of autonomous vehicles and other robots is well understood. As we were creating a simulation based on the Unity3D engine for one of our customers, our goal was to interface with ROS, a middleware and package library which offers a lot of added value for robotic projects. The vehicle automation that we were developing together was to run on ROS2 and it was our goal for the simulation to provide data at the same standard and to work with the same perception, location and path planning algorithms.
Unity Simulation
ROS and Unity3D don’t easily mix because the programming languages, key concepts and coordinate frames are all different. The problem was temporarily addressed by a third-party bridge, which connected both worlds through WebSockets. Apart from only working with the old version of ROS, the bridge had significant reliability and communication issues. Since our simulation involves multiple vehicles and high-resolution sensors, performance of communication is essential. The bridge was failing even with 20% of our minimal requirements and the issue was at the core of its design. We clearly needed something much better.
Solution
We have developed a high-performance communication module for Unity3D, based on our advanced fork of ROS2 C# client. The results not only met our expectations but exceeded them:
- The performance of communication increased by approximately 800 times!
- We were able to support all standard as well as custom messages with message generation.
- Our module is easily reusable between simulation projects.
Ask us for a demo.
Expertise fields
Unity Ros Robot
- Robotics, C++
- ROS2, CycloneDDS
- Simulation, Unity3D, C#
- AV automation