ros 中的环境变量 ROS_MASTER_URI 和 ROS_HOSTNAME 两三事

事件背景。我再同一个物理机上开了两个docker,一个docker负责维护 master 和 一些服务,另一个docker负责调用那些服务。那环境变量应该如何设置?

其实问题就是,多系统的ros应该如何通信?

robot1 192.168.1.1
    locally running ros-package: control1 
         subscribing topic2
         publishing  topic1                 

robot2 192.168.1.2
    locally running ros-package: control2
         subscribing topic1
         publishing  topic2

需要一个ros-master来控制整个通信,选择robot1作为master,因此,在robot1中:

export ROS_MASTER_URI=http://192.168.1.1:11311
export ROS_HOSTNAME=192.168.1.1
或者
export ROS_IP=192.168.1.1   
roscore

为了连接到robot1中的master,在robot2中这么设置:

export ROS_MASTER_URI=http://192.168.1.1:11311            
(export ROS_IP=192.168.1.2 )
或者                               
(export ROS_HOSTNAME=192.168.1.2)

准确回答:

1 两个设备的 export ROS_HOSTNAME .. 是不需要的。

2 在多个设备之间运行ros节点的时候,仅仅需要运行一个master进程。ROS_MASTER_URI 中必须包含运行master设备的ip(通过roscore或者roslaunch等命令)。因此,该环境变量在所有设备中必须是一模一样的。然而,ROS_HOSTNAME or ROS_IP设置为运行ros节点的本机IP. 所以,他们的值在不同设备间是不同的。

3 如果一台机器的hostname设置为其他设备不可寻址的值,你就需要设置 ROS_IP or ROS_HOSTNAME 环境变量,不需要同时设置,他们是互相排斥的。

ROS_IP and ROS_HOSTNAME are optional environment variable that sets the declared network address of a ROS Node or tool. The options are mutually exclusive, if both are set ROS_HOSTNAME will take precedence. Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you are specifying a host name. When a ROS component reports a URI to the master or other components, this value will be used. This setting is only needed in situations where you have multiple addresses for a computer and need to force ROS to a particular one.

With the exception of 'localhost', it does not affect the actual bound address as ROS components bind to all available network interfaces. If the value is set to localhost, the ROS component will bind only to the loopback interface. This will prevent remote components from being able to talk to your local component.

官方文档说明icon-default.png?t=M1FBhttp://wiki.ros.org/ROS/EnvironmentVariables#ROS_IP.2BAC8-ROS_HOSTNAME

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值