ROS2 CLI工具

ros2 pkg

用于创建和管理ROS2的程序包

  • ros2 pkg create:创建一个新包。通过指定不同的参数来决定创建哪种类型的程序包,如:ros2 pkg create --build-type ament_cmake --node-name
  • ros2 pkg executables:列出程序包中所有可执行文件
  • ros2 pkg prefix:列出指定包的安装目录的前缀
  • ros2 pkg xml:返回程序包的xml信息

参数说明

  • --build-type:定义程序包的类型。常见的值包括ament_python(Python程序包)和ament_cmake(C++程序包)。
  • --package-format
  • --dependencies:程序包的依赖项。
  • --maintainer-email:程序包的维护者信息
  • --maintainer-name:程序包的维护者信息
  • --node-name:定义程序包中主节点的名称。
  • --library-name:name of the empty library
  • --description :定义程序包的描述信息。
  • --license:定义程序包的许可证类型。

package.xml

package.xml中定义了软件包的基本属性以及所需要的依赖项,内容大致如下(rclcpp_components):

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
  <name>rclcpp_components</name>
  <version>9.2.2</version>
  <description>Package containing tools for dynamically loadable components</description>
  <maintainer email="ivanpauno@ekumenlabs.com">Ivan Paunovic</maintainer>
  <maintainer email="mabel@openrobotics.org">Mabel Zhang</maintainer>
  <maintainer email="william@openrobotics.org">William Woodall</maintainer>
  <license>Apache License 2.0</license>
  <author email="michael@openrobotics.org">Michael Carroll</author>

  <buildtool_depend>ament_cmake_ros</buildtool_depend>

  <build_depend>ament_index_cpp</build_depend>
  <build_depend>class_loader</build_depend>
  <build_depend>composition_interfaces</build_depend>
  <build_depend>rclcpp</build_depend>
  <build_depend>rcpputils</build_depend>

  <exec_depend>ament_index_cpp</exec_depend>
  <exec_depend>class_loader</exec_depend>
  <exec_depend>composition_interfaces</exec_depend>
  <exec_depend>rclcpp</exec_depend>

  <test_depend>ament_cmake_google_benchmark</test_depend>
  <test_depend>ament_cmake_gtest</test_depend>
  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  <test_depend>launch_testing</test_depend>
  <test_depend>std_msgs</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

其中,

  • name定义了软件包的名称
  • version定义了软件包的版本
  • description定义了软件包的简短描述
  • maintainer定义了维护者的联系方式。可以有多个maintaineremail属性是必需的
  • license定义了软件包的许可证。可以有多个license。如果许可证的文本包含在软件包中,应提供一个相对于软件包目录的路径
  • buildtool_depend定义了构建工具的依赖项。对于使用ament的包,这将是ament_cmake
  • build_dependexec_depend定义了构建和运行时的依赖项
  • dependbuild_dependexec_dependbuild_export_depend的缩写,如果你有一个依赖项在这三个阶段都需要,你可以使用depend
  • test_depend定义了运行测试所需的额外依赖项

node

  • ros2 node list:查看所有node
  • ros2 node info <node_name>:查看某个node的信息

topic

  • ros2 topic echo <topic_name>:查看topic输出:
  • ros2 topic hz <topic_name>:查看topic频率
  • ros2 topic list:查看有哪些topic
    • ros2 topic list -t:查看每个topic及其message type
      在这里插入图片描述
  • 查看topic有哪些pub和sub:ros2 topic info -v <topic_name>
  • 在某个topic上使用命令行pub数据:
    • 按默认周期发送:ros2 topic pub <topic_name> <msg_type> '<args>' 注意,args要使用yaml格式,比如发送std_msgs::msg::String类型的消息:ros2 topic pub /topic std_msgs::msg::String '{data: "hello,world"}'
    • 只发送一次:ros2 topic pub --once <topic_name> <msg_type> '<args>'
    • 按指定周期发送:ros2 topic pub --rate 1 <topic_name> <msg_type> '<args>',1表示频率

参数

launch

录包

录包

命令:ros2 bag record,通过这个命令录制的包是一个包含了选定topic消息的db3文件(文件形式为.db3)。ros2中的bag文件使用了SQLite数据库来存储消息。

  • -a--all:录制所有topic
  • -o:指定录包的文件名,如:ros2 topic record -a -o my_bag.db3
  • 录制指定topic的包:ros2 bag record /topic1 /topic2

查看

  • 查看录包信息:ros2 bag info <bag_file>
  • 查看录制的实际内容:
    • 播放录制的数据:ros2 bag play <bag_file>,循环播放:ros2 bag play <bag_file> -l
    • 继续打开一个新的终端窗口,然后使用ros2 topic命令查看,如ros2 topic list, ros2 topic echo <topic_name>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值