-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: incorrect remapping keys for handover * fix: remove speech server in launch file * feat: statemachine to handle the "talk" gpsr subtask * chore: resolving review comments
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .talk import Talk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import smach | ||
from lasr_skills import Say | ||
import time | ||
from typing import Dict | ||
import rospy | ||
|
||
|
||
# In future we might want to add looking at person talking to the state machine. | ||
class Talk(smach.StateMachine): | ||
class GenerateResponse(smach.State): | ||
def __init__(self): | ||
smach.State.__init__( | ||
self, | ||
outcomes=["succeeded", "failed"], | ||
input_keys=["talk_phrase"], | ||
output_keys=["response"], | ||
) | ||
|
||
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._create_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" | ||
|
||
def __init__(self): | ||
smach.StateMachine.__init__(self, outcomes=["succeeded", "failed"]) | ||
|
||
with self: | ||
smach.StateMachine.add( | ||
"GENERATE_RESPONSE", | ||
self.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={"text": "response"}, | ||
) |