12.ROS编程学习:ROS常用指令

目录

rosnode

1.rosnode list——list active nodes

2.rosnode ping——test connectivity to node

3.rosnode info——print information about node

4.rosnode machine——list nodes running on a particular machine or list machines

5.rosnode kill——kill a running node

6.rosnode——cleanup purge registration information of unreachable nodes

rostopic

1.rostopic list——list active topics

2.rostopic echo——print messages to screen

3.rostopic pub——publish data to topic

rosservice

1.rosservice list——list active services

2.rosservice call——call the service with the provided args

3.rosservice info——print information about service

4.rosservice type——print service type

rosmsg

1.rosmsg list——List all messages

2.rosmsg info——Alias for rosmsg show

rossrv

 1.rossrv list——List all services

2.rossrv info—— Alias for rossrv show

rosparam

1.rosparam list——list parameter names

2.rosparam set——set parameter

3.rosparam delete——delete parameter

4. rosparam load——load parameters from file、rosparam dump——dump parameters to file

学习参考:赵虚左的课程,其他书上不详细。

有必要学习,作为ROS系统动态的常用指令,同时作为一个工具,常用来测试和改错,让测试和改错有理有据。

rosnode

rosnode提供6个指令

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode 
cleanup  info     kill     list     machine  ping     

 添加-h获取帮助。

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode -h
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 ping    测试到节点的连接状态
rosnode list    列出活动节点
rosnode info    打印节点信息
rosnode machine    列出指定设备上节点
rosnode kill    杀死某个节点
rosnode cleanup    清除不可连接的节点

1.rosnode list——list active nodes

准备工作:

4.ROS编程学习:自定义话题消息与c++调用_机械专业的计算机小白的博客-CSDN博客https://blog.csdn.net/wzfafabga/article/details/127161241启动之前实现的c++调用自定义消息类型的话题通信。

启动ROS Master:

roscore

启动订阅者:

source ./devel/setup.bash 
rosrun sub_pub sub_person

启动发布者:

source ./devel/setup.bash 
rosrun sub_pub pub_person

 rosnode list:

rosnode list
rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode list
/ren_pub
/ren_sub
/rosout

其中/ren_pub和/ren_sub节点为发布者和订阅者节点,/rosout是ROS Master的日志输出节点。

2.rosnode ping——test connectivity to node

rosnode ping /节点名

判断节点的连通性。

rosnode ping /ren_pub

 连通成功,而且显示连通的延迟。

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode ping /ren_pub
rosnode: node is [/ren_pub]
pinging /ren_pub with a timeout of 3.0s
xmlrpc reply from http://rosmelodic-virtual-machine:40397/      time=14.780998ms
xmlrpc reply from http://rosmelodic-virtual-machine:40397/      time=0.508070ms
xmlrpc reply from http://rosmelodic-virtual-machine:40397/      time=0.519991ms

查询一个不存在的节点:查询失败。

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode ping /ren_pu
rosnode: node is [/ren_pu]
cannot ping [/ren_pu]: unknown node

3.rosnode info——print information about node

打印节点信息,用处大包含信息全面。

rosnode info /节点名
rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode info /ren_pub
--------------------------------------------------------------------------------
Node [/ren_pub]
Publications: 
 * /renxinxi [sub_pub/Person]
 * /rosout [rosgraph_msgs/Log]

Subscriptions: None

Services: 
 * /ren_pub/get_loggers
 * /ren_pub/set_logger_level


contacting node http://rosmelodic-virtual-machine:40397/ ...
Pid: 50789
Connections:
 * topic: /rosout
    * to: /rosout
    * direction: outbound (34961 - 127.0.0.1:37480) [11]
    * transport: TCPROS
 * topic: /renxinxi
    * to: /ren_sub
    * direction: outbound (34961 - 127.0.0.1:37490) [12]
    * transport: TCPROS

4.rosnode machine——list nodes running on a particular machine or list machines

ROS分布式通信,可能存在多台设备,需要通过这个方式去查询都有哪些机器和某个机器中的节点。

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode machine 
rosmelodic-virtual-machine
rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode machine rosmelodic-virtual-machine
/ren_pub
/ren_sub
/rosout

5.rosnode kill——kill a running node

杀掉一个节点

rosmelodic@rosmelodic-virtual-machine:~/catkin_ws$ rosnode kill
1. /ren_pub
2. /ren_sub
3. /rosout

Please enter the number of the node you wish to kill.
> 1  
killing /ren_pub
killed

被杀掉的节点控制台发出警告:


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值