Dockerで ROS Kinetic 環境を扱う

# 目的
Dockerで ROS Kinetic 環境を扱う際の備忘録です

# Docker ROS Kinetic 環境のイメージファイルを取得する

```
$ docker run -it --rm -p 6080:80 ct2034/vnc-ros-kinetic-full
```

ブラウザから、http://127.0.0.1:6080 へアクセスできればOK

<img width="308" alt="スクリーンショット 2020-05-17 12.27.25.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/344880/7ca4e079-8313-ed9d-4428-efe57e44db90.png">

turtlesimも動きました

```
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
```

<img width="309" alt="スクリーンショット 2020-05-17 12.29.09.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/344880/fb747fd7-9dbb-5f54-20d6-369a93df2a7c.png">

# Dockerfileから起動

```
$ mkdir -p test
$ cd test
$ git clone git https://github.com/ct2034/docker-ubuntu-vnc-desktop
$ cd docker-ubuntu-vnc-desktop
```

Dockerfileはこのようになっている

```
FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

# built-in packages
RUN apt-get update \
    && apt-get install -y --no-install-recommends software-properties-common curl \
    && sh -c "echo 'deb http://download.opensuse.org/repositories/home:/Horst3180/xUbuntu_16.04/ /' >> /etc/apt/sources.list.d/arc-theme.list" \
    && curl -SL http://download.opensuse.org/repositories/home:Horst3180/xUbuntu_16.04/Release.key | apt-key add - \
    && add-apt-repository ppa:fcwu-tw/ppa \
    && apt-get update \
    && apt-get install -y --no-install-recommends --allow-unauthenticated \
        supervisor \
        openssh-server pwgen sudo vim-tiny \
        net-tools \
        lxde x11vnc xvfb \
        gtk2-engines-murrine ttf-ubuntu-font-family \
        firefox \
        nginx \
        python-pip python-dev build-essential \
        mesa-utils libgl1-mesa-dri \
        gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine pinta arc-theme \
        dbus-x11 x11-utils \
        terminator \
    && apt-get autoclean \
    && apt-get autoremove \
    && rm -rf /var/lib/apt/lists/*

# =================================
# install ros (source: https://github.com/osrf/docker_images/blob/5399f380af0a7735405a4b6a07c6c40b867563bd/ros/kinetic/ubuntu/xenial/ros-core/Dockerfile)
# install packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    python-rosdep \
    python-rosinstall \
    python-vcstools \
    && rm -rf /var/lib/apt/lists/*

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# bootstrap rosdep
RUN rosdep init \
    && rosdep update

# install ros packages
ENV ROS_DISTRO kinetic
RUN apt-get update && apt-get install -y \
#    ros-kinetic-ros-core=1.3.1-0* \
    ros-kinetic-desktop-full \
    #              A
    #              +--- full desktop \
    && rm -rf /var/lib/apt/lists/*

# setup entrypoint
# COPY ./ros_entrypoint.sh /


# =================================

# user tools
RUN apt-get update && apt-get install -y \
    terminator \
    gedit \
    okular \
    vim \
    && rm -rf /var/lib/apt/lists/*

# tini for subreap
ENV TINI_VERSION v0.9.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /bin/tini
RUN chmod +x /bin/tini

ADD image /
RUN pip install setuptools wheel && pip install -r /usr/lib/web/requirements.txt

RUN cp /usr/share/applications/terminator.desktop /root/Desktop
RUN echo "source /opt/ros/kinetic/setup.bash" >> /root/.bashrc


EXPOSE 80
WORKDIR /root
ENV HOME=/home/ubuntu \
    SHELL=/bin/bash
ENTRYPOINT ["/startup.sh"]
```


# gnome-terminal をインストールする場合

```
apt-get update
apt-get install -y gnome-terminal
```

# less をインストールする場合

```
apt-get install -y less
```

# ros-kinetic-turtlebot3 関係のパッケージを入れる

一通り必要そうなものをインストール

```
apt-get install -y python-pip; \
pip install requests flask; \
apt-get install -y ros-kinetic-turtlebot3 ros-kinetic-turtlebot3-msgs ros-kinetic-turtlebot3-simulations; \
apt-get install -y ros-kinetic-aruco-ros; \
echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
source ~/.bashrc
```

必要に応じて、GAZEBOモデルのパスを追加する

```
echo "export GAZEBO_MODEL_PATH="GAZEBOモデルのパス" >> ~/.bashrc
source ~/.bashrc
```

# catkin_wsの設定

> [http://wiki.ros.org/ja/catkin/Tutorials/create_a_workspace](http://wiki.ros.org/ja/catkin/Tutorials/create_a_workspace)

```
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
```

# その他
何か不足点あれば教えて頂けますと幸いです。
（新しいエラーに直面した時に、あまり先人の資料がなく解決が難しいです。。）

# 追記

こちらも便利
[https://github.com/Tiryoh/docker-ros-desktop-vnc](https://github.com/Tiryoh/docker-ros-desktop-vnc)

# 参考
[ROS Kinetic の Ubuntu へのインストール](http://wiki.ros.org/ja/kinetic/Installation/Ubuntu)
[ROSトピックの理解](http://wiki.ros.org/ja/ROS/Tutorials/UnderstandingTopics)
[Problem with “gnome-terminal” on Gnome 3.12.2](https://askubuntu.com/questions/608330/problem-with-gnome-terminal-on-gnome-3-12-2)
[ct2034/vnc-ros-kinetic-full](https://hub.docker.com/r/ct2034/vnc-ros-kinetic-full/dockerfile)
[ct2034/docker-ubuntu-vnc-desktop](https://www.github.com/ct2034/docker-ubuntu-vnc-desktop)
[fcwu/docker-ubuntu-vnc-desktop](https://github.com/fcwu/docker-ubuntu-vnc-desktop)
[gnome-terminal-3.36.2](http://lfsbookja.osdn.jp/BLFS/svn-ja/gnome/gnome-terminal.html)
[最小インストールしたDebianの初期設定メモ](https://www.xmisao.com/2014/01/16/debian-initial-settings.html)
> [http://wiki.ros.org/ja/catkin/Tutorials/create_a_workspace](http://wiki.ros.org/ja/catkin/Tutorials/create_a_workspace)
[ROS kineticでmove base使用時にDWAPlannerROS planner周りのエラーが出た時の対策メモ](https://qiita.com/seigot/items/a13558e92c84f676dd0a)