From c320091161b5c7ca77e8a4bfb530d5b677607bce Mon Sep 17 00:00:00 2001 From: tkhmy Date: Thu, 6 Jun 2024 21:45:03 +0900 Subject: [PATCH 1/7] add in experiment Signed-off-by: tkhmy --- .../resource/td5_file/experiment_128x16.td5 | Bin 0 -> 2048 bytes .../resource/td5_file/experiment_80x24.td5 | Bin 0 -> 2560 bytes .../external_signage/external_signage_core.py | 46 +++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/external_signage/resource/td5_file/experiment_128x16.td5 create mode 100644 src/external_signage/resource/td5_file/experiment_80x24.td5 diff --git a/src/external_signage/resource/td5_file/experiment_128x16.td5 b/src/external_signage/resource/td5_file/experiment_128x16.td5 new file mode 100644 index 0000000000000000000000000000000000000000..ce659baa951cdb072c13fa2476698769e483324c GIT binary patch literal 2048 zcmdn__}bmGE4I8pyXV5W^Y;&J4>Q#>VBlb2FfuVPH8e9cGB7tb_>Tk_8IU+Yrhot{ zpHyB|W^r+4eyIWsFfcJNAlm^GhtcTf!^C0qs61*2z`_MaqsspO&%nZf7Nh7YM)|`z z1km#zES=z@8Q2&YzA>Vv83rIg4kH*JokmtO${rjc;C!>hvmO$qjEsy7tHgkD%O}9V z1&TWX0cH@zz<^9CKm?%_M4tNO0Nc;VSnuE{&&UWw|C!iiJ}@x+V`BQjzyL)59TF_~ zF+5z!@Q0y-0gOC6yek;~2?z*Gm@sbw82rajPO|y+E-p~SuxeE!GshgWWIK*}PfySP j9do8^OGdW<7?q6mjv!DEVgln7>;onyrhj0ih_nX)K_@WT literal 0 HcmV?d00001 diff --git a/src/external_signage/resource/td5_file/experiment_80x24.td5 b/src/external_signage/resource/td5_file/experiment_80x24.td5 new file mode 100644 index 0000000000000000000000000000000000000000..fb6e46d709e3d95ed3088cd14b73a81ae54f80a3 GIT binary patch literal 2560 zcmdn__}bmGE4I8pyXV5W^Y;&J4>Q#>VBlh4FfuVPH8e9cGB7tb_>Tk_8IU+cFeSL~ zYpBXBF0RZkRe%8oCI$v%J7D548r@2mIE)^ZM-2g3xWH&s+5i6;SQzj}5W0p@{;&!G z^!x`)C%9;k=NW(iIS`Qf3~USxY`{E>tPWWoS>Gso;6uQ<ODO@|98xpvMm{AEr_-UXJdP0A%+GZ_}>Tu|3S Date: Thu, 6 Jun 2024 21:47:22 +0900 Subject: [PATCH 2/7] add randomname handler Signed-off-by: tkhmy --- .../src/external_signage/external_signage_core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index e181c1e..52000a1 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -6,6 +6,7 @@ from std_srvs.srv import SetBool from ament_index_python.packages import get_package_share_directory import external_signage.packet_tools as packet_tools +import uuid @dataclass @@ -60,9 +61,13 @@ def __init__(self, bus, parser, protocol, node_logger): self._logger = node_logger self._delay_time = 0.02 + def randomname(self): + u = uuid.uuid4() + return u.bytes + def _send_heartbeat(self, data, ACK_QueryACK): timestamp = datetime.datetime.now() - name_time_packet = packet_tools.gen_name_time_packet(data.linename, timestamp, False) + name_time_packet = packet_tools.gen_name_time_packet(self.randomname(), timestamp, False) self._bus.write(name_time_packet) packet_tools.dump_packet(name_time_packet, None, self._protocol.SEND_COLOR) time.sleep(self._delay_time) From 99d9f8aa5dbd6cd49ec31bb432ce6460ab2b6ca4 Mon Sep 17 00:00:00 2001 From: tkhmy Date: Fri, 7 Jun 2024 17:51:10 +0900 Subject: [PATCH 3/7] minor fix Signed-off-by: tkhmy --- .../src/external_signage/external_signage_core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index 52000a1..be01bcc 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -3,6 +3,7 @@ import time import serial import json +import os from std_srvs.srv import SetBool from ament_index_python.packages import get_package_share_directory import external_signage.packet_tools as packet_tools @@ -120,7 +121,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), } - self._settings_file = "/opt/pilot-auto/signage/settings.json" + self._settings_file = "/home/" + os.environ.get("USER") + "/settings.json" if os.path.exists(self._settings_file): with open(self._settings_file, "r") as f: self._settings = json.load(f) From 0f7751c273837dc7f01f67e92515d7aba55975f3 Mon Sep 17 00:00:00 2001 From: tkhmy Date: Fri, 7 Jun 2024 18:34:02 +0900 Subject: [PATCH 4/7] fix typo Signed-off-by: tkhmy --- .../src/external_signage/external_signage_core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index be01bcc..fa1421e 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -102,7 +102,7 @@ class ExternalSignage: def __init__(self, node): self.node = node self.protocol = Protocol() - package_path = get_package_share_directory("signage") + "/resource/td5_file/" + package_path = get_package_share_directory("external_signage") + "/resource/td5_file/" try: self.bus = serial.Serial( "/dev/ttyUSB0", @@ -137,9 +137,9 @@ def __init__(self, node): node.create_service(SetBool, "/signage/mode_change", self.experiment_set) def _load_display_data(self, display, package_path): - auto_path = package_path + f"/automatic_{display.width}x{display.height}.td5" - experiment_path = package_path + f"/experiment_{display.width}x{display.height}.td5" - null_path = package_path + f"/null_{display.width}x{display.height}.td5" + auto_path = package_path + f"automatic_{display.width}x{display.height}.td5" + experiment_path = package_path + f"experiment_{display.width}x{display.height}.td5" + null_path = package_path + f"null_{display.width}x{display.height}.td5" return { "auto": packet_tools.TD5Data( auto_path, display.address1, display.address2, display.height, display.width From 7c0c65e6ff5cf79d994ab67c3d5beae44da5c1d7 Mon Sep 17 00:00:00 2001 From: tkhmy Date: Thu, 13 Jun 2024 10:42:08 +0900 Subject: [PATCH 5/7] update Signed-off-by: tkhmy --- .../src/external_signage/external_signage_core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index fa1421e..b2401e1 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -161,6 +161,9 @@ def send_data(self, display_key, data_key): sender.send(data, ack_query_ack, ack_data_chunk) def trigger_external_signage(self, request, response): + if self._settings["in_experiment"]: + return response + if request.data: self.display_signage("auto") else: From 7989b472f6d431741629051e0020d275fc4d206a Mon Sep 17 00:00:00 2001 From: tkhmy Date: Thu, 28 Nov 2024 16:52:14 +0900 Subject: [PATCH 6/7] add experiment mode status topic Signed-off-by: tkhmy --- .../external_signage/external_signage_core.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index b2401e1..3e730de 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -5,6 +5,7 @@ import json import os from std_srvs.srv import SetBool +from std_msgs.msgs import Bool from ament_index_python.packages import get_package_share_directory import external_signage.packet_tools as packet_tools import uuid @@ -121,6 +122,18 @@ def __init__(self, node): "back": self._load_display_data(self.protocol.back, package_path), "side": self._load_display_data(self.protocol.side, package_path), } + + api_qos = rclpy.qos.QoSProfile( + history=rclpy.qos.QoSHistoryPolicy.KEEP_LAST, + depth=10, + reliability=rclpy.qos.QoSReliabilityPolicy.RELIABLE, + durability=rclpy.qos.QoSDurabilityPolicy.TRANSIENT_LOCAL, + ) + + node.create_service(SetBool, "/signage/trigger_external", self.trigger_external_signage) + node.create_service(SetBool, "/signage/mode_change", self.experiment_set) + self.mode_status_pub_ = node.create_publisher(Bool, "/signage/mode_status", api_qos) + self._settings_file = "/home/" + os.environ.get("USER") + "/settings.json" if os.path.exists(self._settings_file): with open(self._settings_file, "r") as f: @@ -131,10 +144,14 @@ def __init__(self, node): json.dump(self._settings, f, indent=4) if self._settings.get("in_experiment", False): + self.pub_mode_status(True) self.display_signage("experiment") + else: + self.pub_mode_status(False) - node.create_service(SetBool, "/signage/trigger_external", self.trigger_external_signage) - node.create_service(SetBool, "/signage/mode_change", self.experiment_set) + def pub_mode_status(self, status): + msg = Bool() + msg.data = status def _load_display_data(self, display, package_path): auto_path = package_path + f"automatic_{display.width}x{display.height}.td5" @@ -172,9 +189,11 @@ def trigger_external_signage(self, request, response): def experiment_set(self, request, response): if request.data: + self.pub_mode_status(True) self._settings["in_experiment"] = True self.display_signage("experiment") else: + self.pub_mode_status(False) self._settings["in_experiment"] = False self.display_signage("null") From b20116eb09ee81e314e8181933e56b3434653b96 Mon Sep 17 00:00:00 2001 From: tkhmy Date: Wed, 4 Dec 2024 15:39:35 +0900 Subject: [PATCH 7/7] fix erro Signed-off-by: tkhmy --- .../external_signage/external_signage_core.py | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/external_signage/src/external_signage/external_signage_core.py b/src/external_signage/src/external_signage/external_signage_core.py index 3e730de..a9cc044 100644 --- a/src/external_signage/src/external_signage/external_signage_core.py +++ b/src/external_signage/src/external_signage/external_signage_core.py @@ -4,8 +4,9 @@ import serial import json import os +import rclpy from std_srvs.srv import SetBool -from std_msgs.msgs import Bool +from std_msgs.msg import Bool from ament_index_python.packages import get_package_share_directory import external_signage.packet_tools as packet_tools import uuid @@ -114,7 +115,8 @@ def __init__(self, node): ) self.parser = packet_tools.Parser(self.bus) self._external_signage_available = True - except: + except Exception as e: + self.node.get_logger().error(str(e)) self._external_signage_available = False self.displays = { @@ -181,24 +183,32 @@ def trigger_external_signage(self, request, response): if self._settings["in_experiment"]: return response - if request.data: - self.display_signage("auto") - else: - self.display_signage("null") + try: + if request.data: + self.display_signage("auto") + else: + self.display_signage("null") + response.success = True + except Exception as e: + self.node.get_logger().error(str(e)) return response def experiment_set(self, request, response): - if request.data: - self.pub_mode_status(True) - self._settings["in_experiment"] = True - self.display_signage("experiment") - else: - self.pub_mode_status(False) - self._settings["in_experiment"] = False - self.display_signage("null") + try: + if request.data: + self.pub_mode_status(True) + self._settings["in_experiment"] = True + self.display_signage("experiment") + else: + self.pub_mode_status(False) + self._settings["in_experiment"] = False + self.display_signage("null") - with open(self._settings_file, "w") as f: - json.dump(self._settings, f, indent=4) + with open(self._settings_file, "w") as f: + json.dump(self._settings, f, indent=4) + response.success = True + except Exception as e: + self.node.get_logger().error(str(e)) return response def display_signage(self, display_file):