---
# System prepended metadata

title: ROS communication over Machines
tags: [控制組]

---

# ROS communication over Machines

## Procedure: 
1. bind static IP for computers (rpi and xavier)
2. ROS setup

---
## Wiring:
Wired Connections (Ethernet cable)
![](https://hackmd.io/_uploads/rkhqEHQph.png)

> Machine IP in tutorial:
> Rpi :   10.42.0.101
> Xavier: 10.42.0.100
---


## Tutorial:
### 1. Network configuration

#### - On Rpi (Raspbian GNU/Linux os)
```
$ sudo vim /etc/dhcpcd.conf
```
then add settings to file:
```bash
interface eth0
static ip_address=10.42.0.101/24
static routers=10.42.0.1
static domain_name_servers=10.42.0.1 8.8.8.8
```
#### - On Jetson Xavier (Ubuntu os)

- enable systemd-networkd service
```
$ sudo systemctl enable systemd-networkd
$ sudo reboot
```

- install netplan
```
$ sudo apt install netplan.io
```

- add config file
```
$ sudo vim /etc/netplan/network-config.yaml
```

```bash=
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses: [10.42.0.100/24]
      gateway4: 10.42.0.1
      nameservers:
        addresses: [10.42.0.1]
```

- apply netplan configuration
```
$ sudo netplan apply
```
- restart networking service
```
$ sudo systemctl restart systemd-networkd
```
- verify configuration
```
$ ip address show eth0
```
Result:
```
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 48:b0:2d:15:f6:ae brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.100/24 brd 10.42.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::31ca:c65a:20e8:18c1/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
```

### 2. Run ROS on mulitple machines

Run raspberry pi as ROS Master

**In Master (Rpi)**
```
$ vim ~/.bashrc
```
Add in ~/.bashrc
```
# in ~/.bashrc
export ROS_MASTER_URI=http://10.42.0.101:11311
export ROS_IP=10.42.0.101
```
Source ~/.bashrc or reboot
```
$ source ~/.bashrc
```
 **In Slave Machine (Jetson Xavier)**

Add in ~/.bashrc:
```
# in ~/.bashrc
export ROS_MASTER_URI=http://10.42.0.101:11311
export ROS_IP=10.42.0.100
```

### Note: 

**Can only run** <font color="#f00">```roscore```</font> **on Master machine**





