A custom dockerfile designed to containerize PX4 on Ubuntu 22.04 with ROS2 and Gazebo Garden
- Preinstalls ROS2, PX4, and Gazebo Garden
- Creates an organized workspace ready for PX4 Development with dependency management
- Can be directly developed on via VSCode
Docker Desktop comes with all components of Docker that are necessary to make our docker containers, as well as a nice UI to help us manage our containers and images. https://www.docker.com/products/docker-desktop/
They should both be within the same folder so that the Dockerfile can access the installation scripts
This should take quite some time to retrieve all the dependencies from their sources; the expected size is 10.84 gb due to all the dependencies.. When finished, you should be able to see the new image under the images tab of docker desktop. The -t uav sets tags the docker image with the name 'uav' so it's more recognizable. The period denotes the build context which is the directory where the docker file is located.
docker build -t uav .This makes a docker container based off of the custom docker image. -it prevents the container from shutting down as soon as it is started up. -name allows us to set the name of the container, which I set to hummingbird. If you're using Linux, run the following command.
docker run -it --env="DISPLAY=:0" --name=hummingbird uavIf you're using Windows run this command. You can find your ip by typing 'ipconfig' in the terminal:
docker run -it --env="DISPLAY=<your ip>:0" --name=hummingbird uavIf you're using MacOS run this command.
docker run -it --net=host --privileged --env="DISPLAY=host.docker.internal:0" --name=hummingbird uavIf the script repeatedly fails on px4.sh or ros2wkspc.sh you can comment these sections out, build the docker image, and then download PX4 and the PX4 ROS2 workspace manually. This should help with debugging any unexplained errors and you can do hot fix commands intermittently to get the same final output setup.
docker exec -it hummingbird /bin/bashdocker start hummingbird
docker stop hummingbirddocker ps -aIf you see Vmmem wsl consuming a lot of memory after the docker container has been shut down but get a permission denied error when trying to shut it down, you can run the following command to kill wsl processes in Windows:
wsl --shutdownX11 forwarding is a feature that allows the graphical user interface of an application running on a remote machine to be displayed on a local machine's display. It is required to use GUI applications on remote machines or containerized GUI applications. While using linux as your host OS, the X11 server is shared between the docker container and the host machine so no external configuration is required. On windows and MacOS this X11 server must be configured manually with third party software.
Download a X11 server implementation. Many sites recommended Xming but this did NOT work for me and the distribution hasn't been updated since 2013. Instead I used VcXSrv. It can be downloaded here: https://sourceforge.net/projects/vcxsrv/
Launch XLaunch. This window should come up. Click next.
Continue with Start no client and click next.
In Extra settings click Disable access control as well as clipboard and Native opengl.
Click Save Configuration and save it to your desktop. This way you won't need to redo the launch process and can start a server with the config shortcut.
While there might be another built in way to do this, I keep task manager open and close the VcXsrv server through task manager. Watching task manager can help keep track of the high RAM usage that comes with Xservers. The Xserver will also shut down when the computer running it shuts down and does not automatically start up.
In progress. The recommended Xserver software is Xquartz.
The download can be found here: https://www.xquartz.org/.
Step 2: Go to Settings > Security and check Allow connections from network clients. Then restart Xquartz.
This opens up the host machine to recieve display data from the docker container via the localhost network.
xhost +localdocker run -it --net=host --privileged --env="DISPLAY=host.docker.internal:0" --name=hummingbird uavMacOS should automatically close the Xserver when Xquartz is shut down. You can run 'xhost -local' to undo the hosting access you gave to your network from your computer to be safe.
If you have visual studio code on the host machine, you can directly develop on the docker container. I found it to be objectively the best experience for development on the container and it doesn't consume container resources heavily as using an IDE on the container.
Follow these instructions to download Visual Studio Code: https://code.visualstudio.com/download
Step 5: VSC will display a list of running Docker containers. Choose the container you're developing on
Once you select your container VSC should open a window so you can develop on this container like it's your machine. The output should look like the example below, and you can open a terminal to test it by right clicking on the file explorer. You can see I used the cat command on my file test.txt and it outputted the result to the terminal. You can also see the profile in the terminal is that of the docker container user (it won't be root in our project workspace). This makes it easier to run multiple processes as well for our project!
MicroXRCEAgent udp4 -p 8888Run default:
make px4_sitl gz_x500 Copying a custom environment into PX4:
docker cp <source_file> <docker_container_id>:/home/user/work/PX4-Autopilot/Tools/simulation/gz/worlds/<source_file>Run Advanced Settings:
PX4_SYS_AUTOSTART=4001 PX4_GZ_MODEL=x500 PX4_GZ_WORLD=model ./build/px4_sitl_default/bin/px4 source /opt/ros/humble/setup.bash
source install/local_setup.bash
ros2 launch px4_ros_com sensor_combined_listener.launch.py








