Skip to content
Merged
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
74 changes: 32 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,65 @@
FROM ubuntu:20.04
FROM ubuntu:24.04

ENV WORKSPACE_DIR /root
ENV FIRMWARE_DIR ${WORKSPACE_DIR}/Firmware
ENV FIRMWARE_DIR ${WORKSPACE_DIR}/px4
ENV SITL_RTSP_PROXY ${WORKSPACE_DIR}/sitl_rtsp_proxy

ENV DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
ENV DISPLAY :99
ENV LANG C.UTF-8

RUN apt-get update && \
apt-get install -y wget lsb-release && \
apt-get -y autoremove && \
apt-get clean autoclean && \
rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*

RUN 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" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null


RUN apt-get update && \
apt-get install -y bc \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, for the speed factor. Maybe it explains why it didn't fail in my tests 😇. Adding it back!

apt-get install -y \
bc \
cmake \
gazebo11 \
curl \
git \
gnupg \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
iproute2 \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still need the ip route command for

echo "$(ip route | awk '/default/ { print $3 }')"

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, not sure why I removed it!

libeigen3-dev \
libgazebo11-dev \
libgstreamer-plugins-base1.0-dev \
libgstrtspserver-1.0-dev \
libopencv-dev \
libroscpp-dev \
protobuf-compiler \
python3-jsonschema \
python3-numpy \
lsb-release \
python3-pip \
unzip \
xvfb && \
apt-get -y autoremove && \
python3-empy \
python3-future \
python3-jinja2 \
python3-jsonschema \
python3-kconfiglib \
python3-yaml \
xvfb

RUN pip3 install --break-system-packages pyros-genmsg

RUN curl https://packages.osrfoundation.org/gazebo.gpg --output /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" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null && \
apt-get update && \
apt-get install -y gz-harmonic

RUN apt-get -y autoremove && \
apt-get clean autoclean && \
rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*

RUN pip3 install --upgrade pip && \
pip3 install empy==3.3.4 \
future \
jinja2 \
kconfiglib \
packaging \
pyros-genmsg \
toml \
pyyaml

RUN git clone https://github.com/PX4/PX4-Autopilot.git ${FIRMWARE_DIR}
RUN git -C ${FIRMWARE_DIR} checkout main
RUN git -C ${FIRMWARE_DIR} submodule update --init --recursive

COPY edit_rcS.bash ${WORKSPACE_DIR}
COPY entrypoint.sh /root/entrypoint.sh
RUN chmod +x /root/entrypoint.sh

RUN ["/bin/bash", "-c", " \
cd ${FIRMWARE_DIR} && \
DONT_RUN=1 make px4_sitl gazebo && \
DONT_RUN=1 make px4_sitl gazebo \
"]
COPY fix-cmake-build.patch ${FIRMWARE_DIR}
RUN git -C ${FIRMWARE_DIR} apply fix-cmake-build.patch

COPY sitl_rtsp_proxy ${SITL_RTSP_PROXY}
RUN cmake -B${SITL_RTSP_PROXY}/build -H${SITL_RTSP_PROXY}
RUN cmake --build ${SITL_RTSP_PROXY}/build

RUN cmake -DCONFIG=px4_sitl_default -B${FIRMWARE_DIR}/build -S${FIRMWARE_DIR} && \
cmake --build ${FIRMWARE_DIR}/build

COPY edit_rcS.bash ${WORKSPACE_DIR}
COPY entrypoint.sh /root/entrypoint.sh
RUN chmod +x /root/entrypoint.sh

ENTRYPOINT ["/root/entrypoint.sh"]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ where `192.168.0.10` should be replaced by the IP listening on the QGC port 1455

### Exposing a video stream

When running with the Typhoon H480 vehicle (with `-v typhoon_h480`), a video stream will be available. Expose it with e.g. `-p 8554:8554`, like so:
When running with the `gz_x500_mono_cam` vehicle (with `-v gz_x500_mono_cam`), a video stream will be available. Expose it with e.g. `-p 8554:8554`, like so:

```
docker run --rm -it -p 8554:8554 jonasvautherin/px4-gazebo-headless:1.16.0 -v typhoon_h480
docker run --rm -it -p 8554:8554 jonasvautherin/px4-gazebo-headless:1.16.0 -v gz_x500_mono_cam
```

You can then access it with something like:

```
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/live ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
```

### Run with another start location
Expand Down
2 changes: 1 addition & 1 deletion edit_rcS.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ else
API_PARAM=${API_PARAM:-"-t ${HOST}"}
fi

CONFIG_FILE=${FIRMWARE_DIR}/build/px4_sitl_default/etc/init.d-posix/px4-rc.mavlink
CONFIG_FILE=${FIRMWARE_DIR}/build/etc/init.d-posix/px4-rc.mavlink

sed -i "s/mavlink start \-x \-u \$udp_gcs_port_local -r 4000000/mavlink start -x -u \$udp_gcs_port_local -r 4000000 ${QGC_PARAM}/" ${CONFIG_FILE}
sed -i "s/mavlink start \-x \-u \$udp_offboard_port_local -r 4000000/mavlink start -x -u \$udp_offboard_port_local -r 4000000 ${API_PARAM}/" ${CONFIG_FILE}
7 changes: 3 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function get_ip {

OPTIND=1 # Reset in case getopts has been used previously in the shell.

vehicle=iris
world=empty
vehicle=gz_x500
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dakejahl, @julianoes: does gz_x500 have a camera that would enable the video stream? If not, which airframe does have a camera? I used to do it with typhoon_h480, but it doesn't seem to give me a video stream with gazebo harmonic 🤔

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this. The x500_mono_cam is what you're looking for

make px4_sitl gz_x500_mono_cam

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this.

Don't be! It was a draft PR that I finally tested today, and tagged you with this question. So you actually answered really fast 😬.

Let me try gz_x500_mono_cam then, thanks a lot!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I missed it the first time you tagged me. I have failed you. I have failed my family. I have been a bad chatgpt.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works, on the host I can run

gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/live ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink

and get the video 🙌. Thanks for the help!

world=default

while getopts "h?v:w:" opt; do
case "$opt" in
Expand Down Expand Up @@ -65,5 +65,4 @@ Xvfb :99 -screen 0 1600x1200x24+32 &
${SITL_RTSP_PROXY}/build/sitl_rtsp_proxy &

source ${WORKSPACE_DIR}/edit_rcS.bash ${IP_API} ${IP_QGC} &&
cd ${FIRMWARE_DIR} &&
HEADLESS=1 make px4_sitl gazebo_${vehicle}__${world}
HEADLESS=1 PX4_SIM_MODEL=${vehicle} PX4_GZ_WORLD=${world} ${FIRMWARE_DIR}/build/bin/px4
12 changes: 12 additions & 0 deletions fix-cmake-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/src/lib/events/CMakeLists.txt b/src/lib/events/CMakeLists.txt
index fcdb971f64..cdf366199c 100644
--- a/src/lib/events/CMakeLists.txt
+++ b/src/lib/events/CMakeLists.txt
@@ -57,6 +57,7 @@ add_custom_command(OUTPUT ${generated_events_px4_file}
${PX4_SOURCE_DIR}/Tools/px4events/jsonout.py
${PX4_SOURCE_DIR}/Tools/px4events/srcparser.py
${PX4_SOURCE_DIR}/Tools/px4events/srcscanner.py
+ modules__uxrce_dds_client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why is that? Should we try to fix that properly on the PX4 side (at least for the next release)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was failing otherwise 🤷. I didn't investigate further 😇

Copy link
Owner Author

@JonasVautherin JonasVautherin Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the patch, it fails to build with (still on latest main):

[ 16%] Built target ver_gen
gmake[2]: *** No rule to make target 'src/modules/uxrce_dds_client/dds_topics.h', needed by 'events/px4.json'.  Stop.
gmake[1]: *** [CMakeFiles/Makefile2:22205: src/lib/events/CMakeFiles/events_json.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

Maybe I'm missing some magic that the Makefile does before calling CMake? I don't know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd. How is this different in docker? 🤔

Copy link
Owner Author

@JonasVautherin JonasVautherin Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am building with cmake, I think because I didn't manage to run the make wrapper just for building (it's running immediately). So I do this:

RUN cmake -DCONFIG=px4_sitl_default -B${FIRMWARE_DIR}/build -S${FIRMWARE_DIR} && \
    cmake --build ${FIRMWARE_DIR}/build

I could imagine that the Makefile does some more magic before calling CMake, including this module stuff?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to not make it run:
make px4_sitl

prebuild_targets # ensure all generated source files exist
COMMENT "Generating px4 event json file from source"
)
2 changes: 1 addition & 1 deletion sitl_rtsp_proxy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main(int argc, char* argv[]) {
GstRTSPServer* server = gst_rtsp_server_new();
g_object_set(server, "service", "8554", NULL);

std::string launch_string = "udpsrc port=5600 caps=application/x-rtp,encoding-name=(string)H264 ! rtph264depay ! rtph264pay name=pay0";
std::string launch_string = "udpsrc port=5600 caps=application/x-rtp,encoding-name=(string)H264,payload=(int)96 ! rtph264depay ! rtph264pay name=pay0";
GstRTSPMediaFactory* factory = gst_rtsp_media_factory_new();
gst_rtsp_media_factory_set_launch(factory, launch_string.c_str());
gst_rtsp_media_factory_set_shared(factory, true);
Expand Down
Loading