test_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("simple_obstacle_pub")
00028     root_frame = "/odom_combined"
00029 
00030     pub = rospy.Publisher("obstacle_distance/registerObstacle", CollisionObject, queue_size = 1)
00031 
00032     while pub.get_num_connections() < 1:
00033         if rospy.is_shutdown():
00034             exit(0)
00035         rospy.logwarn("Please create a subscriber to 'obstacle_distance/registerObstacle' topic (Type: moveit_msgs/CollisionObject)")
00036         time.sleep(1.0)
00037 
00038     rospy.loginfo("Continue ...")
00039 
00040     # Publish a simple sphere
00041     x = CollisionObject()
00042     x.id = "Funny Sphere"
00043     x.header.frame_id = root_frame
00044     x.operation = CollisionObject.ADD
00045     #x.operation = CollisionObject.REMOVE
00046     sphere = SolidPrimitive()
00047     sphere.type = SolidPrimitive.SPHERE
00048     sphere.dimensions.append(0.1)  # radius
00049     x.primitives.append(sphere)
00050 
00051     pose = Pose()
00052     pose.position.x = 0.35
00053     pose.position.y = -0.45
00054     pose.position.z = 0.8
00055     pose.orientation.x = 0.0;
00056     pose.orientation.y = 0.0;
00057     pose.orientation.z = 0.0;
00058     pose.orientation.w = 1.0;
00059     x.primitive_poses.append(pose)
00060     # pub.publish(x)
00061     time.sleep(1.0)
00062 
00063     # Now publish a mesh and use the db field for the stl-resource name
00064     y = CollisionObject()
00065     y.id = "Funny Mesh"
00066     y.header.frame_id = root_frame
00067     # y.type.db = "package://cob_gazebo_objects/Media/models/milk.dae"
00068     y.type.db = "package://cob_gazebo_objects/Media/models/cabinet_ikea_kallax_4x2.stl"
00069     # y.type.db = "package://cob_twist_controller/files/torus_0_25_inner_rad.stl"
00070     y.operation = CollisionObject.ADD
00071     # y.operation = CollisionObject.REMOVE
00072 
00073     pose = Pose()
00074     pose.position.x = 0.5
00075     pose.position.y = 0.5
00076     pose.position.z = 0.0
00077     pose.orientation.x = 0.0
00078     pose.orientation.y = 0.0
00079     pose.orientation.z = 0.0
00080     pose.orientation.w = 1.0
00081     y.mesh_poses.append(pose)
00082     pub.publish(y)
00083     time.sleep(1.0)
00084 
00085     rospy.loginfo("Done!")


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