example_obstacle_publisher_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import time
19 
20 import rospy
21 from geometry_msgs.msg import Pose
22 from moveit_msgs.msg import CollisionObject
23 from shape_msgs.msg import SolidPrimitive, Mesh
24 
25 
26 if __name__=="__main__":
27  rospy.init_node("example_obstacle_publisher")
28 
29  #Specify a frame_id - transformation to root_frame of obstacle_distance node is handled in according subscriber callback
30  frame_id = rospy.get_param('root_frame')
31 
32  pub = rospy.Publisher("obstacle_distance/registerObstacle", CollisionObject, queue_size=1, latch=True)
33 
34  while pub.get_num_connections() < 1:
35  if rospy.is_shutdown():
36  exit(0)
37  rospy.logwarn("Please create a subscriber to '" + rospy.get_namespace() + "/obstacle_distance/registerObstacle' topic (Type: moveit_msgs/CollisionObject)")
38  time.sleep(1.0)
39 
40  rospy.loginfo("Continue ...")
41 
42  # Publish a simple sphere
43  x = CollisionObject()
44  x.id = "Funny Sphere"
45  x.header.frame_id = frame_id
46  x.operation = CollisionObject.ADD
47  sphere = SolidPrimitive()
48  sphere.type = SolidPrimitive.SPHERE
49  sphere.dimensions.append(0.1) # radius
50  x.primitives.append(sphere)
51 
52  pose = Pose()
53  pose.position.x = 0.35
54  pose.position.y = -0.35
55  pose.position.z = 0.8
56  pose.orientation.x = 0.0;
57  pose.orientation.y = 0.0;
58  pose.orientation.z = 0.0;
59  pose.orientation.w = 1.0;
60  x.primitive_poses.append(pose)
61  pub.publish(x)
62  time.sleep(1.0)
63 
64  # Now publish a mesh and use the db field for the mesh-resource name
65  y = CollisionObject()
66  y.id = "Funny Mesh"
67  y.header.frame_id = frame_id
68  y.type.db = "package://cob_gazebo_objects/Media/models/milk.dae"
69  y.operation = CollisionObject.ADD
70 
71  pose = Pose()
72  pose.position.x = -0.35
73  pose.position.y = -0.35
74  pose.position.z = 0.8
75  pose.orientation.x = 0.0;
76  pose.orientation.y = 0.0;
77  pose.orientation.z = 0.0;
78  pose.orientation.w = 1.0;
79  y.mesh_poses.append(pose)
80  pub.publish(y)
81  time.sleep(1.0)
82 
83  rospy.spin()


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47