-
Notifications
You must be signed in to change notification settings - Fork 0
Connecting ROS and Unity
Go to/open the package manager window (Window > Package Manager), and check that the ROS TCP Connector (v0.7.0) package is installed in the project.
If it is not installed, click the +
to add a package and choose 'Add package from git URL', and use this URL: https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.7.0
Make sure that the Ros Connection
GameObject exists in the scene you want to run (e.g. SquarePool, Quali), and that on the GameObject, the ROSConnection
component has the field Ros IP Address
set to 127.0.0.1
and the field Ros Port
set to 10000
.
First, make sure you have pulled the mcgillrobotics/auv_2025:sim image from the mcgillrobotics Docker Hub. You can do this either through Docker Desktop, or in the CLI via docker pull mcgillrobotics/auv_2025:sim
.
Then, from the AUV-2025/docker/sim/
directory, launch the docker container with docker compose up
. This will take a few minutes the first time around because of dependency downloads.
Subsequent executions of docker compose up
will be a lot faster, e.g.
NOTE: If the docker compose up
command is failing with an error during connect
message, it may be because your Docker Engine's daemon is not running (put simply, Docker is not actively running on your machine).
- If you installed Docker via Docker Desktop then the fix is as simple as checking that the Docker Desktop app is running, and that you see the Engine running status in the app:
- If you didn't install Docker via Docker Desktop, see the Docker Docs page for starting the daemon.
Now that the container is running, we need to attach a terminal to the container so that you can run commands in its shell.
You can do this using VS Code by opening the Docker panel on the primary sidebar, then right clicking on the running AUV sim container, and clicking 'Attach Visual Studio Code'.
This will open up an entirely new VS code window, from which you can open a terminal (Ctrl + J
is the default shortcut to do that) which will be in the container. Once the terminal is opened, you need to cd ..
to go back from the home directory (~
) to the root directory (/
) where all the files have been installed.
From there is where you can execute commands in the container.
More Docker info can be found in the AUV-2025 repo's wiki.
From the container's terminal, run roslaunch sim endpoint.launch tcp_ip:=127.0.0.1
to launch the TCP endpoint for Unity to connect to.
NOTE: If the roslaunch
command does not work, you may need you first cd AUV-2025/catkin-ws/
and run catkin build
, followed by source devel/setup.bash
.
Go back to Unity, and press play. In the container's terminal, check that subscribers/publishers were registered (this means the Unity sim robot is connected to the ROS endpoint), and your simulation is set up and working!
Subscriber/publisher registrations look like this:
NOTE: If your are not getting any subscribers/publishers, and in Unity you are getting the following message(s) in the console:
then try to establish the ROS connection on a different port, e.g. 10001
.
To do this, follow the previous steps, changing the ROSConnection
component's Ros Port
field to 10001
, and for step 6, specify the port explicitly in the roslaunch
command, i.e. run roslaunch sim endpoint.launch tcp_ip:=127.0.0.1 tcp_port:=10001
- this will override the default value for the tcp_port
arg in AUV-2025/catkin_ws/src/sim/launch/endpoint.launch
(i.e. this line: <arg name="tcp_port" default="10000"/>
).
If this happens to you - and changing the port fixes the problem - bring it up, so that if we realise it is a recurring issue, we will change the default port to something else, making everyone's lives just a little easier.
If this guide wasn't enough, and/or you want a video guide, see this video.