Topic numerical field dynamic visualization method and system based on ros2 system
By employing static and dynamic field discovery mechanisms, combined with incremental update strategies and regular expressions to extract values, the visualization problem of complex message types in ROS2 systems has been solved, improving user interaction experience and response speed, and making it suitable for large-scale distributed scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- AUTOCORE INTELLIGENT TECH (NANJING) CO LTD
- Filing Date
- 2026-05-28
- Publication Date
- 2026-06-26
AI Technical Summary
The existing visualization tools for ROS2 systems cannot automatically discover hidden numerical fields stored as strings in complex nested messages and diagnostic messages, and user interaction status is easily lost during topic list refresh.
A two-stage field discovery mechanism is adopted, which automatically discovers visual numerical fields through static type reflection and runtime instance scanning. An incremental update strategy is used to refresh the topic list, array indexes and regular expressions are used to extract values, and a signal bridging module ensures secure data transmission.
It enables automated parsing of complex message types, resolves field path conflicts, improves the interactive experience and response responsiveness, and supports visualization of large-scale distributed scenarios.
Smart Images

Figure CN122289423A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of robot operating system technology, and in particular to a method and system for dynamic visualization of topic numerical fields based on the ROS2 system. Background Technology
[0002] ROS2 is a next-generation robot operating system that uses DDS (Data Distribution Service) as its underlying communication middleware and is widely used in robotics, autonomous driving, and industrial automation. During actual project development and deployment, engineers need to monitor the changing trends of various numerical fields within a topic over time, such as vehicle speed, steering wheel angle, inertial measurement unit data, and LiDAR frequency, to assist in system debugging, fault location, and performance analysis.
[0003] Currently, commonly used tools for visualizing numerical fields in ROS2 systems include the officially provided rqt_plot tool, the third-party open-source tool PlotJuggler, and the 3D visualization tool RViz2. Among these, rqt_plot only supports plotting curves for basic numerical fields; for fields containing nested sub-messages, dynamic arrays, byte types, or other complex data types, users need to manually specify the specific path, as it cannot be automatically discovered. PlotJuggler has relatively complete functionality but is complex to configure; for message types containing special data structures, users need to write their own parsing scripts. RViz2 is mainly used for 3D rendering and is not suitable for time series curve analysis. All of the above tools share the following common drawbacks: First, the ability to parse fields for complex message types is limited. Most existing tools can only recognize standard integer and floating-point basic fields in message types. For deeply nested sub-messages, fixed and dynamic length arrays, byte sequence types, etc., they cannot automatically recursively traverse and extract all visual fields.
[0004] Second, it cannot handle numerical values stored as strings in diagnostic messages. For example, `diagnostic_msgs / msg / DiagnosticArray` is a standard ROS2 diagnostic message type, widely used in autonomous driving systems to report the operating status of sensors, LiDAR, millimeter-wave radar, and other devices. The truly diagnostically valuable numerical data in this message is not stored directly as a numerical type, but rather hidden in multi-level nested arrays as key-string value pairs (KeyValue type). Furthermore, the strings often include unit descriptions, such as "11.00 [Hz]", "1.00 [s]", and "1776055473.87 [s]". Existing visualization tools cannot automatically identify these hidden numerical values; engineers can only view the original text via command line or write custom parsing scripts, which is extremely inefficient.
[0005] Third, there is a problem of name ambiguity in diagnostic messages. Multiple DiagnosticStatus elements often appear in the same DiagnosticArray, and some parts of their name field are the same (for example, the diagnostic status names of four LiDARs all end with lidar_driver_topic_status). The traditional method of indexing by name will lead to field path conflicts and make it impossible to distinguish between different devices.
[0006] Fourth, frequent refreshes of the topic list can lead to the loss of user interaction status. The number of topics in the ROS2 network changes dynamically, and visualization tools need to periodically and automatically refresh the topic list. However, existing tools generally adopt a refresh strategy of clearing and rebuilding, which causes the user's current scroll bar position to be reset to zero and the field selection status to be lost with each refresh, seriously affecting the interactive experience. Summary of the Invention
[0007] To address the shortcomings of existing technologies, the present invention aims to provide a method and system for dynamically visualizing topic numerical fields based on the ROS2 system. This solves the problems of existing technologies failing to automatically discover hidden numerical fields stored as strings in complex nested messages and diagnostic messages, as well as the loss of user interaction status during topic list refresh.
[0008] To achieve the objectives of this invention, the technical solution adopted is as follows: A method for dynamically visualizing topic numerical fields based on the ROS2 system includes the following steps: S1 enumerates all active topics in the ROS2 system, obtains the name, message type string, number of publishers and number of subscribers for each topic, and dynamically imports the corresponding message class based on the message type string; S2, perform static field recursive parsing on the message class of the user-selected topic to obtain a set of candidate numeric field paths; the static field recursive parsing includes: identifying basic numeric type fields, identifying and skipping non-numeric basic type fields, recursively parsing nested sub-message fields, and marking fields containing key-value pair sub-message arrays as runtime placeholders; S3, when there is a runtime placeholder in the candidate numeric field path set, subscribe to the corresponding topic and perform dynamic field scanning based on the first arriving message; the dynamic field scanning includes: generating a unique identifier for the status array in the message according to its position index and element name, applying a preset regular expression numerical extraction algorithm to the string value in each key-value pair element, and adding the keys that can be successfully extracted to the candidate numeric field path set. S4. Based on the field selected by the user from the candidate numerical field path set, extract the value from each subscribed message according to the field path, and pass the value to the graphical interface thread through a thread-safe signal mechanism to draw it in real time in the form of an automatically scrolling time window curve.
[0009] Furthermore, in step S1, the message type string supports two formats: three-segment pkg / msg / Type and two-segment pkg / Type.
[0010] Further, in step S2, the static field recursive parsing specifically includes: obtaining the mapping from field name to field type string through the field type mapping interface of the message class; parsing the internal type of each field type string using a regular expression and determining whether it is an array; maintaining the collection of visited message classes to prevent infinite recursion caused by circular references; automatically identifying message classes containing only two fields, key string and value string, as key-value pair types, and marking their arrays as runtime placeholders.
[0011] Further, in step S3, the method for generating the unique identifier in the dynamic field scan is as follows: generate a unique identifier of the form status[i:label] for the i-th element in the status array, where i is the index of the element in the array and label is a readable label; the method for extracting the readable label is as follows: divide the name field of the element into multiple segments by a colon, take the second segment and remove the common prefix that is the same as the first segment; the regular expression numerical extraction algorithm uses the pattern ^[-+]?(?:\d+\.?\d*|\.\d+) (?:[eE][-+]?\d+)? to match the numerical part from the beginning of the string, compatible with strings with unit suffixes, scientific notation, and plus or minus signs; after successful extraction, the numerical part is converted into a floating-point number.
[0012] Further, in step S4, in the step of extracting values by field path, for dynamic field paths, the index i and key name k are parsed using regular expressions, the i-th element of the state array is directly located by the index, the corresponding key-value pair is found by the key name, and the regular expression value extraction algorithm is applied again to its value string; for ordinary field paths, attribute retrieval and array indexing operations are called recursively in a hierarchical manner, and finally the obtained object is converted according to its Python type. The value conversion supports the following types: standard int, float, and bool types are directly converted to floating-point numbers; bytes types with a length of 1 are converted after taking the first byte integer value; numpy numerical scalar types are converted after type detection.
[0013] Furthermore, it also includes periodically refreshing the topic list through incremental updates, specifically including: constructing a mapping from existing topic names in the currently displayed tree to tree nodes; for newly acquired topic lists, existing topic nodes only update the column text that differs from the previous value; newly appearing topics are appended to the end of the tree and their historical checkmark status is automatically restored; topics that have disappeared are removed from the tree; the current search filter conditions are automatically applied, and nodes that do not match are set to the hidden attribute; and the user's scroll bar position, checkmark status, and search filter status remain completely unchanged.
[0014] Furthermore, it also includes real-time frequency statistics based on sliding windows, specifically including: maintaining a double-ended queue with a fixed capacity of N for each subscribed topic, recording the arrival timestamps of the most recent N messages, calculating the instantaneous frequency according to the formula freq=(len(window)-1) / (window[-1]-window[0]), and displaying it in real time in the corresponding topic entry of the graphical interface.
[0015] A dynamic visualization system for topic numerical fields based on ROS2 includes: The topic discovery module is used to enumerate all active topics in the ROS2 system, obtain the name, message type string, number of publishers and number of subscribers for each topic, and dynamically import the corresponding message class based on the message type string; The field extraction module is used to perform static field recursive parsing on the message class of the user-selected topic to obtain a candidate numerical field path set; when there is a runtime placeholder in the candidate numerical field path set, dynamic field scanning is performed based on the first arriving message, a unique identifier is generated by array index and element name, a regular expression numerical extraction algorithm is applied to the string value in the key-value pair, and the keys from which the numerical value can be successfully extracted are added to the candidate numerical field path set; and the numerical value is extracted from each arriving message according to the field path. The plotting module is used to plot the extracted values in real time as an automatically scrolling time window curve. The graphical interface module is used to periodically refresh the topic list in an incremental update manner, providing search filtering and field selection interaction, while keeping the user's scroll bar position, selection status, and search filtering status unchanged; The signal bridging module is used to securely transmit numerical data received in the ROS2 subscription callback thread to the main thread of the graphical interface.
[0016] Furthermore, the field extraction module includes: a type string parsing submodule, used to parse ROS2 field type strings into tuples indicating internal type and whether it is an array; a message class import submodule, used to support dynamic import of three-part and two-part type string formats; a key-value pair type identification submodule, used to automatically determine whether a message class is a key-value pair type; and a string value extraction submodule, used to extract values from the beginning of the string using regular expressions.
[0017] Furthermore, the system and the monitored topic can be deployed on different devices within the same communication domain.
[0018] The beneficial effects of this invention are that, compared with the prior art, this invention, through a two-stage field discovery mechanism, static type reflection and runtime instance scanning, can automatically discover all visual numerical fields in any standard and custom ROS2 message, with a coverage exceeding that of existing tools. In particular, it is the first to achieve zero-configuration visualization of hidden numerical values stored in the form of strings plus units in messages such as diagnostic_msgs / DiagnosticArray, without requiring users to write any parsing code or pre-configure.
[0019] This invention, based on a composite path identification mechanism using array indexes (status[index:readable label].kv{key name}), completely solves the field path conflict problem in existing solutions under the scenario of duplicate diagnostic status, enabling engineers to accurately distinguish diagnostic indicators with the same name from multiple devices (such as multiple LiDARs, multiple cameras).
[0020] This invention employs an incremental update strategy for refreshing the topic list, avoiding the visual jitter and state loss caused by clearing and rebuilding. The user's scroll bar position, field selection status, and search filter status remain completely unchanged during automatic refresh, significantly improving the user experience. Furthermore, this invention's instantaneous frequency statistics algorithm based on a sliding window is more sensitive than traditional cumulative average algorithms, effectively reflecting the changing trends of topic frequency in a timely manner.
[0021] The signal bridging module of this invention realizes secure data transfer between the ROS2 subscription callback thread and the main thread of the graphical interface through the Qt signal slot mechanism, avoiding the problem of multi-threaded data competition, while ensuring the smoothness of the interface under high-frequency message flow.
[0022] This invention supports any ROS2 standard and custom message types. Its modular design facilitates expansion, and adding new message type parsing requires no modification to the core code. Based on a DDS communication domain architecture, the visualization system and monitored topics can be deployed on different devices, supporting large-scale distributed scenarios. Attached Figure Description
[0023] Figure 1This is a framework diagram of a topic numerical field dynamic visualization system based on the ROS2 system provided in this embodiment of the invention; Figure 2 This is a flowchart of the recursive parsing process for static fields provided in an embodiment of the present invention; Figure 3 This is a flowchart of the runtime dynamic field scanning and extraction process provided in this embodiment of the invention; Figure 4 This is a flowchart of the incremental refresh process for the topic list provided in an embodiment of the present invention. Detailed Implementation
[0024] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and should not be used to limit the scope of protection of this application.
[0025] like Figure 1 As shown, the method for dynamically visualizing topic numerical fields based on the ROS2 system according to the present invention includes the following steps: S1 enumerates all active topics in the ROS2 system, obtains the name, message type string, number of publishers and number of subscribers for each topic, and dynamically imports the corresponding message class based on the message type string; When the system starts, the ROS2 system runtime environment is initialized. The ROS2 communication context is created through rclpy.init(), and a shared node named 'topic_plotter' is created. The shared node enumerates all active topics in the current ROS2 system by calling the get_topic_names_and_types() interface to obtain a list of topic names and message type strings. The number of publishers and subscribers for each topic is obtained by calling the get_publishers_info_by_topic() and get_subscriptions_info_by_topic() interfaces, respectively.
[0026] The message type string supports two formats: a three-part format `pkg / msg / Type` and a two-part format `pkg / Type`. The three-part format `pkg / msg / Type`, such as "geometry_msgs / msg / Twist" and "diagnostic_msgs / msg / DiagnosticArray", corresponds to the Python module path `pkg / msg / Type`. The two-part format `pkg / Type`, such as "std_msgs / Header" and "diagnostic_msgs / DiagnosticStatus", is used by some ROS2 versions to return the type string; it needs to be automatically completed to the Python module path in `pkg / msg / Type`.
[0027] The system dynamically imports the corresponding Python module using the importlib.import_module() method and retrieves the corresponding message class using getattr().
[0028] To improve user experience, the system uses a timer to automatically refresh the topic list periodically (every 3 seconds by default), and also allows users to manually trigger a refresh by clicking the refresh button. A search input box is provided above the topic list; as users enter keywords, matching topics are filtered and displayed in real time. The matching scope covers both topic names and message type strings, and is case-insensitive.
[0029] S2, perform static field recursive parsing on the message class of the user-selected topic to obtain a set of candidate numeric field paths; static field recursive parsing includes: identifying basic numeric type fields, identifying and skipping non-numeric basic type fields, recursively parsing nested sub-message fields, and marking fields containing key-value pair sub-message arrays as runtime placeholders; like Figure 2 As shown, the static field recursive parsing specifically includes: obtaining the mapping from field name to field type string through the field type mapping interface of the message class; parsing the internal type of each field type string using a regular expression and determining whether it is an array; maintaining a collection of visited message classes to prevent infinite recursion caused by circular references; automatically identifying message classes containing only two fields, key string and value string, as key-value pair types, and marking their arrays as runtime placeholders.
[0030] When a user clicks on an item in the topic list, the system calls the get_fields_and_field_types() interface of the message class to obtain a mapping table of field names to field type strings; then it iterates through each field and parses its type string.
[0031] The type string parsing uses the pre-compiled regular expression ^(bounded_)?sequence<\s*(.+?) (?:\s*,\s*\d+)?\s*>$ to match the sequence type, extract the internal type and mark it as an array; for fixed-length array types containing square brackets (such as float64[3]), the internal type is extracted by splitting according to the position of the square brackets; other types are directly used as scalar internal types. The parsing yields the internal type string and a tuple of whether it is an array.
[0032] Categorize and process strings based on their internal type: a) If the internal type belongs to the predefined set of basic numeric types (including boolean, bool, byte, char, octet, float, double, float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64), then the field path is added to the candidate set; if it is an array type, a [] marker is appended to the path, for example, "ranges[]".
[0033] b) If the internal type is a non-numeric basic type (including string and wstring), skip it directly and do not add it to the candidate set.
[0034] c) If the internal type is a sub-message type, first try to dynamically import the sub-message class via the type string (supporting the above three-part and two-part formats). If the import fails, try to import it from the same package as the parent message by short name. After successful import: if the sub-message class is automatically recognized as a key-value pair type (containing only two fields: key:string and value:string), then mark the field path as a runtime placeholder, such as "status[kv]", to be processed at runtime; otherwise, recursively call this step to continue parsing the sub-message fields, and append the recursively obtained sub-field paths to the parent path in an appropriate format.
[0035] To prevent circular references between message types from causing dead recursion (uncommon in ROS2 standard messages, but may exist in custom messages), this step maintains a collection of visited classes, _visited, which is checked and added before each recursion.
[0036] Taking the `geometry_msgs / msg / Twist` message as an example, this message contains two fields, `linear` and `angular`, both of type `geometry_msgs / Vector3`. `Vector3` contains three float64 fields: `x`, `y`, and `z`. The system recursively parses the message to obtain the following candidate field paths: `linear.x`, `linear.y`, `linear.z`, `angular.x`, `angular.y`, and `angular.z`.
[0037] Taking the `diagnostic_msgs / msg / DiagnosticArray` message as an example, this message contains a `header` field (of type `std_msgs / Header`) and a `status` field (of type `DiagnosticStatus[]` array). The `stamp` field in the `header` contains two numeric fields: `sec` and `nanosec`. `DiagnosticStatus` contains `level` (of type `byte`), `name` (of type `string`), `message` (of type `string`), `hardware_id` (of type `string`), and `values` (of type `KeyValue[]` array). `KeyValue` contains only two string fields, `key` and `value`, and is automatically recognized as a key-value pair. The system recursively parses the candidate field paths as follows: `header.stamp.sec`, `header.stamp.nanosec`, `status[].level`, and `status[].values[kv]`. `status[].values[kv]` is a runtime placeholder and needs to be further expanded at runtime.
[0038] S3, when there is a runtime placeholder in the candidate numeric field path set, subscribe to the corresponding topic and perform dynamic field scanning based on the first message that arrives; dynamic field scanning includes: generating a unique identifier for the status array in the message according to its position index and element name, applying a preset regular expression numeric extraction algorithm to the string value in each key-value pair element, and adding the keys that can be successfully extracted to the candidate numeric field path set. When the system detects that the candidate set contains a runtime placeholder, it automatically establishes a subscription to the topic and waits for the first message to arrive. The subscription's Quality of Service (QoS) configuration uses the BEST_EFFORT reliability policy and the KEEP_LAST history policy, with a depth set to 10 to maximize compatibility with various publishers.
[0039] like Figure 3 As shown, after the first message arrives, the system executes the dynamic field scanning sub-process: a) Iterate through the status array in the message (e.g., msg.status) and perform the following processing on the i-th element of the array; b) Extract the name field of the element (e.g., status_i.name), and call the _make_short_label() function to generate a readable label. The implementation of the _make_short_label() function is as follows: the name field is divided into multiple segments by colons, and blank segments are removed; if the result has at least two segments, the second segment is taken, and it is checked whether it is prefixed with the first segment plus an underscore. If so, the common prefix is removed; if there is only one segment, the segment is used directly.
[0040] For example, for the name "topic_state_monitor: topic_state_monitor_rslidar_front_lumotive_ros: lidar_driver_topic_status", the first segment is "topic_state_monitor" and the second segment is "topic_state_monitor _rslidar_front_lumotive_ros". After removing the common prefix "topic_state_monitor_", we get label="rslidar_front_lumotive_ros".
[0041] c) Combine array index i and readable label label to generate a unique identifier in the form of status[i:label]; d) Iterate through the key-value pair array (e.g., status_i.values) of the status element, and perform the following processing on each key-value pair (k, v): Call the _parse_numeric_string() function to attempt to extract the numeric value from the string v; this function uses the pre-compiled regular expression ^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)? to match the numeric part at the beginning of the string. If the match is successful, convert it to a floating-point number and return it; otherwise, return None; only when the extraction is successful, generate a compound field path of the form status[i:label].kv{k} and add it to the dynamic field list; e) Pass the list of dynamic fields back to the main thread of the graphical interface via the Qt signal mechanism (dynamic_fields_ready signal); f) After receiving the signal, the main thread of the graphical interface will append the dynamic fields to the field tree in green highlight form for the user to select.
[0042] Taking a DiagnosticArray message containing 8 DiagnosticStatus elements as an example (4 of which are the statuses of LiDAR in different directions, and 4 are the statuses of different cameras), the set of field paths obtained after dynamic field scanning includes: status[0:camera0_image_raw].kv{warn_rate} status[0:camera0_image_raw].kv{measured_rate} status[0:camera0_image_raw].kv{timeout} ... (Other camera fields) status[4:rslidar_front_lumotive_ros].kv{warn_rate} status[4:rslidar_front_lumotive_ros].kv{measured_rate} status[5:rslidar_back_lumotive_ros].kv{measured_rate} status[6:rslidar_left_lumotive_ros].kv{measured_rate} status[7:rslidar_right_lumotive_ros].kv{measured_rate} ... (Other lidar fields) Because array indices are used as unique identifiers, even though the names of all four LiDARs end with "lidar_driver_topic_status", different devices can still be clearly distinguished by index i.
[0043] S4 extracts values from each subscribed message according to the field selected by the user from the candidate numerical field path set, and transmits the values to the graphical interface thread through a thread-safe signal mechanism, which then draws them in real time in the form of an automatically scrolling time window curve.
[0044] When a user selects a field in the field tree, the system automatically selects the corresponding topic's checkbox (if it is not already selected) and establishes a subscription to that topic (if it is not already subscribed). When each message arrives, the system iterates through the set of selected fields for that topic and calls the extract_value() function to extract the value for each field path.
[0045] like Figure 3 As shown, field value extraction falls into two categories: Scenario 1: Dynamic field path, such as "status[4:rslidar_front_lumotive_ros].kv{measured_rate}". The system uses the regular expression ^status\[(\d+):[^\]]*\]\.kv\{(.+?)\}$ to parse the index i and key name k; it directly locates msg.status[i] by index, iterates through its values array to find the KeyValue element that matches the key name, and applies the _parse_numeric_string() function to extract the value string.
[0046] Case 2: Ordinary field paths, such as "linear.x" or "ranges[0]". The system calls the _parse_path() function to parse the path into a list of (field name, optional index), and performs getattr and array index operations in sequence. After finally obtaining the object, its Python type is determined: if it is a standard int, float, or bool type, float() is called directly for conversion; if it is a bytes type with a length of 1 (corresponding to ROS2's byte / octet / char fields, such as b'\x02'), the first byte integer value is taken and then converted to a floating-point number; if it is a numpy.integer or numpy.floating scalar type (some ROS2 message fields will return numpy values), it is converted after being detected by isinstance; other types return None.
[0047] The extracted values are transmitted to the main thread of the graphical interface via the Qt signal (data_received), and the plotting module appends them to the data buffer of the corresponding curve.
[0048] The drawing module is implemented based on PyQtGraph and employs the following mechanisms to ensure efficient drawing: 1) Each curve maintains a fixed-capacity double-ended queue (deque(maxlen=2000)) as a rolling buffer for timestamps and values, automatically discarding data that is too early; 2) Refresh is triggered periodically by an independent Qt timer (default 20Hz, adjustable by the user). Each refresh calls setData() to update the data of all curves at once, avoiding the performance loss caused by triggering redraw for every message; 3) Automatically scroll the X-axis range to always display the data from the most recent time_window seconds (time_window defaults to 30 seconds, adjustable by the user); 4) Multiple curves are automatically assigned different colors, and the legend is updated synchronously with the curves; when removing curves in batches, the legend is only rebuilt once at the last time to avoid visual residue caused by continuous reconstruction.
[0049] S5 refreshes the topic list periodically using incremental updates, keeping the user interaction state completely unchanged.
[0050] like Figure 4 As shown, the topic list is periodically refreshed using an incremental update method, specifically including: constructing a mapping from existing topic names in the currently displayed tree to tree nodes; for newly acquired topic lists, existing topic nodes only update the column text that differs from the previous value; newly appearing topics are appended to the end of the tree and their historical checkmark status is automatically restored; topics that have disappeared are removed from the tree; the current search filter conditions are automatically applied, and nodes that do not match are set to the hidden attribute; and the user's scroll bar position, checkmark status, and search filter status remain completely unchanged.
[0051] When the topic list refresh timer (default 3 seconds) is triggered, the system executes the incremental refresh algorithm: a) Block the signal emission of the topic tree to avoid triggering callbacks such as itemChanged; b) Construct a mapping from existing topic names in the current display tree to tree nodes (existing); c) Call get_topic_info() to retrieve the latest list of topics and construct a new name set new_names; d) For each newly acquired topic information, perform the following checks: If the topic name already exists in existing, only compare the three columns of publishers, subscribers, and message type, and only call setText() to update if the text is different. This can avoid unnecessary UI redraws and style refreshes; if the topic name does not appear in existing, create a new QTreeWidgetItem and append it to the end of the tree, and automatically set its checkbox state to restore the user's historical selections. e) Traverse all nodes in the current tree in reverse order, and remove nodes whose names are not in new_names by calling takeTopLevelItem(). f) Release the signal blockade; g) Call _filter_topics() to reapply the filter conditions in the current search box.
[0052] With the incremental update algorithm described above, the entire refresh process will not call clear() to clear the topic tree. Therefore, the user's scroll bar position, field selection status, and search filter results remain completely consistent before and after the refresh, without any visual fluctuations.
[0053] In one implementation, a real-time frequency statistics step based on a sliding window is further included: a fixed-capacity double-ended queue collections.deque(maxlen=N) of size N is maintained for each subscribed topic, recording the arrival timestamps of the most recent N messages. When each message arrives, the current timestamp is appended to the end of the queue. When the queue length reaches 2 or more, the instantaneous frequency is calculated according to the formula freq = (len(window)-1) / (window[-1]-window[0]) and stored in the frequency dictionary.
[0054] Compared to the traditional frequency calculation method of cumulative message count / cumulative time, the sliding window algorithm of this invention is more sensitive and can reflect real-time changes in topic frequency in a timely manner. For example, when the posting frequency of a topic suddenly drops or fluctuates, this algorithm can reflect it within seconds, while the cumulative algorithm reacts more slowly due to the dilution effect of historical data. A status timer triggered once every second reads the latest value from the frequency dictionary and updates it to the corresponding entries in the graphical interface status bar and topic tree.
[0055] This invention also supports multiple extension and integration methods: plug-in message type extension: through modular design, users can add new field extraction rules to support custom message types without modifying the core code; data export: curve data can be exported as CSV or JSON format for easy offline analysis; distributed deployment: based on the DDS communication domain, the visualization system and the monitored topics can be deployed on different devices, supporting remote monitoring of autonomous vehicles and robot field data.
[0056] This invention also provides a dynamic visualization system for topic numerical fields based on the ROS2 system, comprising: The topic discovery module is used to enumerate all active topics in the ROS2 system, obtain the name, message type string, number of publishers and number of subscribers for each topic, and dynamically import the corresponding message class based on the message type string; The field extraction module is used to perform static field recursive parsing on the message class of the user-selected topic to obtain a candidate numerical field path set; when there is a runtime placeholder in the candidate numerical field path set, dynamic field scanning is performed based on the first arriving message, a unique identifier is generated by array index and element name, a regular expression numerical extraction algorithm is applied to the string value in the key-value pair, and the keys from which the numerical value can be successfully extracted are added to the candidate numerical field path set; and the numerical value is extracted from each arriving message according to the field path. The plotting module is used to plot the extracted values in real time as an automatically scrolling time window curve. The graphical interface module is used to periodically refresh the topic list in an incremental update manner, providing search filtering and field selection interaction, while keeping the user's scroll bar position, selection status, and search filtering status unchanged; The signal bridging module is used to securely transmit numerical data received in the ROS2 subscription callback thread to the main thread of the graphical interface.
[0057] In one implementation, the field extraction module further includes: a type string parsing submodule, used to parse ROS2 field type strings into tuples indicating internal type and whether they are arrays; a message class import submodule, used to support dynamic import of both three-part and two-part type string formats; a key-value pair type identification submodule, used to automatically determine whether a message class is a key-value pair type; and a string value extraction submodule, used to extract values from the beginning of the string using regular expressions.
[0058] In one implementation, the system and the monitored topic are deployed on different devices within the same communication domain.
[0059] The embodiments of the present invention were also tested and verified in an actual autonomous driving system. The test environment included the topic diagnostic_msgs / msg / DiagnosticArray collected by real vehicles. This topic was published at a frequency of 10Hz. Each message contained 8 DiagnosticStatus elements. The values array of each element contained 8 KeyValue items (topic, status, warn_rate, error_rate, timeout, measured_rate, now, last_message_time).
[0060] Test results show that: 1. The system can automatically discover and expand all 64 dynamic fields without requiring users to write any parsing code or pre-configure; 2. For the same diagnostic status (lidar_driver_topic_status) of 4 lidars, the system correctly distinguishes the measured_rate index of 4 different devices by using a composite path based on array index (such as status[4:rslidar_front_lumotive_ros]), and draws 4 independent curves. Engineers can clearly observe the measured frequency changes of lidars in different directions. 3. During the automatic refresh of the topic list, the 8 fields already selected by the user, the scroll bar position, and the search filter results remain completely unchanged, resulting in a smooth interactive experience; 4. Frequency statistics based on sliding windows can reflect changes in topic frequency within 500ms, which is far superior to the response speed of traditional cumulative algorithms; 5. Under a load of subscribing to 50 topics and simultaneously plotting 20 curves, the CPU utilization rate of the system remained stable at less than 5%, and the plotting refresh rate remained stable at 20Hz, meeting the requirements for real-time visualization.
[0061] The applicant of this invention has provided a detailed description of the embodiments of the invention in conjunction with the accompanying drawings. However, those skilled in the art should understand that the above embodiments are merely preferred embodiments of the invention. The detailed description is only intended to help readers better understand the spirit of the invention and is not intended to limit the scope of protection of the invention. On the contrary, any improvements or modifications made based on the inventive spirit of the invention should fall within the scope of protection of the invention.
Claims
1. A method for dynamically visualizing topic numerical fields based on the ROS2 system, characterized in that, Includes the following steps: S1 enumerates all active topics in the ROS2 system, obtains the name, message type string, number of publishers and number of subscribers for each topic, and dynamically imports the corresponding message class based on the message type string; S2, perform static field recursive parsing on the message class of the topic selected by the user to obtain a set of candidate numerical field paths; The static field recursive parsing includes: identifying basic numeric type fields, identifying and skipping non-numeric basic type fields, recursively parsing nested sub-message fields, and marking fields containing key-value pair sub-message arrays as runtime placeholders; S3, when there is a runtime placeholder in the candidate numeric field path set, subscribe to the corresponding topic and perform dynamic field scanning based on the first arriving message; the dynamic field scanning includes: generating a unique identifier for the status array in the message according to its position index and element name, applying a preset regular expression numerical extraction algorithm to the string value in each key-value pair element, and adding the keys that can be successfully extracted to the candidate numeric field path set. S4. Based on the field selected by the user from the candidate numerical field path set, extract the value from each subscribed message according to the field path, and pass the value to the graphical interface thread through a thread-safe signal mechanism to draw it in real time in the form of an automatically scrolling time window curve.
2. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, In step S1, the message type string supports two formats: three-segment pkg / msg / Type and two-segment pkg / Type.
3. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, In step S2, the static field recursive parsing specifically includes: obtaining the mapping from field name to field type string through the field type mapping interface of the message class; parsing the internal type of each field type string using a regular expression and determining whether it is an array; maintaining the collection of visited message classes to prevent infinite recursion caused by circular references; automatically identifying message classes containing only two fields, key string and value string, as key-value pair types, and marking their arrays as runtime placeholders.
4. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, In step S3, the method for generating unique identifiers in dynamic field scanning is as follows: generate a unique identifier of the form status[i:label] for the i-th element in the status array, where i is the index of the element in the array and label is a readable label; the method for extracting readable labels is as follows: divide the name field of the element into multiple segments by a colon, take the second segment and remove the common prefix that is the same as the first segment; the regular expression numerical extraction algorithm uses the pattern ^[-+]?(?:\d+\.?\d*|\.\d+) (?:[eE][-+]?\d+)? to match the numerical part from the beginning of the string, compatible with strings with unit suffixes, scientific notation, and plus or minus signs; after successful extraction, the numerical part is converted into a floating-point number.
5. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, In step S4, in the step of extracting values by field path, for dynamic field path, index i and key name k are parsed by regular expression, the i-th element of state array is directly located by index, the corresponding key-value pair is found by key name, and the regular expression value extraction algorithm is applied again to its value string. For ordinary field paths, attribute retrieval and array indexing operations are recursively called hierarchically. Finally, the resulting object is numerically converted according to its Python type. The numerical conversion supports the following types: standard int, float, and bool types are directly converted to floating-point numbers; bytes types with a length of 1 are converted after taking the first byte integer value; and numpy numeric scalar types are converted after type checking.
6. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, It also includes periodically refreshing the topic list through incremental updates, specifically: constructing a mapping from existing topic names in the currently displayed tree to tree nodes; for newly acquired topic lists, existing topic nodes only update the column text that differs from the previous value; newly appearing topics are appended to the end of the tree and their historical checkmark status is automatically restored; topics that have disappeared are removed from the tree; the current search filter conditions are automatically applied, and nodes that do not match are set to the hidden attribute; and the user's scroll bar position, checkmark status, and search filter status remain completely unchanged.
7. The method for dynamically visualizing topic numerical fields based on the ROS2 system according to claim 1, characterized in that, It also includes real-time frequency statistics based on sliding windows, specifically: maintaining a double-ended queue with a fixed capacity of N for each subscribed topic, recording the arrival timestamps of the most recent N messages, calculating the instantaneous frequency according to the formula freq=(len(window)-1) / (window[-1]-window[0]), and displaying it in real time in the corresponding topic entry of the graphical interface.
8. A dynamic visualization system for topic numerical fields based on the ROS2 system, characterized in that, include: The topic discovery module is used to enumerate all active topics in the ROS2 system, obtain the name, message type string, number of publishers and number of subscribers for each topic, and dynamically import the corresponding message class based on the message type string; The field extraction module is used to perform static field recursive parsing on the message class of the user-selected topic to obtain a set of candidate numerical field paths; When there are runtime placeholders in the candidate numeric field path set, a dynamic field scan is performed based on the first message that arrives. A unique identifier is generated by array index and element name. A regular expression numeric extraction algorithm is applied to the string values in the key-value pairs. Keys that can be successfully extracted are added to the candidate numeric field path set. And extract values from each arriving message according to the field path; The plotting module is used to plot the extracted values in real time as an automatically scrolling time window curve. The graphical interface module is used to periodically refresh the topic list in an incremental update manner, providing search filtering and field selection interaction, while keeping the user's scroll bar position, selection status, and search filtering status unchanged; The signal bridging module is used to securely transmit numerical data received in the ROS2 subscription callback thread to the main thread of the graphical interface.
9. The topic numerical field dynamic visualization system based on the ROS2 system according to claim 8, characterized in that, The field extraction module includes: a type string parsing submodule, used to parse ROS2 field type strings into tuples indicating internal type and whether they are arrays; a message class import submodule, used to support dynamic import of three-part and two-part string formats; a key-value pair type identification submodule, used to automatically determine whether a message class is a key-value pair type; and a string value extraction submodule, used to extract values from the beginning of a string using regular expressions.
10. The topic numerical field dynamic visualization system based on the ROS2 system according to claim 8, characterized in that, The system and the monitored topic are in the same communication domain and can be deployed on different devices.