Contenuto principale

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.

  1. Start the WSL distribution.

    • Open Command prompt and execute:

      wsl -d <distributionName>

      Replace <distributionName> with the name of your WSL Ubuntu 22.04 distribution.

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

  3. Clone the ArduPilot repository.

    • In the opened WSL distribution execute:

      git clone https://github.com/ArduPilot/ardupilot.git

    This creates an ardupilot folder with the source code.

  4. 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
  5. Update submodules.

    git submodule update --init --recursive

    This ensures all dependencies and submodules are set up.

  6. Set up the toolchain.

    1. Execute the following command to install required dependencies

      Tools/environment_install/install-prereqs-ubuntu.sh -y
    2. Then, update your environment variables.

      . ~/.profile
  7. 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

  1. Navigate to the ardupilot folder inside your WSL2 Ubuntu 22.04 distribution.

    cd ~/ardupilot
  2. Stash your changes:

    git stash push -m "auto-stash-for-switching"
  3. 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)

  1. Navigate to the ardupilot folder inside your WSL2 Ubuntu 22.04 distribution

    cd ~/ardupilot
  2. 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.

  3. Remove any untracked files (such as new files added by Simulink):

    git clean -f
  4. 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.