5.7 KiB
ROS–Unity Initial Setup
The minimum requirements for a ROS–Unity integration. These instructions cover both ROS1 and ROS2.
This symbol indicates instructions only for ROS2 users. If using ROS2, start with ROS2 Environment.
ROS Environment
-
Follow these steps if using ROS (melodic or noetic):
-
Download and copy the TCP Endpoint package to the
src
folder in your Catkin workspace. -
Navigate to your Catkin workspace and run
catkin_make
, thensource devel/setup.bash
. Ensure there are no errors. -
Open a new terminal, navigate to your Catkin workspace, and run:
source devel/setup.bash roscore
Once ROS Core has started, it will print
started core service [/rosout]
to the terminal window. -
In your previous terminal, run the following command, replacing the IP address 127.0.0.1 with your ROS machine's IP or hostname. (If you don't know your IP address, you can find it out with the command
hostname -I
. If you're running ROS in a Docker container, the default incoming IP address is 0.0.0.0.)rosparam set ROS_IP 127.0.0.1
-
(Optional) By default, the server_endpoint will listen on port 10000, but this is also controlled by a parameter. If you need to change it, you can run the command
rosparam set ROS_TCP_PORT 10000
, replacing 10000 with the desired port number. -
Start the server endpoint with the following command:
rosrun ros_tcp_endpoint default_server_endpoint.py
Once the server_endpoint has started, it will print something similar to [INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000
.
Read more about rosparam YAML options here.
Read more about the ROS Parameter Server here.
ROS2 Environment
-
Follow these steps if using ROS2:
-
Download the ROS2 TCP Endpoint repository and copy the folders
ROS2_packages/ros2_tcp_endpoint
andROS2_packages/unity_interfaces
into thesrc
folder in your Colcon workspace. -
Navigate to your Colcon workspace and run the following commands
source install/setup.bash colcon build
``
Ensure there are no errors.
-
Run the following command, replacing the IP address 127.0.0.1 with your ROS machine's IP or hostname. (If you don't know your IP address, you can find it out with the command
hostname -I
. If you're running ROS in a Docker container, the default incoming IP address is 0.0.0.0.)ros2 run ros2_tcp_endpoint default_server_endpoint --ros-args -p ROS_IP:=127.0.0.1
Once the server_endpoint has started, it will print something similar to [INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000
.
-
(Alternative) If you need the server to listen on a port that's different from the default 10000, here's the command line to also set the ROS_TCP_PORT parameter:
ros2 run ros2_tcp_endpoint default_server_endpoint --ros-args -p ROS_IP:=127.0.0.1 -p ROS_TCP_PORT:=10000
``
Unity Scene
- Launch Unity and create a new project.
- Open Package Manager and click the + button at the top left corner. Select "add package from git URL" and enter "https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector" to install the ROS TCP Connector package.
-
From the Unity menu bar, open
Robotics/ROS Settings
, and set theROS IP Address
variable to the IP you set earlier. (If using a Docker container, you can leave it on the default 127.0.0.1).
Setting up the Ros-Unity Integration tutorials
The instructions so far have set up the ROS-TCP-Connector package for general use. If you are specifically following one of the Ros-Unity-Integration tutorials, you'll need to do the following additional steps:
-
Copy
unity_robotics_demo
andunity_robotics_demo_msgs
from thetutorials/ros_unity_integration/ros_packages
folder of this repo into thesrc
folder in your Catkin workspace.- If using ROS2, instead copy the versions from
tutorials/ros_unity_integration/ros2_packages
.
- If using ROS2, instead copy the versions from
-
Run
catkin_make
, and thensource devel/setup.bash
(again) so that ROS can find the newly built messages.- If using ROS2, the commands are
colcon build
, thensource install/setup.bash
.
- If using ROS2, the commands are
-
In the Unity menu bar, go to
Robotics
->Generate ROS Messages...
. In the Message Browser window, click the Browse button at the top right to set the ROS message path totutorials/ros_unity_integration/ros_packages/unity_robotics_demo_msgs
in this repo.
(Note: The version in the ros2_packages folder is equivalent; Ros2 users can feel free to use it, or not.)
- In the message browser, expand the unity_robotics_demo_msgs subfolder and click "Build 2 msgs" and "Build 2 srvs" to generate C# scripts from the ROS .msg and .srv files.
The generated files will be saved in the default directories Assets/RosMessages/UnityRoboticsDemo/msg
and Assets/RosMessages/UnityRoboticsDemo/srv
.