Setting up the Unity Game Engine as a robotics simulator using Robot Operating System(ROS) and ROS#.
The Unity Game Engine is the world's most popular development platform for creating 2D and 3D multiplatform games.
The platform is known for the highly accurate PhysX Engine and also the great user interface.
These advantages can be used for setting up complex simulation environments fo robots. Robots can be extensively tested on a platform like Unity.
In this repository a simulation platform for robots was developed on the Unity Game Engine and essential features of a simulation environment were incorporated into the framework. A complete end to end framework of ROS and Unity was set-up to achieve this task.
This project sets up the motion of a simple differential drive robot in Unity and is controlled from the ROS side using teleoperation.
- Installation:
- ROS-Melodic
- Unity3D
- rosbridge webserver
- ROS#
- Communication between ROS and Unity is set-up using RosBridge webserver(on the ROS side) and Ros#(on the Unity side).
- Essential sensor data i.e. the pose of the bot in Unity is communicated to ROS and is published on a topic.
- Velocity commands on the cmd_vel topic are subscribed on the Unity side and a control script ensures traversal of the bot with accordance to the subscribed commands.
The set-up was done on a Ubuntu 18.04 system.
ROS-melodic and Unity 2019.4.7 version were used.
Rosbridge server facilitates communication on the ROS side. Simply using sudo-apt
sudo apt-get install ros-<rosdistro>-rosbridge-server
For tutorials: http://wiki.ros.org/rosbridge_suite
ROS# are a set of tools that facilitate communication on the Unity side.
ROS# can be installed using the Unity Asset Store in the Unity Project itself (Window->Asset Store) or by cloning the ROS# repository in the Assets folder of the unity project.
git clone https://github.com/siemens/ros-sharp.git
The commmunication is setup by launching rosbridge server.
roslaunch rosbridge_server rosbridge_websocket.launch
The Pose_Stamped_Publisher script of ROS# is used to send pose of the bot to ROS. The script is simply attached to the gameObject(The robot here) and some minor settings in the inspector and the script facilitates sending of pose to ROS.
The velocity commands are accepted from the user using the turtlebot3 teleoperation package.
export TURTLEBOT3_MODEL=waffle_pi
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
On the Unity side, Twist_Subscriber script of the ROS# package subscribes to the incoming Twist messages on cmd_vel. A control script written in C# (updown.cs) makes sure that the velocity commands recieved are converted to motion.
Below are screen captures for the simulation. A similar simulation is also done in gazebo to point out that Unity has equal or maybe more capabilties than Gazebo for robot simulations.
Unity_SIm.mp4
Gazebo_sim.mp4
UnityROS is the complete Unity Project.