ROS命令行工具

ROS命令行工具

这里主要参考了wiki上的ros文档,还有需要命令没有包含到,便用边学吧,当然建议使用万能的--help : )

1. 常用用户工具

1.1 roscore

使用roscore命令启动ros的核心节点(包括Master, Paremeter Server, rosout等等),启动时直接运行如下命令即可:

roscore

B5TpOs.png


1.2 rosrun

我们使用rosrun命令来运行某个功能包中的某个节点,如下是帮助信息

Usage: rosrun [--prefix cmd] [--debug] PACKAGE EXECUTABLE [ARGS]
  rosrun will locate PACKAGE and try to find
  an executable named EXECUTABLE in the PACKAGE tree.
  If it finds it, it will run it with ARGS.

主要使用方法是:

rosrun [功能包名] [节点名]

举个栗子,运行我们的小海龟仿真节点

B57Fud.png


1.3 rosnode

使用rosnode命令可以打印出ROS节点的信息,命令如下

rosnode is a command-line tool for printing information about ROS Nodes.

Commands:
	rosnode ping	test connectivity to node
	rosnode list	list active nodes
	rosnode info	print information about node
	rosnode machine	list nodes running on a particular machine or list machines
	rosnode kill	kill a running node
	rosnode cleanup	purge registration information of unreachable nodes

Type rosnode <command> -h for more detailed usage, e.g. 'rosnode ping -h'

举个栗子:

查看当前节点列表(rosout节点是ros默认的一个节点,用于采集节点信息):

rosnode list

B5TccQ.png

查看小海龟仿真节点的详细信息(发布信息、订阅信息、服务、进程PID等等):

rosnode info /turtlesim

B573bn.png


1.4 rostopic

主要用于打印当前的一些话题信息

rostopic is a command-line tool for printing information about ROS Topics.

Commands:
	rostopic bw	display bandwidth used by topic
	rostopic delay	display delay of topic from timestamp in header
	rostopic echo	print messages to screen
	rostopic find	find topics by type
	rostopic hz	display publishing rate of topic    
	rostopic info	print information about active topic
	rostopic list	list active topics
	rostopic pub	publish data to topic
	rostopic type	print topic or field type

举个栗子:
查看当前的话题:

rostopic list

B5HGsH.png

其中的/turtle1/cmd_vel就是我们控制小海龟的一个话题,我们可以使用rostopic pub命令(使用--help获取命令细节)给想该话题发布数据。比如说我们这里给小海龟发布数据(linear是线速度,angular是角速度,一般使用常用单位m/s和rad/s,这就是这个消息的数据结构):

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
  x: 1.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0"

然后就能看到小海龟向前跑动了,但是很快停了下来,因为我们只发布了一次数据,我们可以灵活的使用参数定义这个发布的过程(如加-r设定发布频率,-1发布一次退出等等,万能的help命令!)


1.5 rosmsg

rosmsg命令用于查看话题消息(Message)的数据结构的定义

rosmsg is a command-line tool for displaying information about ROS Message types.

Commands:
	rosmsg show	Show message description
	rosmsg info	Alias for rosmsg show
	rosmsg list	List all messages
	rosmsg md5	Display message md5sum
	rosmsg package	List messages in a package
	rosmsg packages	List packages that contain messages

Type rosmsg <command> -h for more detailed usage

举个栗子:

我们现在查看控制小海龟话题的消息的数据结构,我们首先使用rostopic info查看话题的详细信息,获得消息名,然后再使用rosmsg show查看消息的数据结构,可以看到六个速度都是使用float64数据格式。

B5LTOg.png


1.6 rosservice

rosservice命令用于查看和控制服务相关信息

Commands:
	rosservice args	print service arguments
	rosservice call	call the service with the provided args
	rosservice find	find services by service type
	rosservice info	print information about service
	rosservice list	list active services
	rosservice type	print service type
	rosservice uri	print service ROSRPC uri

Type rosservice <command> -h for more detailed usage, e.g. 'rosservice call -h'

举个栗子:
我们查看当前存在的服务

rosservice list

B5XCgf.png

然后我们将当前的终端作为客户端,小海龟模拟器作为服务端,使用rosservice call命令调用/spawn服务(产卵服务)产生一个新的小海龟:

rosservice call /spawn "x: 3.0
y: 3.0
theta: 0.0
name: 'turtle2'" 
name: "turtle2"

BIpbi4.png

产生了一只新的小海龟,我们对应的话题也就相应增加了,简单查看一下:

BICH29.png

1.7 rosbag

rosbag命令可以通过记录消息包(bag)或者发送消息包来实现过程的记录与复现(仿真),所谓消息包(bag)就是一串消息的序列。

Usage: rosbag <subcommand> [options] [args]

A bag is a file format in ROS for storing ROS message data. The rosbag command can record, replay and manipulate bags.

Available subcommands:
   check  	Determine whether a bag is playable in the current system, or if it can be migrated.
   compress  	Compress one or more bag files.
   decompress  	Decompress one or more bag files.
   decrypt  	Decrypt one or more bag files.
   encrypt  	Encrypt one or more bag files.
   filter  	Filter the contents of the bag.
   fix  	Repair the messages in a bag file so that it can be played in the current system.
   help  
   info  	Summarize the contents of one or more bag files.
   play  	Play back the contents of one or more bag files in a time-synchronized fashion.
   record  	Record a bag file with the contents of specified topics.
   reindex  	Reindexes one or more bag files.

For additional information, see http://wiki.ros.org/rosbag

举个栗子:

我们现在使用bag记录我们用键盘操控小海龟的过程,然后保存消息bag用于后续复现。

使用rosbag record记录小海龟的message,运行如下命令(-a记录全部消息,-O 输出为文件,更多命令参数参考–help),然后我们移动小海龟。

rosbag record -a -O turtle_path

记录完成后 ctrl+c 结束记录,可以看到保存到了当前目录下:

BIkDLn.png

然后我们运行这个消息bag

rosbag play turtle_path.bag 

就可以发现小海龟复现了之前用键盘操作的过程(这里我重新开了个小海龟)

BIkbFK.png

2. 可视化工具

2.1 rxgraph

rxgraph用于显示ROS节点以及话题的计算图。

其中rosgraph是命令行版本,rqt_graph的基于QT开发的图形界面版本

运行rosgraph可以看到节点信息(以及入站出站接口)和服务信息(Services)

B5IhKs.png

运行rqt_graph ,可以以图形界面的形式展示计算图

B5PO9H.png

  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值