ROS机器人终端命令

通过输入以下来重新安装全部软件,会全部刷新 info 目录 不过这个方法就要多花点时间去等

1
sudo apt-get --reinstall install `dpkg --get-selections | grep '[[:space:]]install' | cut -f1`

安装ROS机器人包:其中melodic为虚拟机版本

1
sudo apt-get install ros-melodic-ros-tutorials

运行小乌龟程序,首先要启动  roscore

1
roscore

新建一个终端,运行小乌龟的demo

1
rosrun turtlesim turtlesim_node

新建一个终端,输入 rosnode list 可以列出相应的节点

1
rosnode list

如何想详细看小乌龟某个节点的信息,可以输入:

1
rosnode info /turtlesim

如果想详细看小乌龟某个话题的信息,可以输入:

1
rostopic info /turtle1/cmd_vel

开启键盘控制小乌龟的移动:

1
2
3
rosrun turtle

rosrun turtlesim turtle_teleop_key

通过 rqt 查看节点之间如何通信流图,新建一个终端,输入

1
rosrun rqt_graph rqt_graph

新建一个终端,查看一个话题消息的发布

1
2
3
rostopic echo /  

rostopic echo /turtle1/cmd_vel

输入完成后,切换到键盘控制小乌龟终端,通过键盘控制小乌龟移动,即可在话题终端看到ROS机器人的消息

rostopic echo /    表示可以收听的消息

输入一下命令可以看到小乌龟当前位置颜色的 rgb 值

1
rostopic echo /turtle1/color_sensor

通过命令行指令的方式发布话题:

1
2
3
4
5
6
7
8
9
rostopic pub /
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0"

通过命令行指令的方式发布话题:一秒钟发布十次这样的话题:加 -r 10

1
2
3
4
5
6
7
8
9
rostopic pub /
rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0"

查看消息发布的频率:

1
rostopic hz /turtle1/cmd_vel

查看 topic 相应的功能:

1
rostopic -h

输出:

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