您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

5.7 KiB

ROS–Unity Initial Setup

The minimum requirements for a ROS–Unity integration. These instructions cover both ROS1 and ROS2.

ros2 This symbol indicates instructions only for ROS2 users. If using ROS2, start with ROS2 Environment.

ROS Environment

  1. Follow these steps if using ROS (melodic or noetic):

  2. Download and copy the TCP Endpoint package to the src folder in your Catkin workspace.

  3. Navigate to your Catkin workspace and run catkin_make, then source devel/setup.bash. Ensure there are no errors.

  4. 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.

  5. 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
    
  6. (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.

  7. 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 ROS2 Environment

  1. Follow these steps if using ROS2:

  2. Download the ROS2 TCP Endpoint repository and copy the folders ROS2_packages/ros2_tcp_endpoint and ROS2_packages/unity_interfaces into the src folder in your Colcon workspace.

  3. Navigate to your Colcon workspace and run the following commands

    source install/setup.bash
    colcon build
    

    ``

    Ensure there are no errors.

  4. 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.

  1. (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

  1. Launch Unity and create a new project.
  2. 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.

  1. From the Unity menu bar, open Robotics/ROS Settings, and set the ROS 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).

  2. ros2 ROS2 users should also switch the protocol to ROS2 now.

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:

  1. Copy unity_robotics_demo and unity_robotics_demo_msgs from the tutorials/ros_unity_integration/ros_packages folder of this repo into the src folder in your Catkin workspace.

    • ros2 If using ROS2, instead copy the versions from tutorials/ros_unity_integration/ros2_packages.
  2. Run catkin_make, and then source devel/setup.bash (again) so that ROS can find the newly built messages.

    • ros2 If using ROS2, the commands are colcon build, then source install/setup.bash.
  3. 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 to tutorials/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.)

  1. 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.