LaurieCheers
3 年前
当前提交
024ec3ed
共有 31 个文件被更改,包括 405 次插入 和 36 次删除
-
13tutorials/ros_unity_integration/network.md
-
26tutorials/ros_unity_integration/publisher.md
-
8tutorials/ros_unity_integration/service.md
-
20tutorials/ros_unity_integration/setup.md
-
29tutorials/ros_unity_integration/subscriber.md
-
2tutorials/ros_unity_integration/unity_scripts/RosPublisherExample.cs
-
8tutorials/ros_unity_integration/unity_scripts/RosServiceExample.cs
-
2tutorials/ros_unity_integration/unity_scripts/RosSubscriberExample.cs
-
6tutorials/ros_unity_integration/unity_scripts/RosUnityServiceExample.cs
-
6tutorials/ros_unity_integration/unity_service.md
-
32tutorials/ros_unity_integration/ros_packages/robotics_demo/scripts/color_publisher.py
-
32tutorials/ros_unity_integration/ros_packages/robotics_demo/scripts/object_pose_client.py
-
27tutorials/ros_unity_integration/ros_packages/robotics_demo/scripts/position_service.py
-
45tutorials/ros_unity_integration/ros2_packages/robotics_demo/CMakeLists.txt
-
19tutorials/ros_unity_integration/ros2_packages/robotics_demo/launch/robo_demo.launch
-
7tutorials/ros_unity_integration/ros2_packages/robotics_demo/msg/PosRot.msg
-
4tutorials/ros_unity_integration/ros2_packages/robotics_demo/msg/UnityColor.msg
-
31tutorials/ros_unity_integration/ros2_packages/robotics_demo/package.xml
-
32tutorials/ros_unity_integration/ros2_packages/robotics_demo/scripts/color_publisher.py
-
32tutorials/ros_unity_integration/ros2_packages/robotics_demo/scripts/object_pose_client.py
-
27tutorials/ros_unity_integration/ros2_packages/robotics_demo/scripts/position_service.py
-
27tutorials/ros_unity_integration/ros2_packages/robotics_demo/scripts/server_endpoint.py
-
3tutorials/ros_unity_integration/ros2_packages/robotics_demo/srv/ObjectPoseService.srv
-
3tutorials/ros_unity_integration/ros2_packages/robotics_demo/srv/PositionService.srv
-
0/tutorials/ros_unity_integration/ros_packages
|
|||
#!/usr/bin/env python |
|||
|
|||
import random |
|||
import rospy |
|||
from robotics_demo.msg import UnityColor |
|||
|
|||
|
|||
TOPIC_NAME = 'color' |
|||
NODE_NAME = 'color_publisher' |
|||
|
|||
|
|||
def post_color(): |
|||
pub = rospy.Publisher(TOPIC_NAME, UnityColor, queue_size=10) |
|||
rospy.init_node(NODE_NAME, anonymous=True) |
|||
rate = rospy.Rate(10) # 10hz |
|||
|
|||
while not rospy.is_shutdown(): |
|||
|
|||
r = random.randint(0, 255) |
|||
g = random.randint(0, 255) |
|||
b = random.randint(0, 255) |
|||
color = UnityColor(r, g, b, 1) |
|||
pub.publish(color) |
|||
rate.sleep() |
|||
break |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
try: |
|||
post_color() |
|||
except rospy.ROSInterruptException: |
|||
pass |
|
|||
#!/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))) |
|
|||
#!/usr/bin/env python |
|||
|
|||
from __future__ import print_function |
|||
|
|||
import random |
|||
import rospy |
|||
|
|||
from robotics_demo.srv import PositionService, PositionServiceResponse |
|||
|
|||
|
|||
def new_position(req): |
|||
print("Request: \n{}".format(req.input)) |
|||
req.input.pos_x = random.uniform(-4.0, 4.0) |
|||
req.input.pos_z = random.uniform(-4.0, 4.0) |
|||
|
|||
return PositionServiceResponse(req.input) |
|||
|
|||
|
|||
def translate_position_server(): |
|||
rospy.init_node('position_server') |
|||
s = rospy.Service('pos_srv', PositionService, new_position) |
|||
print("Ready to move cubes!") |
|||
rospy.spin() |
|||
|
|||
|
|||
if __name__ == "__main__": |
|||
translate_position_server() |
|
|||
cmake_minimum_required(VERSION 2.8.3) |
|||
project(robotics_demo) |
|||
|
|||
find_package(catkin REQUIRED COMPONENTS |
|||
rospy |
|||
std_msgs |
|||
geometry_msgs |
|||
ros_tcp_endpoint |
|||
message_generation |
|||
) |
|||
|
|||
add_message_files(DIRECTORY msg) |
|||
|
|||
add_service_files(DIRECTORY srv) |
|||
|
|||
generate_messages( |
|||
DEPENDENCIES |
|||
geometry_msgs |
|||
std_msgs |
|||
) |
|||
|
|||
catkin_package(CATKIN_DEPENDS |
|||
ros_tcp_endpoint |
|||
message_runtime) |
|||
|
|||
catkin_install_python(PROGRAMS |
|||
scripts/server_endpoint.py |
|||
scripts/position_service.py |
|||
scripts/color_publisher.py |
|||
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} |
|||
) |
|||
|
|||
|
|||
############# |
|||
## Testing ## |
|||
############# |
|||
|
|||
## Add gtest based cpp test target and link libraries |
|||
# catkin_add_gtest(${PROJECT_NAME}-test test/test_robotics_demo.cpp) |
|||
# if(TARGET ${PROJECT_NAME}-test) |
|||
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) |
|||
# endif() |
|||
|
|||
## Add folders to be run by python nosetests |
|||
# catkin_add_nosetests(test) |
|
|||
<launch> |
|||
|
|||
<env name="ROS_IP" value="192.168.1.116"/> |
|||
<env name="ROS_HOSTNAME" value="$(env ROS_IP)"/> |
|||
|
|||
<param name="ROS_IP" type="str" value="$(env ROS_IP)" /> |
|||
<param name="ROS_TCP_PORT" type="int" value="10000" /> |
|||
<param name="TCP_NODE_NAME" type="str" value="TCPServer" /> |
|||
<param name="TCP_BUFFER_SIZE" type="int" value="1024" /> |
|||
<param name="TCP_CONNECTIONS" type="int" value="10" /> |
|||
|
|||
<param name="UNITY_IP" type="str" value="192.168.1.105" /> |
|||
<param name="UNITY_SERVER_PORT" type="int" value="5005" /> |
|||
|
|||
<group ns="position_service_and_endpoint"> |
|||
<node pkg="robotics_demo" name="position_service" type="position_service.py"/> |
|||
<node pkg="robotics_demo" name="server_endpoint" type="server_endpoint.py"/> |
|||
</group> |
|||
</launch> |
|
|||
float32 pos_x |
|||
float32 pos_y |
|||
float32 pos_z |
|||
float32 rot_x |
|||
float32 rot_y |
|||
float32 rot_z |
|||
float32 rot_w |
|
|||
int32 r |
|||
int32 g |
|||
int32 b |
|||
int32 a |
|
|||
<?xml version="1.0"?> |
|||
<package format="2"> |
|||
<name>robotics_demo</name> |
|||
<version>0.0.0</version> |
|||
<description>The robotics_demo package</description> |
|||
|
|||
<maintainer email="unity-robotics@unity3d.com">Unity Robotics</maintainer> |
|||
|
|||
|
|||
<license>Apache 2.0</license> |
|||
|
|||
<buildtool_depend>catkin</buildtool_depend> |
|||
<build_depend>rospy</build_depend> |
|||
<build_depend>message_generation</build_depend> |
|||
<build_depend>std_msgs</build_depend> |
|||
<build_depend>ros_tcp_endpoint</build_depend> |
|||
<build_export_depend>rospy</build_export_depend> |
|||
<build_export_depend>std_msgs</build_export_depend> |
|||
<build_export_depend>ros_tcp_endpoint</build_export_depend> |
|||
<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 --> |
|||
<export> |
|||
<!-- Other tools can request additional information be placed here --> |
|||
|
|||
</export> |
|||
</package> |
|
|||
#!/usr/bin/env python |
|||
|
|||
import random |
|||
import rospy |
|||
from robotics_demo.msg import UnityColor |
|||
|
|||
|
|||
TOPIC_NAME = 'color' |
|||
NODE_NAME = 'color_publisher' |
|||
|
|||
|
|||
def post_color(): |
|||
pub = rospy.Publisher(TOPIC_NAME, UnityColor, queue_size=10) |
|||
rospy.init_node(NODE_NAME, anonymous=True) |
|||
rate = rospy.Rate(10) # 10hz |
|||
|
|||
while not rospy.is_shutdown(): |
|||
|
|||
r = random.randint(0, 255) |
|||
g = random.randint(0, 255) |
|||
b = random.randint(0, 255) |
|||
color = UnityColor(r, g, b, 1) |
|||
pub.publish(color) |
|||
rate.sleep() |
|||
break |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
try: |
|||
post_color() |
|||
except rospy.ROSInterruptException: |
|||
pass |
|
|||
#!/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))) |
|
|||
#!/usr/bin/env python |
|||
|
|||
from __future__ import print_function |
|||
|
|||
import random |
|||
import rospy |
|||
|
|||
from robotics_demo.srv import PositionService, PositionServiceResponse |
|||
|
|||
|
|||
def new_position(req): |
|||
print("Request: \n{}".format(req.input)) |
|||
req.input.pos_x = random.uniform(-4.0, 4.0) |
|||
req.input.pos_z = random.uniform(-4.0, 4.0) |
|||
|
|||
return PositionServiceResponse(req.input) |
|||
|
|||
|
|||
def translate_position_server(): |
|||
rospy.init_node('position_server') |
|||
s = rospy.Service('pos_srv', PositionService, new_position) |
|||
print("Ready to move cubes!") |
|||
rospy.spin() |
|||
|
|||
|
|||
if __name__ == "__main__": |
|||
translate_position_server() |
|
|||
#!/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() |
|
|||
string object_name |
|||
--- |
|||
geometry_msgs/Pose object_pose |
|
|||
PosRot input |
|||
--- |
|||
PosRot output |
撰写
预览
正在加载...
取消
保存
Reference in new issue