ROS之多机通信

官网链接http://wiki.ros.org/ROS/Tutorials/MultipleMachines

实验描述:
parallels1(主机),parallels2(从机)parallels1启动roscore,并监听,parallels2发布主题

实验步骤:
1.主机环境变量配置

vim ~/.bashrc
#末尾添加
export ROS_MASTER_URI=http://parallels1.local:11311
export ROS_IP=parallels1.local

修改完后source ~/.bashrc
2.修改主机/etc/hosts文件

sudo vim /etc/hosts
#添加从机映射
127.0.0.1       localhost
127.0.1.1       parallels1
10.211.55.5     parallels2  #添加的从机
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

修改完后重启下网络服务

sudo /etc/init.d/networking restart

3.修改从机环境变量

vim ~/.bashrc
#末尾添加
export ROS_MASTER_URI=http://parallels1.local:11311
export ROS_IP=parallels2.local

修改完后source下

source ~/.bashrc

4.修改从机/etc/hosts文件

sudo vim /etc/hosts
##添加主机映射
127.0.0.1       localhost
127.0.1.1       parallels2
10.211.55.6     parallels1  #添加的主机
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

修改完后重启下网络服务

sudo /etc/init.d/networking restart

5.测试两台机子是否能ping通,以及能否相互ssh连上

#主机SSH从机
$ ssh parallels2
The authenticity of host 'parallels2 (10.211.55.5)' can't be established.
ECDSA key fingerprint is SHA256:ZmDo5Rgbt/c5BtVvQHE9S0ZKpZf1+gTnTlhHELQXaiI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'parallels2,10.211.55.5' (ECDSA) to the list of known hosts.
parallels@parallels2's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

259 packages can be updated.
11 updates are security updates.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
#从机ping主机
$ ping parallels1
PING parallels1 (10.211.55.6) 56(84) bytes of data.
64 bytes from parallels1 (10.211.55.6): icmp_seq=1 ttl=64 time=1.66 ms
64 bytes from parallels1 (10.211.55.6): icmp_seq=2 ttl=64 time=1.04 ms
64 bytes from parallels1 (10.211.55.6): icmp_seq=3 ttl=64 time=1.34 ms
64 bytes from parallels1 (10.211.55.6): icmp_seq=4 ttl=64 time=0.551 ms
64 bytes from parallels1 (10.211.55.6): icmp_seq=5 ttl=64 time=0.559 ms


#从机SSH主机
ssh parallels1

6.主机终端运行

#启动
$ roscore
... logging to /home/parallels/.ros/log/2f92ff0e-d1e2-11e8-ad20-001c42818464/roslaunch-parallels1-3240.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://parallels1.local:38775/
ros_comm version 1.12.14


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES

auto-starting new master
process[master]: started with pid [3260]
ROS_MASTER_URI=http://parallels1.local:11311/

setting /run_id to 2f92ff0e-d1e2-11e8-ad20-001c42818464
process[rosout-1]: started with pid [3276]
started core service [/rosout]
#启动监听
$ rosrun rospy_tutorials listener.py

7.从机上运行

$ rosrun rospy_tutorials talker.py

结果:

#主机终端1
$ roscore
... logging to /home/parallels/.ros/log/2f92ff0e-d1e2-11e8-ad20-001c42818464/roslaunch-parallels1-3240.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://parallels1.local:38775/
ros_comm version 1.12.14


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES

auto-starting new master
process[master]: started with pid [3260]
ROS_MASTER_URI=http://parallels1.local:11311/

setting /run_id to 2f92ff0e-d1e2-11e8-ad20-001c42818464
process[rosout-1]: started with pid [3276]
started core service [/rosout]

#主机终端2
$ rosrun rospy_tutorials listener.py
[INFO] [1539763171.713668]: /listener_3622_1539763100223I heard hello world 1539763171.71
[INFO] [1539763171.814558]: /listener_3622_1539763100223I heard hello world 1539763171.81
[INFO] [1539763171.913797]: /listener_3622_1539763100223I heard hello world 1539763171.91
[INFO] [1539763172.014481]: /listener_3622_1539763100223I heard hello world 1539763172.01
[INFO] [1539763172.113369]: /listener_3622_1539763100223I heard hello world 1539763172.11
#从机终端
$ rosrun rospy_tutorials talker.py
[INFO] [1539763171.507567]: hello world 1539763171.51
[INFO] [1539763171.610851]: hello world 1539763171.61
[INFO] [1539763171.708195]: hello world 1539763171.71
[INFO] [1539763171.808843]: hello world 1539763171.81
[INFO] [1539763171.908206]: hello world 1539763171.91

OK,实验完成!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值