ros 中的环境变量 ROS_MASTER_URI 和 ROS_HOSTNAME 两三事
事件背景。我再同一個物理機上開了兩個docker,一個docker負責維護 master 和 一些服務,另一個docker負責調用那些服務。那環境變量應該如何設置?
其實問題就是,多系統的ros應該如何通信?
robot1 192.168.1.1locally running ros-package: control1 subscribing topic2publishing topic1 robot2 192.168.1.2locally running ros-package: control2subscribing topic1publishing 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.
官方文檔說明http://wiki.ros.org/ROS/EnvironmentVariables#ROS_IP.2BAC8-ROS_HOSTNAME
總結
以上是生活随笔為你收集整理的ros 中的环境变量 ROS_MASTER_URI 和 ROS_HOSTNAME 两三事的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Eurofins欧陆科技集团颁发全球首张
- 下一篇: 自己写的APP如何禁掉安卓锁屏