ROS2編程基礎課程--命令行工具

  • 2019 年 10 月 5 日
  • 筆記

版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。

本文鏈接:https://blog.csdn.net/ZhangRelay/article/details/100773460

Introspection with command line tools 使用命令行工具進行自檢

ROS 2 includes a suite of command-line tools for introspecting a ROS 2 system.

ROS 2包括一套用於ROS 2系統自檢的命令行工具。

Usage 用法

The main entry point for the tools is the command ros2, which itself has various sub-commands for introspecting and working with nodes, topics, services, and more.

這些工具的主要入口點是命令ros2,它本身具有各類子命令,用於自檢和處理節點、主題、服務等。

To see all available sub-commands run: 要查看運行的所有可用子命令:

ros2 --help

每個子命令的細節,如節點:

ros2 node -h

Examples of sub-commands that are available include:

可用的子命令示例包括:

  • daemon: Introspect/configure the ROS 2 daemon 自檢/配置ROS 2守護程式
  • launch: Run a launch file 運行啟動文件
  • lifecycle: Introspect/manage nodes with managed lifecycles 使用託管生命周期自檢/管理節點
  • msg: Introspect msg types 自檢msg類型
  • node: Introspect ROS nodes 自檢ROS節點
  • param: Introspect/configure parameters on a node 在節點上自檢/配置參數
  • pkg: Introspect ROS packages 自檢ROS包
  • run: Run ROS nodes 運行ROS節點
  • security: Configure security settings 配置安全性設置
  • service: Introspect/call ROS services 自檢/調用ROS服務
  • srv: Introspect srv types 自檢srv類型
  • topic: Introspect/publish ROS topics 自檢/發布ROS主題

Example 示例

To produce the typical talker-listener example using command-line tools, the topic sub-command can be used to publish and echo messages on a topic.

要使用命令行工具生成典型的talker-listener示例,topic子命令可用於發布和回顯主題上的消息。

Publish messages in one terminal with:

在一個終端中發布消息:

$ ros2 topic pub /chatter std_msgs/String "data: Hello world"

publisher: beginning loop

publishing std_msgs.msg.String(data='Hello world')

publishing std_msgs.msg.String(data='Hello world')

Echo messages received in another terminal with:

在另一個終端收到的回應消息:

$ ros2 topic echo /chatter

data: Hello world

data: Hello world

如果ok,可以看到如下:

Behind the scenes 背後機制

ROS 2 uses a distributed discovery process for nodes to connect to each other. As this process purposefully does not use a centralized discovery mechanism (like the ROS Master in ROS 1), it can take time for ROS nodes to discover all other participants in the ROS graph. Because of this, there is a long-running daemon in the background that stores information about the ROS graph to provide faster responses to queries, e.g. the list of node names.

ROS 2使用分散式發現過程來連接節點。由於此過程刻意不使用集中式發現機制(如ROS 1中的ROS Master),因此ROS節點可能需要一段時間才能發現ROS圖中的所有其他參與者。因此,後台存在一個長時間運行的守護程式,它存儲有關ROS圖的資訊,以便更快地響應查詢,例如節點名稱列表。

The daemon is automatically started when the relevant command-line tools are used for the first time. You can run ros2 daemon --help for more options for interacting with the daemon.

首次使用相關命令行工具時,守護程式將自動啟動。可以運行ros2 daemon --help更多選項以與守護程式進行交互。

Implementation 實現

The source code for the ros2 command is available at https://github.com/ros2/ros2cli

關於ros2命令的源程式碼可在網頁https://github.com/ros2/ros2cli上找到。

The ros2 tool has been implemented as a framework that can be extended via plugins. For example, the sros2 package provides a security sub-command that is automatically detected by the ros2 tool if the sros2 package is installed.

ros2工具實現了可通過插件擴展的框架。例如,sros2包提供了一個security子命令,ros2如果安裝了sros2包,工具會自動檢測該子命令。

Tags: