example_obstacle_publisher_node.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 
00017 
00018 import time
00019 
00020 import rospy
00021 from geometry_msgs.msg import Pose
00022 from moveit_msgs.msg import CollisionObject
00023 from shape_msgs.msg import SolidPrimitive, Mesh
00024 
00025 
00026 if __name__=="__main__":
00027     rospy.init_node("example_obstacle_publisher")
00028 
00029     #Specify a frame_id - transformation to root_frame of obstacle_distance node is handled in according subscriber callback
00030     frame_id = rospy.get_param('root_frame')
00031 
00032     pub = rospy.Publisher("obstacle_distance/registerObstacle", CollisionObject, queue_size=1, latch=True)
00033 
00034     while pub.get_num_connections() < 1:
00035         if rospy.is_shutdown():
00036             exit(0)
00037         rospy.logwarn("Please create a subscriber to '" + rospy.get_namespace() + "/obstacle_distance/registerObstacle' topic (Type: moveit_msgs/CollisionObject)")
00038         time.sleep(1.0)
00039 
00040     rospy.loginfo("Continue ...")
00041 
00042     # Publish a simple sphere
00043     x = CollisionObject()
00044     x.id = "Funny Sphere"
00045     x.header.frame_id = frame_id
00046     x.operation = CollisionObject.ADD
00047     sphere = SolidPrimitive()
00048     sphere.type = SolidPrimitive.SPHERE
00049     sphere.dimensions.append(0.1) # radius
00050     x.primitives.append(sphere)
00051 
00052     pose = Pose()
00053     pose.position.x = 0.35
00054     pose.position.y = -0.35
00055     pose.position.z = 0.8
00056     pose.orientation.x = 0.0;
00057     pose.orientation.y = 0.0;
00058     pose.orientation.z = 0.0;
00059     pose.orientation.w = 1.0;
00060     x.primitive_poses.append(pose)
00061     pub.publish(x)
00062     time.sleep(1.0)
00063 
00064     # Now publish a mesh and use the db field for the mesh-resource name
00065     y = CollisionObject()
00066     y.id = "Funny Mesh"
00067     y.header.frame_id = frame_id
00068     y.type.db = "package://cob_gazebo_objects/Media/models/milk.dae"
00069     y.operation = CollisionObject.ADD
00070 
00071     pose = Pose()
00072     pose.position.x = -0.35
00073     pose.position.y = -0.35
00074     pose.position.z = 0.8
00075     pose.orientation.x = 0.0;
00076     pose.orientation.y = 0.0;
00077     pose.orientation.z = 0.0;
00078     pose.orientation.w = 1.0;
00079     y.mesh_poses.append(pose)
00080     pub.publish(y)
00081     time.sleep(1.0)
00082 
00083     rospy.spin()


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Jun 6 2019 21:19:14