PX4Docker/Docker_PX4/Dockerfile

319 lines
10 KiB
Docker

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN apt-get update && apt-get install -y gnupg
#RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
#RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
RUN apt-get update && apt-get -y --quiet --no-install-recommends install \
sudo \
nano \
gedit \
net-tools \
iputils-* \
bash-completion \
autotools-dev \
dh-autoreconf \
bzip2 \
ca-certificates \
ccache \
cmake \
cppcheck \
curl \
dirmngr \
doxygen \
file \
g++ \
gcc \
gdb \
git \
gnupg \
gosu \
lcov \
libfreetype6-dev \
libgtest-dev \
libpng-dev \
lsb-release \
make \
ninja-build \
openjdk-8-jdk \
openjdk-8-jre \
openssh-client \
pkg-config \
python-pip \
python-pygments \
python-setuptools \
python-wstool \
python3-dev \
python3-pip \
python3-pygments \
python3-setuptools \
locate \
rsync \
shellcheck \
tzdata \
unzip \
wget \
xsltproc \
zip \
xterm \
vim \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
RUN python -m pip install --upgrade pip \
&& pip install setuptools pkgconfig wheel \
&& pip install argparse argcomplete coverage jinja2 empy numpy requests serial toml pyyaml cerberus
# Python 3 dependencies installed by pip
RUN pip3 install argparse argcomplete coverage cerberus empy jinja2 \
matplotlib==3.0.* numpy pkgconfig pyros-genmsg pyulog pyyaml \
requests serial toml pyulog wheel
# create arrow with id 1000 with sudo access
RUN useradd --shell /bin/bash -u 1000 -c "" -m arrow && usermod -a -G dialout arrow && echo "arrow:arrow" | chpasswd && adduser arrow sudo
RUN sed -i '/force_color_prompt/s/^#//g' ~/.bashrc
RUN sed -i '/force_color_prompt/s/^#//g' /home/arrow/.bashrc
# setup virtual X server
RUN mkdir /tmp/.X11-unix && \
chmod 1777 /tmp/.X11-unix && \
chown -R root:root /tmp/.X11-unix
ENV DISPLAY :99
ENV CCACHE_UMASK=000
ENV FASTRTPSGEN_DIR="/usr/local/bin/"
ENV PATH="/usr/lib/ccache:$PATH"
ENV TERM=xterm
ENV TZ=UTC
RUN echo "source /etc/profile.d/bash_completion.sh" >> /home/arrow/.bashrc
# SITL UDP PORTS
EXPOSE 14556/udp
EXPOSE 14557/udp
#start of ros install
ENV ROS_DISTRO melodic
ARG TOKEN
RUN echo "arrow" | sudo -S apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
RUN echo "arrow" | sudo -S apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
RUN pip3 install --upgrade pip
RUN wget --quiet http://packages.osrfoundation.org/gazebo.key -O - | apt-key add - \
&& sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -sc` main" > /etc/apt/sources.list.d/gazebo-stable.list' \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 \
&& sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list' \
&& sh -c 'echo "deb http://packages.ros.org/ros-shadow-fixed/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-shadow.list' \
&& curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - \
&& apt-get update \
&& apt-get -y upgrade \
&& apt-get -y dist-upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
ant \
gazebo9 \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
libeigen3-dev \
libgazebo9-dev \
libgstreamer-plugins-base1.0-dev \
libimage-exiftool-perl \
libopencv-dev \
libxml2-utils \
pkg-config \
protobuf-compiler \
geographiclib-tools \
libeigen3-dev \
libgeographic-dev \
libopencv-dev \
python-catkin-tools \
python-tk \
python3-pip \
ros-$ROS_DISTRO-gazebo-ros-pkgs \
ros-$ROS_DISTRO-mavlink \
ros-$ROS_DISTRO-mavros \
ros-$ROS_DISTRO-mavros-extras \
ros-$ROS_DISTRO-pcl-conversions \
ros-$ROS_DISTRO-pcl-msgs \
ros-$ROS_DISTRO-pcl-ros \
ros-$ROS_DISTRO-ros-base \
ros-$ROS_DISTRO-rostest \
ros-$ROS_DISTRO-rosunit \
ros-$ROS_DISTRO-xacro \
ros-$ROS_DISTRO-tf2-ros \
ros-$ROS_DISTRO-roslint \
ros-$ROS_DISTRO-rviz \
xvfb \
python-pil \
python-yaml \
libgeos-dev \
python-lxml \
libgdal-dev \
build-essential \
python-dev \
libjpeg-dev \
zlib1g-dev \
libfreetype6-dev \
python-virtualenv \
python-rosdep \
&& geographiclib-get-geoids egm96-5 \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/* \
&& pip3 install setuptools wheel \
&& pip3 install pyulog matplotlib \
&& pip3 install catkin_pkg px4tools pymavlink \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
RUN echo "source /opt/ros/melodic/setup.bash" >> /home/arrow/.bashrc
# install MAVLink headers
RUN git clone --depth 1 https://github.com/mavlink/c_library_v2.git /usr/local/include/mavlink/v2.0 && rm -rf /usr/local/include/mavlink/v2.0/.git
# Some QT-Apps/Gazebo don't not show controls without this
ENV QT_X11_NO_MITSHM 1
# Use UTF8 encoding in java tools (needed to compile jMAVSim)
ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
# Install MAVSDK library
RUN wget https://github.com/mavlink/MAVSDK/releases/download/v0.23.0/mavsdk_0.23.0_ubuntu18.04_amd64.deb \
&& dpkg -i mavsdk_0.23.0_ubuntu18.04_amd64.deb
RUN rosdep init && su -c "rosdep update -c /home/arrow/.ros/rosdep/sources.cache" - arrow
RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
USER arrow
ENV ARROW_HOME /home/arrow
ENV CATKIN_WS $ARROW_HOME/catkin_ws
RUN echo "Working Folder is:$ARROW_HOME"
RUN echo "Setting up the workspace"
#Create & build catkin_ws
RUN mkdir -p $ARROW_HOME/catkin_ws/src \
&& echo "arrow" | sudo -S chown -R arrow:arrow $ARROW_HOME/catkin_ws \
&& cd ~/catkin_ws \
&& catkin init \
&& catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release \
&& catkin config --merge-devel \
&& catkin config --extend /opt/ros/$ROS_DISTRO \
&& catkin build \
&& cd ~/catkin_ws/src
#start of px4 setup
RUN echo "arrow" | sudo -S apt-get update && sudo apt-get -y --quiet --no-install-recommends install software-properties-common apt-utils
RUN sed -i '/source ~\/catkin_ws\/devel\/setup.bash/d' $HOME/.bashrc && \
sed -i 's+source /opt/ros/melodic/setup.bash+source /opt/ros/melodic/setup.bash\nsource ~/catkin_ws/devel/setup.bash+g' $ARROW_HOME/.bashrc
# Install some useful ros tf packages
RUN echo "arrow" | sudo -S apt-get install ros-melodic-tf-conversions ros-melodic-rqt-tf-tree -y
RUN if [ ! -d "$ARROW_HOME/src" ]; then \
mkdir -p $ARROW_HOME/src; fi
RUN git clone https://git.spirirobotics.com/scorpio1/oscillation_ctrl.git ~/catkin_ws/src/oscillation_ctrl
RUN pip3 install --user jsonschema
RUN cd $ARROW_HOME \
&& git clone https://github.com/PX4/PX4-Autopilot.git --recursive \
&& cd PX4-Autopilot \
&& echo 'argcomplete \n\
argparse>=1.2 \n\
cerberus \n\
coverage \n\
empy>=3.3 \n\
future \n\
jinja2>=2.8 \n\
jsonschema \n\
kconfiglib \n\
lxml \n\
matplotlib>=3.0.* \n\
numpy>=1.13 \n\
nunavut>=1.1.0 \n\
packaging \n\
pandas>=0.21 \n\
pkgconfig \n\
psutil \n\
pygments \n\
wheel>=0.31.1 \n\
pymavlink \n\
pyros-genmsg \n\
pyserial \n\
pyulog>=0.5.0 \n\
pyyaml \n\
requests \n\
setuptools>=39.2.0 \n\
six>=1.12.0 \n\
toml>=0.9' > Tools/setup/requirements.txt \
&& echo "arrow" | sudo -S bash ./Tools/setup/ubuntu.sh \
&& echo "arrow" | sudo -SH pip3 install kconfiglib \
&& DONT_RUN=1 make px4_sitl_default gazebo
RUN echo "export PATH=\$PATH:/home/arrow/.local/bin:/home/arrow/.local/bin" >> /home/arrow/.bashrc
RUN echo "export PATH=\$PATH:/usr/local/cuda-10.1/bin" >> /home/arrow/.bashrc
RUN echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/cuda-10.1/lib64:/usr/local/cuda-10.1/targets/x86_64-linux/lib/:/usr/local/cuda/extras/CUPTI/lib64/" >> /home/arrow/.bashrc
RUN echo "export CUDA_HOME=/usr/local/cuda" >> /home/arrow/.bashrc
RUN echo "arrow" | sudo -S apt-get update
RUN echo "arrow" | sudo -S pip install scipy
RUN echo "arrow" | sudo -S apt install ros-melodic-tf2-geometry-msgs
RUN bash ~/catkin_ws/src/oscillation_ctrl/px4_setup/ubuntu_sim_ros_melodic.sh
RUN cd ~/PX4-Autopilot && DONT_RUN=1 make px4_sitl_default gazebo
#setup models for px4
RUN cp ~/catkin_ws/src/oscillation_ctrl/px4_setup/airframe_changes ~/PX4-Autopilot/platforms/posix/cmake/sitl_target.cmake
RUN mkdir -p ~/PX4-Autopilot/Tools/sitl_gazebo/models
RUN mkdir -p ~/PX4-Autopilot/Tools/sitl_gazebo/worlds
RUN cp -R ~/catkin_ws/src/oscillation_ctrl/models/* ~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models
RUN cp -R ~/catkin_ws/src/oscillation_ctrl/worlds/* ~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds
RUN cd ~/PX4-Autopilot && DONT_RUN=1 make px4_sitl_default gazebo
RUN cp ~/catkin_ws/src/oscillation_ctrl/px4_setup/CMakeLists.txt ~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/CMakeLists.txt
RUN cd ~/PX4-Autopilot && DONT_RUN=1 make px4_sitl_default gazebo
RUN mkdir -p /home/arrow/PX4-Autopilot/ROMFS/px4fmu_common/init.d-posix/airframes
RUN cp -R ~/catkin_ws/src/oscillation_ctrl/airframes/18.04/* ~/PX4-Autopilot/ROMFS/px4fmu_common/init.d-posix
RUN cd ~/PX4-Autopilot && DONT_RUN=1 make px4_sitl_default gazebo
RUN bash ~/catkin_ws/src/oscillation_ctrl/px4_setup/px4setup.sh
#install QGroundControl
RUN echo "arrow" | sudo -S apt-get remove modemmanager -y
RUN echo "arrow" | sudo -S apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl libqt5gui5 libfuse2 libpulse-dev fuse xmlstarlet -y
RUN cd ~ && wget https://github.com/mavlink/qgroundcontrol/releases/download/v4.2.6/QGroundControl.AppImage
#final setup
SHELL ["/bin/bash", "-c"]
RUN cd ~/PX4-Autopilot\
&& source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default \
&& export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd) \
&& export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/simulation/gazebo-classic/sitl_gazebo-classic