load_scene_example.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 rospy
19 from geometry_msgs.msg import PoseStamped
20 from tf.transformations import quaternion_from_euler
21 from simple_moveit_interface import get_planning_scene_interface, add_ground, clear_objects
22 
23 
24 def gen_pose(frame_id="/odom_combined", pos=[0,0,0], euler=[0,0,0]):
25  pose = PoseStamped()
26  pose.header.frame_id = frame_id
27  pose.header.stamp = rospy.Time.now()
28  pose.pose.position.x, pose.pose.position.y, pose.pose.position.z = pos
29  pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w = quaternion_from_euler(*euler)
30  return pose
31 
32 if __name__ == '__main__':
33  rospy.init_node('load_scene')
34  while rospy.get_time() == 0.0: pass
35 
37  rospy.sleep(1.0)
38 
39  ### Add a floor
40  add_ground()
41 
42  ### Add primitives (box, sphere, cylinder)
43  pose = gen_pose(pos=[-0.9, 0.8, 0.5])
44  psi.add_box("box", pose, size=(0.3, 0.5, 0.7))
45 
46  pose = gen_pose(pos=[0.0, 0.0, 2.5])
47  psi.add_sphere("sphere", pose, radius=(0.3))
48 
49  # CollisionChecking with cylinder primitives does not work correctly, thus this is not supported! Use a mesh instead!
50 
51  ### ADDING A MESH
52  #ToDo: use rospack to find package
53  #ToDo: meshes cannot be scaled yet
54  pose = gen_pose(pos=[0.6, 0.0, 0.9], euler=[-1.57, 0, 3.14])
55  filename = '/opt/ros/groovy/stacks/simulator_gazebo/gazebo_worlds/Media/models/mug-test.stl'
56  psi.add_mesh("mug", pose, filename)
57 
58  rospy.sleep(1.0)
59 
60  ### ADDING DETECT and URDF not supported anymore
61  #ToDo: Add if needed
62 
63  ### ATTACHING AN OBJECT
64  #ToDo: attach without creating objects again
65  pose = gen_pose(pos=[0.4, 0.1, 1.0])
66  psi.attach_box("tray_link", "box2", pose, (0.1,0.1,0.1))
67 
68  pose = gen_pose(pos=[0.5, -0.9, 0.9], euler=[-1.57, 0, 3.14])
69  filename = '/opt/ros/groovy/stacks/simulator_gazebo/gazebo_worlds/Media/models/mug-test.stl'
70  touch_links = ["sdh_grasp_link", "sdh_palm_link", "sdh_finger_11_link", "sdh_finger_12_link", "sdh_finger_13_link", "sdh_finger_21_link", "sdh_finger_22_link", "sdh_finger_23_link", "sdh_thumb_1_link", "sdh_thumb_2_link", "sdh_thumb_3_link"]
71  psi.attach_mesh("arm_7_link", "mug", pose, filename, touch_links)
72 
73  rospy.sleep(1.0)
74 
75  ### DETACHING AN OBJECT
76  #ToDo: detach without stating link?
77  psi.remove_attached_object("arm_7_link", "mug")
78 
79  rospy.sleep(1.0)
80 
81  ### REMOVING AN OBJECT
82  psi.remove_world_object("sphere")
83 
84  ### CLEAR ALL OBJECTS
86 
def gen_pose(frame_id="/odom_combined", pos=[0, euler=[0)


cob_moveit_interface
Author(s): Felix Messmer
autogenerated on Sun Dec 6 2020 03:25:57