Archived: Building ArduPilot for APM2.x on Windows with Arduino

Warning

ARCHIVED ARTICLE

ArduPilot no longer supports Arduino or AVR.

This article shows how to build ArduPilot for APM2.x targets on Windows, using the Arduino toolchain.

Tip

An alternative approach is covered in Building ArduPilot for APM2.x on Windows with Make.

Warning

Copter 3.3 firmware (and later) and builds after Plane 3.4.0 no longer fit on APM boards. Plane, Rover and AntennaTracker builds can still be installed at time of writing but you can no longer build APM2.x off the master branch (you will need to build off a supported release branch).

The last Copter firmware that can be built on APM 2.x can be downloaded from here.

In addition to the above restrictions, this article covers:

  • From Copter version 3.1 to version 3.2.1

  • From Plane version 2.76 to version 3.4.0

  • APM 2.0, 2.5, and 2.6 only

Install Git-SCM

  1. Download and run the install file from: https://git-scm.com/download/win

  2. Follow the screenshots below to make your selections during install.

    ../_images/git_setup_wizard_welcome.jpg ../_images/git_setup_wizard_license.jpg
  3. On the Welcome screen and then again on the License screen click the Next button

    ../_images/git_setup_wizard_components.jpg ../_images/git_setup_wizard_view_release_notes.jpg
  4. On the Select Components screen click on the Next button, then click the Finish button

    ../_images/git_setup_wizard_replace_in_use_files.jpg ../_images/git_setup_wizard_installing_files.jpg
  5. Click the Next button in the Replacing in Use Files Screen, then wait for Git to finish loading

    ../_images/git_setup_wizard_set_line_endings.jpg ../_images/git_setup_wizard_run_git_command_prompt.jpg
  6. Select the Checkout Windows item and the Next button then Select the Run Git from Windows item and the Next button.

Download source

  1. In your C: drive, make a folder called GIT (C:\GIT on my computer). Navigate to the folder Windows Explorer

    ../_images/git_setup_create_git_directory.jpg
  2. Right click anywhere in the folder and click git bash

    ../_images/git_bash_command_prompt.jpg

    This screen will come up

    ../_images/git_bash_prompt.jpg
  3. In this screen type

    git clone --recurse-submodules git://github.com/ArduPilot/ardupilot.git
    
    ../_images/git_bash_clone_ardupilot.jpg

    When it is finished it should look like this….

    ../_images/git_bash_clone_ardupilot_complete.jpg
  4. A little more initialisation is required for the source code. Initialise referenced dependencies like this:

    cd ardupilot
    git submodule update --init --recursive
    

Install MHV_AVR_Tools to its default location

  1. Download and install the MHV_AVR Tools: https://firmware.ardupilot.org/Tools/Arduino/MHV_AVR_Tools_20121007.exe

    ../_images/mhv_avr_tools_installer_welcome.jpg ../_images/mhv_avr_tools_installer_choose_start_menu_folder.jpg
  2. Select the Next button in the setup wizard screen then select the Install button for MHV AVR Tools

    ../_images/mhv_avr_tools_installer_choose_components.jpg ../_images/mhv_avr_tools_installer_choose_destination_folder.jpg
  3. Check both items in the Choose Components Screen and select Next then select Next again to install to the default location

    ../_images/mhv_avr_tools_installer_license_agreement.jpg
  4. Select the I Agree button on the License Agreement screen.

Install ArduPilot-Arduino

Download and unzip the ArduPilot Arduino package: https://firmware.ardupilot.org/Tools/Arduino/ArduPilot-Arduino-1.0.3-gcc-4.8.2-windows.zip

This can be unzipped directly to the C: drive or C:\Program Files\

Note

This is a special ArduPilot Arduino package which contains gcc 4.8.2

Configure Arduino

  1. Go to your Arduino folder

  2. Double click the Arduino icon

    ../_images/arduino_icon.jpg
  3. When Arduino opens, go to the file menu

    ../_images/arduino_menu_preferences.jpg
  4. Select preferences

    ../_images/arduino_preferences_dialog.png
    • Set Sketchbook location to your ArduPilot directory in your GIT folder.

    • Set verbose for both compile and upload

    • And DO NOT check for updates on start-up… (Remember, this is a special version just for ArduPilot.)

  5. Click OK and close Arduino

Connect your APM to your USB

  1. Re-open ArduPilot and under the file tab, click on sketchbook, then the program you wish to load onto your APM2.x (for this example we will use Copter, though the others use the same methods.

    ../_images/arduino_tools_sketchbook_copter.jpg
  2. Once this is loaded, click on the ArduPilot tab, and select ArduPilot mega 2.x out of the HAL options.

    ../_images/arduino_tools_target_apm2.jpg
  3. Then click the “Tools” tab and select “Arduino Mega 2560 or Mega ADK” from the “Board” tab.

    ../_images/arduino_tools_select_target_board.jpg
  4. Next select the Tools tab again, and set the “Serial Port” to the one your APM is connected to.

    ../_images/arduino_tools_serial_port.jpg
  5. In my case it was COM4, but check under device manager / Ports to find out on your system.

    ../_images/arduino_tools_confirm_correct_com_port_in_drivers.jpg

Configure Copter

  1. Click on the APM_Config.h file tab.

  2. Set your frame type (e.g. #define FRAME_CONFIG HEXA_FRAME) in order to get the right image for your frame

  3. Enable or disable the features you wish in this file.

    Ie if you want to compile with auto tune disabled, simply un-comment the line

    //# AUTOTUNE DISABLED // disable the auto tune functionality to save 7k of flash
    

    To disable Auto Tune which is enabled by default you would change it to:

    # AUTOTUNE DISABLED // disable the auto tune functionality to save 7k of flash
    

    The commented out options are the NON-default and all that needs to be done is to un-comment them to use them instead.

  4. Save this file and select the file Copter.

    At this point you are ready to compile.

    I would choose Verify for the first attempt.

    ../_images/arduino_tools_verify_button.jpg

Upload to your ArduPilot

  1. Then if all is well upload to the autopilot, as shown:

    ../_images/arduino_tools_upload_ardupilot_button.png

    This may take a while…

  2. You should end up with the message as shown below.

    ../_images/arduino_tools_upload_complete_message.jpg
  3. Configure Your ArduPilot using planner, as normal.

    Warning

    The code you have just compiled is now UN-TESTED in your configuration. Please use only for testing. If you are not confident, please just use mission planner to upload pre-compiled code.

Updating your code

Please ensure that the version of code on your PC is the latest version, use git to update your code to the latest code.