feat(ros2): migrate ROS2 tools from subprocess CLI to rclpy native API - #88
Open
lijzijie wants to merge 1 commit into
Open
feat(ros2): migrate ROS2 tools from subprocess CLI to rclpy native API#88lijzijie wants to merge 1 commit into
lijzijie wants to merge 1 commit into
Conversation
Author
|
Here are the benchmark and demo scripts to verify the performance improvements locally. I have attached a zip file Sample Benchmark ResultsFor reference, running the latency benchmark yields the following significant improvements: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
feat(ros2): migrate ROS2 tools from subprocess CLI to rclpy native APIBranch:
feat/ros2-native-api-demoFiles Changed: 5 files, +624 / -51 lines
1. What is the problem?
All ROS2 tools in ROSA (
ros2_node_list,ros2_topic_list,ros2_service_list,ros2_node_info,ros2_topic_info,ros2_service_info) query the ROS2 graph by forking a subprocess to execute theros2CLI tool:Each invocation triggers the following expensive chain:
fork()a child processrclpy+ DDS stack from scratchThis is in stark contrast to the ROS1 implementation, where tools like
rostopic_list()directly call the native Python APIrostopic.get_topic_list()— a simple XML-RPC query to the ROS Master that returns instantly.Additionally, the current ROS2 toolset is missing
ros2_topic_pub— the ability to publish messages to topics. This means the agent cannot control any ROS2 robot's motion, a critical gap compared to the ROS1 turtle_agent which has full publish capabilities.2. Why does this need to be fixed?
ros2_topic_pub, ROSA cannot sendgeometry_msgs/Twistcommands to control robot motion in ROS2 — a fundamental capability gap.3. How is it fixed?
This PR introduces a hybrid native/fallback architecture:
Singleton Node pattern:
Automatic fallback:
Each tool first attempts the native
rclpypath. Ifrclpyis unavailable (e.g., in CI/testing environments), it transparently falls back to the secure subprocess path:New
ros2_topic_pubtool:Adds the ability to publish messages to ROS2 topics using native
rclpypublishers. Supportsrate(Hz) andduration(seconds) parameters to handle continuous publishing (e.g. for smooth robot movement commands like cmd_vel).Security hardening (included):
All subprocess fallback paths use
shell=FalsewithList[str]arguments and_validate_ros_arg()input sanitization.4. What are the benefits?
ros2_topic_pubtool added (with rate/duration control)shell=True(vulnerable)shell=False+ input validation5. How to reproduce and verify the improvement
To verify the performance improvement, we have developed a set of benchmark and demo scripts.
Since these scripts are only for evaluation purposes and not intended for the main repository, they are provided separately in the attached ros2_native_api_benchmarks.zip archive.
Please download the attached zip file, extract it to the root of this repository, and follow the instructions in the included
README_BENCHMARK.mdto observe the ~450x latency reduction and test the newros2_topic_pubcapability in a standalone ROS2 Turtlesim Docker environment.6. How to verify no existing functionality is broken
# Inside the Docker container: python3 -m pytest tests/test_rosa/tools/test_ros2.py -vAll existing tests pass without modification because:
rclpyis available and the singleton node initializes successfully.The original
demo.shand ROS1 TurtleSim demo are completely untouched.Summary of Changes
src/rosa/tools/ros2.pyROSANodesingleton,ros2_topic_pub(with rate & duration support)