Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On branch mavsdk_docker_image #839

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Tools/run_docker_hitl_gzsim_mavsdk_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

#This script is designed to run HITL simulation and MAVSDK testing through a docker image.

#usage example
#./Tools/run_docker_hitl_gzsim_mavsdk_server.sh <docker_image> <script_and_arguments>

#examples
#To run hitl simulation
#./Tools/run_docker_hitl_gzsim_mavsdk_server.sh local_hitl_gzsim_server ./Tools/simulation/gz/hitl_run.sh ssrc_holybro_x500/model_hitl.sdf
#To run mavsdk testing
#./Tools/run_docker_hitl_gzsim_mavsdk_server.sh local_hitl_gzsim_server ./test/mavsdk_tests/mavsdk_test_runner.py test/mavsdk_tests/configs/hitl_gz_harm.json --gui --case "Takeoff and Land"

#command for local building the docker image
#docker build -t local_hitl_gzsim_server -f px4-firmware/packaging/Dockerfile.hitl_gzsim_mavsdk .


YELLOW='\033[0;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'

if [ "$#" -eq 0 ]; then
echo -e "You should specify ${RED}a docker image${NC} and ${YELLOW}a script for running.${NC}"
echo -e "${GREEN}Usage example:${NC}"
echo -e " ./Tools/run_docker_hitl_gzsim_mavsdk_server.sh ${RED}<docker_image>${NC} ${YELLOW}<script_and_arguments>${NC}"
echo
echo -e "${GREEN}Examples ${NC}"
echo -e " 1.To run hitl simulation"
echo -e " ./Tools/run_docker_hitl_gzsim_mavsdk_server.sh ${RED}local_hitl_gzsim_server ${YELLOW}./Tools/simulation/gz/hitl_run.sh ssrc_holybro_x500/model_hitl.sdf${NC}"
echo
echo -e " 2.To run mavsdk testing"
echo -e " ./Tools/run_docker_hitl_gzsim_mavsdk_server.sh ${RED}local_hitl_gzsim_server ${YELLOW}./test/mavsdk_tests/mavsdk_test_runner.py test/mavsdk_tests/configs/hitl_gz_harm.json --gui --case \"Takeoff and Land\"${NC}"
echo
echo -e "${GREEN}command for local building the docker image${NC}"
echo -e "docker build -t ${RED}local_hitl_gzsim_server${NC} -f px4-firmware/packaging/Dockerfile.hitl_gzsim_mavsdk ."
exit 1
fi

BASE_COMMAND=(
docker run -it --rm
--network host
--env DISPLAY=${DISPLAY}
--volume /tmp/.docker.xauth:/tmp/.docker.xauth
--volume /tmp/.X11-unix:/tmp/.X11-unix
--privileged
)

xhost si:localuser:root
${BASE_COMMAND[@]} "$@"
91 changes: 91 additions & 0 deletions packaging/Dockerfile.hitl_gzsim_mavsdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FROM docker.io/ros:humble-ros-base as builder

# Install build dependencies
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y \
git \
curl \
lsb-release \
gnupg \
astyle \
build-essential \
cmake \
cppcheck \
file \
g++ \
gcc \
gdb \
git \
lcov \
libfuse2 \
libxml2-dev \
libxml2-utils \
make \
ninja-build \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
rsync \
shellcheck \
unzip \
ros-humble-fastrtps \
ros-humble-rmw-fastrtps-cpp \
fastddsgen \
wget \
libboost-filesystem-dev

RUN curl http://packages.osrfoundation.org/gazebo.key | apt-key add -
RUN sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'

RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null

RUN apt update
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y \
gz-harmonic

RUN wget --no-check-certificate https://github.com/mavlink/MAVSDK/releases/download/v1.3.1/libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb && \
dpkg -i libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb && \
rm libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb

# Copy source from host
COPY px4-firmware px4-firmware
RUN python3 -m pip install -r px4-firmware/Tools/setup/requirements.txt
RUN cp px4-firmware/packaging/build_px4_hitl_gzsim_mavsdk.sh ./build.sh
RUN ./build.sh


FROM ghcr.io/tiiuae/gz-sim-server:sha-954fefc

RUN apt update
RUN apt install -y \
curl \
wget \
lsb-release \
gnupg \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
libboost-filesystem-dev

RUN wget --no-check-certificate https://github.com/mavlink/MAVSDK/releases/download/v1.3.1/libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb && \
dpkg -i libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb && \
rm libmavsdk-dev_1.3.1_ubuntu20.04_amd64.deb

COPY px4-firmware/packaging/entrypoint_hitl_gzsim_mavsdk.sh /px4-firmware/entrypoint.sh
COPY px4-firmware/Tools/setup/requirements.txt /px4-firmware/Tools/setup/requirements.txt
RUN python3 -m pip install -r /px4-firmware/Tools/setup/requirements.txt

WORKDIR /px4-firmware

COPY --from=builder /px4-firmware/build/px4_sitl_default /px4-firmware/build/px4_sitl_default
COPY --from=builder /px4-firmware/test/mavsdk_tests /px4-firmware/test/mavsdk_tests
COPY --from=builder /px4-firmware/Tools/simulation/gz /px4-firmware/Tools/simulation/gz

ENTRYPOINT [ "/px4-firmware/entrypoint.sh" ]

CMD [ "echo", "Available scripts for run: ./Tools/simulation/gz/hitl_run.sh and test/mavsdk_tests/mavsdk_test_runner.py" ]
11 changes: 11 additions & 0 deletions packaging/build_px4_hitl_gzsim_mavsdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

source /opt/ros/humble/setup.sh

pushd px4-firmware
rm -rf build
make clean
make px4_sitl_default
make px4_sitl mavsdk_tests
make px4_sitl gzsim-plugins
popd
3 changes: 3 additions & 0 deletions packaging/entrypoint_hitl_gzsim_mavsdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec "$@"
Loading