bb_placement.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('srs_training')
00004 import rospy
00005 from geometry_msgs.msg import Vector3, PoseStamped, Pose
00006 from srs_interaction_primitives.srv import GetUnknownObject, SetAllowObjectInteraction, AddUnknownObject
00007 from srs_interaction_primitives.msg import PoseType
00008 
00009 class bb_placement():
00010     
00011     def __init__(self):
00012         
00013         but_gui_ns = '/interaction_primitives'
00014         self.s_add_unknown_object = but_gui_ns + '/add_unknown_object'
00015         self.s_get_object = but_gui_ns + '/get_unknown_object'
00016         self.s_allow_interaction = but_gui_ns + '/set_allow_object_interaction'
00017         
00018         rospy.wait_for_service(self.s_add_unknown_object)
00019         rospy.wait_for_service(self.s_get_object)
00020         rospy.wait_for_service(self.s_allow_interaction)     
00021         
00022         self.a = 0.4 # height (z)
00023         self.b = 0.4 # length (x)
00024         self.c = 0.2 # width (y)
00025         
00026         self.pz = 0.0
00027     
00028     def spawn(self):
00029         
00030        bb_pose = Pose()
00031        
00032        bb_pose.position.x = 0.0
00033        bb_pose.position.y = 0.0
00034        bb_pose.position.z = self.pz
00035        
00036        bb_pose.orientation.x = 0.0
00037        bb_pose.orientation.y = 0.0
00038        bb_pose.orientation.z = 0.
00039        bb_pose.orientation.w = 1.0
00040        
00041        bb_lwh = Vector3()
00042        
00043        bb_lwh.x = self.b
00044        bb_lwh.y = self.c
00045        bb_lwh.z = self.a
00046     
00047        add_object = rospy.ServiceProxy(self.s_add_unknown_object, AddUnknownObject)
00048     
00049        try:
00050             
00051             add_object(frame_id='/map',
00052                        name='unknown_object',
00053                        description='Object to be grasped',
00054                        pose_type= PoseType.POSE_BASE,
00055                        pose = bb_pose,
00056                        scale = bb_lwh,
00057                        disable_material=True)
00058           
00059        except Exception, e:
00060           
00061           rospy.logerr('Cannot add IM object to the scene, error: %s',str(e))
00062           
00063           return False
00064           
00065           
00066        allow_interaction = rospy.ServiceProxy(self.s_allow_interaction, SetAllowObjectInteraction)
00067        
00068        try:
00069             
00070             allow_interaction(name = 'unknown_object',
00071                               allow = True)
00072           
00073        except Exception, e:
00074           
00075           rospy.logerr('Cannot allow interaction, error: %s',str(e))
00076           
00077           return False
00078        
00079       
00080        return True
00081         
00082             
00083         
00084 if __name__ == '__main__':
00085     
00086     rospy.init_node('bb_placement')
00087     
00088     rospy.loginfo('Starting bb_placement node')
00089     
00090     bb = bb_placement()
00091     
00092     rospy.loginfo('Initialized')
00093     
00094     bb.spawn()
00095     
00096     rospy.loginfo('Finished')
00097         
00098         


srs_training
Author(s): Florian Weisshardt
autogenerated on Mon Oct 6 2014 08:56:22