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

[jsk_fetch_startup] speak also battery information in english #1293

Merged
merged 3 commits into from
Jul 16, 2021
Merged
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
41 changes: 26 additions & 15 deletions jsk_fetch_robot/jsk_fetch_startup/scripts/battery_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

class BatteryWarning(object):
def __init__(self):
self.speak_client = actionlib.SimpleActionClient('/robotsound_jp', SoundRequestAction)
self.client_en = actionlib.SimpleActionClient(
'/sound_play', SoundRequestAction)
self.client_jp = actionlib.SimpleActionClient(
'/robotsound_jp', SoundRequestAction)
self.duration = rospy.get_param('~duration', 180.0)
self.threshold = rospy.get_param('~charge_level_threshold', 40.0)
self.step = rospy.get_param('~charge_level_step', 10.0)
Expand All @@ -23,27 +26,35 @@ def __init__(self):
self.prev_charge_level = None
self.is_charging = False

def _speak(self, sentence):
req = SoundRequest()
req.command = SoundRequest.PLAY_ONCE
req.sound = SoundRequest.SAY
req.arg = sentence
req.arg2 = 'ja'
req.volume = 0.8
self.speak_client.send_goal(SoundRequestGoal(sound_request=req))
self.speak_client.wait_for_result(timeout=rospy.Duration(10))
def _speak(self, client, speech_text, lang=None):
client.wait_for_server(timeout=rospy.Duration(1.0))
sound_goal = SoundRequestGoal()
sound_goal.sound_request.sound = -3
sound_goal.sound_request.command = 1
sound_goal.sound_request.volume = 1.0
if lang is not None:
sound_goal.sound_request.arg2 = lang
sound_goal.sound_request.arg = speech_text
client.send_goal(sound_goal)
client.wait_for_result()
return client.get_result()

def _warn(self):
if self.charge_level < self.threshold and not self.is_charging:
rospy.logerr("Low battery: only {}% remaining".format(self.charge_level))
sentence = "バッテリー残り{}パーセントです。".format(self.charge_level)
sentence += "もう限界ですので、僕をお家にかえしてください。"
self._speak(sentence)
sentence_jp = "バッテリー残り{}パーセントです。".format(self.charge_level)
sentence_jp += "もう限界ですので、僕をお家にかえしてください。"
sentence_en = "My battery is {} percent remaining.".format(self.charge_level)
sentence_en += "I want to go back home to charge my battery."
self._speak(self.client_jp, sentence_jp, 'jp')
self._speak(self.client_en, sentence_en)
self.prev_charge_level = self.charge_level
elif (self.prev_charge_level // self.step) > (self.charge_level // self.step):
rospy.loginfo("Battery: {}% remaining".format(self.charge_level))
sentence = "バッテリー残り{}パーセントです。".format(self.charge_level)
self._speak(sentence)
sentence_jp = "バッテリー残り{}パーセントです。".format(self.charge_level)
sentence_en = "My battery is {} percent remaining.".format(self.charge_level)
self._speak(self.client_jp, sentence_jp, 'jp')
self._speak(self.client_en, sentence_en)
self.prev_charge_level = self.charge_level

def _cb(self, msg):
Expand Down