ROS21讲命令行工具使用

ROS21讲命令行工具使用

1、在运行所有ROS程序前首先要运行的命令,启动rosmaster

roscore

启动完成

started core service [/rosout]

2、rosrun
允许你使用包名直接运行一个包内的节点(而不需要知道这个包的路径)
用法:再打开一个终端
rosls [ 本地包名称[/子目录] ]
示例:双击按tap键自动列出该功能包下的节点

chen@ubuntu:~$ rosrun turtlesim 
draw_square        mimic              turtlesim_node     turtle_teleop_key
chen@ubuntu:~$ rosrun turtlesim 

2.1、运行第三仿真器节点

rosrun turtlesim turtlesim_node 

回车后,打开仿真器界面,如下图在这里插入图片描述
2.2 运行键盘控制节点
新建终端

rosrun turtlesim turtle_teleop_key 

然后通过键盘,可以移动海龟。
3、显示系统计算图

rqt_graph

在这里插入图片描述
4、rosnode 显示当前的节点信息,输入后直接回车
4.1、

chen@ubuntu:~$ 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'

4.2 显示三个节点,/rosout 是默认话题

chen@ubuntu:~$ rosnode list
/rosout
/teleop_turtle
/turtlesim

4.3 查看节点信息 /turtlesim

chen@ubuntu:~$ rosnode info /turtlesim
--------------------------------------------------------------------------------
Node [/turtlesim]
Publications: 
 * /rosout [rosgraph_msgs/Log]
 * /turtle1/color_sensor [turtlesim/Color]
 * /turtle1/pose [turtlesim/Pose]

Subscriptions: 
 * /turtle1/cmd_vel [geometry_msgs/Twist]

Services: 

5.话题
5.1 rostopic,直接回车

chen@ubuntu:~$ rostopic
rostopic is a command-line tool for printing information about ROS Topics.

5.2 话题列表

chen@ubuntu:~$ rostopic list
/rosout
/rosout_agg
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose

5.3 通过命令行,让海龟移动
例子:
在这里插入图片描述
chen@ubuntu:~$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist “linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0”
5.4、设定线速度和角速度,pub指令只会发布一次,想要连续运动需要给循环,-r频率,10

  chen@ubuntu:~$ 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: 1.0
  z: 0.0" 

旋转Z向,垂直于电脑平面上,X方向海龟头方向。
6、查看消息数据结构,写入到Twist后按tab键补全

chen@ubuntu:~$ 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

上面显示发布指令的含义,线速度,角速度,X,Y,Z
7、服务命令行

chen@ubuntu:~$ 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

服务端:海龟仿真器
客户端:就是终端
6.1、/spawn 产生两只小海龟,同样按tab键补全,仿真器左下角为0点
设置坐标和名字

chen@ubuntu:~$ rosservice call /spawn "x: 3.0
y: 3.0
theta: 0.0
name: 'turtle2'" 
name: "turtle2"

6.2、话题里面就会有turtle2的话题,可以控制它运动

chen@ubuntu:~$ rostopic list
/rosout
/rosout_agg
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
/turtle2/cmd_vel
/turtle2/color_sensor
/turtle2/pose

控制海龟2运动

chen@ubuntu:~$  rostopic pub -r 10 /turtle2/cmd_vel geometry_msgs/Twist "linear: 
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.0" 

在这里插入图片描述
7、rosbag话题记录及复现
使用方法:rosbag record -a(所有参数都保存) -O(保存成1个压缩包) cmd_record(压缩包名字)

chen@ubuntu:~$ rosbag record -a -O cmd_record
[ INFO] [1582616136.187106436]: Subscribing to /turtle1/color_sensor
[ INFO] [1582616136.192318325]: Subscribing to /turtle2/color_sensor
[ INFO] [1582616136.193249810]: Recording to cmd_record.bag.
[ INFO] [1582616136.195759848]: Subscribing to /rosout
[ INFO] [1582616136.202357404]: Subscribing to /turtle2/pose
[ INFO] [1582616136.204658934]: Subscribing to /rosout_agg
[ INFO] [1582616136.207321729]: Subscribing to /turtle1/cmd_vel
[ INFO] [1582616136.210592803]: Subscribing to /turtle1/pose
^Cchen@ubuntu:~$ 

按ctrl+c,退出并保存当前记录数据,数据在home主文件夹下
在这里插入图片描述
7.2 复现
先关掉仿真器控制节点
重新启动roscore,和仿真器节点rosrun turtlesim turtlesim_node ,不启动键盘控制节点。
命令

rosbag play cmd_record.bag

复现如下
在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值