ros2_medkit_gateway
This section contains design documentation for the ros2_medkit_gateway project.
Architecture
The following diagram shows the relationships between the main components of the gateway.
ROS 2 Medkit Gateway Class Architecture
Main Components
GatewayNode - The main ROS 2 node that orchestrates the system - Extends
rclcpp::Node- Manages periodic discovery and cache refresh - Runs the REST server in a separate thread - Provides thread-safe access to the entity cache - Manages periodic cleanup of old action goals (60s interval)DiscoveryManager - Discovers ROS 2 entities and maps them to the SOVD hierarchy - Discovers Areas from node namespaces - Discovers Components from nodes, topics, and services - Discovers Services and Actions using native rclcpp APIs - Attaches operations (services/actions) to their parent components - Uses O(n+m) algorithm with hash maps for efficient service/action attachment
OperationManager - Executes ROS 2 operations (services and actions) - Calls ROS 2 services synchronously via
ros2 service callCLI - Sends action goals viaros2 action send_goalCLI (3s timeout for acceptance) - Tracks active action goals with status, feedback, and timestamps - Subscribes to/_action/statustopics for real-time goal status updates - Supports goal cancellation viaros2 action cancelCLI - Automatically cleans up completed goals older than 5 minutesRESTServer - Provides the HTTP/REST API - Discovery endpoints:
/health,/,/areas,/components,/areas/{area_id}/components- Data endpoints:/components/{component_id}/data,/components/{component_id}/data/{topic_name}- Operations endpoints:POST .../operations/{op}(execute),GET .../operations/{op}/status(status),DELETE .../operations/{op}(cancel) - Configurations endpoints:GET/PUT .../configurations,GET/PUT .../configurations/{param}- Retrieves cached entities from the GatewayNode - Uses DataAccessManager for runtime topic data access - Uses OperationManager for service/action execution - Uses ConfigurationManager for parameter CRUD operations - Runs on configurable host and port with CORS supportConfigurationManager - Manages ROS 2 node parameters - Lists all parameters for a node via
rclcpp::SyncParametersClient- Gets/sets individual parameter values with type conversion - Provides parameter descriptors (description, constraints, read-only flag) - Caches parameter clients per node for efficiency - Converts between JSON and ROS 2 parameter types automaticallyDataAccessManager - Reads runtime data from ROS 2 topics - Uses native rclcpp APIs for fast topic discovery and sampling - Checks publisher counts before sampling to skip idle topics instantly - Returns metadata (type, schema) for topics without publishers - Falls back to ROS 2 CLI only for publishing (
ros2 topic pub) - Returns topic data as JSON with metadata (topic name, timestamp, type info) - Parallel topic sampling with configurable concurrency limit (max_parallel_topic_samples, default: 10)NativeTopicSampler - Fast topic sampling using native rclcpp APIs - Discovers topics via
node->get_topic_names_and_types()- Checkscount_publishers()before sampling to skip idle topics - Returns metadata instantly for topics without publishers (no CLI timeout) - Significantly improves UX when robot has many idle topicsROS2CLIWrapper - Executes ROS 2 CLI commands safely - Used for publishing (
ros2 topic pub), service calls, and action operations - Wrapspopen()with RAII for exception safety during command execution - Checks command exit status to detect failures - Prevents command injection with shell argument escaping - Validates command availability before executionOutputParser - Converts ROS 2 CLI output to JSON - Parses YAML output from
ros2 topic echoandros2 service call- Preserves type information (bool → int → double → string precedence) - Handles multi-document YAML streams correctly - Converts ROS message structures to nested JSON objects - Provides staticyaml_to_json()utility for reuseData Models - Entity representations -
Area- Physical or logical domain -Component- Hardware or software component with attached operations -ServiceInfo- Service metadata (path, name, type) -ActionInfo- Action metadata (path, name, type) -EntityCache- Thread-safe cache of discovered entities