Download ArduPilot Source Code and Set Up Toolchain in Windows Subsystem for Linux
This section helps you complete the Download ArduPilot code and Set Up Toolchain on WSL step of the Hardware Setup process (using the Hardware Setup screens).
To build and customize the ArduPilot firmware for your hardware, you need to download the ArduPilot source code and set up the required toolchain within Windows Subsystem for Linux (WSL) for the corresponding airframe you selected on the previous screen.

If you select ArduCopter, the UAV Toolbox Support Package for
ArduPilot Autopilots uses ArduPilot Copter firmware v4.6.2. If you
select ArduPlane, it uses ArduPilot Plane firmware
v4.6.2.
Download ArduPilot Source Code
Perform these steps to download ArduPilot® source code.
Start the WSL distribution.
Open Command prompt and execute:
wsl -d <distributionName>
Replace
<distributionName>with the name of your WSL Ubuntu 22.04 distribution.
Choose the clone location.
To clone the repository to your home directory, execute:
cd ~
Or, to clone to a specific folder, execute:
cd <path>
Replace
<path>with your desired directory.
Clone the ArduPilot repository.
In the opened WSL distribution execute:
git clone https://github.com/ArduPilot/ardupilot.git
This creates an
ardupilotfolder with the source code.Checkout the required firmware branch.
Navigate to the cloned directory:
cd ardupilot
Based on your selection in the previous screen, execute one of the following:
For Copter firmware:
git checkout Copter-4.6.2
For Plane firmware:
git checkout Plane-4.6.2
If you get an error about the branch/tag not existing, execute:
git fetch origin --tags
Update submodules.
git submodule update --init --recursive
This ensures all dependencies and submodules are set up.
Set up the toolchain.
Execute the following command to install required dependencies
Tools/environment_install/install-prereqs-ubuntu.sh -y
Then, update your environment variables.
. ~/.profile
Click Next in the Download ArduPilot code and Set Up Toolchain on WSL screen.
Note
If you need to restart the hardware setup process, Start MATLAB® and navigate to Add-Ons -> Manage Add-Ons and click the setup icon next to UAV Toolbox Support Package for ArduPilot Autopilots.
Note
When switching the airframe, you must discard any local firmware changes before running the git checkout command. Otherwise, the checkout might fail with an error.
If you encounter a checkout issue, follow one of the workflows mentioned below. Unless you have made custom changes to the firmware that you want to keep, it is recommended to use the second option (discard changes).
Option1: Stash the changes
Navigate to the
ardupilotfolder inside your WSL2 Ubuntu 22.04 distribution.cd ~/ardupilot
Stash your changes:
git stash push -m "auto-stash-for-switching"
To revert back the changes (restore old checkout version).
Execute this command to get the stash ID for "auto-stash-for-switching"
git stash list
Then execute:
git stash pop stash@{<stashIndex>}Replace
<stashIndex>with the stash ID you obtained from the previous command.
Option2: Discard the Changes (Recommended)
Navigate to the
ardupilotfolder inside your WSL2 Ubuntu 22.04 distributioncd ~/ardupilot
Discard all local changes:
git reset --hard
This will reset your working directory to match the last commit of the current branch, discarding any changes.
Remove any untracked files (such as new files added by Simulink):
git clean -f
Update the tag history (if the checkout tag is not available):
git fetch --all --tags
Next Steps
Clone and run the provided scripts to patch ArduPilot for UAV Toolbox.