This is the material that will be used during the PX4 Developer Summit 2022.
This repository contains everything that the participant will need to follow & try out the demos presented during the workshop!
- Friday June 24, 2022 10:50am - 12:30pm CDT
- Lone Star A, JW Mariott Austin Texas
Have you struggled with getting started in PX4 Development? Did you ever get stuck after running the example in the user doc and couldn't develop what you wanted? This workshop explains all the essential concepts and knowledge you need to get started with PX4 Autopilot Development!
In this workshop, you will learn the core concepts in PX4 like NuttX, Modules, Drivers, uORB, and Parameters. We will show you how to set up a development environment using Docker and program a small custom module, compile it, and test using SITL (Software-In-The-Loop Simulation) to verify its behavior and intuitively understand how a module works.
We will also construct a more advanced module that will require more advanced concepts like Work Queue, Scheduling, MAVLink, and more. With this process, you will gain tangible insight into constructing a proper module that does more than one task. Finally, we will demonstrate uploading the custom modules into actual Hardware.
We will also share tips and tricks that will make your PX4 development experience more pleasant, and we will stick around to answer as many questions as possible in the time we have.
In order to follow the Workshop without delay, you must have the following prerequisites satisfied: Click the links on the right of each condition that you don't satisfy
- Have Git installed: https://git-scm.com/downloads
- Have Docker installed: https://docs.docker.com/get-docker/
- Have the Docker image for PX4 development ready
- Do:
docker pull px4io/px4-dev-ros-melodic:latest
- Do:
- Have QGC installed: https://docs.qgroundcontrol.com/master/en/getting_started/download_and_install.html
Workshop content start here!
Official PX4 Architecture Documentation.
You can learn briefly about the concept of an Operating System here. Or if you feel like it, here's a more in-depth explanation on Operating System.
PX4-Autopilot holds the NuttX related files the platform/nuttx
folder
In the nuttx/src
folder, you can find commonly used OS-level px4 commands like: px4_task_spawn_cmd
There are 2 submodules inside the nuttx/nuttX
[folder]:
The nuttx/NuttX/apps
submodule handles:
- Shells (MAVLink Shell utilizes this)
The nuttx/NuttX/nuttx
submodule handles:
- Task Scheduling
- IO resource management
- Networking
- File System
- Hardware level abstraction (Drivers)
All the PX4-Autopilot modules are located in the src/modules
folder.
Official PX4 Modules Documentation
You can check out the colorful and interactive uORB graph here!
We will be following PX4 Docker Documentation
Follow the instructions here: https://docs.docker.com/get-docker/
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
- It is important that you
cd
into the PX4-Autopilot directory as we will map the current directory where Command prompt is at as the PX4-Autopilot directory in the Docker container!
Here, you can either pull it from the docker hub or load it from the USB file that is supplied during the workshop.
How to pull from internet: docker pull px4io/px4-dev-ros-melodic:latest
How to load from a USB drive tar file: docker load -i .\px4-dev-ros-melodic_latest.tar
.
Note, the path you supply should be where the Docker Image TAR file is located in your device.
You first need to create a running Docker container
docker run -it --privileged \
--env=LOCAL_USER_ID="$(id -u)" \
-v "$(pwd):/src/PX4-Autopilot/:rw" \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-e DISPLAY=:0 \
px4io/px4-dev-ros-melodic:latest bash
# Or, if you prefer a continuous one-line command:
docker run -it --privileged -v "$(pwd):/src/PX4-Autopilot/:rw" -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=:0 px4io/px4-dev-ros-melodic:latest bash
- If you don't have the "" around the volume mapping of the PX4-Autopilot directory, it may include a space character, which can cause error messages such as "invalid reference format: repository name must be lowercase".
- Check out the Stack Overflow answer.
Then navigate into the directory src/PX4-Autopilot
and build the px4 target px4_sitl
as an example
cd /src/PX4-Autopilot
make px4_sitl_default
This should produce a file build/px4_sitl_default/bin/px4
.
Now you have your first target built!
- All the PX4IO Docker Images
- Ubuntu PX4 Build Toolchain setup Documentation
- PX4 Docker container usage Documentation
cd /src/PX4-Autopilot
make px4_sitl_default gazebo HEADLESS=1
make px4_sitl_default jmavsim HEADLESS=1 # In case Gazebo is taking up too much resource you can try this!
- If the build process in the Docker is taking too much resource in Windows, checkout this article for a fix (for limiting the RAM usage of WSL process)
Running the docker container should automatically allow the QGC to connect!
You can either do one of the following:
- In QGC, select the 'Takeoff' button on the left panel in the main map screen, and slide to confirm takeoff command
- In PX4 terminal, type
commander takeoff
This should have your drone flying in the air! And you can see how the simulation actually works :)
Let's develop a simple module to get an understanding of how to create one of the most fundamental blocks of PX4!
This is where the custom branch for the simple module is located!
First, add the remote repository
git remote add junwoo https://github.com/junwoo091400/PX4-Autopilot.git
git remote add junwoo [email protected]:junwoo091400/PX4-Autopilot.git # In case you are using a SSH credentials for github interface
Second, fetch the branch devsummit2022_px4_fundamentals_workshop_simple_module
from the repository
git fetch junwoo devsummit2022_px4_fundamentals_workshop_simple_module
git checkout junwoo/devsummit2022_px4_fundamentals_workshop_simple_module # Checkout the branch, but you will be in a detached HEAD state!
git switch -c devsummit2022_px4_fundamentals_workshop_simple_module # Create a new local branch off of the remote branch
PX4 uses a lot of different submodules and it may become outdated once you switch to another branch and so on. Therefore it is important to update the submodules when you switch the branch!
git submodule update --init --recursive # `--init` is for initializing a submodule in case it doesn't exist at all (wasn't fetched)
make px4_sitl_default jmavsim HEADLESS=1 # Lightweight simulator!
Upload the sample mission plan file via QGC.
Does all of this run in Hardware? If so, how do we do that?
I will be using Pixhawk 4, but you can use any hardware you want that is supported by PX4! Here is the list of all of them.
For Pixhawk 4, px4_fmu-v5
is the target name!
Uploading can be done in 2 different ways:
You can refer to the Docs here, but basically you need to append upload
at the end of the make command of building the target.
make px4_fmu-v5_default upload
This method is the most convenient one, but it requires the Docker container to be able to connect to the board.
Select 'Custom' Firmware selection in the Firmware update tab, and upload! :P
'SIH Quadcopter X' from the Airframes Tab, to run simple simulation inside the hardware!
You can have the output through QGC's MAVLink Shell (Anaylize Tools tab > MAVLink Shell > Breakout panel)