ROS2进阶:如何查找特定的包(package)并列出包中所有节点(node)

说明:ROS或ROS2在Windows下没有ubuntu那样的grep指令,相应的指令是使用find。

我这里以examples中的cpp publisher为例进行说明。

源码参考地址,

GitHub - ros2/examples: Example packages for ROS2icon-default.png?t=M276https://github.com/ros2/examples

(1)查找所有名字包含"example的"包(package)

D:\ros2prj\examples_ws>ros2 pkg list | find "example"
example_interfaces
examples_rclcpp_cbg_executor
examples_rclcpp_minimal_action_client
examples_rclcpp_minimal_action_server
examples_rclcpp_minimal_client
examples_rclcpp_minimal_composition
examples_rclcpp_minimal_publisher
examples_rclcpp_minimal_service
examples_rclcpp_minimal_subscriber
examples_rclcpp_minimal_timer
examples_rclcpp_multithreaded_executor
examples_rclpy_executors
examples_rclpy_guard_conditions
examples_rclpy_minimal_action_client
examples_rclpy_minimal_action_server
examples_rclpy_minimal_client
examples_rclpy_minimal_publisher
examples_rclpy_minimal_service
examples_rclpy_minimal_subscriber
examples_rclpy_pointcloud_publisher
examples_tf2_py

 

(2)查找包examples_rclcpp_minimal_publisher下面的所有节点

办法1:直接在文件夹下通过搜索*.exe文件找到所有的节点(用C++时节点都是可执行文件),这在windows下是非常简单的。

但是,如果你用的python那这个办法就行不通了,因为不能保证所有的*.py都是节点文件。

同样,这个办法在ubunbut等linux系统下也不行,因为没有.exe这样的后缀。

办法2:通过ROS命令查找。适用于所有操作系统。

首先我们看一下ros2 pkg都支持哪些指令,

D:\ros2prj\examples_ws>ros2 pkg --help
usage: ros2 pkg [-h] Call `ros2 pkg  -h` for more detailed usage. ...

Various package related sub-commands

optional arguments:
  -h, --help            show this help message and exit

Commands:
  create       Create a new ROS 2 package
  executables  Output a list of package specific executables
  list         Output a list of available packages
  prefix       Output the prefix path of a package
  xml          Output the XML of the package manifest or a specific tag

  Call `ros2 pkg  -h` for more detailed usage.

这里我们发现有一个指令叫做

ros2 pkg executables

我们试一下,

D:\ros2prj\examples_ws>ros2 pkg executables
action_tutorials_cpp fibonacci_action_client.exe
action_tutorials_cpp fibonacci_action_server.exe
action_tutorials_py fibonacci_action_client-script.py
action_tutorials_py fibonacci_action_client.exe
action_tutorials_py fibonacci_action_server-script.py
action_tutorials_py fibonacci_action_server.exe
camera_calibration_parsers convert.exe
composition dlopen_composition.exe
composition linktime_composition.exe
composition manual_composition.exe
demo_nodes_cpp add_two_ints_client.exe
demo_nodes_cpp add_two_ints_client_async.exe
demo_nodes_cpp add_two_ints_server.exe
demo_nodes_cpp allocator_tutorial.exe
demo_nodes_cpp even_parameters_node.exe
demo_nodes_cpp list_parameters.exe
demo_nodes_cpp list_parameters_async.exe
........

最后发现,这个指令列出了所有的可执行节点信息,包括c++和python的全部节点。

这就好办了,我们可以直接通过过滤命令来实现精确查找,如下,

D:\ros2prj\examples_ws>ros2 pkg executables | find "examples_rclcpp_minimal_publisher"
examples_rclcpp_minimal_publisher publisher_lambda.exe
examples_rclcpp_minimal_publisher publisher_member_function.exe
examples_rclcpp_minimal_publisher publisher_member_function_with_unique_network_flow_endpoints.exe
examples_rclcpp_minimal_publisher publisher_not_composable.exe

本文结束

你可能感兴趣的:(ROS2,ROS2)