init commit

This commit is contained in:
EricX-Zhao
2026-02-11 17:54:06 +03:00
commit c15a3552ae
18 changed files with 1593 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
## Build Image
ROS Jazzy + GZ Harmonic
```
docker buildx build -f gz_harmonic_sim_dev.dockerfile -t sim_dev:gz_harmonic .
```
## NOTICE
When you build code in container with error:
> fatal: detected dubious ownership in repository at '/code/PX4-Autopilot'
> To add an exception for this directory, call:
> git config --global --add safe.directory
you should run this command in container:
```
git config --global --add safe.directory '*'
```
## Ubuntu With GUI&GPU Support
1. Install nvidia-container-toolkit
```
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt install -y nvidia-container-toolkit
sudo systemctl restart docker
```
2. Run container with docker compose
```
# in host bash
# x11 permission
xhost +local:root
# 修改 docker-compose-ubuntu.yml 中${HOST_WS} 为你主机上的工作空间的目录
docker compose -f docker-compose-ubuntu.yml up -d
docker exec -it sim_dev_container bash
# in container bash
git config --global --add safe.directory '*'
cd /simulation_ws
sudo apt update
rosdep install --from-paths src/autonomy --ignore-src -r -y
/simulation_ws/src/autonomy/drivers/mavros/mavros/scripts/install_geographiclib_datasets.sh
colcon build --symlink-install --packages-up-to mavlink mavros px4_bringup
```
## How to enter container again with bash
```
# get container id
docker container ls -a
# start container if not
docker container start [container id]
docker exec -it [container id] bash
```
## WSL2 With GUI&GPU Support
> NOTICE: replace `~/code` on your host
```
docker run -it \
-v ~/code:/code \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-v /usr/lib/wsl:/usr/lib/wsl \
-e DISPLAY=$DISPLAY \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
-e PULSE_SERVER=$PULSE_SERVER \
--device=/dev/dxg \
--device /dev/dri/card0 \
--device /dev/dri/renderD128 \
--gpus all sim_dev:gz_harmonic
```
docker-compose
```
docker compose -f docker-compose-wsl.yml up -d
docker exec -it sim_dev_container bash
cd /simulation_ws
sudo apt update
rosdep install --from-paths src/autonomy --ignore-src -r -y
/simulation_ws/src/autonomy/drivers/mavros/mavros/scripts/install_geographiclib_datasets.sh
colcon build --symlink-install --packages-up-to mavlink mavros px4_bringup
```
## Simulation
### build simulation worksapce
```bash
MAKEFLAGS="-j4" colcon build --symlink-install \
--packages-up-to \
mavlink mavros mavros_extras px4_bringup vins_estimator usb_cam \
--cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
```
+23
View File
@@ -0,0 +1,23 @@
services:
sim_dev:
image: sim_dev:gz_harmonic
container_name: sim_dev_container
runtime: nvidia # 启用 NVIDIA GPU 支持
stdin_open: true # 保持标准输入打开
tty: true # 分配一个伪终端
privileged: true # 特权模式,允许访问所有 /dev 设备
ports:
- 2222:22 # ssh server
environment:
- DISPLAY=${DISPLAY}
- NVIDIA_DRIVER_CAPABILITIES=all
volumes:
- /dev/dri:/dev/dri
- ${HOST_WS}:/workspace
- ${DATASET}:/dataset
- /tmp/.X11-unix:/tmp/.X11-unix
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
+18
View File
@@ -0,0 +1,18 @@
services:
sim_dev:
image: sim_dev:gz_harmonic
container_name: sim_dev_container
volumes:
- ~/simulation_ws:/simulation_ws
- /tmp/.X11-unix:/tmp/.X11-unix
- /mnt/wslg:/mnt/wslg
- /usr/lib/wsl:/usr/lib/wsl
environment:
- DISPLAY=${DISPLAY}
- WAYLAND_DISPLAY=${WAYLAND_DISPLAY}
- XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}
- PULSE_SERVER=${PULSE_SERVER}
devices:
- /dev/dxg
- /dev/dri/card0
- /dev/dri/renderD128
@@ -0,0 +1,69 @@
FROM osrf/ros:jazzy-desktop-full AS builder
ARG DEBIAN_FRONTEND=noninteractive
# catkin-tools
RUN apt-get update && apt-get install -y \
ca-certificates \
gnupg \
sudo \
curl \
wget \
&& rm -rf /var/lib/apt/lists/*
# PX4 dependencies
WORKDIR /root
RUN wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/ubuntu.sh \
&& wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/requirements.txt \
&& chmod +x /root/ubuntu.sh \
&& ./ubuntu.sh \
&& rm -rf /var/lib/apt/lists/* \
&& rm /root/requirements.txt /root/ubuntu.sh
# COPY requirements.txt /requirements.txt
# COPY ubuntu.sh /ubuntu.sh
# RUN /ubuntu.sh && rm -rf /var/lib/apt/lists/* && rm /requirements.txt /ubuntu.sh
# for WSL2 GPU Support
ENV LD_LIBRARY_PATH=/usr/lib/wsl/lib
RUN apt update && apt install -y \
mesa-utils \
vainfo \
mesa-va-drivers \
vim \
net-tools \
openssh-server \
libasio-dev \
python3-future \
libgeographiclib-dev \
ros-jazzy-eigen-stl-containers \
ros-jazzy-diagnostic-updater \
ros-jazzy-rmw-zenoh-cpp \
ros-jazzy-ros-gz \
&& rm -rf /var/lib/apt/lists/*
# ceres
WORKDIR /root
RUN apt update && apt install -y \
libgoogle-glog-dev \
libgflags-dev \
libatlas-base-dev \
libeigen3-dev \
libsuitesparse-dev \
&& rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/ceres-solver/ceres-solver/archive/refs/tags/2.1.0.tar.gz \
&& tar -zxf 2.1.0.tar.gz \
&& cd ceres-solver-2.1.0 \
&& mkdir build && cd build \
&& cmake .. -DCXSPARSE=OFF \
&& make install -j4 \
&& rm -rf /root/ceres-solver-2.1.0 /root/2.1.0.tar.gz
# spdlog
RUN wget https://github.com/gabime/spdlog/archive/refs/tags/v1.12.0.tar.gz \
&& tar -zxf v1.12.0.tar.gz \
&& cd spdlog-1.12.0 \
&& mkdir build && cd build \
&& cmake .. -DSPDLOG_BUILD_SHARED=ON \
&& make install -j \
&& rm -rf /root/v1.12.0.tar.gz /root/spdlog-1.12.0
+28
View File
@@ -0,0 +1,28 @@
argcomplete
cerberus
coverage
empy>=3.3,<4
future
jinja2>=2.8
jsonschema
kconfiglib
lxml
matplotlib>=3.0
numpy>=1.13
nunavut>=1.1.0
packaging
pandas>=0.21
pkgconfig
psutil
pygments
wheel>=0.31.1
pymavlink
pyros-genmsg
pyserial
pyulog>=0.5.0
pyyaml
requests
setuptools>=39.2.0
six>=1.12.0
toml>=0.9
sympy>=1.10.1
+231
View File
@@ -0,0 +1,231 @@
#! /usr/bin/env bash
set -e
## Bash script to setup PX4 development environment on Ubuntu LTS (24.04, 22.04).
## Can also be used in docker.
##
## Installs:
## - Common dependencies and tools for nuttx, jMAVSim, Gazebo
## - NuttX toolchain (omit with arg: --no-nuttx)
## - jMAVSim and Gazebo9 simulator (omit with arg: --no-sim-tools)
##
INSTALL_NUTTX="true"
INSTALL_SIM="true"
INSTALL_ARCH=`uname -m`
# Parse arguments
for arg in "$@"
do
if [[ $arg == "--no-nuttx" ]]; then
INSTALL_NUTTX="false"
fi
if [[ $arg == "--no-sim-tools" ]]; then
INSTALL_SIM="false"
fi
done
# detect if running in docker
if [ -f /.dockerenv ]; then
echo "Running within docker, installing initial dependencies";
apt-get --quiet -y update && DEBIAN_FRONTEND=noninteractive apt-get --quiet -y install \
ca-certificates \
gnupg \
gosu \
lsb-release \
software-properties-common \
sudo \
wget \
;
fi
# script directory
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# check requirements.txt exists (script not run in source tree)
REQUIREMENTS_FILE="requirements.txt"
if [[ ! -f "${DIR}/${REQUIREMENTS_FILE}" ]]; then
echo "FAILED: ${REQUIREMENTS_FILE} needed in same directory as ubuntu.sh (${DIR})."
return 1
fi
# check ubuntu version
# otherwise warn and point to docker?
UBUNTU_RELEASE="`lsb_release -rs`"
echo "Ubuntu ${UBUNTU_RELEASE}"
echo
echo "Installing PX4 general dependencies"
sudo apt-get update -y --quiet
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
astyle \
build-essential \
cmake \
cppcheck \
file \
g++ \
gcc \
gdb \
git \
lcov \
libssl-dev \
libxml2-dev \
libxml2-utils \
make \
ninja-build \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
rsync \
shellcheck \
unzip \
zip \
;
# Python3 dependencies
echo
echo "Installing PX4 Python3 dependencies"
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}')
REQUIRED_VERSION="3.11"
if [[ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" == "$REQUIRED_VERSION" ]]; then
python3 -m pip install --break-system-packages -r ${DIR}/requirements.txt
else
if [ -n "$VIRTUAL_ENV" ]; then
# virtual environments don't allow --user option
python -m pip install -r ${DIR}/requirements.txt
else
python3 -m pip install --user -r ${DIR}/requirements.txt
fi
fi
# NuttX toolchain (arm-none-eabi-gcc)
if [[ $INSTALL_NUTTX == "true" ]]; then
echo
echo "Installing NuttX dependencies"
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
automake \
binutils-dev \
bison \
build-essential \
flex \
g++-multilib \
gcc-arm-none-eabi \
gcc-multilib \
gdb-multiarch \
genromfs \
gettext \
gperf \
kconfig-frontends \
libelf-dev \
libexpat-dev \
libgmp-dev \
libisl-dev \
libmpc-dev \
libmpfr-dev \
libncurses-dev \
libncurses6 \
libncursesw6 \
libnewlib-arm-none-eabi \
libstdc++-arm-none-eabi-newlib \
libtool \
libunwind-dev \
pkg-config \
screen \
texinfo \
u-boot-tools \
util-linux \
vim-common \
;
if [ -n "$USER" ]; then
# add user to dialout group (serial port access)
sudo usermod -aG dialout $USER
fi
fi
# Simulation tools
if [[ $INSTALL_SIM == "true" ]]; then
echo
echo "Installing PX4 simulation dependencies"
# General simulation dependencies
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
bc \
;
# Gazebo / Gazebo classic installation
if [[ "${UBUNTU_RELEASE}" == "18.04" || "${UBUNTU_RELEASE}" == "20.04" ]]; then
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
# Update list, since new gazebo-stable.list has been added
sudo apt-get update -y --quiet
# Install Gazebo classic
if [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then
gazebo_classic_version=9
gazebo_packages="gazebo$gazebo_classic_version libgazebo$gazebo_classic_version-dev"
else
# default and Ubuntu 20.04
gazebo_classic_version=11
gazebo_packages="gazebo$gazebo_classic_version libgazebo$gazebo_classic_version-dev"
fi
elif [[ "${UBUNTU_RELEASE}" == "21.3" ]]; then
echo "Gazebo (Garden) will be installed"
echo "Earlier versions will be removed"
# Add Gazebo binary repository
sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable jammy main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
sudo apt-get update -y --quiet
# Install Gazebo
gazebo_packages="gz-garden"
else
# Expects Ubuntu 22.04 > by default
echo "Gazebo (Harmonic) will be installed"
echo "Earlier versions will be removed"
# Add Gazebo binary repository
sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
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
sudo apt-get update -y --quiet
# Install Gazebo
gazebo_packages="gz-harmonic libunwind-dev"
if [[ "${UBUNTU_RELEASE}" == "24.04" ]]; then
gazebo_packages="$gazebo_packages cppzmq-dev"
fi
fi
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
dmidecode \
$gazebo_packages \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
libeigen3-dev \
libgstreamer-plugins-base1.0-dev \
libimage-exiftool-perl \
libopencv-dev \
libxml2-utils \
pkg-config \
protobuf-compiler \
;
if sudo dmidecode -t system | grep -q "Manufacturer: VMware, Inc." ; then
# fix VMWare 3D graphics acceleration for gazebo
echo "export SVGA_VGPU10=0" >> ~/.profile
fi
fi