# ROS2 Container to container communication

### <span style="color: rgb(53, 152, 219);">To-Do</span>

- Determine why multicast send and receive are not working on our network.
- More testing with other ROS2 packages.

### <span style="color: rgb(53, 152, 219);">Setup</span>

In this setup, we have two containers:

1. The Boston Dynamics ROS2 [Spot ROS2](https://github.com/rshu-bd/spot_ros2/tree/rshu-bd/spot_core_extension) container in the an extension file build using [these instructions](https://github.com/rshu-bd/spot_ros2/tree/rshu-bd/spot_core_extension/spot_coreio_extension).
2. Our container built for Spot.

### <span style="color: rgb(53, 152, 219);">Network</span>

<div drawio-diagram="72"><img src="https://secretlibrary.rccf.club/uploads/images/drawio/2023-11/FlD4EmK7HLdFJ3Oe-drawing-4-1699647246.png" alt=""/></div>

### <span style="color: rgb(53, 152, 219);">Container Configuration</span>

##### <span style="color: rgb(53, 152, 219);">Extension Container</span>

1. You need to ssh into the CORE I/O via the default IP of 192.168.80.3 or 192.168.50.3 if you are connected directly to the CORE I/O. 
    - ```bash
        ssh 192.168.80.3
        ```
2. You will need to lock down the CORE I/O to a specific port range. This is so that the containers choose ports that are open. 
    - ```bash
        echo "21000 22000" | sudo tee /proc/sys/net/ipv4/ip_local_port_range
        ```
3. **<span style="text-decoration: underline;"><span style="color: rgb(241, 196, 15); text-decoration: underline;">You must restart the containers/extension after changing the ports on the CORE I/O</span></span>**
4. You need to find the container id of your ROS2 installation. 
    - ```bash
        sudo docker container ls
        ```

1. Once you have your container id you will need to open up into the container. 
    - ```bash
        sudo docker exec -it 8966bcde886b /bin/bash # replace "8966bcde886b" with your container id
        ```
2. Once inside the container. 
    - The Extension container was setup with the following commands to test:

```bash
ping 192.168.50.20 # Ping test the dev computer.

export ROS_DISCOVERY_SERVER=192.168.50.5:21000 # This was changed from the BD default of 192.168.80.3 because we are using our own WiFi setup that bypasses Spot's internal network.

source ./install/setup.bash # Source workspace
source /opt/ros/humble/setup.bash # Source ROS2

ros2 run demo_nodes_cpp listener --ros-args --remap __node:=listener_discovery_server

```

##### <span style="color: rgb(53, 152, 219);">Dev Container</span>

The Dev container was setup with the following commands to test:

```bash
ping 192.168.50.5 # Ping test the CORE I/O.

export ROS_DISCOVERY_SERVER=192.168.50.5:21000 # This was changed from the BD default of 192.168.80.3 because we are using our own WiFi setup that bypasses Spot's internal network.

source ./install/setup.bash # Source workspace
source /opt/ros/humble/setup.bash # Source ROS2

ros2 run demo_nodes_cpp talker --ros-args --remap __node:=talker_discovery_server

```