Ardupilot Setup - ahiver/docs GitHub Wiki

Create Ardupilot Custom Build

https://custom.ardupilot.org/

For visual odometry EKF3, EKF3_EXTNAV, VISUALODOM features are needed.

{"selected_features": ["EKF3", "EKF3_EXTNAV", "TEMPCAL", "VISUALODOM", "SBUS Output", "BATTERY_SMBUS", "Camera", "Camera_MAVLink", "Camera_Servo", "RUNCAM", "AK09916", "BMM150", "HMC5843", "ICM20948", "IST8308", "LIS3MDL", "MMC3416", "QMC5883L", "RM3100", "MODE_BRAKE", "MODE_FLIP", "MODE_GUIDED_NOGPS", "MODE_SYSTEMID", "MODE_TURTLE", "MODE_ZIGZAG", "KILL_IMU", "FILESYSTEM_MISSION", "FILESYSTEM_PARAM", "FILESYSTEM_ROMFS", "FILESYSTEM_SYS", "UBLOX", "GENERATOR", "MSP", "MSP_COMPASS", "MSP_DISPLAYPORT", "MSP_GPS", "LED_CONTROL", "NOTIFY_NCP5623", "NOTIFY_NEOPIXEL", "NOTIFY_PROFILED", "PLAY_TUNE", "TONEALARM", "OSD", "OSD_PARAM", "OSD_SIDEBARS", "ADVANCED_FAILSAFE", "BARO_WIND_COMP", "DISPLAY", "GyroFFT", "NMEA_OUTPUT", "SDCARD_FORMATTING", "PrecLand", "PrecLand - Companion", "PrecLand - IRLock", "RC_CRSF", "RC_IBUS", "RC_Protocol", "RC_SBUS", "RC_SRXL", "RC_SRXL2", "RC_ST24", "RC_SUMD", "AIRSPEED", "BEACON", "GPS_MOVING_BASELINE", "MSP_BARO", "RPM", "RPM_ESC_TELEM", "RPM_HARMONIC_NOTCH", "RPM_PIN", "SPL06", "AUX_FUNCTION_STRINGS", "CRSF", "FrSky", "FrSky D", "FrSky SPort", "FrSky SPort PassThrough", "HIGHLAT2", "HOTT", "LTM", "SPEKTRUM", "QUAD", "SMARTAUDIO", "VIDEO_TX"], "git_hash_short": "9f9be8da0f"}

Flash Firmware using STM32CubeProgrammer

  • Hold down the board’s DFU button or temporarily bridge its “BOOT” pins, and plug in a USB cable (attached to your PC). Release button or unbridge once powered.
  • Select the connection method: USB
  • Make sure a USB port shows…that means the board is detected in DFU mode.
  • Press “Connect”
  • Then the boards cpu specifics will appear here.
  • Press “Open file” to select the “arduXXX_with_bl.hex” file you downloaded.
  • Press “Download” to flash the file to the board.

The file name will appear in the tab. https://ardupilot.org/copter/docs/common-loading-firmware-onto-chibios-only-boards.html

Tune Ardupilot with Mission Planner

Memory

Make sure that freemem > 20Kb (better 64Kb)

Decreasing memory usage:

  • Make sure IMU Batch Sampling (used for FFT analysis) is not running by setting INS_LOG_BAT_MASK = 0.
  • Try temporarily disabling logging by setting LOG_BACKEND_TYPE to 0, then returning to 1 (default) after calibrating.
  • Reduce the size of LOG_FILE_BUFSIZE. However, lowering below 16KB can introduce small gaps in the log. This may be used temporarily to download terrain or calibrate compass.
  • Disable Terrain Following temporarily by setting TERRAIN_ENABLE to 0.
  • Disable SmartRTL on Copter by setting SRTL_POINTS = 0.

Frame

Setup -> Frame Type X for inside rotation, H for outside rotation

Initial Parameters

Setup -> Initial Tune Parameters Size in inch: 7 Battery cellcount: 6

Screenshot 2023-07-31 10:37:14

Screenshot 2023-07-31 10:40:31

Accelerometer

Setup -> Accel Calibration

Calibrate Accelerometer Calibrate Level

Radio

Setup -> Radio Calibration

Channels mapping:

Channel 7 to use for flight mode control:

FLTMODE_CH = 7

RC7_OPTION = 0

Arm/Disarm switch on Channel 5:

RC5_OPTION = 153

Reverse pitch if needed:

RC2_REVERSED 1

Motors

Enable DShot600 ESC protocol

MOT_PWM_TYPE 6

Use Setup -> Mandatory Hardware -> Servo Output to adjust mapping to correspond to the selected frame

SpeedyBee f403 motors layout on ESC:

F405-V3-14

motororder-quad-x-2d

Result mapping:

Pos 1: Motor 4

Pos 2: Motor 1

Pos 3: Motor 2

Pos 4: Motor 3

Use Setup -> Optional Hardware -> Motor Test to check motor mapping

With correct mapping between position and Motor you get the following assignment:

A is forward right motor

B - backward right

C - backward left

D - forward left

Battery Monitor

Defaults are invalid for SpeedyBee f405v3

I used the following:

BATT_MONITOR = 4

BATT_VOLT_PIN = 10

BATT_CURR_PIN = 11

BATT_VOLT_MULT = 10.885

To estimate scales: Setup -> Optional Hardware -> Battery Monitor

Formula for current evaluation from Ardupilot sources:

current_amps = (_curr_pin_analog_source->voltage_average() - _cur_amp_offset) * _curr_amp_per_volt

_cur_amp_offset corresponds to BATT_AMP_OFFSET

_curr_amp_per_volt corresponds to BATT_AMP_PERVOLT

Steps I used to calculate _cur_amp_offset and _curr_amp_per_volt:

  1. Set BATT_AMP_OFFSET = 0, BATT_AMP_PERVOLT = 1

  2. Measure real current using multimeter attached between battery and fcu in two states (current_amps): disarmed and armed. Also write down corresponding battery_current value shown in ardupilot (_curr_pin_analog_source->voltage_average()).

  3. Values of battery_current will stand for corresponding _curr_pin_analog_source->voltage_average() values

  4. Solve system of equations with measured values for _curr_pin_analog_source->voltage_average() and current_amps

1690879405161

BATT_AMP_OFFSET = 0.049

BATT_AMP_PERVLT = 27.27

Flight Modes

Set channel

FLTMODE_CH = 7

https://ardupilot.org/copter/docs/parameters.html#fltmode-ch

Assign AltHold, Landing, AutoTune modes

Test Fly in stabilize mode

adjust pids if any oscilations are seen

https://ardupilot.org/copter/docs/initial-tuning-flight.html

The first priority when tuning an multirotor aircraft is to establish a stable tune, free of oscillations, that can be used to do further tests.

Arm the aircraft in STABILIZE

Increase the throttle slowly until the aircraft leaves the ground

If the aircraft starts to oscillate immediately abort the takeoff and/or land the aircraft

Reduce all the following parameters by 50%

ATC_RAT_PIT_P

ATC_RAT_PIT_I

ATC_RAT_PIT_D

ATC_RAT_RLL_P

ATC_RAT_RLL_I

ATC_RAT_RLL_D

Manual Tunning of Roll and Pitch (in case of oscillations and overshooting)

Manual tuning may be required to provide a stable tune before Autotune is run, or if Autotune does not produce an acceptable tune. The process below can be done on roll and pitch at the same time for a quick manual tune provided the aircraft is symmetrical. If the aircraft is not symmetrical, then the process should be done for roll and pitch individually.

The pilot should be especially careful to ensure that ATC_THR_MIX_MAN and MOT_THST_HOVER are set correctly before manual tuning is started.

If using Transmitter based tuning, set the minimum value of the tuning range to the current safe value and the upper range to approximately 4 times the current value.

For each axis:

  • If the vehicle already oscillates in an axis, first lower the P, D, and I terms in 50% steps until stable, before starting manual tuning.
  • Increase the D term in steps of 50% until oscillation is observed
  • Reduce the D term in steps of 10% until the oscillation disappears
  • Reduce the D term by a further 25%
  • Increase the P term in steps of 50% until oscillation is observed
  • Reduce the P term in steps of 10% until the oscillation disappears
  • Reduce the P term by a further 25%
  • Each time the P term is changed set the I term equal to the P term.

Fly in Altitude hold mode

  • MOT_HOVER_LEARN = 2

  • Take off in STABILIZE and increase altitude to 5m

  • Switch to AltHold and be ready to switch back to STABILIZE.

  • Throttle should be at middle position otherwise drone will slowly descend or ascend.

  • Ensure the aircraft has spent at least 30 seconds in hover to let the hover throttle parameter converge to the correct value.

  • Land and disarm the aircraft.

  • PSC_ACCZ_I to 2 x MOT_THST_HOVER

  • PSC_ACCZ_P to MOT_THST_HOVER

If AltHold starts to oscillate up and down the position and velocity controllers may need to be reduced by 50%

  • PSC_POSZ_P Position (vertical) controller P gain. Converts the difference between the desired altitude and actual altitude into a climb or descent rate which is passed to the throttle rate controller (1.000 to 3.000)

  • PSC_VELZ_P Velocity (vertical) controller P gain. Converts the difference between desired vertical speed and actual speed into a desired acceleration that is passed to the throttle acceleration controller (1.000 to 8.000)

Potential Problems:

  • High vibrations can lead to the copter rapidly climbing as soon as altitude hold is engaged. Copter slowly descends or climbs until the pilot retakes control in stabilize. Normally this is caused by not having the throttle stick in the mid position. This commonly happens when the pilot is switching into AltHold from a manual flight mode (like Stabilize) on a copter that does not hover at mid throttle.
  • The motors seem to stop for a moment just as AltHold is engaged but then it soon recovers. This normally occurs when the pilot enters AltHold while climbing rapidly. The target altitude is set at the moment the pilot switches into alt hold but because the vehicle is rising quickly it flies above the target. The aggressive altitude hold controller then responds by momentarily reducing the motors to near minimum until the copter begins falling back to the target altitude. The workaround is to enter AltHold while the copter is flying at a stable altitude.
  • Air pressure changes cause the vehicle to drift up or down by a couple of meters over longer period of time or for the altitude shown on the GCS to be inaccurate by a couple of meters including occasional negative altitudes (meaning altitudes below the home altitude).
  • Momentary altitude loss of 1m ~ 2m when the copter levels out after a high speed forward flight. This is caused by an aerodynamic effect which leads to a momentary low pressure bubble forming on the top of the copter where the autopilot is mounted which leads the altitude hold controller to believe it is climbing so it responds by descending. There is no cure for this behaviour at the moment although increasing the EK2_ALT_M_NSE parameter reduces the effect but increases the change of Common Problem #1 listed above. The EK2_ALT_M_NSE parameter has a range from 0.1 to 10.0 and allows increments of 0.1.
  • Altitude hold becomes erratic when the vehicle is close to the ground or during landing. This can be caused by the barometer being affected by pressure changes created by prop-wash. The solution is to move the autopilot out of the prop wash effect or shield it within an appropriately ventilated enclosure. https://learn.parallax.com/elev-8-v3-quadcopter-assembly-guide/step-16-shield-sensors-and-install-fc-cover

After First flight without goggles

Increase thrust/attitude ratio from 0.1 to make throttle more responsive. Comfortable value depends on drone weight. ATC_THR_MIX_MAN = 0.3 (careful, too high values may cause high jump of the copter on start)

PSC_ACCZ_P = MOT_THST_HOVER * 2 = 0.4

PSC_ACCZ_I = MOT_THST_HOVER * 2 = 0.4

Adjust MOT_SPIN_ARM and MOT_SPIN_MIN

Autotune PIDs

AutoTune attempts to automatically tune the Stabilize P, Rate P and D, and maximum rotational accelerations to provide the highest response without significant overshoot.

There a number of problems that can prevent AutoTune from providing a good tune including:

  • Strong wind
  • High levels of gyro noise
  • Non-linear ESC response caused by incorrect value of MOT_THST_EXPO
  • Flexible frame or payload mount
  • Overly flexible vibration isolation mount
  • Very low setting for MOT_SPIN_MIN
  • Overloaded propellers or motors

Setup before Autotune

  1. Set up one flight mode switch position to be AltHold.
  2. Set an RC channel Auxiliary Function to AutoTune to allow you to turn the auto tuning on/off with a switch. You can also set the AUTOTUNE flight mode as a mode on your flight mode switch to activate AutoTune
  3. Remove the camera gimbal or any other parts of the frame that could wobble in flight
  4. Select which combination of axis (roll, pitch, yaw) you wish to tune using the AUTOTUNE_AXES Autotune axis bitmask 1-byte bitmap of axes to autotune 0 - Roll, 1 - Pitch, 2 - Yaw, 3 - YawD
  5. Set the autotune’s aggressiveness using the AUTOTUNE_AGGR parameter AUTOTUNE_AGGR Defines the bounce back used to detect size of the D term. (0.05 to 0.10) (0.1=agressive, 0.075=medium, 0.050=weak), normally start with the default 0.1.
  6. For large copters (with props at least 13inch or 33cm diameter) set the Rate Roll and Pitch filters to 10hz, these are: ATC_RAT_RLL_FLTT, ATC_RAT_RLL_FLTD, ATC_RAT_PIT_FLTT, ATC_RAT_PIT_FLTD, (in Copter-3.4 they are ATC_RAT_RLL_FILT and ATC_RAT_PIT_FILT)
  7. It is recommended to enable Battery Voltage Scaling of PID gains MOT_BAT_VOLT_MAX, MOT_BAT_VOLT_MIN, MOT_BAT_CURR_MAX

Only MOT_BAT_VOLT_MAX, MOT_BAT_VOLT_MIN are useful for Autotune

How to invoke Autotune in AltHold

  • Take off and put the copter into AltHold mode at a comfortable altitude.
  • Face the vehicle so that it will twitch at 90degrees from the direction the wind is blowing (i.e. if tuning Roll first, point the vehicle into the wind)
  • Switch to Autotune
  • Throttle, Roll, Pitch sticks should be in the middle positions
  • When the tune completes the copter will change back to the original PID gains.
  • Switch off Autotune then switch on Autotune to test the tuned PID gains
  • switch out of AUTOTUNE flight mode, to fly using the original PID gains
  • If you are happy with the autotuned PID gains switch back into AUTOTUNE flight mode and land and disarm to save the PIDs permanently.
  • If you DO NOT like the new PIDS, switch out of AUTOTUNE flight mode, to return to the original PIDs. The gains will not be saved when you disarm.
  • If you find after performing an AutoTune that the vehicle feels overly twitchy when flying Stabilize, AltHold or PosHold (but ok in more autonomous modes like Loiter, RTL, Auto) try increasing the ATC_INPUT_TC parameter to 0.25.

This smooths out the pilot’s input. Alternatively try reducing the AUTOTUNE_AGGR parameter (it should always be in the range 0.05 to 0.10) and try again.

If the vehicle feels sloppy after the AutoTune, try increasing the AUTOTUNE_AGGR parameter as high as 0.10 and attempt the autotune again.

ATC_INPUT_TC - Attitude control input time constant. Low numbers lead to sharper response, higher numbers to softer response (seconds 0 - 1) 0.5 - Very Soft, 0.2 - Soft, 0.15 - Medium, 0.1 - Crisp, 0.05 - Very Crisp

It is possible to invoke Autotune in PositionHold but better results in AltHold

AutoTune performs a weak position hold if invoked from Loiter or PosHold flight modes (as opposed to AltHold) while doing an autotune. If using the AUTOTUNE flight mode, this weak position hold is also used.

The altitude is maintained with the altitude hold controller so the vehicle will attempt to hold its current altitude when the sticks are placed with 10% of mid-throttle. It will climb or descend at up to 2.5m/s (this speed is adjustable with the PILOT_SPEED_UP and PILOT_SPEED_DN. The acceleration used to establish these speeds is set by PILOT_ACCEL_Z.

PILOT_SPEED_UPPilot maximum vertical speed ascending (50 to 500) The maximum vertical ascending velocity the pilot may request in cm/s 250 PILOT_SPEED_DN Pilot maximum vertical speed descending (0 to 500ce) The maximum vertical descending velocity the pilot may request in cm/s. If 0 PILOT_SPEED_UP value is used. 0 PILOT_ACCEL_Z The vertical acceleration used when pilot is controlling the altitude (cm/s2) 50 to 500 250

If Autotune fails

If AutoTune has failed you will need to do a manual tune.

Some signs that AutoTune has been successful are (besides DataFlash logs and Ground Control Station messages):

  • An increase in the values of ATC_ANG_PIT_P and ATC_ANG_RLL_P. ATC_ANG_RLL_P: Roll axis angle controller P gain Roll axis angle controller P gain. Converts the error between the desired roll angle and actual angle to a desired roll rate 3.000 to 12.000 4.5 ATC_ANG_PIT_P Pitch axis angle controller P gain Pitch axis angle controller P gain. Converts the error between the desired pitch angle and actual angle to a desired pitch rate 3.000 to 12.000 4.5 ATC_RAT_PIT_D and ATC_RAT_RLL_D are larger than AUTOTUNE_MIN_D. AUTOTUNE_MIN_D Defines the minimum D gain 0.001 to 0.006 0.001 AutoTune will attempt to tune each axis as tight as the aircraft can tolerate.

In some aircraft this can be unnecessarily responsive.

A guide for most aircraft:

ATC_ANG_PIT_P should be reduced from 10 to 6

ATC_ANG_RLL_P should be reduced from 10 to 6

ATC_ANG_YAW_P should be reduced from 10 to 6

ATC_RAT_YAW_P should be reduced from 1 to 0.5

ATC_RAT_YAW_I:[ ATC_RAT_YAW_P] (https://ardupilot.org/copter/docs/parameters.html#atc-rat-yaw-p-ac-attitudecontrol-multi) x 0.1

These values should only be changed if AutoTune produces higher values. Small aerobatic aircraft may prefer to keep these values as high as possible

The full list of parameters that may be updated by AutoTune

  • Roll angular P gain ATC_ANG_RLL_P
  • Roll rate P, I and D gains ATC_RAT_RLL_P, ATC_RAT_RLL_I, ATC_RAT_RLL_D
  • Roll max acceleration ATC_ACCEL_R_MAX
  • Pitch angular P gain ATC_ANG_PIT_P
  • Pitch rate P, I and D gains ATC_RAT_PIT_P, ATC_RAT_PIT_I, ATC_RAT_PIT_D
  • Pitch max acceleration ATC_ACCEL_P_MAX
  • Yaw angular P gain ATC_ANG_YAW_P
  • Yaw rate P, I gain ATC_RAT_YAW_P, ATC_RAT_YAW_I, ATC_RAT_YAW_D
  • Yaw rate filter ATC_RAT_YAW_FLTT, ATC_RAT_YAW_FLTE (in AC3.6: ATC_RAT_YAW_FLT)
  • Yaw max acceleration ATC_ACCEL_Y_MAXRoll
  • pitch axis rate feed-forward is enabled (ATC_RATE_FF_ENAB)

Be advised that AutoTune will engage from Stabilize, so don’t accidentally flip your AutoTune switch until you are in AltHold and ready to begin the procedure.

As a general rule, for Pitch and Roll, P and I should be equal, and D should be 1/10th P. For Yaw, I should be 1/10th P and D = 0, in most cases.

Common Problems

  • If the vehicle will not start tuning (i.e. it won’t twitch) even though it is in AutoTune mode then the problem is likely that the roll, pitch, yaw or throttle sticks are not exactly in the middle.

It may help to increase the deadzone on the RC input by increasing RC1_DZ, RC2_DZ, RC3_DZ and RC4_DZ to 50 (or higher).

RC#_DZ: RC dead-zone¶ PWM dead zone in microseconds around trim or bottom 0 to 200PWM in microseconds 20

  • If the AutoTune produces a sloppy vehicle, try increasing the AUTOTUNE_AGGR parameter (should never be above 0.1) and perform the AutoTune again.

  • If the AutoTune produces an overly twitchy vehicle try reducing the AUTOTUNE_AGGR parameter (should never be below 0.05) and perform the AutoTune again.

Dataflash logging ATUN (auto tune overview) and ATDE (auto tune details) messages are written to the dataflash logs.

Calibrate Compass

Test PosHold, RTL modes

Mavlink connection to uart

Ardupilot:

SERIAL3_PROTOCOL = 2 (MavLink 2)

SERIAL3_BAUD = 921

Test fly (hover) in AltHold or Loiter until the hover thrust value has been learned. You will know this has happened when it is hovering with the throttle at mid stick. Or you can hover in any mode and then review the log and look at the average CTUN>Tho value.

Set IMU rate to 300 hz

QGC set SR0_RAW_SENS to 300. QGC does not show valid value, but parameter is really changed

  • Mission Planner updates SR0_RAW_SENS value to default 2Hz on connection to ardupilot.

Visual Odemtry Setup

Enable Visual Odometry through Mavlink

VISO_TYPE = 1

Disable fusing of velocities

EK3_SRC_OPTIONS = 0

Assign 3 position switch to EKF Source:

RC8_OPTION = 90 (EKF Pos Source)

Set first EKF source to GPS:

EK3_SRC1_POSXY = 3 (Primary horizontal position from GPS)

EK3_SRC1_VELXY = 3 (Primary horizontal velocity from GPS)

EK3_SRC1_POSZ = 1 (Primary vertical position from barometer)

EK3_SRC1_VELZ = 3 (Primary vertical velocity from GPS)

EK3_SRC1_YAW = 1 (Primary yaw/heading from compass)

Set second EKF source to External Navigation:

EK3_SRC2_POSXY = 6 (Secondary horizontal position from External Nav)

EK3_SRC2_VELXY = 6 (Secondary horizontal velocity from External Nav)

EK3_SRC2_POSZ = 1 (Secondary vertical position from barometer)

EK3_SRC2_VELZ = 6 (Secondary vertical velocity from External Nav)

EK3_SRC2_YAW = 6 (Secondary yaw/heading from External Nav)

#VTX + SmartAudio https://www.youtube.com/watch?v=eFqASNHHWD0

VTX: Foxeer Extreme Reaper https://download.foxeer.com/Foxeer_Reaper_Extreme_VTX_Manual.pdf

Solded to T1 on F405V3

T1 corresponds to SERIAL1

SERIAL1_BAUD = 4800

SERIAL1_OPTIONS = 4 (Half Duplex)

SERIAL_PROTOCOL = 37 (SmartAudio)

VTX_ENABLED = Enable

vtx

vtx2