浏览代码

Package setup

/laurie-Ros2Update
LaurieCheers 4 年前
当前提交
9602ce0d
共有 5 个文件被更改,包括 35 次插入100 次删除
  1. 6
      tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/setup.py
  2. 2
      tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo_msgs/CMakeLists.txt
  3. 91
      tutorials/ros_unity_integration/setup.md
  4. 36
      tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/unity_robotics_demo/server_endpoint.py
  5. 0
      /tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/resource/unity_robotics_demo

6
tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/setup.py


from setuptools import setup
package_name = 'ros2_test'
package_name = 'unity_robotics_demo'
setup(
name=package_name,

('share/ament_index/resource_index/packages', ['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name), ['launch/test_launcher.py']),
maintainer_email='laurie.cheers@unity3d.com',
maintainer_email='unity-robotics@unity3d.com',
'server_endpoint = ros2_test.server_endpoint:main',
'color_publisher = ros2_test.color_publisher:main',
'position_service = ros2_test.position_service:main',
],

2
tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo_msgs/CMakeLists.txt


cmake_minimum_required(VERSION 3.5)
project(unity_interfaces)
project(unity_robotics_demo_msgs)
# Default to C99
if(NOT CMAKE_C_STANDARD)

91
tutorials/ros_unity_integration/setup.md


The minimum requirements for a ROS–Unity integration. These instructions cover both ROS1 and ROS2.
<img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> This symbol indicates instructions for ROS2 users. If using ROS2, you should skip to [ROS2 Environment](setup.md#-ros2-environment).
<img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> This symbol indicates instructions only for ROS2 users. If using ROS2, start with [ROS2 Environment](setup.md#-ros2-environment).
## ROS Environment

```bash
source devel/setup.bash
roscore &
roscore
1. The `server_endpoint` script we'll be using will require the ros parameter ROS_IP to be defined. You will need to know the IP address of your ROS machine; the command `hostname -I` can be used to find it. Or, if you're using Docker, the IP address to use is `0.0.0.0`.
1. Set the ros parameter using the command `rosparam set ROS_IP 127.0.0.1`, replacing this IP address with the appropriate IP address or hostname.
1. 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_IP 10000`, replacing 10000 with the desired port number.
1. (Optional) If you're going through this process often, you may find it useful to set the ROS parameter values using a YAML file. To do this, create a `params.yaml` file in your package, e.g. `./config/params.yaml`. Open the file for editing.
Update the `ROS_IP` below with the appropriate address and copy the contents into the `params.yaml` file.
```yaml
ROS_IP: <your ROS IP>
ROS_TCP_PORT: 10000
5. 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.)
```bash
rosparam set ROS_IP 127.0.0.1
e.g.
```yaml
ROS_IP: 127.0.0.1
ROS_TCP_PORT: 10000
```
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.
Set these newly defined parameters by running `rosparam load`, e.g.:
7. Start the server endpoint with the following command:
```bash
rosparam load PATH/TO/config/params.yaml
```
Alternatively, this YAML can be loaded from a launch file, e.g.:
```bash
rosrun ros_tcp_endpoint default_server_endpoint.py
```
```xml
<launch>
<rosparam file="$(find <PACKAGE_NAME>)/config/params.yaml" command="load"/>
</launch>
```
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](http://wiki.ros.org/rosparam).
>

Ensure there are no errors.
5. Open a new terminal window and run the following commands, 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.)
```bash
source install/setup.bash
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`.
6. (Alternative) If you need the server to listen on a port that's different from the default 10000, here's the command line to set the ROS_TCP_PORT parameter:
```bash
`ros2 run unity_robotics_demo 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](https://github.com/Unity-Technologies/ROS-TCP-Connector) package.

![](images/add_package_2.png)
3. For this step you'll need to know the incoming IP address of your ROS machine; if you don't know it, the command `hostname -I` will print it. Or, if you're using Docker, the default IP address to use is `0.0.0.0`.
3. From the Unity menu bar, open `Robotics/ROS Settings`, and set the `ROS IP Address` variable to the IP you set earlier.
From the Unity menu bar, open `Robotics/ROS Settings`, and set the `ROS IP Address` variable to your ROS IP.
4. <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If you're using ROS2, still in the ROS Settings window, switch the protocol to ROS2.
4. <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If you're using ROS2, you should also switch the protocol to ROS2 now.
![](images/ros2_protocol.png)
## Setting up the Ros-Unity Integration tutorials

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, and run `catkin_make` again.
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, and then run `catkin_make`.
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If using ROS2, instead copy them from`tutorials/ros_unity_integration/ros2_packages` into the `src` folder of your Colcon workspace, and run `colcon build` again.
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If using ROS2, instead copy the versions from `tutorials/ros_unity_integration/ros2_packages`, and then run `colcon build`.
2. Open a new terminal window and run the following commands, replacing the IP address 127.0.0.1 with the IP or hostname you set in Unity earlier. (If using Docker, the IP to use is 127.0.0.1.)
```bash
source devel/setup.bash
rosparam set ROS_IP 127.0.0.1
rosrun ros_tcp_endpoint default_server_endpoint.py
```
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If using ROS2, use these commands instead:
```bash
source install/setup.bash
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`.
3. (Optional) If you need the server to listen on a port that's different from the default 10000, you can also set the ROS_TCP_PORT parameter with the command `rosparam set ROS_TCP_PORT 20000` (or whatever port you want.)
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> In ROS2 the command becomes `ros2 run unity_robotics_demo server_endpoint --ros-args -p ROS_IP:=127.0.0.1 -p ROS_TCP_PORT:=20000`
4. 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 whatever path you downloaded the Unity-Robotics-Hub repo into.
2. 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.
5. 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.
3. 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.
![](images/generate_messages_1.png)

36
tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/unity_robotics_demo/server_endpoint.py


import rclpy
from ros2_tcp_endpoint.server import TcpServer
from ros2_tcp_endpoint.publisher import RosPublisher
from ros2_tcp_endpoint.subscriber import RosSubscriber
from ros2_tcp_endpoint.service import RosService
from ros2_tcp_endpoint.unity_service import UnityService
#from unity_interfaces.msg import UnityColor
#from unity_interfaces.msg import PosRot, UnityColor
#from unity_interfaces.srv import PositionService, ObjectPoseService
def main(args=None):
rclpy.init(args=args)
ros_node_name = 'TCPServer'
buffer_size = 1024
connections = 10
tcp_server = TcpServer(ros_node_name, buffer_size, connections)
tcp_server.start({
#'pos_srv': RosService('pos_srv', PositionService),
#'pos_rot': RosPublisher('pos_rot', PosRot, queue_size=10),
#'color': RosSubscriber('color', UnityColor(), tcp_server),
#'obj_pose_srv': UnityService('obj_pose_srv', ObjectPoseService, tcp_server),
})
# Setup executors for nodes defined in source_destination_dict
tcp_server.setup_executor()
# Clean up nodes defined in source_destination_dict
tcp_server.destroy_nodes()
rclpy.shutdown()
if __name__ == '__main__':
main()

/tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/resource/robotics_demo → /tutorials/ros_unity_integration/ros2_packages/unity_robotics_demo/resource/unity_robotics_demo

正在加载...
取消
保存