Skip to content

Commit

Permalink
Merge pull request #1194 from knorth55/add-time-signal-app
Browse files Browse the repository at this point in the history
[jsk_fetch_startup] add time_signal app in jsk_fetch_startup
  • Loading branch information
k-okada authored Mar 19, 2020
2 parents 59d48b4 + 267b1c8 commit 55907d3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
2 changes: 2 additions & 0 deletions jsk_fetch_robot/jsk_fetch_startup/apps/fetch_apps.installed
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ apps:
display: fetch patrol in 73B2
- app: jsk_fetch_startup/speak_battery
display: speak battery information
- app: jsk_fetch_startup/time_signal
display: speak time signal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
display: Speak time signal
platform: fetch
launch: jsk_fetch_startup/time_signal.xml
interface: jsk_fetch_startup/time_signal.interface
icon: jsk_fetch_startup/time_signal.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
published_topics: {}
subscribed_topics: {}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<node name="run_time_signal" pkg="jsk_fetch_startup" type="time_signal.py" output="screen"/>
</launch>
79 changes: 57 additions & 22 deletions jsk_fetch_robot/jsk_fetch_startup/scripts/time_signal.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import actionlib
from datetime import datetime
from sound_play.msg import SoundRequestActionGoal
from sound_play.msg import SoundRequestAction
from sound_play.msg import SoundRequestGoal
import json
import rospy
import sys
Expand All @@ -11,9 +13,10 @@

class TimeSignal(object):
def __init__(self):
self.pub = rospy.Publisher('/robotsound_jp/goal',
SoundRequestActionGoal, queue_size=1)
rospy.sleep(1)
self.client_en = actionlib.SimpleActionClient(
'/sound_play', SoundRequestAction)
self.client_jp = actionlib.SimpleActionClient(
'/robotsound_jp', SoundRequestAction)
self.now_time = datetime.now()
self.now_hour = self.now_time.hour
self.day = self.now_time.strftime('%a')
Expand All @@ -23,39 +26,71 @@ def __init__(self):
self.resp = json.loads(
urllib2.urlopen('http://weather.livedoor.com/forecast/webservice/json/v1?city=%s'%self.citycode).read())

def speak(self):
sound_goal = SoundRequestActionGoal()
sound_goal.goal_id.stamp = rospy.Time.now()
sound_goal.goal.sound_request.sound = -3
sound_goal.goal.sound_request.command = 1
sound_goal.goal.sound_request.volume = 1.0
sound_goal.goal.sound_request.arg2 = "jp"
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 speak_jp(self):
# time signal
speech_text = str(self.now_hour) + '時です。'
if (self.now_hour == 0):
if self.now_hour == 0:
speech_text += '早く帰りましょう。'
if (self.day == 'Mon') and (self.now_hour == 12):
if self.now_hour == 12:
speech_text += '昼食の時間です。'
if self.now_hour == 19:
speech_text += '夕食の時間です。'
if self.day == 'Mon' and self.now_hour == 12:
speech_text += 'そろそろ研究会です。'
if (self.day == 'Tue') and (self.now_hour == 12):
if self.day == 'Tue' and self.now_hour == 12:
speech_text += 'そろそろ輪講です。'
if (self.day == 'Tue') and (self.now_hour == 15):
if self.day == 'Tue' and self.now_hour == 15:
speech_text += '掃除の時間です。'
if (self.day == 'Fri') and (self.now_hour == 14):
if self.day == 'Fri' and self.now_hour == 14:
speech_text += '創造輪講の時間です。'
if (self.day == 'Fri') and (self.now_hour == 16):
if self.day == 'Fri' and self.now_hour == 16:
speech_text += '掃除の時間です。'

# weather forecast
if (self.now_hour == 0) or (self.now_hour == 19):
if self.now_hour == 0 or self.now_hour == 19:
speech_text += '今日の天気は' + self.resp['forecasts'][0]['telop'] + 'です。'

rospy.loginfo('time signal')
sound_goal.goal.sound_request.arg = speech_text
self.pub.publish(sound_goal)
self.speak(self.client_jp, speech_text, lang='jp')


def speak_en(self):
speech_text = self._get_text(self.now_hour)
# time signal
if self.now_hour == 0:
speech_text += " Let's go home."
if self.now_hour == 12:
speech_text += " Let's go to lunch."
self.speak(self.client_en, speech_text)

def _get_text(self, hour):
if hour == 0:
text = 'midnight'
elif hour == 12:
text = 'noon'
else:
if hour > 12:
text = str(hour % 12) + ' PM'
else:
text = str(hour % 12) + ' AM'
text = "It's " + text + "."
return text


if __name__ == '__main__':
rospy.init_node('time_signal')
t = TimeSignal()
t.speak()
t.speak_jp()
t.speak_en()

0 comments on commit 55907d3

Please sign in to comment.