智能机器人(04):通用网络配置

分布式特点的ROS对网络配置的要求主要四点:

1、只能有一台作为master,
2、所有节点node必须通过ROS_MASTER_URI配置为相同的master,
3、配对机器的所有端口必须具有完全的双向连接,
4、所有机器必须广播一个其他机器可以解析的机器名。

先设置三个环境变量,$ROS_MASTER_URI,$ROS_HOSTNAME,$ROS_IP :
ROS_MASTER_URI,整个ROS系统的主机IP+端口,启动roscore
ROS_HOSTNAME 和 ROS_IP设置ROS节点公网地址,两者互斥,ROS_HOSTNAME优先

常规可以这样设置:
export ROS_MASTER_URI=http://`hostname -I`:11311
export ROS_HOSTNAME=`hostname`
export ROS_IP=`hostname -I`
不带i的是主机名、带了i的输出主机地址(需要先设/etc/hosts)

再假设三台机器的应用场景:
一台笔记本作为robot的主机,master230 ,172.20.10.5;
一个台式机作为workstation的客户端,client501 ,172.20.10.3;
然后我们工作在远程的第三台笔记本上,client480,172.20.10.1.

1、edit  /etc/hosts file

To know the mapping of some hostnames to IP addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In the absence of a name server, any network program on your system consults this file to determine the IP address that corresponds to a host name. For example in master’s netbook :

IPAddress—– Hostname—–Alias

127.0.0.1 localhost master230 .xxx.com

172.20.10.5 master230 master230.xxx.com

172.20.10.3 client501 client501.xxx.com

172.20.10.1 client480 client480.xxx.com

然后我们工作在远程的第三台笔记本上,client480,172.20.10.1。

don’t forget to restart your network for the changes to take effect:

$ /etc/init.d/networking restart

2、网络设置

首先,master230和client480的所有端口需要完整的双向连接。
1、自身ping
测试robot ,$ping master230
测试客户端 ,$ping client480
2、互相ping
测试robot ,$ping master230
测试客户端 ,$ping client480
3、netcat
只能自身ping通和相互ping通仅仅检查了相互之间的ICMP包正常,但这还是不够的,需要验证所有端口可用,完整地检查很困难,因为有65K个端口,可以使用netcat尝试
特定的端口测试。挑选大于1024的端口号:
(1)测试master230到client480, 启动netcat监听:
$netcat -l 1234
(2)在client480连接master230,
$netcat master230 1234
(3)互相聊一聊,正常。
(4)然后更换一个方向,正常。

3、多机互联

1、启动master
注意只能有一台作为master,这里选择master230作为master:
$roscore
$export ROS_MASTER_URI=http://p110:11311/
2、启动一个听者
$ssh hal
$export ROS_IP=p110.local
$export ROS_MASTER_URI=http://p110.local:11311
$rosrun rospy_tutorials listener.py
3、启动一个讲者
$ssh marvin
$export ROS_IP=dehao-B3.local
$export ROS_MASTER_URI=http://p110.local:11311
$rosrun rospy_tutorials talker.py
此时可以看到p110接收到来自dehao-B3的消息。
4、其实这是双向的,下一步互换:
把讲者和听者在两台机器之间互换,同样工作。
5、便利操作
如果长期这样使用,可以把上面的命令添加到.bashrc中。

在ROS节点node广播主题topic时,提供的是hostname:port组合也就是URI,有几种设置方法。
1、显式的设置名字
ROS_IP和ROS_HOSTNAME是设置ROS的node时候可选的环境变量,他们是互斥的,同时设置的话优先的是ROS_HOSTNAME,所以我们一般是设置ROS_HOSTNAME而不是设置ROS_IP。

4、时间同步

在坐标变换出现错误:TF complaining about extrapolation into the future时,首先要检查不同机器之间的时间矛盾:
$ntpdate -q other_computer_ip
必要的话安转chrony同一时间。

1. Check one machine against another machine:
$ ntpdate -q other_computer_ip or hostname
2. Install Chrony:
$ sudo apt-get install chrony
3. For instance computer c2 gets its time from computer c1 then add following line:
$ sudo /etc/chrony/chrony.conf
server c1 minpoll 0 maxpoll 5 maxdelay .05
4. That machine will then slowly move its time towards the server.
$ sudo /etc/init.d/chrony stop
$ ntpdate other_computer_ip
$ sudo /etc/init.d/chrony start
5. manually sync NTP
$ sudo ntpdate ntp.ubuntu.com

实际环境中:
需要把多个机器人rbt1、rbt2…和不同服务器server-vpn、server-web…和各个管理计算机pc1、pc2…配置在同一个虚拟专网里面,并配发不同的vpn证书已进行安全管理。
对于后台管理系统,需要通过ssl配发不同的证书进行安全管理。对于远程操操纵,更要配发证书进行安全管理。

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论