Skip to content

Commit

Permalink
feat: logic for second guest and pass guest id through constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jws-1 committed Apr 16, 2024
1 parent 36e323d commit 9976d2b
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 29 deletions.
191 changes: 168 additions & 23 deletions tasks/receptionist/src/receptionist/sm_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,86 +25,85 @@ def __init__(

with self:

self.userdata.guest_id = "guest1"
# TODO: correctly set guest_id
self.userdata.guest_data = {"host": host_data, "guest1": {}, "guest2": {}}

smach.StateMachine.add(
"GO_TO_WAIT_LOCATION",
"GO_TO_WAIT_LOCATION_GUEST_1",
GoToLocation(wait_pose),
transitions={
"succeeded": "SAY_WAITING",
"succeeded": "SAY_WAITING_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_WAITING",
"SAY_WAITING_GUEST_1",
Say(text="I am waiting for a guest."),
transitions={
"succeeded": "WAIT_FOR_PERSON",
"succeeded": "WAIT_FOR_PERSON_GUEST_1",
"aborted": "failed",
"preempted": "failed",
},
)

smach.StateMachine.add(
"WAIT_FOR_PERSON",
"WAIT_FOR_PERSON_GUEST_1",
WaitForPersonInArea(wait_area),
transitions={
"succeeded": "succeeded",
"succeeded": "GET_NAME_AND_DRINK_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"GET_NAME_AND_DRINK",
"GET_NAME_AND_DRINK_GUEST_1",
AskAndListen("What is your name and favourite drink?"),
transitions={
"succeeded": "PARSE_NAME_AND_DRINK",
"succeeded": "PARSE_NAME_AND_DRINK_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"PARSE_NAME_AND_DRINK",
ParseNameAndDrink(),
"PARSE_NAME_AND_DRINK_GUEST_1",
ParseNameAndDrink("guest1"),
transitions={
"succeeded": "GET_GUEST_ATTRIBUTES",
"succeeded": "GET_GUEST_ATTRIBUTES_GUEST_1",
"failed": "failed",
},
remapping={"guest_transcription": "transcribed_speech"},
)

smach.StateMachine.add(
"GET_GUEST_ATTRIBUTES",
GetGuestAttributes(),
"GET_GUEST_ATTRIBUTES_GUEST_1",
GetGuestAttributes("guest1"),
transitions={
"succeeded": "SAY_FOLLOW",
"succeeded": "SAY_FOLLOW_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_FOLLOW",
"SAY_FOLLOW_GUEST_1",
Say(text="Please follow me, I will guide you to the other guests"),
transitions={
"succeeded": "GO_TO_SEAT_LOCATION",
"succeeded": "GO_TO_SEAT_LOCATION_GUEST_1",
"preempted": "failed",
"aborted": "failed",
},
)

smach.StateMachine.add(
"GO_TO_SEAT_LOCATION",
"GO_TO_SEAT_LOCATION_GUEST_1",
GoToLocation(seat_pose),
transitions={
"succeeded": "SAY_WAIT",
"succeeded": "SAY_WAIT_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_WAIT",
"SAY_WAIT_GUEST_1",
Say(text="Please wait here on my left"),
transitions={
"succeeded": "INTRODUCE_GUEST_1_TO_HOST",
Expand All @@ -126,17 +125,163 @@ def __init__(
"INTRODUCE_HOST_TO_GUEST_1",
Introduce(guest_to_introduce="host", guest_to_introduce_to="guest1"),
transitions={
"succeeded": "SEAT_GUEST",
"succeeded": "SEAT_GUEST_1",
"failed": "failed",
},
)

smach.StateMachine.add(
"SEAT_GUEST",
"SEAT_GUEST_1",
SeatGuest(seat_area),
transitions={
"succeeded": "GO_TO_WAIT_LOCATION_GUEST_2",
"failed": "failed",
},
)

"""
Guest 2
"""

smach.StateMachine.add(
"GO_TO_WAIT_LOCATION_GUEST_2",
GoToLocation(wait_pose),
transitions={
"succeeded": "SAY_WAITING_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_WAITING_GUEST_2",
Say(text="I am waiting for a guest."),
transitions={
"succeeded": "WAIT_FOR_PERSON_GUEST_2",
"aborted": "failed",
"preempted": "failed",
},
)

smach.StateMachine.add(
"WAIT_FOR_PERSON_GUEST_2",
WaitForPersonInArea(wait_area),
transitions={
"succeeded": "GET_NAME_AND_DRINK_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"GET_NAME_AND_DRINK_GUEST_2",
AskAndListen("What is your name and favourite drink?"),
transitions={
"succeeded": "PARSE_NAME_AND_DRINK_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"PARSE_NAME_AND_DRINK_GUEST_2",
ParseNameAndDrink("guest2"),
transitions={
"succeeded": "GET_GUEST_ATTRIBUTES_GUEST_2",
"failed": "failed",
},
remapping={"guest_transcription": "transcribed_speech"},
)

smach.StateMachine.add(
"GET_GUEST_ATTRIBUTES_GUEST_2",
GetGuestAttributes("guest2"),
transitions={
"succeeded": "SAY_FOLLOW_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_FOLLOW_GUEST_2",
Say(text="Please follow me, I will guide you to the other guests"),
transitions={
"succeeded": "GO_TO_SEAT_LOCATION_GUEST_2",
"preempted": "failed",
"aborted": "failed",
},
)

smach.StateMachine.add(
"GO_TO_SEAT_LOCATION_GUEST_2",
GoToLocation(seat_pose),
transitions={
"succeeded": "SAY_WAIT_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"SAY_WAIT_GUEST_2",
Say(text="Please wait here on my left"),
transitions={
"succeeded": "INTRODUCE_GUEST_2_TO_HOST",
"preempted": "failed",
"aborted": "failed",
},
)

smach.StateMachine.add(
"INTRODUCE_GUEST_2_TO_EVERYONE",
Introduce(guest_to_introduce="guest2", everyone=True),
transitions={
"succeeded": "INTRODUCE_HOST_TO_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"INTRODUCE_HOST_TO_GUEST_2",
Introduce(guest_to_introduce="host", guest_to_introduce_to="guest2"),
transitions={
"succeeded": "INTRODUCE_GUEST_1_TO_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"INTRODUCE_GUEST_1_TO_GUEST_2",
Introduce(guest_to_introduce="guest1", guest_to_introduce_to="guest2"),
transitions={
"succeeded": "SEAT_GUEST_2",
"failed": "failed",
},
)

smach.StateMachine.add(
"SEAT_GUEST_2",
SeatGuest(seat_area),
transitions={"succeeded": "succeeded", "failed": "failed"},
)

"""
Finish
"""
smach.StateMachine.add(
"GO_TO_FINISH_LOCATION",
GoToLocation(wait_pose),
transitions={
"succeeded": "SAY_FINISHED",
"failed": "failed",
},
)
smach.StateMachine.add(
"SAY_FINISHED",
Say(text="I am done."),
transitions={
"succeeded": "succeeded",
"aborted": "failed",
"preempted": "failed",
},
)


if __name__ == "__main__":
rospy.init_node("receptionist")
Expand Down
5 changes: 3 additions & 2 deletions tasks/receptionist/src/receptionist/states/get_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class GetGuestAttributes(smach.State):
def __init__(
self,
guest_id: str,
attribute_service: Union[str, None] = None,
outcomes: List[str] = ["succeeded", "failed"],
input_keys: List[str] = ["guest_id", "guest_data"],
Expand All @@ -28,7 +29,7 @@ def __init__(
input_keys=input_keys,
output_keys=output_keys,
)

self._guest_id: str = guest_id
self._attribute_service: Union[str, None] = attribute_service

def _call_attribute_service(self):
Expand All @@ -46,6 +47,6 @@ def execute(self, userdata: UserData) -> str:
"height": "short",
}

userdata.guest_data[userdata.guest_id]["attributes"] = attributes
userdata.guest_data[self._guest_id]["attributes"] = attributes

return "succeeded"
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ParseNameAndDrink(smach.State):
def __init__(
self,
guest_id: str,
param_key: str = "priors",
):
"""Parses the transcription of the guests' name and favourite drink.
Expand All @@ -23,9 +24,10 @@ def __init__(
smach.State.__init__(
self,
outcomes=["succeeded", "failed"],
input_keys=["guest_transcription", "guest_id", "guest_data"],
input_keys=["guest_transcription", "guest_data"],
output_keys=["guest data", "guest_transcription"],
)
self._guest_id = guest_id
prior_data: Dict[str, List[str]] = rospy.get_param(param_key)
self._possible_names = [name.lower() for name in prior_data["names"]]
self._possible_drinks = [drink.lower() for drink in prior_data["drinks"]]
Expand All @@ -44,7 +46,6 @@ def execute(self, userdata: UserData) -> str:
"""

outcome = "succeeded"
guest_id = userdata.guest_id
name_found = False
drink_found = False
print(userdata)
Expand All @@ -55,14 +56,14 @@ def execute(self, userdata: UserData) -> str:

for name in self._possible_names:
if name in transcription:
userdata.guest_data[guest_id]["name"] = name
userdata.guest_data[self._guest_id]["name"] = name
rospy.loginfo(f"Guest Name identified as: {name}")
name_found = True
break

for drink in self._possible_drinks:
if drink in transcription:
userdata.guest_data[guest_id]["drink"] = drink
userdata.guest_data[self._guest_id]["drink"] = drink
rospy.loginfo(f"Guest Drink identified as: {drink}")
drink_found = True
break
Expand Down

0 comments on commit 9976d2b

Please sign in to comment.