Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpsr-talk-skill #160

Merged
merged 7 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasks/gpsr/src/gpsr/states/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .talk import Talk
70 changes: 70 additions & 0 deletions tasks/gpsr/src/gpsr/states/talk.py
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"},
)
Loading