Skip to content

Commit

Permalink
feat: get name and drink skill & prior data yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Apr 11, 2024
1 parent 4001a10 commit f48ba89
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tasks/receptionist/config/lab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
priors:
names:
- Adel
- Angel
- Axel
- Charlie
- Jane
- Jules
- Morgan
- Paris
- Robin
- Simone
drinks:
- cola
- iced tea
- juice pack
- milk
- orange juice
- red wine
- tropical juice
58 changes: 58 additions & 0 deletions tasks/receptionist/src/receptionist/states/get_name_and_drink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import rospy
import smach
from typing import List, Dict, Any


class ParseNameAndDrink(smach.State):
def __init__(self, param_key: str = "priors"):
"""Parses the transcription of the guests' name and favourite drink.
Args:
param_key (str, optional): Name of the parameter that contains the list of
possible . Defaults to "priors".
"""

prior_data: Dict[str, List[str]] = rospy.get_param(param_key)
self._possible_names = prior_data["names"]
self._possible_drinks = prior_data["drinks"]

def execute(self, userdata: Dict[str, Any]) -> str:
"""Parses the transcription of the guests' name and favourite drink.
Args:
userdata (Dict[str, Any]): State machine userdata assumed to contain a key
called "guest transcription" with the transcription of the guest's name and
favourite drink.
Returns:
str: state outcome. Updates the userdata with the parsed name and drink, under
the parameter "guest data".
"""

outcome = "succeeded"
guest_id = userdata["guest id"]
name_found = False
drink_found = False

for name in self._possible_names:
if name in userdata["guest transcription"]:
userdata["guest data"][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 userdata["guest transcription"]:
userdata["guest data"][guest_id]["drink"] = drink
rospy.loginfo(f"Guest Drink identified as: {drink}")
drink_found = True
break

if not name_found:
rospy.loginfo("Name not found in transcription")
outcome = "failed"
if not drink_found:
rospy.loginfo("Drink not found in transcription")
outcome = "failed"

return outcome

0 comments on commit f48ba89

Please sign in to comment.