test_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("simple_obstacle_pub")
28  root_frame = "/odom_combined"
29 
30  pub = rospy.Publisher("obstacle_distance/registerObstacle", CollisionObject, queue_size = 1)
31 
32  while pub.get_num_connections() < 1:
33  if rospy.is_shutdown():
34  exit(0)
35  rospy.logwarn("Please create a subscriber to 'obstacle_distance/registerObstacle' topic (Type: moveit_msgs/CollisionObject)")
36  time.sleep(1.0)
37 
38  rospy.loginfo("Continue ...")
39 
40  # Publish a simple sphere
41  x = CollisionObject()
42  x.id = "Funny Sphere"
43  x.header.frame_id = root_frame
44  x.operation = CollisionObject.ADD
45  #x.operation = CollisionObject.REMOVE
46  sphere = SolidPrimitive()
47  sphere.type = SolidPrimitive.SPHERE
48  sphere.dimensions.append(0.1) # radius
49  x.primitives.append(sphere)
50 
51  pose = Pose()
52  pose.position.x = 0.35
53  pose.position.y = -0.45
54  pose.position.z = 0.8
55  pose.orientation.x = 0.0;
56  pose.orientation.y = 0.0;
57  pose.orientation.z = 0.0;
58  pose.orientation.w = 1.0;
59  x.primitive_poses.append(pose)
60  # pub.publish(x)
61  time.sleep(1.0)
62 
63  # Now publish a mesh and use the db field for the stl-resource name
64  y = CollisionObject()
65  y.id = "Funny Mesh"
66  y.header.frame_id = root_frame
67  # y.type.db = "package://cob_gazebo_objects/Media/models/milk.dae"
68  y.type.db = "package://cob_gazebo_objects/Media/models/cabinet_ikea_kallax_4x2.stl"
69  # y.type.db = "package://cob_twist_controller/files/torus_0_25_inner_rad.stl"
70  y.operation = CollisionObject.ADD
71  # y.operation = CollisionObject.REMOVE
72 
73  pose = Pose()
74  pose.position.x = 0.5
75  pose.position.y = 0.5
76  pose.position.z = 0.0
77  pose.orientation.x = 0.0
78  pose.orientation.y = 0.0
79  pose.orientation.z = 0.0
80  pose.orientation.w = 1.0
81  y.mesh_poses.append(pose)
82  pub.publish(y)
83  time.sleep(1.0)
84 
85  rospy.loginfo("Done!")


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