11
11
import rospy
12
12
import visualization_msgs .msg
13
13
from geometry_msgs .msg import PoseStamped , Vector3
14
+ from pykdl_ros import FrameStamped
14
15
15
16
from 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 ,
19
18
ITEM_VECTOR_DICT ,
20
19
item_vector_to_item_frame ,
21
20
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 ,
27
23
)
28
24
from robot_skills import get_robot
29
25
from robot_smach_states .human_interaction import Say
35
31
36
32
37
33
class PlaceItemOnTable (StateMachine ):
38
- def __init__ (self , robot , table_id ):
34
+ def __init__ (self , robot , table_id , retract = True ):
39
35
StateMachine .__init__ (self , outcomes = ["succeeded" , "failed" ], input_keys = ["item_picked" ])
40
36
# noinspection PyProtectedMember
41
37
arm = robot .get_arm ()._arm
38
+ self .retract = retract
42
39
43
- def send_joint_goal (position_array , wait_for_motion_done = True ):
44
- # noinspection PyProtectedMember
45
- arm ._send_joint_trajectory ([position_array ], timeout = 0.0 )
40
+ def send_goal (pose_goal , wait_for_motion_done = True ):
41
+ arm .send_goal (pose_goal , timeout = 0.0 )
46
42
if wait_for_motion_done :
47
43
arm .wait_for_motion_done ()
48
44
49
45
def send_gripper_goal (open_close_string , wait_for_motion_done = True ):
50
46
arm .gripper .send_goal (open_close_string )
51
47
52
48
@cb_interface (outcomes = ["done" ], input_keys = ["item_picked" ])
53
- def _pre_place (user_data ):
49
+ def _place (user_data ):
54
50
item_name = user_data ["item_picked" ]
55
51
rospy .loginfo (f"Preplacing { item_name } ..." )
56
52
@@ -59,55 +55,52 @@ def _pre_place(user_data):
59
55
robot .head .look_up ()
60
56
robot .head .wait_for_motion_done ()
61
57
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 )
63
60
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 )
68
63
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 )
75
66
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 )
78
69
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 ()
81
72
82
- @cb_interface (outcomes = ["done" ], input_keys = ["item_picked" ])
83
- def _place_and_retract (user_data ):
84
73
rospy .loginfo ("Placing..." )
85
- item_name = user_data ["item_picked" ]
86
- if item_name in ["milk_carton" , "cereal_box" ]:
87
- send_joint_goal (JOINTS_PLACE_HORIZONTAL_MILK )
88
- else :
89
- send_joint_goal (JOINTS_PLACE_VERTICAL )
90
-
91
- rospy .loginfo ("Dropping..." )
74
+ send_goal (place_fs )
92
75
send_gripper_goal ("open" )
93
- robot .head .look_up ()
94
- robot .head .wait_for_motion_done ()
95
76
96
- if item_name != "cereal_box" :
97
- rospy .loginfo ("Retract ..." )
98
- 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 )
99
80
robot .base .force_drive (- 0.1 , 0 , 0 , 3 ) # Drive backwards at 0.1m/s for 3s, so 30cm
100
81
send_gripper_goal ("close" , wait_for_motion_done = False )
101
82
arm .send_joint_goal ("carrying_pose" )
102
83
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
+
103
98
robot .head .reset ()
104
99
105
100
return "done"
106
101
107
102
with self :
108
- self .add_auto ("PRE_PLACE" , CBState (_pre_place ), ["done" ])
109
- self .add_auto ("ALIGN_WITH_TABLE" , CBState (_align_with_table ), ["done" ])
110
- self .add ("PLACE_AND_RETRACT" , CBState (_place_and_retract ), transitions = {"done" : "succeeded" })
103
+ self .add ("PLACE" , CBState (_place ), {"done" : "succeeded" })
111
104
112
105
113
106
class NavigateToAndPlaceItemOnTable (StateMachine ):
@@ -157,7 +150,7 @@ def __init__(self, robot, table_id, table_close_navigation_area):
157
150
158
151
StateMachine .add (
159
152
"PLACE_ITEM_ON_TABLE" ,
160
- PlaceItemOnTable (robot , table_id ),
153
+ PlaceItemOnTable (robot , table_id , retract = False ),
161
154
transitions = {"succeeded" : "succeeded" , "failed" : "failed" },
162
155
)
163
156
@@ -182,7 +175,6 @@ def _publish_item_poses(user_data, marker_array_pub, items):
182
175
marker_msg .type = visualization_msgs .msg .Marker .SPHERE
183
176
marker_msg .action = 0
184
177
marker_msg .pose = posestamped .pose
185
- marker_msg .pose .position .z = 1.0
186
178
marker_msg .scale = Vector3 (0.05 , 0.05 , 0.05 )
187
179
marker_msg .color = COLOR_DICT [k ]
188
180
array_msg .markers .append (marker_msg )
0 commit comments