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] Use dynamicreconfigure to change speak volume of time_signal.py #1837

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
6 changes: 4 additions & 2 deletions jsk_fetch_robot/jsk_fetch.rosinstall.melodic
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# https://github.com/PR2/app_manager/pull/50
# In order to run multiple app_managers in one master, we need this PR
# https://github.com/PR2/app_manager/pull/54
# This PR add run_name entry to specif node name when we use run entry
# https://github.com/PR2/app_manager/pull/64
- git:
local-name: PR2/app_manager
uri: https://github.com/knorth55/app_manager.git
version: fetch15
uri: https://github.com/tkmtnt7000/app_manager.git
version: add-run-name-entry-fetch15
# we need this for proximity sensors
- git:
local-name: RoboticMaterials/FA-I-sensor
Expand Down
9 changes: 8 additions & 1 deletion jsk_fetch_robot/jsk_fetch_startup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif()
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
dynamic_reconfigure
roscpp
std_msgs
sensor_msgs
Expand All @@ -24,10 +25,16 @@ find_package(catkin REQUIRED COMPONENTS
)
find_package(Boost REQUIRED COMPONENTS)

generate_dynamic_reconfigure_options(
cfg/TimeSignal.cfg
)

###################################
## catkin specific configuration ##
###################################
catkin_package()
catkin_package(
CATKIN_DEPENDS dynamic_reconfigure
)

catkin_add_env_hooks(99.jsk_fetch_startup SHELLS bash zsh sh
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/env-hooks)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
display: Speak time signal
platform: fetch
run: jsk_fetch_startup/time_signal.py
run_name: "time_signal"
# run_name needs https://github.com/PR2/app_manager/pull/64
interface: jsk_fetch_startup/time_signal.interface
icon: jsk_fetch_startup/time_signal.png
timeout: 120
Expand Down
11 changes: 11 additions & 0 deletions jsk_fetch_robot/jsk_fetch_startup/cfg/TimeSignal.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env python


from dynamic_reconfigure.parameter_generator_catkin import *

PACKAGE = 'jsk_fetch_startup'

gen = ParameterGenerator()
gen.add("volume", double_t, 0, "Volume of sound.", 1.0, 0.0, 1.0)

exit(gen.generate(PACKAGE, PACKAGE, "TimeSignal"))
2 changes: 2 additions & 0 deletions jsk_fetch_robot/jsk_fetch_startup/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<buildtool_depend>catkin</buildtool_depend>

<build_depend version_gte="0.7.11">fetch_teleop</build_depend>
<build_depend>dynamic_reconfigure</build_depend>

<run_depend>dynamic_reconfigure</run_depend>
<run_depend>image_proc</run_depend>
<run_depend>jsk_fetch_accessories</run_depend>
<run_depend>jsk_fetch_diagnosis</run_depend>
Expand Down
22 changes: 20 additions & 2 deletions jsk_fetch_robot/jsk_fetch_startup/scripts/time_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import sys
import urllib2

from dynamic_reconfigure.server import Server
from jsk_fetch_startup.cfg import TimeSignalConfig as Config
from sound_play.msg import SoundRequestAction
from sound_play.msg import SoundRequestGoal


class TimeSignal(object):
def __init__(self):
def __init__(self, volume=1.0):
self.client_en = actionlib.SimpleActionClient(
'/sound_play', SoundRequestAction)
self.client_jp = actionlib.SimpleActionClient(
Expand All @@ -23,6 +25,8 @@ def __init__(self):
self.now_hour = self.now_time.hour
self.now_minute = self.now_time.minute
self.day = self.now_time.strftime('%a')
self.volume = volume
self.srv = Server(Config, self.config_callback)
reload(sys)
sys.setdefaultencoding('utf-8')
api_key_file = rospy.get_param(
Expand All @@ -35,7 +39,7 @@ def speak(self, client, speech_text, lang=None):
sound_goal = SoundRequestGoal()
sound_goal.sound_request.sound = -3
sound_goal.sound_request.command = 1
sound_goal.sound_request.volume = 1.0
sound_goal.sound_request.volume = self.volume
if lang is not None:
sound_goal.sound_request.arg2 = lang
sound_goal.sound_request.arg = speech_text
Expand Down Expand Up @@ -153,6 +157,20 @@ def _get_weather_forecast(self, lang='en'):
forecast_text += " The wind speed is {} meter per second.".format(wind_speed)
return forecast_text

def _set_volume(self, volume):
'''
Set speak volume between 0.0 and 1.0
'''
volume = min(max(0.0, volume), 1.0)
if self.volume != volume:
self.volume = volume
rospy.loginfo("time_signal's volume was set to {}".format(
self.volume))

def config_callback(self, config, level):
self._set_volume(config.volume)
return config


if __name__ == '__main__':
rospy.init_node('time_signal')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
(ros::set-dynamic-reconfigure-param "/tweet_client_uptime" "volume" :double 0.2)
(ros::set-dynamic-reconfigure-param "/tweet_client_warning" "volume" :double 0.2)
(ros::set-dynamic-reconfigure-param "/tweet_client_worktime" "volume" :double 0.2)
(ros::set-dynamic-reconfigure-param "/time_signal" "volume" :double 0.2)
(exit)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
(ros::set-dynamic-reconfigure-param "/tweet_client_uptime" "volume" :double 1.0)
(ros::set-dynamic-reconfigure-param "/tweet_client_warning" "volume" :double 1.0)
(ros::set-dynamic-reconfigure-param "/tweet_client_worktime" "volume" :double 1.0)
(ros::set-dynamic-reconfigure-param "/time_signal" "volume" :double 1.0)
(exit)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
(ros::set-dynamic-reconfigure-param "/tweet_client_uptime" "volume" :double 0.0)
(ros::set-dynamic-reconfigure-param "/tweet_client_warning" "volume" :double 0.0)
(ros::set-dynamic-reconfigure-param "/tweet_client_worktime" "volume" :double 0.0)
(ros::set-dynamic-reconfigure-param "/time_signal" "volume" :double 0.0)
(exit)