Skip to content

Commit

Permalink
update service for trigger external signage (#97)
Browse files Browse the repository at this point in the history
* update service for trigger external signage

Signed-off-by: tkhmy <[email protected]>

* fix new external node (#98)

* fix launch and depend

---------

Signed-off-by: tkhmy <[email protected]>
Co-authored-by: yabuta <[email protected]>
  • Loading branch information
tkhmy and yabuta authored Mar 29, 2024
1 parent 20f363b commit 2316a6f
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/external_signage/launch/external_signage.launch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<launch>
<node pkg="external_signage" exec="external_signage" output="screen" />
</launch>
26 changes: 26 additions & 0 deletions src/external_signage/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<package format="2">
<name>external_signage</name>
<version>0.1.0</version>
<description>The signage package</description>

<maintainer email="[email protected]">yabuta</maintainer>

<license>Apache License 2.0</license>
<exec_depend>ament_index_python</exec_depend>
<exec_depend>signage_version</exec_depend>

<depend>autoware_auto_system_msgs</depend>
<depend>diagnostic_updater</depend>
<depend>python-pulsectl-pip</depend>
<depend>rclpy</depend>
<depend>std_srvs</depend>
<depend>tier4_api_msgs</depend>
<depend>tier4_debug_msgs</depend>
<depend>tier4_external_api_msgs</depend>
<depend>tier4_hmi_msgs</depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions src/external_signage/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script-dir=$base/lib/external_signage
[install]
install-scripts=$base/lib/external_signage
47 changes: 47 additions & 0 deletions src/external_signage/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import os

from setuptools import setup


def package_files(directory):
paths = []
for (path, directories, filenames) in os.walk(directory):
for filename in filenames:
paths.append(os.path.join(path, filename))
return paths


package_name = "external_signage"
setup(
name=package_name,
version="0.1.0",
package_dir={"": "src"},
packages=[package_name],
data_files=[
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
("share/" + package_name + "/resource/td5_file", package_files("resource/td5_file")),
("share/" + package_name, ["package.xml"]),
("share/" + package_name + "/launch", ["launch/external_signage.launch.xml"]),
],
install_requires=["setuptools"],
zip_safe=True,
author="Makoto Yabuta",
maintainer="Makoto Yabuta",
maintainer_email="[email protected]",
keywords=["ROS"],
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Topic :: Software Development",
],
description=("external_signage provides a GUI for passanger."),
license="TODO",
entry_points={
"console_scripts": [
"external_signage = external_signage.external_signage:main",
]
},
)
4 changes: 4 additions & 0 deletions src/external_signage/src/external_signage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This Python file uses the following encoding: utf-8

# if__name__ == "__main__":
# pass
23 changes: 23 additions & 0 deletions src/external_signage/src/external_signage/external_signage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This Python file uses the following encoding: utf-8
import sys

import rclpy
from rclpy.node import Node

from external_signage.external_signage_core import ExternalSignage
from ament_index_python.packages import get_package_share_directory

def main(args=None):
package_path = get_package_share_directory("external_signage")

rclpy.init(args=args)
node = Node("external_signage")

external_signage = ExternalSignage(node)

while True:
rclpy.spin_once(node, timeout_sec=0.01)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import datetime
import time
import serial
from std_srvs.srv import SetBool
from ament_index_python.packages import get_package_share_directory
import signage.packet_tools as packet_tools
import external_signage.packet_tools as packet_tools


@dataclass
Expand Down Expand Up @@ -113,6 +114,7 @@ def __init__(self, node):
"back": self._load_display_data(self.protocol.back, package_path),
"side": self._load_display_data(self.protocol.side, package_path),
}
node.create_service(SetBool, "/signage/trigger_external", self.trigger_external_signage)

def _load_display_data(self, display, package_path):
auto_path = package_path + f"/automatic_{display.width}x{display.height}.td5"
Expand All @@ -134,17 +136,15 @@ def send_data(self, display_key, data_key):
sender = DataSender(self.bus, self.parser, self.protocol, self.node.get_logger())
sender.send(data, ack_query_ack, ack_data_chunk)

def trigger(self):
def trigger_external_signage(self, request, response):
if not self._external_signage_available:
return

for display_key in self.displays:
self.send_data(display_key, "auto")
time.sleep(1)

def close(self):
if not self._external_signage_available:
return

for display_key in self.displays:
self.send_data(display_key, "null")
return response

if request.data:
for display_key in self.displays:
self.send_data(display_key, "auto")
time.sleep(1)
else:
for display_key in self.displays:
self.send_data(display_key, "null")
return response
File renamed without changes.
1 change: 1 addition & 0 deletions src/signage/launch/signage.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<node pkg="signage" exec="signage" output="screen">
<param from="$(var signage_param)"/>
</node>
<node pkg="external_signage" exec="external_signage" output="screen" />
</launch>
2 changes: 2 additions & 0 deletions src/signage/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
<depend>diagnostic_updater</depend>
<depend>python-pulsectl-pip</depend>
<depend>rclpy</depend>
<depend>std_srvs</depend>
<depend>tier4_api_msgs</depend>
<depend>tier4_debug_msgs</depend>
<depend>tier4_external_api_msgs</depend>
<depend>tier4_hmi_msgs</depend>
<depend>external_signage</depend>

<export>
<build_type>ament_python</build_type>
Expand Down
9 changes: 8 additions & 1 deletion src/signage/src/signage/ros_service_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import rclpy
import time
import threading

from std_srvs.srv import SetBool
from autoware_adapi_v1_msgs.srv import AcceptStart

from std_srvs.srv import Trigger
Expand All @@ -31,13 +31,20 @@ def __init__(self, node, parameter_interface):
self._parameter = parameter_interface.parameter
if self._parameter.signage_stand_alone:
self._cli_accept_start = self.__create_client(AcceptStart, "/api/motion/accept_start")
self._cli_trigger_external = self.__create_client(SetBool, "/signage/trigger_external")

# service call function
def accept_start(self):
if self._parameter.signage_stand_alone:
request = AcceptStart.Request()
self.__service_call(self._cli_accept_start, request, True)

# service call function
def trigger_external_signage(self, on):
request = SetBool.Request()
request.data = on
self.__service_call(self._cli_trigger_external, request, True)

# common denominator
def __create_client(self, service_type, service_name):
client = self._node.create_client(service_type, service_name)
Expand Down
8 changes: 3 additions & 5 deletions src/signage/src/signage/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ def __init__(
autoware_interface,
parameter_interface,
ros_service_interface,
external_signage,
):
self._node = node
self._viewController = viewController
self._announce_interface = announceController
self._autoware = autoware_interface
self._parameter = parameter_interface.parameter
self._service_interface = ros_service_interface
self._external_signage = external_signage
self.AUTOWARE_IP = os.getenv("AUTOWARE_IP", "localhost")
self._fms_payload = {
"method": "get",
Expand Down Expand Up @@ -145,7 +143,7 @@ def announce_engage_when_starting(self):
self._parameter.accept_start,
):
self._announce_interface.send_announce("restart_engage")
self._external_signage.trigger()
self._service_interface.trigger_external_signage(True)
self._trigger_external_signage = True
self._engage_trigger_time = self._node.get_clock().now()

Expand Down Expand Up @@ -281,7 +279,7 @@ def route_checker_callback(self):
self._is_stopping = False
if not self._announce_engage and self._parameter.signage_stand_alone:
self._announce_interface.send_announce("engage")
self._external_signage.trigger()
self._service_interface.trigger_external_signage(True)
self._trigger_external_signage = True
self._announce_engage = True
elif self._autoware.information.route_state == RouteState.ARRIVED:
Expand All @@ -295,7 +293,7 @@ def route_checker_callback(self):
self._autoware.information.operation_mode != OperationModeState.AUTONOMOUS
and self._trigger_external_signage
):
self._external_signage.close()
self._service_interface.trigger_external_signage(False)
self._trigger_external_signage = False

if self._prev_route_state != RouteState.SET:
Expand Down
3 changes: 0 additions & 3 deletions src/signage/src/signage/signage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from signage.parameter_interface import ParameterInterface
from signage.route_handler import RouteHandler
from signage.ros_service_interface import RosServiceInterface
from signage.external_signage import ExternalSignage
from ament_index_python.packages import get_package_share_directory


Expand All @@ -34,15 +33,13 @@ def main(args=None):
ros_service_interface = RosServiceInterface(node, parameter_interface)
viewController = ViewControllerProperty(node, parameter_interface)
announceController = AnnounceControllerProperty(node, autoware_interface, parameter_interface)
external_signage = ExternalSignage(node)
route_handler = RouteHandler(
node,
viewController,
announceController,
autoware_interface,
parameter_interface,
ros_service_interface,
external_signage,
)

ctx = engine.rootContext()
Expand Down

0 comments on commit 2316a6f

Please sign in to comment.