Skip to content

A custom dockerfile designed to containerize PX4 on Ubuntu 22.04 with ROS2 and Gazebo Garden

Notifications You must be signed in to change notification settings

saiccoumar/PX4_Docker_Config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

PX4_Docker_Config

A custom dockerfile designed to containerize PX4 on Ubuntu 22.04 with ROS2 and Gazebo Garden

Features:

  • Preinstalls ROS2, PX4, and Gazebo Garden
  • Creates an organized workspace ready for PX4 Development with dependency management
  • Can be directly developed on via VSCode

Build Instructions:

Step 1: Install Docker Desktop and run Docker Desktop.

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/

Step 2: Download the docker file and the install scripts from this repository.

They should both be within the same folder so that the Dockerfile can access the installation scripts

Step 3: Open terminal and run 'docker build'

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 .

Step 4: Run 'docker run'.

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 uav

If 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 uav

If you're using MacOS run this command.

docker run -it --net=host --privileged --env="DISPLAY=host.docker.internal:0" --name=hummingbird uav

If 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.

Container Management.

If you exit out of the docker container in terminal you can re-enter with 'docker exec'

docker exec -it hummingbird /bin/bash

To start or stop the docker container you can use 'docker start' and 'docker stop'

docker start hummingbird
docker stop hummingbird

Docker container status can be managed from the terminal with 'docker ps'

docker ps -a

If 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 --shutdown

X11 Forwarding:

X11 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.

Windows X11 Server setup:

Step 1:

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/

Step 2:

Launch XLaunch. This window should come up. Click next.

Step 3:

Continue with Start no client and click next.

Step 4:

In Extra settings click Disable access control as well as clipboard and Native opengl.

Step 5:

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.

Closing the Xserver:

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.

MacOS X11 Server setup:

In progress. The recommended Xserver software is Xquartz.

Step 1: Download a X11 server implementation.

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.

image

Step 3: run xhost in terminal.

This opens up the host machine to recieve display data from the docker container via the localhost network.

xhost +local

Step 4: Run docker run

docker run -it --net=host --privileged --env="DISPLAY=host.docker.internal:0" --name=hummingbird uav

Closing the Xserver:

MacOS 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.

Connecting Visual Studio Code to the Docker container:

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.

Step 1: Download VSC

Follow these instructions to download Visual Studio Code: https://code.visualstudio.com/download

Step 2: Download Dev Containers extension

Screenshot 2023-06-27 193614

Step 3: Press Ctrl+Shift+P or Cmd+Shift+P to open your command pallete in VSC

Screenshot 2023-06-27 193814

Step 4: Search for "Attach to Running Container..."

Screenshot 2023-06-27 193932

Step 5: VSC will display a list of running Docker containers. Choose the container you're developing on

Screenshot 2023-06-27 194108

Ex:

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!

GetImage

Starting Your First Project:

Run the Microagent:

MicroXRCEAgent udp4 -p 8888

Start Gazebo:

Run 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 

Start ROS2:

source /opt/ros/humble/setup.bash  
source install/local_setup.bash  
ros2 launch px4_ros_com sensor_combined_listener.launch.py

I modified it and updated the scripts generalize the use and to match the PX4 ROS2 user guide found here: https://docs.px4.io/main/en/ros/ros2_comm.html

About

A custom dockerfile designed to containerize PX4 on Ubuntu 22.04 with ROS2 and Gazebo Garden

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published