Skip to content

Commit

Permalink
add sound on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
yabuta committed Jan 25, 2024
1 parent 6f895ba commit 19b2d4f
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/signage/config/announce_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
signage:
ros__parameters:
emergency: true
restart_engage: true
door_close: true
door_open: true
engage: true
thank_you: true
in_emergency: true
going_to_depart: true
going_to_arrive: true
2 changes: 2 additions & 0 deletions src/signage/launch/signage.launch.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0"?>
<launch>
<arg name="signage_param" default="$(find-pkg-share signage)/config/signage_param.yaml" />
<arg name="announce_settings_param" default="$(find-pkg-share signage)/config/announce_settings.yaml" />
<node pkg="signage" exec="signage" output="screen">
<param from="$(var signage_param)"/>
<param from="$(var announce_settings_param)"/>
</node>
</launch>
Binary file removed src/signage/resource/sound/arrived.wav
Binary file not shown.
Binary file added src/signage/resource/sound/restart_engage.wav
Binary file not shown.
Binary file not shown.
Binary file removed src/signage/resource/sound/wait_for_walker.wav
Binary file not shown.
1 change: 1 addition & 0 deletions src/signage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def package_files(directory):
("share/" + package_name, ["package.xml"]),
("share/" + package_name + "/launch", ["launch/signage.launch.xml"]),
("share/" + package_name + "/config", ["config/signage_param.yaml"]),
("share/" + package_name + "/config", ["config/announce_settings.yaml"]),
],
install_requires=["setuptools"],
zip_safe=True,
Expand Down
14 changes: 14 additions & 0 deletions src/signage/src/signage/announce_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt5.QtMultimedia import QSound
from rclpy.duration import Duration
from ament_index_python.packages import get_package_share_directory
from dataclasses import asdict

# The higher the value, the higher the priority
PRIORITY_DICT = {
Expand All @@ -27,6 +28,7 @@ def __init__(self, node, autoware_interface, parameter_interface):

self._node = node
self._parameter = parameter_interface.parameter
self._announce_settings = parameter_interface.announce_settings
self._current_announce = ""
self._pending_announce_list = []
self._sound = QSound("")
Expand Down Expand Up @@ -62,10 +64,22 @@ def play_sound(self, message):
self._sound = QSound(self._package_path + message + ".wav")
self._sound.play()

# skip announce by setting
def check_announce_or_not(self, message):
try:
self._node.get_logger().info(message)
return asdict(self._announce_settings).get(message, False)
except Exception as e:
self._node.get_logger().error("check announce or not: " + str(e))
return False

def send_announce(self, message):
priority = PRIORITY_DICT.get(message, 0)
previous_priority = PRIORITY_DICT.get(self._current_announce, 0)

if not self.check_announce_or_not(message):
return

if priority == 3:
self._sound.stop()
self.play_sound(message)
Expand Down
53 changes: 53 additions & 0 deletions src/signage/src/signage/parameter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ class SignageParameter:
monitor_width: int = 1920
monitor_height: int = 540

@dataclass
class AnnounceParameter:
emergency: bool = True
restart_engage: bool = True
door_close: bool = True
door_open: bool = True
engage: bool = True
arrived: bool = True
thank_you: bool = True
in_emergency: bool = True
going_to_depart: bool = True
going_to_arrive: bool = True

class ParameterInterface:
def __init__(self, node):
self.parameter = SignageParameter()
self.announce_settings = AnnounceParameter()

node.declare_parameter("signage_stand_alone", False)
node.declare_parameter("ignore_manual_driving", False)
Expand All @@ -34,6 +47,17 @@ def __init__(self, node):
node.declare_parameter("monitor_width", 1920)
node.declare_parameter("monitor_height", 540)

node.declare_parameter("emergency", True)
node.declare_parameter("restart_engage", True)
node.declare_parameter("door_close", True)
node.declare_parameter("door_open", True)
node.declare_parameter("engage", True)
node.declare_parameter("thank_you", True)
node.declare_parameter("in_emergency", True)
node.declare_parameter("going_to_depart", True)
node.declare_parameter("going_to_arrive", True)


self.parameter.signage_stand_alone = (
node.get_parameter("signage_stand_alone").get_parameter_value().bool_value
)
Expand Down Expand Up @@ -64,3 +88,32 @@ def __init__(self, node):
self.parameter.monitor_height = (
node.get_parameter("monitor_height").get_parameter_value().integer_value
)

self.announce_settings.emergency = (
node.get_parameter("emergency").get_parameter_value().bool_value
)
self.announce_settings.restart_engage = (
node.get_parameter("restart_engage").get_parameter_value().bool_value
)
self.announce_settings.door_close = (
node.get_parameter("door_close").get_parameter_value().bool_value
)
self.announce_settings.door_open = (
node.get_parameter("door_open").get_parameter_value().bool_value
)
self.announce_settings.engage = (
node.get_parameter("engage").get_parameter_value().bool_value
)
self.announce_settings.thank_you = (
node.get_parameter("thank_you").get_parameter_value().bool_value
)
self.announce_settings.in_emergency = (
node.get_parameter("in_emergency").get_parameter_value().bool_value
)
self.announce_settings.going_to_depart = (
node.get_parameter("going_to_depart").get_parameter_value().bool_value
)
self.announce_settings.going_to_arrive = (
node.get_parameter("going_to_arrive").get_parameter_value().bool_value
)

3 changes: 2 additions & 1 deletion src/signage/src/signage/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def announce_engage_when_starting(self):
self._engage_trigger_time,
self._parameter.accept_start,
):
self._announce_interface.send_announce("engage")
self._announce_interface.send_announce("restart_engage")
self._engage_trigger_time = self._node.get_clock().now()

if self._autoware.information.motion_state == MotionState.STARTING:
Expand Down Expand Up @@ -347,6 +347,7 @@ def calculate_time_callback(self):
self._announce_interface.announce_going_to_depart_and_arrive("going_to_depart")
elif self._is_driving:
# handle text and announce while bus is running
self._node.get_logger().info(str(self._autoware.information.goal_distance))
if self._autoware.information.goal_distance < 100:
# display text and announce if the goal is within 100m
self._display_phrase = utils.handle_phrase("arriving")
Expand Down

0 comments on commit 19b2d4f

Please sign in to comment.