ROS命令行工具的使用
运行小海龟
- 第一个终端启动roscore
roscore
- 第二个终端运行小海龟
rosrun + 对应功能包的模块 可以运行对应模块
通过双击tab键可以查看包中的模块
rosrun turtlesim turtlesim_node
- 第三个终端运行键盘控制小海龟的模块
rosrun turtlesim turtle_teleop_key
在这个终端的方向键可以控制小海龟移动
输入q退出
分析
rqt_graph
输入rqt_graph查看节点之间的关系
rqt开头的指令是关于可视化的指令
rqt_graph
得到下图
有2个节点,节点间的通讯是话题,发布者为/teleop,发布内容为/turtle1/cmd_vel,订阅者为/turtlesim.
rosnode 节点相关的命令行
输入
rosnode
可以查看该命令行的具体参数
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'
输入
rosnode list
查看当前的节点
有3个节点
其中rosout是默认的节点,用于收集节点信息。
rosnode info /turtlesim
或者
rosnode info turtlesim
查看节点的具体信息
给出了该节点的订阅信息,服务等
rostopic 关于话题类的命令行
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
Type rostopic <command> -h for more detailed usage, e.g. 'rostopic echo -h'
查看当前话题信息
rostopic list
pup命令可以发送话题到某个节点
用tab键自动补齐得到上面的命令,这个命令包含了线速度和角速度,修改线速度和角速度控制海龟移动,因为海龟回捕获/turtle1/cmd_vel的话题。
小海龟移动了一点,这是因为只发送了一次。可以通过-r参数来调发送频率
现在小海龟做匀速圆周运动。通过ctrl+c停止指令
rosmsg信息查看类
可以查看信息类型
rosmsg
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
rosservice服务类命令
查看有哪些服务
调用/spawn服务创建一个新的海龟
rosservice call /spawn
然后通过tab键补齐指令
服务类命令会有一个反馈
通过rostopic list
查看当前话题
多出了海龟2的话题,通过发送话题可以控制海龟2
rosbag数据存储(有用)
会把话题保存下来,在下次运行时可以直接调用
使用方法:
rosbag record -a -O cmd_record
record是告诉要执行记录,-a 参数是all的意思,记录所有话题,-O是重定向输出到一个cmd_record的文件中
现在给出了记录话题的条目。
控制海龟移动,数据会被记录在cmd_record文件中,通过ctrl+c可以停止记录
得到这样一个文件。
现在重新运行海龟,关闭键盘操作海关的终端。
现在通过cmd_record.bag玩家操作海龟移动
rosbag play cmd_record.bag
本文来自博客园,作者:墨镜一戴谁也不爱,转载请注明原文链接:https://www.cnblogs.com/hnuzmh/p/16196558.html