浏览代码

Updated to make ros1 work

/laurie-Ros2Update
LaurieCheers 3 年前
当前提交
6e6b04bc
共有 12 个文件被更改,包括 21 次插入89 次删除
  1. 6
      tutorials/ros_unity_integration/publisher.md
  2. 13
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/CMakeLists.txt
  3. 7
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/package.xml
  4. 2
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/color_publisher.py
  5. 2
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/position_service.py
  6. 14
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo_msgs/CMakeLists.txt
  7. 5
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo_msgs/package.xml
  8. 2
      tutorials/ros_unity_integration/subscriber.md
  9. 27
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/server_endpoint.py
  10. 32
      tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/object_pose_client.py

6
tutorials/ros_unity_integration/publisher.md


- Add a plane and a cube to the empty Unity scene
- Move the cube a little ways up so it is hovering above the plane
- In the main menu bar, open `Robotics/ROS Settings`.
- Set the ROS IP address and port to match the ROS IP and port variables defined when you started the ROS endpoint.
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> If using ROS2, switch the protocol to ROS2.
![](images/ros2_protocol.png)
- Create another empty GameObject, name it `RosPublisher` and attach the `RosPublisherExample` script.
- Drag the cube GameObject onto the `Cube` parameter.

13
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/CMakeLists.txt


cmake_minimum_required(VERSION 2.8.3)
project(robotics_demo)
project(unity_robotics_demo)
find_package(catkin REQUIRED COMPONENTS
rospy

message_generation
)
add_message_files(DIRECTORY msg)
add_service_files(DIRECTORY srv)
generate_messages(
DEPENDENCIES
geometry_msgs
std_msgs
)
scripts/server_endpoint.py
scripts/position_service.py
scripts/color_publisher.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

7
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/package.xml


<?xml version="1.0"?>
<package format="2">
<name>robotics_demo</name>
<name>unity_robotics_demo</name>
<description>The robotics_demo package</description>
<description>The unity_robotics_demo package (ROS1 version)</description>
<maintainer email="unity-robotics@unity3d.com">Unity Robotics</maintainer>

<build_depend>message_generation</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>ros_tcp_endpoint</build_depend>
<build_depend>unity_robotics_demo_msgs</build_depend>
<build_export_depend>unity_robotics_demo_msgs</build_export_depend>
<exec_depend>unity_robotics_demo_msgs</exec_depend>
<!-- The export tag contains other, unspecified, tags -->

2
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/color_publisher.py


import random
import rospy
from robotics_demo.msg import UnityColor
from unity_robotics_demo_msgs.msg import UnityColor
TOPIC_NAME = 'color'

2
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/position_service.py


import random
import rospy
from robotics_demo.srv import PositionService, PositionServiceResponse
from unity_robotics_demo_msgs.srv import PositionService, PositionServiceResponse
def new_position(req):

14
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo_msgs/CMakeLists.txt


cmake_minimum_required(VERSION 2.8.3)
project(robotics_demo)
project(unity_robotics_demo_msgs)
find_package(catkin REQUIRED COMPONENTS
rospy

)
add_message_files(DIRECTORY msg)
add_service_files(DIRECTORY srv)
add_message_files(FILES
PosRot.msg
UnityColor.msg
)
add_service_files(FILES
ObjectPoseService.srv
PositionService.srv
)
generate_messages(
DEPENDENCIES

catkin_package(CATKIN_DEPENDS
ros_tcp_endpoint
message_runtime)
#############

5
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo_msgs/package.xml


<?xml version="1.0"?>
<package format="2">
<name>unity_robotics_demo</name>
<name>unity_robotics_demo_msgs</name>
<description>The robotics_demo package (ROS1 version)</description>
<description>Messages for the unity_robotics_demo package (ROS1 version)</description>
<maintainer email="unity-robotics@unity3d.com">Unity Robotics</maintainer>

<exec_depend>message_runtime</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>ros_tcp_endpoint</exec_depend>
<!-- The export tag contains other, unspecified, tags -->

2
tutorials/ros_unity_integration/subscriber.md


- Press play in the editor
### In ROS Terminal Window
- Run the following command: `rosrun robotics_demo color_publisher.py` to change the color of the cube GameObject in Unity to a random color.
- Run the following command: `rosrun unity_robotics_demo color_publisher.py` to change the color of the cube GameObject in Unity to a random color.
- <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> In ROS2, instead run `ros2 run unity_robotics_demo color_publisher`.

27
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/server_endpoint.py


#!/usr/bin/env python
import rospy
from ros_tcp_endpoint import TcpServer, RosPublisher, RosSubscriber, RosService, UnityService
from robotics_demo.msg import PosRot, UnityColor
from robotics_demo.srv import PositionService, ObjectPoseService
def main():
ros_node_name = rospy.get_param("/TCP_NODE_NAME", 'TCPServer')
buffer_size = rospy.get_param("/TCP_BUFFER_SIZE", 1024)
connections = rospy.get_param("/TCP_CONNECTIONS", 10)
tcp_server = TcpServer(ros_node_name, buffer_size, connections)
rospy.init_node(ros_node_name, anonymous=True)
tcp_server.start({
'pos_rot': RosPublisher('pos_rot', PosRot, queue_size=10),
'color': RosSubscriber('color', UnityColor, tcp_server),
'pos_srv': RosService('pos_srv', PositionService),
'obj_pose_srv': UnityService('obj_pose_srv', ObjectPoseService, tcp_server),
})
rospy.spin()
if __name__ == "__main__":
main()

32
tutorials/ros_unity_integration/ros_packages/unity_robotics_demo/scripts/object_pose_client.py


#!/usr/bin/env python
from __future__ import print_function
import random
import rospy
import sys
from robotics_demo.srv import ObjectPoseService, ObjectPoseServiceResponse
def get_object_pose_client(name):
rospy.wait_for_service('obj_pose_srv')
try:
get_obj_pose = rospy.ServiceProxy('obj_pose_srv', ObjectPoseService)
obj_pose_resp = get_obj_pose(name)
return obj_pose_resp.object_pose
except rospy.ServiceException as e:
print("Service call failed: %s"%e)
def usage():
return "%s [object_name]"%sys.argv[0]
if __name__ == "__main__":
if len(sys.argv) == 2:
name = str(sys.argv[1])
else:
print(usage())
sys.exit(1)
print("Requesting pose for %s"%(name))
print("Pose for %s: %s"%(name, get_object_pose_client(name)))
正在加载...
取消
保存