接着 ROS 笔记(01)— Ubuntu 18.04 ROS 环境搭建 我们在最后启动了一个海龟的仿真器。下面我们来看看 ROS
中常用的命令。
所有节点可视化图
topic
示意图
具体命令可参考:http://wiki.ros.org/ROS/CommandLineTools
系统当中对节点进行操作的指令。使用方法
$ 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
/rosout
/rqt_gui_py_node_12788
/teleop_turtle
/turtlesim
其中:
/rosout
为当启动 roscore
命令之后系统默认的节点;/rqt_gui_py_node_12788
为显示的 GUI
界面的节点;/teleop_turtle
和 /turtlesim
分别上面的两个节点;测试节点是否正常
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:~$
查看节点详细信息
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:~$
查看指定机器的节点列表
$ rosnode machine wohu-pc
/rosout
/rqt_gui_py_node_12788
/teleop_turtle
/turtlesim
wohu@wohu-pc:~$
结束某个节点
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:~$
用于打印 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'
我们以 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"
其中:
-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:~$
查看 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
使用示例:
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:~$
与服务相关的命令
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
/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
调用 /spawn
服务产生第二个海龟
$ rosservice call /spawn "x: 2.0
y: 0.0
theta: 0.0
name: 'second_turtle'"
name: "second_turtle"
用于记录过程中的数据和回放数据
$ 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
其中 :
-a
表示记录所有信息-O
表示保存的文件名catkin_create_pkg 自定义包名 依赖包 === 创建新的ROS功能包
sudo apt install xxx === 安装 ROS功能包
sudo apt purge xxx ==== 删除某个功能包
rospack list === 列出所有功能包
rospack find 包名 === 查找某个功能包是否存在,如果存在返回安装路径
roscd 包名 === 进入某个功能包
rosls 包名 === 列出某个包下的文件
apt search xxx === 搜索某个功能包
rosed 包名 文件名 === 修改功能包文件
roscore
是 ROS
的系统先决条件节点和程序的集合, 必须运行 roscore
才能使 ROS
节点进行通信。
roscore
将启动:ros master
、ros
参数服务器、rosout
日志节点。
用法:
roscore
或(指定端口号)
roscore -p xxxx
rosrun 包名 可执行文件名 === 运行指定的ROS节点,示例
rosrun turtlesim turtlesim_node
roslaunch 包名 launch文件名 === 执行某个包下的 launch 文件