1111import rospy
1212import visualization_msgs .msg
1313from geometry_msgs .msg import PoseStamped , Vector3
14+ from pykdl_ros import FrameStamped
1415
1516from challenge_serve_breakfast .tuning import (
16- JOINTS_PRE_PRE_PLACE ,
17- JOINTS_PRE_PLACE_HORIZONTAL ,
18- JOINTS_PRE_PLACE_VERTICAL ,
17+ get_item_place_pose ,
1918 ITEM_VECTOR_DICT ,
2019 item_vector_to_item_frame ,
2120 item_frame_to_pose ,
22- JOINTS_PLACE_HORIZONTAL ,
23- JOINTS_PLACE_HORIZONTAL_MILK ,
24- JOINTS_PLACE_VERTICAL ,
25- JOINTS_RETRACT ,
26- COLOR_DICT , REQUIRED_ITEMS ,
21+ COLOR_DICT ,
22+ REQUIRED_ITEMS ,
2723)
2824from robot_skills import get_robot
2925from robot_smach_states .human_interaction import Say
3531
3632
3733class PlaceItemOnTable (StateMachine ):
38- def __init__ (self , robot , table_id ):
34+ def __init__ (self , robot , table_id , retract = True ):
3935 StateMachine .__init__ (self , outcomes = ["succeeded" , "failed" ], input_keys = ["item_picked" ])
4036 # noinspection PyProtectedMember
4137 arm = robot .get_arm ()._arm
38+ self .retract = retract
4239
43- def send_joint_goal (position_array , wait_for_motion_done = True ):
44- # noinspection PyProtectedMember
45- arm ._send_joint_trajectory ([position_array ], timeout = rospy .Duration (0 ))
40+ def send_goal (pose_goal , wait_for_motion_done = True ):
41+ arm .send_goal (pose_goal , timeout = 0.0 )
4642 if wait_for_motion_done :
4743 arm .wait_for_motion_done ()
4844
4945 def send_gripper_goal (open_close_string , wait_for_motion_done = True ):
5046 arm .gripper .send_goal (open_close_string )
5147
5248 @cb_interface (outcomes = ["done" ], input_keys = ["item_picked" ])
53- def _pre_place (user_data ):
49+ def _place (user_data ):
5450 item_name = user_data ["item_picked" ]
5551 rospy .loginfo (f"Preplacing { item_name } ..." )
5652
@@ -59,57 +55,52 @@ def _pre_place(user_data):
5955 robot .head .look_up ()
6056 robot .head .wait_for_motion_done ()
6157
62- send_joint_goal (JOINTS_PRE_PRE_PLACE )
58+ item_place_pose = get_item_place_pose (user_data ["item_picked" ])
59+ place_fs = FrameStamped (item_place_pose , rospy .Time (0 ), table_id )
6360
64- if item_name in ["milk_carton" , "cereal_box" ]:
65- send_joint_goal (JOINTS_PRE_PLACE_HORIZONTAL )
66- else :
67- send_joint_goal (JOINTS_PRE_PLACE_VERTICAL )
61+ pre_place_fs = copy .deepcopy (place_fs )
62+ pre_place_fs .frame .p .z (place_fs .frame .p .z () + 0.1 )
6863
69- return "done"
70-
71- @cb_interface (outcomes = ["done" ], input_keys = ["item_picked" ])
72- def _align_with_table (user_data ):
73- item_placement_vector = ITEM_VECTOR_DICT [user_data ["item_picked" ]]
74- item_frame = item_vector_to_item_frame (item_placement_vector )
64+ post_place_fs = copy .deepcopy (place_fs )
65+ post_place_fs .frame .p .z (place_fs .frame .p .z () + 0.2 )
7566
76- goal_pose = item_frame_to_pose ( item_frame , table_id )
77- rospy . loginfo ( "Placing {} at {}" . format ( user_data [ "item_picked" ], goal_pose ) )
67+ rospy . loginfo ( "Pre Placing..." )
68+ send_goal ( pre_place_fs )
7869 robot .head .look_down ()
79- ControlToPose ( robot , goal_pose , ControlParameters ( 0.5 , 1.0 , 0.3 , 0.3 , 0.3 , 0.02 , 0.1 )). execute ({} )
80- return "done"
70+ robot . head . look_up ( )
71+ robot . head . wait_for_motion_done ()
8172
82- @cb_interface (outcomes = ["done" ], input_keys = ["item_picked" ])
83- def _place_and_retract (user_data ):
8473 rospy .loginfo ("Placing..." )
85- item_name = user_data ["item_picked" ]
86- if item_name in ["milk_carton" ]:
87- send_joint_goal (JOINTS_PLACE_HORIZONTAL_MILK )
88- elif item_name in ["milk_carton" , "cereal_box" ]:
89- send_joint_goal (JOINTS_PLACE_HORIZONTAL )
90- else :
91- send_joint_goal (JOINTS_PLACE_VERTICAL )
92-
93- rospy .loginfo ("Dropping..." )
74+ send_goal (place_fs )
9475 send_gripper_goal ("open" )
95- robot .head .look_up ()
96- robot .head .wait_for_motion_done ()
9776
98- if item_name != "cereal_box" :
99- rospy .loginfo ("Retract ..." )
100- send_joint_goal ( JOINTS_RETRACT , wait_for_motion_done = False )
77+ if item_name != "cereal_box" or self . retract :
78+ rospy .loginfo ("Retracting ..." )
79+ send_goal ( post_place_fs )
10180 robot .base .force_drive (- 0.1 , 0 , 0 , 3 ) # Drive backwards at 0.1m/s for 3s, so 30cm
10281 send_gripper_goal ("close" , wait_for_motion_done = False )
10382 arm .send_joint_goal ("carrying_pose" )
10483
84+ #if item_name in ["milk_carton", "cereal_box"]:
85+ # send_joint_goal(JOINTS_PRE_PLACE_HORIZONTAL)
86+ #else:
87+ # send_joint_goal(JOINTS_PRE_PLACE_VERTICAL)
88+
89+ #rospy.loginfo("Placing...")
90+ #item_name = user_data["item_picked"]
91+ #if item_name in ["milk_carton"]:
92+ # send_joint_goal(JOINTS_PLACE_HORIZONTAL_MILK)
93+ #elif item_name in ["milk_carton", "cereal_box"]:
94+ # send_joint_goal(JOINTS_PLACE_HORIZONTAL)
95+ #else:
96+ # send_joint_goal(JOINTS_PLACE_VERTICAL)
97+
10598 robot .head .reset ()
10699
107100 return "done"
108101
109102 with self :
110- self .add_auto ("PRE_PLACE" , CBState (_pre_place ), ["done" ])
111- self .add_auto ("ALIGN_WITH_TABLE" , CBState (_align_with_table ), ["done" ])
112- self .add ("PLACE_AND_RETRACT" , CBState (_place_and_retract ), transitions = {"done" : "succeeded" })
103+ self .add ("PLACE" , CBState (_place ), {"done" : "succeeded" })
113104
114105
115106class NavigateToAndPlaceItemOnTable (StateMachine ):
@@ -129,7 +120,7 @@ def __init__(self, robot, table_id, table_close_navigation_area):
129120 )
130121 StateMachine .add (
131122 "NAVIGATE_TO_TABLE_CLOSE" ,
132- NavigateToSymbolic (robot , {table : table_close_navigation_area }, table ),
123+ NavigateToSymbolic (robot , {table : table_close_navigation_area }, table , speak = False ),
133124 transitions = {
134125 "arrived" : "PLACE_ITEM_ON_TABLE" ,
135126 "unreachable" : "SAY_PICK_AWAY_THE_CHAIR" ,
@@ -159,12 +150,12 @@ def __init__(self, robot, table_id, table_close_navigation_area):
159150
160151 StateMachine .add (
161152 "PLACE_ITEM_ON_TABLE" ,
162- PlaceItemOnTable (robot , table_id ),
153+ PlaceItemOnTable (robot , table_id , retract = False ),
163154 transitions = {"succeeded" : "succeeded" , "failed" : "failed" },
164155 )
165156
166157@cb_interface (outcomes = ["done" ])
167- def _publish_item_poses (marker_array_pub , items ):
158+ def _publish_item_poses (user_data , marker_array_pub , items ):
168159 """
169160 Publishes item poses as a visualization marker array
170161
@@ -184,7 +175,6 @@ def _publish_item_poses(marker_array_pub, items):
184175 marker_msg .type = visualization_msgs .msg .Marker .SPHERE
185176 marker_msg .action = 0
186177 marker_msg .pose = posestamped .pose
187- marker_msg .pose .position .z += 1.0
188178 marker_msg .scale = Vector3 (0.05 , 0.05 , 0.05 )
189179 marker_msg .color = COLOR_DICT [k ]
190180 array_msg .markers .append (marker_msg )
0 commit comments