ROS终端基本命令


一、启动命令roscore

roscore

你在运行所有ROS程序前首先要运行的命令。

二、相对包的快捷命令

【注意】:出现没有此包的原因是没有加载环境变量ROS_PACKAGE_PATH中没有要找的包的环境变量。你要先加载环境变量。

1.打开roscd

roscd [本地包名称[/子目录]]

roscdcd的快捷版,可以直接打开到包的位置。

比如:/home/volume/catkin_ws/src/my_package

# cd
volume@lenovo:~$ cd ~/catkin_ws/src/my_package
volume@lenovo:~/catkin_ws/src/my_package$ 

# roscd
volume@lenovo:~$ roscd my_package/
volume@lenovo:~/catkin_ws/src/my_package$ 

2.找到包的位置

rospack find [包名称]

输出包所在的位置

volume@lenovo:~$ rospack find my_package 
/home/volume/catkin_ws/src/my_package

3.列出rosls

rosls [本地包名称[/子目录]]

roslsls的快捷版,可以直接罗列软件包的名称下的目录。

#ls
volume@lenovo:~$ ls ~/catkin_ws/src/my_package
action  CMakeLists.txt  include  msg  package.xml  src  srv

# rosls
volume@lenovo:~$ rosls my_package/
action  CMakeLists.txt  include  msg  package.xml  src  srv

二、查看命令

1.rosnode

(1)列出当前节点list

rosnode list

在这里插入图片描述

其中:

  • /rosout:ROS中相当于stdout/stderr。这个节点用于收集和记录节点调试输出信息,所以它总是在运行的。

(2)查看节点信息info

rosnode info node_name
# 例子
volume@lenovo:~$ rosnode info /turtlesim 
--------------------------------------------------------------------------------
Node [/turtlesim]								# 节点名字
Publications: 									# 节点发布的话题Publications
 * /rosout [rosgraph_msgs/Log]
 * /turtle1/color_sensor [turtlesim/Color]
 * /turtle1/pose [turtlesim/Pose]

Subscriptions: 									# 节点订阅的话题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://lenovo:35497/ ...
Pid: 4365										# 节点的Pid
Connections:									# 计算图中链接的节点
 * topic: /rosout
    * to: /rosout
    * direction: outbound
    * transport: TCPROS
 * topic: /turtle1/cmd_vel
    * to: /teleop_turtle (http://lenovo:35617/)
    * direction: inbound
    * transport: TCPROS

(3)ping测试节点ping

rosnode ping my_turtle

在这里插入图片描述

扫描二维码关注公众号,回复: 9018832 查看本文章

2.rostopic

(1)列出所有的话题list

不分类:

rostopic list

在这里插入图片描述
按订阅和发布分类:

rostopic list -v

在这里插入图片描述

(2)查看话题信息info

rostopic info topic_name

例如:

volume@lenovo:~$ rostopic info /turtle1/cmd_vel 
Type: geometry_msgs/Twist						# 数据类型

Publishers: 									# 话题的发布者
 * /teleop_turtle (http://lenovo:35617/)

Subscribers: 									# 话题的订阅者
 * /turtlesim (http://lenovo:35497/)

(3)查看话题类型type

rostopic type topic_name

例如:

volume@lenovo:~$ rostopic type /turtle1/cmd_vel 
geometry_msgs/Twist

(4)监听话题消息echo

rostopic echo topic_name

在这里插入图片描述
这里显示了小海龟的线速度和角速度。

(5)发布消息pub

用来在cmd中调试。

  • 单次执行:发布一次
rostopic pub topic_name topic_type
  • 连续执行:一秒中发布rate_times
rostopic pub -r rate_times topic_name topic_type

例子:

# 消息内容打个tab就能自动补全,然后修改其内容成我们想要的
volume@lenovo:~$ 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" 
publishing and latching message. Press ctrl-C to terminate
volume@lenovo:~$ 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" 

3.rosservice

(1)列出服务list

rosservice list

在这里插入图片描述

(2)查看服务信息info

rosservice info service_name

在这里插入图片描述

(3)调用服务call

rosservice call service_name
# 这个服务的作用是新生成一只海龟,可以看到图中中央位置生成了一只海龟
rosservice call /spawn "x: 5.0
y: 5.0
theta: 0.0
name: 'myturtle'" 

在这里插入图片描述

三、运行命令

1.rosrun

(1)基本用法

rosrun 允许你使用包名直接运行一个包内的节点(而不需要知道这个包的路径)。

用法:

rosrun [package_name] [node_name]

例如:rosrun turtlesim turtlesim_node,现在我们可以运行turtlesim包中的 turtlesim_node。

(2)重命名节点

用法:

rosrun [package_name] [node_name] __name:=[node_new_name]

例如:

rosrun turtlesim turtlesim_node __name:=my_turtle

在这里插入图片描述

发布了411 篇原创文章 · 获赞 144 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/sandalphon4869/article/details/103927552