Skip to content

Commit a6ac652

Browse files
authored
Rwc2023 challenge serve breakfast (#1326)
- Challenge serve breakfast adopted to impuls but not tuned for it. - issue #1325 keeps track of the issues that are still in the code. - Additional PRs to follow that fix the issues
2 parents f718daf + 72abef7 commit a6ac652

File tree

6 files changed

+74
-40
lines changed

6 files changed

+74
-40
lines changed

challenge_serve_breakfast/images/spoon.jpg

100755100644
23.4 KB
Loading

challenge_serve_breakfast/src/challenge_serve_breakfast/navigate_to_and_pick_item.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
from challenge_serve_breakfast.tuning import REQUIRED_ITEMS, JOINTS_HANDOVER, PICK_ROTATION
1212
from robot_skills import get_robot
13+
from robot_skills.arm.arms import GripperTypes
14+
# ROS
15+
from pykdl_ros import VectorStamped
16+
from robot_smach_states.human_interaction import Say
1317
from robot_smach_states.navigation import NavigateToSymbolic
1418
from robot_smach_states.util.designators import EdEntityDesignator
1519
from smach import StateMachine, cb_interface, CBState
@@ -31,7 +35,7 @@ def __init__(self, robot):
3135

3236
def send_joint_goal(position_array, wait_for_motion_done=True):
3337
# noinspection PyProtectedMember
34-
arm._send_joint_trajectory([position_array], timeout=rospy.Duration(0))
38+
arm._send_joint_trajectory([position_array], timeout=0.0)
3539
if wait_for_motion_done:
3640
arm.wait_for_motion_done()
3741

@@ -52,10 +56,17 @@ def show_image(package_name, path_to_image_in_package):
5256

5357
@cb_interface(outcomes=["done"])
5458
def _rotate(_):
55-
arm.gripper.send_goal("close", timeout=0.)
56-
robot.head.look_up()
57-
vyaw = 0.5
58-
robot.base.force_drive(0, 0, vyaw, PICK_ROTATION / vyaw)
59+
arm.gripper.send_goal("close", timeout=0.0)
60+
61+
# Look to the operator
62+
robot.head.look_at_point(VectorStamped.from_xyz(0.2, -0.2, 1.75, stamp=rospy.Time.now(),
63+
frame_id=robot.base_link_frame))
64+
robot.head.wait_for_motion_done()
65+
return "done"
66+
67+
@cb_interface(outcomes=["done"])
68+
def _handover_pose(user_data):
69+
send_joint_goal(JOINTS_HANDOVER, wait_for_motion_done=False)
5970
return "done"
6071

6172
@cb_interface(outcomes=["succeeded", "failed"], output_keys=["item_picked"])
@@ -67,29 +78,33 @@ def _ask_user(user_data):
6778

6879
item_name = leftover_items[0]
6980

70-
send_joint_goal(JOINTS_HANDOVER, wait_for_motion_done=False)
71-
7281
picked_items.append(item_name)
7382

7483
robot.speech.speak("Please put the {} in my gripper, like this".format(item_name), block=False)
7584
show_image("challenge_serve_breakfast", item_img_dict[item_name])
7685

7786
send_gripper_goal("open")
78-
rospy.sleep(10.0)
79-
robot.speech.speak("Thanks for that!", block=False)
87+
rospy.sleep(7.0)
8088
send_gripper_goal("close", max_torque=0.6)
8189
robot.head.reset()
8290

8391
# Set output data
8492
user_data["item_picked"] = item_name
93+
return "succeeded"
8594

95+
@cb_interface(outcomes=["done"])
96+
def _carrying_pose(user_data):
8697
arm.send_joint_goal("carrying_pose", timeout=0.)
87-
88-
return "succeeded"
98+
robot.speech.speak("Thanks for that!", block=False)
99+
return "done"
89100

90101
with self:
91-
self.add("ROTATE", CBState(_rotate), transitions={"done": "ASK_USER"})
92-
self.add("ASK_USER", CBState(_ask_user), transitions={"succeeded": "succeeded", "failed": "failed"})
102+
self.add("ROTATE", CBState(_rotate), transitions={"done": "HANDOVER_POSE"})
103+
self.add("HANDOVER_POSE", CBState(_handover_pose), transitions={"done": "ASK_USER"})
104+
self.add("ASK_USER", CBState(_ask_user),
105+
transitions={"succeeded": "CARRYING_POSE", "failed": "failed"})
106+
107+
self.add("CARRYING_POSE", CBState(_carrying_pose), transitions={"done": "succeeded"})
93108

94109

95110
class NavigateToAndPickItem(StateMachine):
@@ -101,7 +116,7 @@ def __init__(self, robot, pick_spot_id, pick_spot_navigation_area):
101116
with self:
102117
StateMachine.add(
103118
"NAVIGATE_TO_PICK_SPOT",
104-
NavigateToSymbolic(robot, {pick_spot: pick_spot_navigation_area}, pick_spot),
119+
NavigateToSymbolic(robot, {pick_spot: pick_spot_navigation_area},pick_spot, speak=False),
105120
transitions={"arrived": "PICK_ITEM", "unreachable": "failed", "goal_not_defined": "failed"},
106121
)
107122

challenge_serve_breakfast/src/challenge_serve_breakfast/navigate_to_and_place_item_on_table.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, robot, table_id):
4242

4343
def send_joint_goal(position_array, wait_for_motion_done=True):
4444
# noinspection PyProtectedMember
45-
arm._send_joint_trajectory([position_array], timeout=rospy.Duration(0))
45+
arm._send_joint_trajectory([position_array], timeout=0.0)
4646
if wait_for_motion_done:
4747
arm.wait_for_motion_done()
4848

@@ -83,10 +83,8 @@ def _align_with_table(user_data):
8383
def _place_and_retract(user_data):
8484
rospy.loginfo("Placing...")
8585
item_name = user_data["item_picked"]
86-
if item_name in ["milk_carton"]:
86+
if item_name in ["milk_carton", "cereal_box"]:
8787
send_joint_goal(JOINTS_PLACE_HORIZONTAL_MILK)
88-
elif item_name in ["milk_carton", "cereal_box"]:
89-
send_joint_goal(JOINTS_PLACE_HORIZONTAL)
9088
else:
9189
send_joint_goal(JOINTS_PLACE_VERTICAL)
9290

@@ -129,7 +127,7 @@ def __init__(self, robot, table_id, table_close_navigation_area):
129127
)
130128
StateMachine.add(
131129
"NAVIGATE_TO_TABLE_CLOSE",
132-
NavigateToSymbolic(robot, {table: table_close_navigation_area}, table),
130+
NavigateToSymbolic(robot, {table: table_close_navigation_area}, table, speak=False),
133131
transitions={
134132
"arrived": "PLACE_ITEM_ON_TABLE",
135133
"unreachable": "SAY_PICK_AWAY_THE_CHAIR",
@@ -164,7 +162,7 @@ def __init__(self, robot, table_id, table_close_navigation_area):
164162
)
165163

166164
@cb_interface(outcomes=["done"])
167-
def _publish_item_poses(marker_array_pub, items):
165+
def _publish_item_poses(user_data, marker_array_pub, items):
168166
"""
169167
Publishes item poses as a visualization marker array
170168
@@ -184,7 +182,7 @@ def _publish_item_poses(marker_array_pub, items):
184182
marker_msg.type = visualization_msgs.msg.Marker.SPHERE
185183
marker_msg.action = 0
186184
marker_msg.pose = posestamped.pose
187-
marker_msg.pose.position.z += 1.0
185+
marker_msg.pose.position.z = 1.0
188186
marker_msg.scale = Vector3(0.05, 0.05, 0.05)
189187
marker_msg.color = COLOR_DICT[k]
190188
array_msg.markers.append(marker_msg)

challenge_serve_breakfast/src/challenge_serve_breakfast/pick_pour_place_cereal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, robot, table_id):
2525

2626
def send_joint_goal(position_array, wait_for_motion_done=True):
2727
# noinspection PyProtectedMember
28-
arm._send_joint_trajectory([position_array], timeout=rospy.Duration(0))
28+
arm._send_joint_trajectory([position_array], timeout=0.0)
2929
if wait_for_motion_done:
3030
arm.wait_for_motion_done()
3131

@@ -54,6 +54,7 @@ def _align_pour(_):
5454
def _pour(_):
5555
robot.speech.speak("Hope this goes well", block=False)
5656
send_joint_goal(JOINTS_PRE_POUR)
57+
rospy.sleep(0.5)
5758
send_joint_goal(JOINTS_POUR)
5859
send_joint_goal(JOINTS_PRE_POUR)
5960
send_joint_goal(JOINTS_POST_PICK)

challenge_serve_breakfast/src/challenge_serve_breakfast/serve_breakfast.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from robot_smach_states.navigation import NavigateToWaypoint
1010
from robot_smach_states.startup import StartChallengeRobust
1111
from robot_smach_states.util.designators import EdEntityDesignator
12+
from robot_smach_states.world_model import UpdateEntityPose
1213
from robot_smach_states.utility import WaitTime
1314
from smach import State, StateMachine
14-
from .navigate_to_and_pick_item import NavigateToAndPickItem
15+
from .navigate_to_and_pick_item import NavigateToAndPickItem, NavigateToSymbolic
1516
from .navigate_to_and_place_item_on_table import NavigateToAndPlaceItemOnTable
1617
from .pick_pour_place_cereal import PickPourPlaceCereal
1718
from .tuning import REQUIRED_ITEMS
@@ -51,34 +52,53 @@ def execute(self, userdata):
5152
def setup_statemachine(robot):
5253
state_machine = StateMachine(outcomes=["done"])
5354
state_machine.userdata["item_picked"] = None
54-
pick_id = "dinner_table"
55+
pick_id = "closet"
5556
pick_area_id = "in_front_of"
5657
place_id = "dinner_table"
5758
place_area_id = "in_front_of"
5859
exit_id = "starting_pose"
60+
table_des = EdEntityDesignator(robot=robot, uuid=place_id)
5961

6062
with state_machine:
6163
# Intro
6264

6365
StateMachine.add(
6466
"START_CHALLENGE_ROBUST",
6567
StartChallengeRobust(robot, "initial_pose"),
66-
transitions={"Done": "SAY_START", "Aborted": "done", "Failed": "SAY_START"},
68+
transitions={"Done": "NAVIGATE_TO_TABLE", "Aborted": "GOODBYE", "Failed": "NAVIGATE_TO_TABLE"},
69+
)
70+
#Main loop
71+
StateMachine.add(
72+
"NAVIGATE_TO_TABLE",
73+
NavigateToSymbolic(robot, {table_des:place_area_id}, table_des, speak=True),
74+
transitions={"arrived": "UPDATE_TABLE_POSE", "unreachable": "SAY_OPERATOR_WHERE_TO_STAND", "goal_not_defined": "SAY_OPERATOR_WHERE_TO_STAND"},
75+
)
76+
77+
StateMachine.add(
78+
"UPDATE_TABLE_POSE",
79+
UpdateEntityPose(robot=robot, entity_designator=table_des),
80+
transitions={"done": "SAY_OPERATOR_WHERE_TO_STAND"},
81+
)
82+
83+
StateMachine.add(
84+
"SAY_OPERATOR_WHERE_TO_STAND",
85+
Say(
86+
robot,
87+
"Operator, please stand at the RIGHT of the dishwasher",
88+
block=False,
89+
),
90+
transitions={"spoken": "SAY_START"},
6791
)
6892

6993
StateMachine.add(
7094
"SAY_START",
7195
Say(
7296
robot,
73-
#f"Lets serve some breakfast baby! If there are any chairs near the {place_id}, please remove them",
7497
"Lets serve some breakfast baby! I will be asking for some fast handovers.",
7598
block=False,
7699
),
77100
transitions={"spoken": "NAVIGATE_AND_PICK_ITEM"},
78101
)
79-
80-
# Main loop
81-
82102
StateMachine.add(
83103
"NAVIGATE_AND_PICK_ITEM",
84104
NavigateToAndPickItem(robot, pick_id, pick_area_id),
@@ -87,7 +107,7 @@ def setup_statemachine(robot):
87107

88108
StateMachine.add(
89109
"NAVIGATE_AND_PICK_ITEM_FAILED", WaitTime(robot, 2),
90-
transitions={"waited": "NAVIGATE_AND_PICK_ITEM", "preempted": "done"}
110+
transitions={"waited": "NAVIGATE_AND_PICK_ITEM", "preempted": "GOODBYE"}
91111
)
92112

93113
StateMachine.add(
@@ -97,7 +117,7 @@ def setup_statemachine(robot):
97117
)
98118

99119
StateMachine.add(
100-
"WAIT", WaitTime(robot, 2), transitions={"waited": "CHECK_IF_WE_HAVE_IT_ALL", "preempted": "done"}
120+
"WAIT", WaitTime(robot, 2), transitions={"waited": "CHECK_IF_WE_HAVE_IT_ALL", "preempted": "GOODBYE"}
101121
)
102122

103123
StateMachine.add(

challenge_serve_breakfast/src/challenge_serve_breakfast/tuning.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
REQUIRED_ITEMS = ["spoon", "bowl", "milk_carton", "cereal_box"]
1616

1717
ITEM_VECTOR_DICT = {
18-
"spoon": PyKDL.Vector(0.03, -0.15, 0),
19-
"bowl": PyKDL.Vector(0.1, -0.04, 0),
20-
"milk_carton": PyKDL.Vector(-0.1, 0.3, 0),
21-
"cereal_box": PyKDL.Vector(-0.1, -0.3, 0),
18+
"spoon": PyKDL.Vector(0.0, -0.15, 0),
19+
"bowl": PyKDL.Vector(0.0, 0.0, 0),
20+
"milk_carton": PyKDL.Vector(-0.05, 0.15, 0),
21+
"cereal_box": PyKDL.Vector(-0.05, -0.2, 0),
2222
}
2323

2424
COLOR_DICT = {
@@ -28,7 +28,7 @@
2828
"cereal_box": ColorRGBA(1, 1, 0, 1),
2929
}
3030

31-
PICK_ROTATION = 2.
31+
PICK_ROTATION = 0
3232

3333
JOINTS_HANDOVER = [0.4, -0.2, 0.0, -1.37, 0]
3434

@@ -45,16 +45,16 @@
4545

4646
JOINTS_POST_PICK = [0.7, -1.2, 0, 0, 0]
4747

48-
JOINTS_PRE_POUR = [0.5, -1.2, -1.5, 0, 0]
48+
JOINTS_PRE_POUR = [0.35, -1.2, 0, 0, 0]
4949

50-
JOINTS_POUR = [0.5, -1.2, -2.5, 0, 0]
50+
JOINTS_POUR = [0.4, -1.2, -2.5, 0, 0]
5151

52-
POUR_OFFSET_X = 0.03
52+
POUR_OFFSET_X = -0.15
5353
POUR_OFFSET_Y = 0.15
5454

5555

5656
def item_vector_to_item_frame(item_vector):
57-
frame = PyKDL.Frame(PyKDL.Rotation.RPY(0, 0, -math.pi / 2), PyKDL.Vector(-0.05, 0.75, 0))
57+
frame = PyKDL.Frame(PyKDL.Rotation.RPY(0, 0, math.pi), PyKDL.Vector(0.7, 0, 0))
5858

5959
item_placement_vector = item_vector
6060
item_frame = frame

0 commit comments

Comments
 (0)