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..bfe18db --- /dev/null +++ b/ros/src/dashboard_api/dashboard_api/dashboard_api.py @@ -0,0 +1,73 @@ +from json import dumps +from rclpy.node import Node +from std_msgs.msg import String + +class DashboardApi(): + def __init__(self, node: Node) -> None: + self.node = node + self.publisher = node.create_publisher(String, "hmi_dashboard_data", 10) + + def _publish_dashboard(self, msg: String) -> None: + self.publisher.publish(msg) + self.node.get_logger().info(f"Published: {msg.data}") + + 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, + _id: str, + screen: str, + title: str, + content: str=None + ) -> None: + data = { + "title": title, + "content": content + } + msg = self._make_msg(_id, screen, "card", data) + self._publish_dashboard(msg) + + 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(_id, screen, "color", data) + self._publish_dashboard(msg) + + 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, + "value": value, + "min": min_value, + "max": max_value + } + msg = self._make_msg(_id, screen, "bar", data) + self._publish_dashboard(msg) diff --git a/ros/src/dashboard_api/package.xml b/ros/src/dashboard_api/package.xml new file mode 100644 index 0000000..d5dd266 --- /dev/null +++ b/ros/src/dashboard_api/package.xml @@ -0,0 +1,16 @@ + + + + dashboard_api + 0.0.0 + 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 + std_msgs + + + 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..98274d9 --- /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@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