• ROS 笔记(03)— ROS 命令行工具(rostopic、rosservice、rosnode、rosmsg、rosparam、rossrv)


    接着 ROS 笔记(01)— Ubuntu 18.04 ROS 环境搭建 我们在最后启动了一个海龟的仿真器。下面我们来看看 ROS 中常用的命令。

    所有节点可视化图
    node
    topic 示意图
    在这里插入图片描述
    具体命令可参考:http://wiki.ros.org/ROS/CommandLineTools

    1. 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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    1.1 rosnode list

    显示系统当中所有节点

    $ rosnode list
    /rosout
    /rqt_gui_py_node_12788
    /teleop_turtle
    /turtlesim
    
    • 1
    • 2
    • 3
    • 4
    • 5

    其中:

    • /rosout 为当启动 roscore 命令之后系统默认的节点;
    • /rqt_gui_py_node_12788 为显示的 GUI 界面的节点;
    • /teleop_turtle/turtlesim 分别上面的两个节点;

    1.2 rosnode ping

    测试节点是否正常

    wohu@wohu-pc:~$ rosnode ping -h
    Usage: rosnode ping [options] <node>
    
    Options:
      -h, --help  show this help message and exit
      -a, --all   ping all nodes
      -c COUNT    number of pings to send. Not available with --all
    
    wohu@wohu-pc:~$ rosnode ping /rqt_gui_py_node_12788
    rosnode: node is [/rqt_gui_py_node_12788]
    pinging /rqt_gui_py_node_12788 with a timeout of 3.0s
    xmlrpc reply from http://wohu-pc:44729/	time=0.697851ms
    xmlrpc reply from http://wohu-pc:44729/	time=1.399994ms
    xmlrpc reply from http://wohu-pc:44729/	time=1.129150ms
    xmlrpc reply from http://wohu-pc:44729/	time=1.396894ms
    xmlrpc reply from http://wohu-pc:44729/	time=1.387119ms
    xmlrpc reply from http://wohu-pc:44729/	time=1.389980ms
    ^Cping average: 1.233498ms
    wohu@wohu-pc:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    1.3 rosnode info

    查看节点详细信息

    wohu@wohu-pc:~$ rosnode info -h
    Usage: rosnode info [options] node1 [node2...]
    
    Options:
      -h, --help   show this help message and exit
      -q, --quiet  Prints only basic information such as pubs/subs and does not
                   contact nodes for more information
    wohu@wohu-pc:~$ rosnode info /teleop_turtle
    --------------------------------------------------------------------------------
    Node [/teleop_turtle]
    Publications: 
     * /rosout [rosgraph_msgs/Log]
     * /turtle1/cmd_vel [geometry_msgs/Twist]
    
    Subscriptions: None
    
    Services: 
     * /teleop_turtle/get_loggers
     * /teleop_turtle/set_logger_level
    
    
    contacting node http://wohu-pc:39985/ ...
    Pid: 12719
    Connections:
     * topic: /rosout
        * to: /rosout
        * direction: outbound (57111 - 127.0.0.1:35592) [12]
        * transport: TCPROS
     * topic: /turtle1/cmd_vel
        * to: /turtlesim
        * direction: outbound (57111 - 127.0.0.1:35594) [10]
        * transport: TCPROS
    
    wohu@wohu-pc:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    1.4 rosnode machine

    查看指定机器的节点列表

    $ rosnode machine wohu-pc
    /rosout
    /rqt_gui_py_node_12788
    /teleop_turtle
    /turtlesim
    wohu@wohu-pc:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    1.5 rosnode kill

    结束某个节点

    wohu@wohu-pc:~$ rosnode kill /rqt_gui_py_node_12788
    killing /rqt_gui_py_node_12788
    killed
    wohu@wohu-pc:~$ rosnode ping /rqt_gui_py_node_12788
    rosnode: node is [/rqt_gui_py_node_12788]
    cannot ping [/rqt_gui_py_node_12788]: unknown node
    wohu@wohu-pc:~$ 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2. rostopic

    用于打印 ROS topic 相关的信息。

    $ 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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    我们以 rostopic pub 为例,

    $ rostopic pub  -r 10 /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" 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    其中:

    • -r 10 表示 10 Hz,即一秒 10 次向 /turtle1/cmd_vel 主题发布消息,这样海龟会自动运行起来。

    其它命令示例:

    wohu@wohu-pc:~$ rostopic list
    /rosout
    /rosout_agg
    /turtle1/cmd_vel
    /turtle1/color_sensor
    /turtle1/pose
    wohu@wohu-pc:~$ rostopic info /turtle1/cmd_vel 
    Type: geometry_msgs/Twist
    
    Publishers: 
     * /teleop_turtle (http://wohu-pc:39985/)
    
    Subscribers: 
     * /turtlesim (http://wohu-pc:42993/)
    
    
    wohu@wohu-pc:~$ rostopic type /turtle1/cmd_vel 
    geometry_msgs/Twist
    wohu@wohu-pc:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3. rosmsg

    查看 msg 的各种信息

    $ 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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    使用示例:

    wohu@wohu-pc:~$ rosmsg show -h
    Usage: rosmsg show [options] <message type>
    
    Options:
      -h, --help            show this help message and exit
      -r, --raw             show raw message text, including comments
      -b BAGFILE, --bag=BAGFILE
                            show message from .bag file
    wohu@wohu-pc:~$ rosmsg show geometry_msgs/Twist
    geometry_msgs/Vector3 linear # 线速度
      float64 x
      float64 y
      float64 z
    geometry_msgs/Vector3 angular # 角速度
      float64 x
      float64 y
      float64 z
    
    wohu@wohu-pc:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    4. 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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    显示所有可用的服务列表

    $ rosservice list
    /clear
    /kill
    /reset
    /rosout/get_loggers
    /rosout/set_logger_level
    /spawn
    /teleop_turtle/get_loggers
    /teleop_turtle/set_logger_level
    /turtle1/set_pen
    /turtle1/teleport_absolute
    /turtle1/teleport_relative
    /turtlesim/get_loggers
    /turtlesim/set_logger_level
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    调用 /spawn 服务产生第二个海龟

    $ rosservice call  /spawn "x: 2.0
    y: 0.0
    theta: 0.0
    name: 'second_turtle'" 
    name: "second_turtle"
    
    • 1
    • 2
    • 3
    • 4
    • 5

    5. rosbag

    用于记录过程中的数据和回放数据

    $ rosbag record -a -O bag_record
    [ INFO] [1655476325.543621020]: Recording to 'bag_record.bag'.
    [ INFO] [1655476325.544208278]: Subscribing to /turtle1/color_sensor
    [ INFO] [1655476325.545058928]: Subscribing to /second_turtle/pose
    [ INFO] [1655476325.545845012]: Subscribing to /second_turtl2e/pose
    [ INFO] [1655476325.546629458]: Subscribing to /rosout
    [ INFO] [1655476325.547521141]: Subscribing to /rosout_agg
    [ INFO] [1655476325.548365290]: Subscribing to /second_turtle/color_sensor
    [ INFO] [1655476325.549216211]: Subscribing to /second_turtl2e/color_sensor
    [ INFO] [1655476325.550270641]: Subscribing to /turtle1/cmd_vel
    [ INFO] [1655476325.551304824]: Subscribing to /turtle1/pose
    ^Cwohu@wohu-pc:~$ rosbag play bag_record.bag 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    其中 :

    • -a 表示记录所有信息
    • -O 表示保存的文件名

    6. 其它常用命令

    catkin_create_pkg 自定义包名 依赖包 === 创建新的ROS功能包
    sudo apt install xxx === 安装 ROS功能包
    
    sudo apt purge xxx ==== 删除某个功能包
    
    rospack list === 列出所有功能包
    rospack find 包名 === 查找某个功能包是否存在,如果存在返回安装路径
    roscd 包名 === 进入某个功能包
    rosls 包名 === 列出某个包下的文件
    apt search xxx === 搜索某个功能包
    
    rosed 包名 文件名 === 修改功能包文件
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    6.1 roscore

    roscoreROS 的系统先决条件节点和程序的集合, 必须运行 roscore 才能使 ROS 节点进行通信。

    roscore 将启动:ros masterros 参数服务器、rosout 日志节点。

    用法:

    roscore
    
    • 1

    或(指定端口号)

    roscore -p xxxx
    
    • 1

    6.2 rosrun

    rosrun 包名 可执行文件名 === 运行指定的ROS节点,示例

    rosrun turtlesim turtlesim_node
    
    • 1

    6.3 roslaunch

    roslaunch 包名 launch文件名 === 执行某个包下的 launch 文件
    
    • 1
  • 相关阅读:
    m基于MIMO中继通信和非规则LDPC编译码的matlab仿真,其中波束形成为SVD,MMSE,中继包括AF,DF,CF
    【Java分享客栈】一文搞定CompletableFuture并行处理,成倍缩短查询时间。
    LeetCode - Easy - 509. Fibonacci Number
    C语言实现用递归方法求 () = ∑ (^2)
    java-初识Servlet,Tomcat,JDBC
    Docker仓库harbor私服搭建
    第五篇、Callable接口实现多线程
    C++Primer笔记:第一章:开始
    [JavaScript]_[初级]_[关于forof或者for...of循环语句的用法]
    16.希尔排序
  • 原文地址:https://blog.csdn.net/wohu1104/article/details/125340521