Skip to content

Commit

Permalink
feat: statemachine to handle the "talk" gpsr subtask
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Apr 18, 2024
1 parent 7740d2f commit 5e84cce
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Empty file.
73 changes: 73 additions & 0 deletions tasks/gpsr/src/gpsr/states/talk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import smach
from lasr_skills import Say
import time
from typing import Dict
import rospy


class GenerateResponse(smach.State):
def __init__(self):
smach.State.__init__(
self,
outcomes=["succeeded", "failed"],
input_keys=["talk_phrase"],
output_keys=["response"],
)

self._possible_responses: Dict[str, str] = self._create_responses()

def _create_responses(self) -> Dict[str, str]:
response = {}
response["something about yourself"] = (
"I am a Tiago -- a helpful assistive robot developed by PAL Robotics."
)
current_time = time.strftime("%H:%M")
response["the time"] = f"The current time is {current_time}."
current_day = time.strftime("%A")
response["what day is today"] = f"Today is {current_day}."
tomorrow = time.strftime("%A", time.localtime(time.time() + 86400))
response["what day is tomorrow"] = f"Tomorrow is {tomorrow}."
response["your teams name"] = "Our team is called LASR."
response["your teams country"] = "Our team is from the United Kingdom."
response["your teams affiliation"] = (
"Our team is affiliated with King's College London."
)
day_of_the_week = current_day
day_of_the_month = time.strftime("%d")
response["the day of the week"] = f"Today is {day_of_the_week}."

response["the day of the month"] = (
f"The day of the month is {day_of_the_month}."
)
return response

def execute(self, userdata):
try:
userdata.response = self._possible_responses[userdata.talk_phrase]
except KeyError:
rospy.loginfo(
f"Failed to generate response for {userdata.talk_phrase} as it is not in the list of possible questions."
)
return "failed"
return "succeeded"


# In future we might want to add looking at person talking to the state machine.
class Talk(smach.StateMachine):
def __init__(self):
smach.StateMachine.__init__(self, outcomes=["succeeded", "failed"])

with self:
smach.StateMachine.add(
"GENERATE_RESPONSE",
GenerateResponse(),
transitions={"succeeded": "SAY_RESPONSE", "failed": "failed"},
remapping={"talk_phrase": "talk_phrase", "response": "response"},
)

smach.StateMachine.add(
"SAY_RESPONSE",
Say(),
transitions={"succeeded": "succeeded", "failed": "failed"},
remapping={"phrase": "response"},
)

0 comments on commit 5e84cce

Please sign in to comment.