以小海龟为例
启动ROS Master
roscore
启动小海龟仿真器 (运行一个节点需重新打开一个终端)
rosrun turtlesim turtlesim_node#rosrun+功能包名+节点名
启动海龟键盘控制节点
rosrun turtlesim turtle_teleop_key
基于qt的可视化工具命令–rqt_graph
rqt_graph
/teleop_tutle:键盘控制节点
/turtlesim:小海龟仿真器节点
/turtle/cmd_vel:一个话题
显示ros系统相关节点的指令rosnode
把系统中的结点全部都列出来
rosnode list
输出
/rosout
/teleop_turtle
/turtlesim
查看某一节点具体的信息
rosnode info turtlesim #rosnode info +节点名
输出
--------------------------------------------------------------------------------
Node [/turtlesim]
Publications:
* /rosout [rosgraph_msgs/Log]
* /turtle1/color_sensor [turtlesim/Color]
* /turtle1/pose [turtlesim/Pose]
Subscriptions:
* /turtle1/cmd_vel [geometry_msgs/Twist]
Services:
* /clear
* /kill
* /reset
* /spawn
* /turtle1/set_pen
* /turtle1/teleport_absolute
* /turtle1/teleport_relative
* /turtlesim/get_loggers
* /turtlesim/set_logger_level
contacting node http://sxc:33697/ ...
Pid: 2768
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound
* transport: TCPROS
* topic: /turtle1/cmd_vel
* to: /teleop_turtle (http://sxc:39695/)
* direction: inbound
* transport: TCPROS
话题指令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'
发布话题
#tab键自动补全
#rostopic pub [话题名称] [消息类型] [参数]
#重复发布为rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist (10为发布频率10Hz)
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"
输出
小海龟向前移动1米(要旋转需要调z角度)
publishing and latching message. Press ctrl-C to terminate
服务指令rosservice
rosservice list
输出
/clear
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/rostopic_5859_1602574431210/get_loggers
/rostopic_5859_1602574431210/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
发布服务请求,再生成一只小海龟
#使用TAB自动补全
#名字不能数字开头
rosservice call /spawn "x: 3.0
y: 2.0
theta: 1.0
name: 't123'"
rosbag指令
#rosbag record -a -O [保存名字]
#ctrl+C停止保存
#数据保存在终端的默认路径/home下面
rosbag record -a -O cmd_record
输出
[ INFO] [1602575574.470557135]: Recording to cmd_record.bag.
[ INFO] [1602575574.472277478]: Subscribing to /turtle1/color_sensor
[ INFO] [1602575574.476421995]: Subscribing to /t126/pose
[ INFO] [1602575574.480495891]: Subscribing to /t122/color_sensor
[ INFO] [1602575574.484927372]: Subscribing to /t123/color_sensor
[ INFO] [1602575574.489632244]: Subscribing to /t126/color_sensor
[ INFO] [1602575574.492828161]: Subscribing to /t123/pose
[ INFO] [1602575574.495855609]: Subscribing to /rosout
[ INFO] [1602575574.501550474]: Subscribing to /rosout_agg
[ INFO] [1602575574.505169971]: Subscribing to /turtle2/cmd_vel
[ INFO] [1602575574.508091612]: Subscribing to /t122/pose
[ INFO] [1602575574.510642892]: Subscribing to /turtle1/cmd_vel
[ INFO] [1602575574.513499301]: Subscribing to /turtle1/pose
显示其开始订阅该节点的一些话题
复现数据
#rosbag play [保存名字]
#需要把包名写完整
rosbag play cmd_record.bag
输出
[ INFO] [1602575953.066716673]: Opening cmd_record.bag
Waiting 0.2 seconds after advertising topics... done.
Hit space to toggle paused, or 's' to step.
[DELAYED] Bag Time: 1602575574.516566 Duration: 0.000000 / 69.617541 Delay [RUNNING] Bag Time: 1602575574.516566 Duration: 0.000000 / 69.617541 [RUNNING] Bag Time: 1602575574.516566 Duration: 0.000000 / 69.617541 [RUNNING] Bag Time: 1602575574.518096 Duration: 0.001530 / 69.617541 [RUNNING] Bag Time: 1602575574.618222 Duration: 0.101656 / 69.617541 [RUNNING] Bag Time: 1602575574.676242 Duration: 0.159676 / 69.617541 [RUNNING] Bag Time: 1602575574.677091 Duration: 0.160526 / 69.617541 [RUNNING] Bag Time: 1602575574.693258 Duration: 0.176692 / 69.617541 [RUNNING] Bag Time: 1602575574.709516 Duration: 0.192950 / 69.617541 [RUNNING] Bag Time: 1602575574.725487 Duration: 0.208921 / 69.617541 [RUNNING] Bag Time: 1602575574.725611 Duration: 0.209046 / 69.617541