From 679de9d587e975cb30befd6b9f58424fe16e282c Mon Sep 17 00:00:00 2001 From: Hudson111-s <145516182+Hudson111-s@users.noreply.github.com> Date: Thu, 5 Feb 2026 18:24:15 -0500 Subject: [PATCH 1/4] Add dashboard_api package and dashboard_interface --- .../dashboard_api/dashboard_api/__init__.py | 7 ++ .../dashboard_api/dashboard_api.py | 75 +++++++++++++++++++ ros/src/dashboard_api/package.xml | 16 ++++ ros/src/dashboard_api/resource/dashboard_api | 0 ros/src/dashboard_api/setup.cfg | 4 + ros/src/dashboard_api/setup.py | 23 ++++++ ros/src/dashboard_interface/CMakeLists.txt | 14 ++++ ros/src/dashboard_interface/msg/Dashboard.msg | 4 + ros/src/dashboard_interface/package.xml | 19 +++++ 9 files changed, 162 insertions(+) create mode 100644 ros/src/dashboard_api/dashboard_api/__init__.py create mode 100644 ros/src/dashboard_api/dashboard_api/dashboard_api.py create mode 100644 ros/src/dashboard_api/package.xml create mode 100644 ros/src/dashboard_api/resource/dashboard_api create mode 100644 ros/src/dashboard_api/setup.cfg create mode 100644 ros/src/dashboard_api/setup.py create mode 100644 ros/src/dashboard_interface/CMakeLists.txt create mode 100644 ros/src/dashboard_interface/msg/Dashboard.msg create mode 100644 ros/src/dashboard_interface/package.xml diff --git a/ros/src/dashboard_api/dashboard_api/__init__.py b/ros/src/dashboard_api/dashboard_api/__init__.py new file mode 100644 index 0000000..83cb554 --- /dev/null +++ b/ros/src/dashboard_api/dashboard_api/__init__.py @@ -0,0 +1,7 @@ +from .dashboard_api import ( + init, + get, + card, + color, + bar +) diff --git a/ros/src/dashboard_api/dashboard_api/dashboard_api.py b/ros/src/dashboard_api/dashboard_api/dashboard_api.py new file mode 100644 index 0000000..71a5264 --- /dev/null +++ b/ros/src/dashboard_api/dashboard_api/dashboard_api.py @@ -0,0 +1,75 @@ +from json import dumps +from rclpy.node import Node +from dashboard_interface.msg import Dashboard + +class DashboardApi(): + def __init__(self, node: Node, _id: int) -> None: + self.node = node + self.id = _id + self.publisher = node.create_publisher(Dashboard, "hmi_dashboard_data", 10) + + def _publish_dashboard(self, msg: Dashboard) -> None: + self.publisher.publish(msg) + self.node.get_logger().info(f"Published {msg.id} of type {msg.type}: {msg.data}") + + def _make_msg(self, screen: str, _type: str, data: dict) -> Dashboard: + msg = Dashboard() + msg.id = self.id + msg.screen = screen + msg.type = _type + msg.data = dumps(data) + return msg + + def card(self, screen: str, title: str, content: str) -> None: + data = { + "title": title, + "content": content + } + msg = self._make_msg(screen, "card", data) + self._publish_dashboard(msg) + + def color(self, screen: str, title: str, content: str, color: str) -> None: + data = { + "title": title, + "content": content, + "color": color + } + msg = self._make_msg(screen, "color", data) + self._publish_dashboard(msg) + + def bar(self, screen: str, title: str, content: str, value: int, min_value: int=0, max_value: int=1) -> None: + data = { + "title": title, + "content": content, + "value": value, + "min": min_value, + "max": max_value + } + msg = self._make_msg(screen, "bar", data) + self._publish_dashboard(msg) + +_dashboard: DashboardApi | None = None + +def init(node: Node, _id: int=0) -> None: + global _dashboard + if _dashboard is not None: + raise RuntimeError("Dashboard already initialized") + _dashboard = DashboardApi(node, _id) + + +def get() -> DashboardApi: + if _dashboard is None: + raise RuntimeError("Dashboard not initialized. Call init() first.") + return _dashboard + + +def card(screen: str, title: str, content: str) -> None: + get().card(screen, title, content) + + +def color(screen: str, title: str, content: str, color: str): + get().color(screen, title, content, color) + + +def bar(screen: str, title: str, content: str, value: int, min_value: int=0, max_value: int=1) -> None: + get().bar(screen, title, content, value, min_value, max_value) diff --git a/ros/src/dashboard_api/package.xml b/ros/src/dashboard_api/package.xml new file mode 100644 index 0000000..93923dc --- /dev/null +++ b/ros/src/dashboard_api/package.xml @@ -0,0 +1,16 @@ + + + + dashboard_api + 0.0.0 + TODO: Package description + GoldRushRobotics + MIT + + rclpy + dashboard_interface + + + ament_python + + diff --git a/ros/src/dashboard_api/resource/dashboard_api b/ros/src/dashboard_api/resource/dashboard_api new file mode 100644 index 0000000..e69de29 diff --git a/ros/src/dashboard_api/setup.cfg b/ros/src/dashboard_api/setup.cfg new file mode 100644 index 0000000..d7e05fa --- /dev/null +++ b/ros/src/dashboard_api/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/dashboard_api +[install] +install_scripts=$base/lib/dashboard_api diff --git a/ros/src/dashboard_api/setup.py b/ros/src/dashboard_api/setup.py new file mode 100644 index 0000000..816384a --- /dev/null +++ b/ros/src/dashboard_api/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup + +package_name = 'dashboard_api' + +setup( + name=package_name, + version='0.0.0', + packages=[package_name], + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + ], + install_requires=['setuptools'], + zip_safe=True, + maintainer='GoldRushRobotics', + maintainer_email='goldrushrobotics@gmail.com', + description='TODO: Package description', + license='MIT', + entry_points={ + 'console_scripts': [], + }, +) diff --git a/ros/src/dashboard_interface/CMakeLists.txt b/ros/src/dashboard_interface/CMakeLists.txt new file mode 100644 index 0000000..2e138ef --- /dev/null +++ b/ros/src/dashboard_interface/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.8) +project(dashboard_interface) + +# Dependencies. +find_package(ament_cmake REQUIRED) +find_package(rosidl_default_generators REQUIRED) + +# Interface. +rosidl_generate_interfaces(${PROJECT_NAME} + "msg/Dashboard.msg" +) + +# Export. +ament_package() diff --git a/ros/src/dashboard_interface/msg/Dashboard.msg b/ros/src/dashboard_interface/msg/Dashboard.msg new file mode 100644 index 0000000..315349b --- /dev/null +++ b/ros/src/dashboard_interface/msg/Dashboard.msg @@ -0,0 +1,4 @@ +int32 id +string screen +string type +string data diff --git a/ros/src/dashboard_interface/package.xml b/ros/src/dashboard_interface/package.xml new file mode 100644 index 0000000..b52866e --- /dev/null +++ b/ros/src/dashboard_interface/package.xml @@ -0,0 +1,19 @@ + + + + dashboard_interface + 0.0.0 + TODO: Package description + GoldRushRobotics + MIT + + ament_cmake + + rosidl_default_generators + rosidl_default_runtime + rosidl_interface_packages + + + ament_cmake + + From 01cbc5aba83fc60a788cd4b552b4cf4a0b543eb1 Mon Sep 17 00:00:00 2001 From: Hudson111-s <145516182+Hudson111-s@users.noreply.github.com> Date: Fri, 13 Feb 2026 20:05:37 -0500 Subject: [PATCH 2/4] Move id into cards, add optional arguments, change ROS type to String, and remove dashboard_interface --- .../dashboard_api/dashboard_api.py | 93 ++++++++++++++----- ros/src/dashboard_api/package.xml | 2 +- ros/src/dashboard_interface/CMakeLists.txt | 14 --- ros/src/dashboard_interface/msg/Dashboard.msg | 4 - ros/src/dashboard_interface/package.xml | 19 ---- 5 files changed, 69 insertions(+), 63 deletions(-) delete mode 100644 ros/src/dashboard_interface/CMakeLists.txt delete mode 100644 ros/src/dashboard_interface/msg/Dashboard.msg delete mode 100644 ros/src/dashboard_interface/package.xml diff --git a/ros/src/dashboard_api/dashboard_api/dashboard_api.py b/ros/src/dashboard_api/dashboard_api/dashboard_api.py index 71a5264..dc421f1 100644 --- a/ros/src/dashboard_api/dashboard_api/dashboard_api.py +++ b/ros/src/dashboard_api/dashboard_api/dashboard_api.py @@ -1,43 +1,67 @@ from json import dumps from rclpy.node import Node -from dashboard_interface.msg import Dashboard +from std_msgs.msg import String class DashboardApi(): - def __init__(self, node: Node, _id: int) -> None: + def __init__(self, node: Node) -> None: self.node = node - self.id = _id - self.publisher = node.create_publisher(Dashboard, "hmi_dashboard_data", 10) + self.publisher = node.create_publisher(String, "hmi_dashboard_data", 10) - def _publish_dashboard(self, msg: Dashboard) -> None: + def _publish_dashboard(self, msg: String) -> None: self.publisher.publish(msg) - self.node.get_logger().info(f"Published {msg.id} of type {msg.type}: {msg.data}") + self.node.get_logger().info(f"Published: {msg.data}") - def _make_msg(self, screen: str, _type: str, data: dict) -> Dashboard: - msg = Dashboard() - msg.id = self.id - msg.screen = screen - msg.type = _type + def _make_msg(self, _id: str, screen: str, _type: str, data: dict) -> String: + msg = String() + data = { + "id": _id, + "screen": screen, + "type": _type, + "data": data + } msg.data = dumps(data) return msg - def card(self, screen: str, title: str, content: str) -> None: + def card( + self, + _id: str, + screen: str, + title: str, + content: str=None + ) -> None: data = { "title": title, "content": content } - msg = self._make_msg(screen, "card", data) + msg = self._make_msg(_id, screen, "card", data) self._publish_dashboard(msg) - def color(self, screen: str, title: str, content: str, color: str) -> None: + def color( + self, + _id: str, + screen: str, + title: str, + color: str, + content: str=None + ) -> None: data = { "title": title, "content": content, "color": color } - msg = self._make_msg(screen, "color", data) + msg = self._make_msg(_id, screen, "color", data) self._publish_dashboard(msg) - def bar(self, screen: str, title: str, content: str, value: int, min_value: int=0, max_value: int=1) -> None: + def bar( + self, + _id: str, + screen: str, + title: str, + value: int, + content: str=None, + min_value: int=0, + max_value: int=1 + ) -> None: data = { "title": title, "content": content, @@ -45,16 +69,16 @@ def bar(self, screen: str, title: str, content: str, value: int, min_value: int= "min": min_value, "max": max_value } - msg = self._make_msg(screen, "bar", data) + msg = self._make_msg(_id, screen, "bar", data) self._publish_dashboard(msg) _dashboard: DashboardApi | None = None -def init(node: Node, _id: int=0) -> None: +def init(node: Node) -> None: global _dashboard if _dashboard is not None: raise RuntimeError("Dashboard already initialized") - _dashboard = DashboardApi(node, _id) + _dashboard = DashboardApi(node) def get() -> DashboardApi: @@ -63,13 +87,32 @@ def get() -> DashboardApi: return _dashboard -def card(screen: str, title: str, content: str) -> None: - get().card(screen, title, content) +def card( + _id: str, + screen: str, + title: str, + content: str=None +) -> None: + get().card(_id=_id, screen=screen, title=title, content=content) -def color(screen: str, title: str, content: str, color: str): - get().color(screen, title, content, color) +def color( + _id: str, + screen: str, + title: str, + color: str, + content: str=None +) -> None: + get().color(_id=_id, screen=screen, title=title, content=content, color=color) -def bar(screen: str, title: str, content: str, value: int, min_value: int=0, max_value: int=1) -> None: - get().bar(screen, title, content, value, min_value, max_value) +def bar( + _id: str, + screen: str, + title: str, + value: int, + content: str=None, + min_value: int=0, + max_value: int=1 +) -> None: + get().bar(_id=_id, screen=screen, title=title, content=content, value=value, min_value=min_value, max_value=max_value) diff --git a/ros/src/dashboard_api/package.xml b/ros/src/dashboard_api/package.xml index 93923dc..c20b950 100644 --- a/ros/src/dashboard_api/package.xml +++ b/ros/src/dashboard_api/package.xml @@ -8,7 +8,7 @@ MIT rclpy - dashboard_interface + std_msgs ament_python diff --git a/ros/src/dashboard_interface/CMakeLists.txt b/ros/src/dashboard_interface/CMakeLists.txt deleted file mode 100644 index 2e138ef..0000000 --- a/ros/src/dashboard_interface/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(dashboard_interface) - -# Dependencies. -find_package(ament_cmake REQUIRED) -find_package(rosidl_default_generators REQUIRED) - -# Interface. -rosidl_generate_interfaces(${PROJECT_NAME} - "msg/Dashboard.msg" -) - -# Export. -ament_package() diff --git a/ros/src/dashboard_interface/msg/Dashboard.msg b/ros/src/dashboard_interface/msg/Dashboard.msg deleted file mode 100644 index 315349b..0000000 --- a/ros/src/dashboard_interface/msg/Dashboard.msg +++ /dev/null @@ -1,4 +0,0 @@ -int32 id -string screen -string type -string data diff --git a/ros/src/dashboard_interface/package.xml b/ros/src/dashboard_interface/package.xml deleted file mode 100644 index b52866e..0000000 --- a/ros/src/dashboard_interface/package.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - dashboard_interface - 0.0.0 - TODO: Package description - GoldRushRobotics - MIT - - ament_cmake - - rosidl_default_generators - rosidl_default_runtime - rosidl_interface_packages - - - ament_cmake - - From 9bc11e884b37014d990e4e7129191b0588f9492d Mon Sep 17 00:00:00 2001 From: Hudson111-s <145516182+Hudson111-s@users.noreply.github.com> Date: Tue, 17 Feb 2026 19:41:08 -0500 Subject: [PATCH 3/4] Add description and update email --- ros/src/dashboard_api/package.xml | 4 ++-- ros/src/dashboard_api/setup.py | 4 ++-- ros/src/hmi_com/package.xml | 2 +- ros/src/hmi_com_interface/package.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ros/src/dashboard_api/package.xml b/ros/src/dashboard_api/package.xml index c20b950..d5dd266 100644 --- a/ros/src/dashboard_api/package.xml +++ b/ros/src/dashboard_api/package.xml @@ -3,8 +3,8 @@ dashboard_api 0.0.0 - TODO: Package description - GoldRushRobotics + A ROS 2 API for publishing structured dashboard data as JSON to a web-based HMI, allowing nodes to send cards, bars, and color indicators. + GoldRushRobotics MIT rclpy diff --git a/ros/src/dashboard_api/setup.py b/ros/src/dashboard_api/setup.py index 816384a..98274d9 100644 --- a/ros/src/dashboard_api/setup.py +++ b/ros/src/dashboard_api/setup.py @@ -14,8 +14,8 @@ install_requires=['setuptools'], zip_safe=True, maintainer='GoldRushRobotics', - maintainer_email='goldrushrobotics@gmail.com', - description='TODO: Package description', + maintainer_email='goldrushrobotics@charlotte.edu', + description='A ROS 2 API for publishing structured dashboard data as JSON to a web-based HMI, allowing nodes to send cards, bars, and color indicators.', license='MIT', entry_points={ 'console_scripts': [], diff --git a/ros/src/hmi_com/package.xml b/ros/src/hmi_com/package.xml index 9abb79f..b494857 100644 --- a/ros/src/hmi_com/package.xml +++ b/ros/src/hmi_com/package.xml @@ -4,7 +4,7 @@ hmi_com 0.0.0 This ROS package provides real-time insights into active ROS nodes by publishing JSON-formatted information about their publishers, subscribers, service servers, and service clients. - GoldRushRobotics + GoldRushRobotics MIT rclpy diff --git a/ros/src/hmi_com_interface/package.xml b/ros/src/hmi_com_interface/package.xml index 82fe9a1..cbcf42a 100644 --- a/ros/src/hmi_com_interface/package.xml +++ b/ros/src/hmi_com_interface/package.xml @@ -4,7 +4,7 @@ hmi_com_interface 0.0.0 This ROS interface provides a service that is used in the hmi_com package to allow the request of information about active nodes. - GoldRushRobotics + GoldRushRobotics MIT ament_cmake From d2b140555cbabbcc23b7c12cac78d436c700f837 Mon Sep 17 00:00:00 2001 From: Hudson111-s <145516182+Hudson111-s@users.noreply.github.com> Date: Tue, 17 Feb 2026 20:09:53 -0500 Subject: [PATCH 4/4] Refactor DashboardApi to use per-node instances --- .../dashboard_api/dashboard_api.py | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/ros/src/dashboard_api/dashboard_api/dashboard_api.py b/ros/src/dashboard_api/dashboard_api/dashboard_api.py index dc421f1..bfe18db 100644 --- a/ros/src/dashboard_api/dashboard_api/dashboard_api.py +++ b/ros/src/dashboard_api/dashboard_api/dashboard_api.py @@ -71,48 +71,3 @@ def bar( } msg = self._make_msg(_id, screen, "bar", data) self._publish_dashboard(msg) - -_dashboard: DashboardApi | None = None - -def init(node: Node) -> None: - global _dashboard - if _dashboard is not None: - raise RuntimeError("Dashboard already initialized") - _dashboard = DashboardApi(node) - - -def get() -> DashboardApi: - if _dashboard is None: - raise RuntimeError("Dashboard not initialized. Call init() first.") - return _dashboard - - -def card( - _id: str, - screen: str, - title: str, - content: str=None -) -> None: - get().card(_id=_id, screen=screen, title=title, content=content) - - -def color( - _id: str, - screen: str, - title: str, - color: str, - content: str=None -) -> None: - get().color(_id=_id, screen=screen, title=title, content=content, color=color) - - -def bar( - _id: str, - screen: str, - title: str, - value: int, - content: str=None, - min_value: int=0, - max_value: int=1 -) -> None: - get().bar(_id=_id, screen=screen, title=title, content=content, value=value, min_value=min_value, max_value=max_value)