publish_moveit_collision.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import sys
3 import rospy
4 import shape_msgs.msg
5 import moveit_msgs.msg
6 import geometry_msgs.msg
7 from std_msgs.msg import String
8 
10  rospy.init_node('publish_scene_collision', anonymous=True)
11  collision_pub = rospy.Publisher('/collision_object', moveit_msgs.msg.CollisionObject, queue_size=1)
12  coll_ob = moveit_msgs.msg.CollisionObject()
13  shape = shape_msgs.msg.SolidPrimitive()
14 
15  #Create ground plane shape
16  shape.type = shape.BOX
17  shape.dimensions = [1.4, 1.4, 0.01]
18 
19  #Create ground plane pose
20  g_pose = geometry_msgs.msg.Pose()
21  g_pose.position.z = -0.01
22 
23 
24  #Create buffer shapes
25  buff1 = shape_msgs.msg.SolidPrimitive()
26  buff1.type = buff1.BOX
27  buff1.dimensions = [0.8, 1.825, 0.05]
28  buff1_pose = geometry_msgs.msg.Pose()
29  buff1_pose.position.x = -0.5
30  buff1_pose.position.z = 0.025
31 
32  buff2_pose = geometry_msgs.msg.Pose()
33  buff2_pose.position.x = 0.5
34  buff2_pose.position.z = 0.025
35 
36  buff3 = shape_msgs.msg.SolidPrimitive()
37  buff3.type = buff3.BOX
38  buff3.dimensions = [0.4, 0.825, 0.05]
39  buff3_pose = geometry_msgs.msg.Pose()
40  buff3_pose.position.y = -0.5
41  buff3_pose.position.z = 0.025
42 
43  buff4_pose = geometry_msgs.msg.Pose()
44  buff4_pose.position.y = 0.5
45  buff4_pose.position.z = 0.025
46 
47 
48  #Example of wall, behind robot
49  wall1 = shape_msgs.msg.SolidPrimitive()
50  wall1.type = wall1.BOX
51  wall1.dimensions = [0.02, 2.5, 1.0]
52  wall1_pose = geometry_msgs.msg.Pose()
53  wall1_pose.position.x = -0.15
54  wall1_pose.position.y = 0.3
55  wall1_pose.position.z = 0.5
56 
57  #Create a ground plane
58  coll_ob.operation = coll_ob.ADD
59  coll_ob.header.frame_id = "base_link"
60  coll_ob.id = "ground_plane"
61  #coll_ob.primitives.append(shape)
62  #coll_ob.primitive_poses.append(g_pose)
63 
64  #coll_ob.primitives.append(buff1)
65  #coll_ob.primitive_poses.append(buff1_pose)
66 
67  coll_ob.primitives.append(buff1)
68  coll_ob.primitive_poses.append(buff2_pose)
69 
70  coll_ob.primitives.append(buff3)
71  coll_ob.primitive_poses.append(buff3_pose)
72 
73  coll_ob.primitives.append(buff3)
74  coll_ob.primitive_poses.append(buff4_pose)
75 
76 
77  coll_ob.primitives.append(wall1)
78  coll_ob.primitive_poses.append(wall1_pose)
79 
80  #Annoyingly need to publish many times, if not spinning continuously
81  collision_pub.publish(coll_ob)
82  rospy.sleep(1.0)
83  collision_pub.publish(coll_ob)
84  collision_pub.publish(coll_ob)
85  collision_pub.publish(coll_ob)
86  rospy.sleep(1.0)
87 
88 if __name__=='__main__':
89  try:
91  except rospy.ROSInterruptException:
92  pass


svenzva_utils
Author(s): Max Svetlik
autogenerated on Wed Oct 28 2020 03:31:33