sushi_demo.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('sushi_executive')
00003 from pr2_tasks.table_tasks import TableTasks, Setting
00004 from pr2_python.torso import Torso
00005 import rospy
00006 import pr2_python.visualization_tools as vt
00007 from visualization_msgs.msg import MarkerArray
00008 import pymongo as pm
00009 from sushi_turntable.grasp_turntable import GraspTurntable
00010 from pr2_tasks.exceptions import DetectionError
00011 from geometry_msgs.msg import PoseStamped
00012 
00013 class SushiParameters:
00014     def __init__(self, clean_table, eating_table, dirty_table, setting):
00015         self.clean_table = clean_table
00016         self.dirty_table = dirty_table
00017         self.eating_table = eating_table
00018         self.setting = setting
00019 
00020 
00021 def get_tables_from_db():
00022     """
00023     Get table info from db
00024     Note that we have a slight difference in naming.  What the db calls the
00025     'serving table', this script refers to as the 'eating table', and what the
00026     db calls the 'shelves', this script refers to the as the 'clean table'
00027     """
00028     conn = pm.Connection(port=rospy.get_param('warehouse_port', 27017))
00029     coll = conn.semantic_world_model.sushi_planes
00030     l = list(coll.find({}))
00031     if len(l) != 1:
00032         raise RuntimeError("DB collection {0} was empty".format(coll))
00033 
00034     def get_table(name):
00035         if name in l[0]:
00036             return dict(zip(('x', 'y', 'z'), l[0][name]))
00037         else:
00038             raise RuntimeError("Stored db hypothesis {0} doesn't include {1}".\
00039                                format(l[0], name))
00040 
00041     try:
00042         locs = l[0]['place-locs']
00043     except KeyError:
00044         rospy.logwarn('No setting centers found')
00045         locs = None
00046     return (get_table('shelves'),
00047             get_table('dirty-table'),
00048             get_table('serving-table'),
00049             locs)
00050 
00051 def get_params(tables_from_db=False):
00052     if tables_from_db:
00053         clean_table, dirty_table, eating_table, setting_centers = get_tables_from_db()
00054     else:
00055         clean_table = rospy.get_param('sushi_groups/clean_table')
00056         dirty_table = rospy.get_param('sushi_groups/dirty_table')
00057         eating_table = rospy.get_param('sushi_groups/eating_table')
00058         setting_centers = None
00059     setting_places_dict = rospy.get_param('sushi_groups/setting/places')
00060     setting_places = {}
00061     for label in setting_places_dict:
00062         setting_places[label] = (setting_places_dict[label]['x'], setting_places_dict[label]['y'])
00063     setting_dimensions = rospy.get_param('sushi_groups/setting/dimensions')
00064     return SushiParameters((clean_table['x'], clean_table['y'], clean_table['z']),
00065                            (eating_table['x'], eating_table['y'], eating_table['z']),
00066                            (dirty_table['x'], dirty_table['y'], dirty_table['z']),
00067                            Setting(setting_places, (setting_dimensions['x'], setting_dimensions['y']),
00068                                    setting_centers))   
00069 
00070 def set_table(tt, setting, clean_table, eating_table):
00071     try:
00072         tt.set_setting(setting, clean_table, eating_table)
00073         return True
00074     except DetectionError:
00075         return False
00076 
00077 def clear_table(tt, eating_table, dirty_table):
00078     tt.clear_table(eating_table, dirty_table)
00079     
00080 def show_setting():
00081     params = get_params()
00082     tt = TableTasks()
00083     places = tt.go_get_setting_places(params.setting, params.eating_table)
00084     vpub = rospy.Publisher('setting_markers', MarkerArray)
00085     marray = MarkerArray()
00086     for p in places:
00087         rospy.loginfo(p +': (' + str(places[p].pose.position.x)+', '+str(places[p].pose.position.y)+
00088                       str(places[p].pose.position.z)+')')
00089         marray.markers.append(vt.marker_at(places[p], ns=p))
00090     while not rospy.is_shutdown():
00091         vpub.publish(marray)
00092         rospy.sleep(0.1)
00093         
00094 def main():
00095     #read in the parameters
00096     params = get_params()
00097     rospy.loginfo('Shelves are '+str(params.clean_table))
00098     rospy.loginfo('Centers are '+str(params.setting.centers))
00099     torso = Torso()
00100     rospy.loginfo('Raising torso')
00101     torso.up()
00102     
00103     tt = TableTasks()
00104     gg = GraspTurntable(arm_name='right_arm')
00105     gg.reset()
00106 #    rospy.loginfo('Clearing table')
00107 #    clear_table(tt, params.eating_table, params.dirty_table)
00108     rospy.loginfo('Setting table')
00109     if not set_table(tt, params.setting, params.clean_table, params.eating_table):
00110         rospy.loginfo('Could not set table')
00111     rospy.loginfo('Returning to home position')
00112     tt._tasks.move_arms_to_side()
00113 
00114     rospy.loginfo('Trying to pick up bowl from turntable')
00115     tt._base.move_to_look(2.2375, -0.5375, 0.5875)
00116     tt._tasks._head.look_at_map_point(2.2375,-0.5375,0.5875)
00117 
00118 
00119     if not rospy.is_shutdown():
00120         # torso height for Willow = 0.25
00121         # torso height for Turtlebot = 0.10
00122         gg.torso.move(0.25)
00123         gg.pickup_object()
00124         
00125         pose_stamped = PoseStamped()
00126         pose_stamped.pose.position.x = 0.462
00127         pose_stamped.pose.position.y = 1.589
00128         pose_stamped.pose.position.z = 0.752
00129         pose_stamped.pose.orientation.w = 1.0
00130         pose_stamped.header.frame_id = '/map'
00131 
00132         tt._tasks.go_and_place('right_arm',pose_stamped)
00133 
00134 
00135 rospy.init_node('sushi_demo_node')
00136 main()
00137 #show_setting()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


tidyup_executive
Author(s): Daniel Benamy
autogenerated on Wed Dec 26 2012 16:15:09