ads ros and lgsvl talk in dockers

backgound

previously, we had integrated ads ros nodes into one launch file. now we try to put ads nodes into docker, and talk to lgsvl simulator in another docker.

run dockerimage

1
2
docker build -t ads_ros .
docker run -it ads_ros /bin/bash

unable to run cakin_make in dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
RUN /bin/bash -c '. /opt/ros/kinetic/setup.bash; cd <into the desired folder e.g. ~/catkin_ws/src>; catkin_make'
```
#### dockerfile for ads ros
```
FROM ros:kinetic
# create local catkin workspace
ENV CATKIN_WS=/root/catkin_ws
ENV ROS_DISTRO=kinetic
RUN mkdir -p $CATKIN_WS/src
## install catkin_make
## https://docs.ros.org/api/catkin/html/user_guide/installation.html
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
build-essential \
apt-utils \
ca-certificates \
psmisc \
cmake \
vim \
python-catkin-pkg \
ros-${ROS_DISTRO}-catkin \
ros-${ROS_DISTRO}-tf \
ros-${ROS_DISTRO}-turtlesim \
ros-${CATKIN_WS}-rosbridge-suite
iputils-ping \
net-tools
### add third-party headers
# RUN source ~/.bashrc
# copy ads ros into ws
COPY /src $CATKIN_WS/src
### build msgs
RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash; cd ${CATKIN_WS}; catkin_make --pkg pcl_msgs pb_msgs autoware_msgs mobileye_msgs ibeo_msgs nmea_msgs '
### build ros nodes
RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash; cd ${CATKIN_WS}; catkin_make '
# copy ros scripts
COPY /script $CATKIN_WS/scripts
# run ros shell
WORKDIR ${CATKIN_WS}/scripts

ros envs

set ROS_IP on all involved containers to their IP, and set ROS_MASTER_URI to the IP of the roscore container. That would avoid the DNS problem. understand ros environment variables

  • $ROS_ROOT : set the location whre the ROS core packages are installed

  • $ROS_MASTER_URI : a required setting that tells nodes where they can locate the master

  • $ROS_IP or $ROS_HOSTNAME : sets the declared network address of a ROS node

get docker container’s IP

docker inspect -f "{{ .NetworkSettings.Networks..IPAddress }}" <container_name||container_id> 

tips, network_name: e.g. host, bridge, ingress e.t.c.

with docker host net, then the container doesn’t have its own IP address allocated, but the application is available on the host’s IP address with customized port.

run roscore in docker and talk to rosnodes at host

  • start roscore from docker container as following :

    sudo docker run -it –net host ads_ros /bin/bash
    roscore

  • start other ros nodes at host

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
rosnode list ## >>> /rosout
source $ROS_PACKAGE/setup.sh
rosrun rtk_sensor rtk_sensor ### run successfully
```
how to understand ? once the docker container start with `host network`, the `roscore` run inside docker, is same as run in the host machine !!
#### ads ros in docker talk to lgsvl in another docker with HOST network
* once we start ads ros docker as following:
```shell
sudo docker run -it --net host ads_ros /bin/bash
roscore
```
* start lgsvl in docker:
```shell
#! /usr/bin/env bash
xhost +
sudo nvidia-docker run -it -p 8080:8080 -e DISPLAY=unix$DISPLAY --net host -v /tmp/.X11-unix:/tmp/.X11-unix lgsvlsimulator /bin/bash

then access webUI in host machine, and add host: 10.20.181.132 in Clusters page, and add 10.20.181.132:9090 for Selected Vehicles. as lgsvl is also in host network. so these two docker can communicate through ros well !!

ads ros container talk to lgsvl container with ROS_IP

since lgsvl will run in docker swarm env, we can’t depend on host network, which requires ROS_IP env. the following test is in one host machine.

  • in host terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export ROS_MASTER_URI=http://192.168.0.10:11311
export ROS_HOSTNAME=192.168.0.10
export ROS_IP=192.168.0.10
roscore
```
* in ads ros docker
```shell
sudo docker run -it \
--env ROS_MASTER_URI=http://10.20.181.132:11311 \
--env ROS_IP=10.20.181.132 \
ads_ros /bin/bash
rosnod list
```
however, when start `roscore` in docker, it reports:
```shell
Unable to contact my own server at [http://10.20.181.132:33818/].
This usually means that the network is not configured properly.
A common cause is that the machine cannot ping itself. Please check
for errors by running:
ping 10.20.181.132
```
if checking the IP address inside the docker container by `ifconfig`, which reports `172.17.0.3`, which then make sense that the container can't talk to `10.20.181.132`, which means we can't assign a special IP address for a docker container. so reset in the docker container as:
```shell
export ROS_MASTER_URI=http://172.17.0.3:11311
export ROS_HOSTNAME=172.17.0.3

actually, the host terminal can talk to the ads ros container directly, with no need to set $ROS_HOSTNAME & $ROS_MASTER_URI specially; as well as another docker container in this host machine, e.g. lgsvl.

a little bit knowledge about docker network. so each docker container does have an virtual IP, e.g. 172.17.0.1. while if run the docker image with host network, there is no special container IP, but the container directly share the IP of the host machine. as multi docker containers run in the same host machine, even without host network, they are in the same network range, so they can communicate to each other. additionaly for ros_master, which may requires to add $ROS_HOSTNAME & $ROS_MASTER_URI.

  • start lgsvl in another docker
1
2
3
4
5
6
7
8
9
#! /usr/bin/env bash
xhost +
sudo nvidia-docker run -it \
-p 8080:8080 \
-e DISPLAY=unix$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--env ROS_MASTER_URI=http://172.17.0.3:11311 \
--env ROS_HOSTNAME=172.17.0.3
lgsvlsimulator /bin/bash

in summary

so far, we have host ads ros in one docker, and lgsvl in another docker, and they are in the same machine, and they can talk to each other. the next thing is to put ads ros and lgsvl in one image.

refer

rosdep

docker 1.10 container’s IP in LAN

listening to ROS messages in docker containers

exposing ROS containers to host machine

why you need IP address of Docker container

catkin_make not found in dockerfile