joplin-mdbooks-website/content/drone-stuff/ardupilot-setup-checklist.md

237 lines
11 KiB
Markdown
Raw Normal View History

2021-01-07 16:49:18 -05:00
+++
title = "Ardupilot setup checklist"
weight = 2
sort_by = "weight"
insert_anchor_links = "right"
+++
This is a short guide for setting up [ArduPilot](https://ardupilot.org/) on a flying wing. I use an Omnibus F4 that was previously set up for INAV (so motor on 1, elevons on 3/4), so most of this guide will be geared to that. If you use a different controller, your mileage may vary.
You should keep the [full list of ArduPilot parameters](https://ardupilot.org/plane/docs/parameters.html) open, for your reference while tuning.
2021-02-23 16:30:56 -05:00
## Building ArduPilot
Because building ArduPilot is a bit complicated, I've written a short script that uses Docker to build AP in a controlled environment.
2021-02-27 15:37:16 -05:00
Copy it from here, save it to a file called `docker_build.sh` in the root of the ArduPilot repo, and run it with `docker_build.sh <your board>`. Output files will be stored in `build/<yourboard>/bin/`, and you can flash them with the [INAV configurator](https://github.com/iNavFlight/inav-configurator/releases) by putting your board in DFU mode and uploading the `arduplane_with_bl.hex` file:
2021-02-23 16:30:56 -05:00
```bash
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ne 1 ]
then
echo "No board supplied, run as ./docker_build.sh <board name> or ./docker_build.sh list"
exit 1
fi
BOARD=$1
2021-02-27 15:37:16 -05:00
cd "$(git rev-parse --show-toplevel)"
2021-02-23 16:30:56 -05:00
git submodule update --init --recursive
git checkout Dockerfile
2021-02-23 17:24:21 -05:00
echo "RUN pip install intelhex" >> Dockerfile
2021-02-27 15:37:16 -05:00
echo 'ENV PATH="/home/ardupilot/.local/bin:/usr/lib/ccache:/ardupilot/Tools/autotest:/opt/gcc-arm-none-eabi-6-2017-q2-update/bin:${PATH}"' >> Dockerfile
2021-02-23 17:24:21 -05:00
2021-02-23 16:30:56 -05:00
docker build . -t ardupilot
git checkout Dockerfile
docker run --rm -it -v "$(pwd)":/ardupilot ardupilot:latest ./waf configure --board="$BOARD"
docker run --rm -it -v "$(pwd)":/ardupilot ardupilot:latest ./waf build
2021-02-27 15:37:16 -05:00
2021-02-23 16:30:56 -05:00
```
2021-01-07 16:49:18 -05:00
## Hardware setup
The values in this section are specific to the Omnibus F4, but the settings aren't, so you'll usually need to adjust your outputs to your specific configuration but you probably won't need to skip many of the steps here.
2021-03-03 19:24:46 -05:00
- [ ] Connect GPS to UART 6 (SERIAL4). You don't need to do anything else for GPS, it should work out of the box.
2021-01-08 12:49:20 -05:00
- [ ] Connect Fport to a UART. I chose UART 3 (SERIAL2). If you want to use UART 1, you should set the RC input jumper to PPM on the F4 to disconnect the SBUS inverter from the pin.
2021-01-07 16:49:18 -05:00
- [ ] To get Fport working with UART 3, you need to set `BRD_ALT_CONFIG=1`, to get UART 3 to act like a UART instead of I2C on the Omnibus F4.
2021-01-08 12:49:20 -05:00
- [ ] Change the board orientation with `AHRS_ORIENTATION`.
2021-01-07 16:49:18 -05:00
- [ ] Set the following for Fport on UART 3:
```
2021-03-03 19:24:46 -05:00
SERIAL2_PROTOCOL = 23 (RCIN)
2021-01-07 16:49:18 -05:00
SERIAL2_BAUD=115
2021-03-03 19:24:46 -05:00
SERIAL2_OPTION=4
2021-01-16 15:34:47 -05:00
RSSI_TYPE=3
2021-01-07 16:49:18 -05:00
```
2021-04-17 18:40:15 -04:00
- [ ] Once Fport works, reverse the elevator with `RC2_REVERSED=1`.
2021-01-07 16:49:18 -05:00
- [ ] Set up your servo functions and trims:
```
SERVO1_FUNCTION=70
SERVO1_MIN=1000
SERVO1_MAX=2000
SERVO1_TRIM=1000
SERVO3_FUNCTION=77
SERVO3_MIN=1000
SERVO3_MAX=2000
SERVO3_TRIM=1500
SERVO4_FUNCTION=78
SERVO4_MIN=1000
SERVO4_MAX=2000
SERVO4_TRIM=1500
```
All these values are necessary, because usually the `SERVOn_TRIM` won't be at 1500.
- [ ] Set `SERVO_BLH_OTYPE=4` for DShot150 and `SERVO_BLH_MASK=1` to enable it for the motor.
- [ ] Set `COMPASS_ENABLE=0` if you don't have a compass, otherwise calibrate it (not detailed here).
- [ ] Set `TERRAIN_ENABLE=0` to get rid of the terrain warning.
- [ ] Set the board orientation with `AHRS_TRIM_Y` and check that FBWA mode flies level.
2021-01-08 12:49:20 -05:00
- [ ] If you don't use logging, set `LOG_BACKEND_TYPE=0`.
- [ ] Check the preflight errors to warn on, though usually leaving it set to "all" is fine.
2021-01-07 17:02:38 -05:00
- [ ] Set up the OSD (Mission Planner has a very nice UI for that). Keep in mind that ArduPilot's airspeed and windspeed estimation are quite good, so you may want to add those even if you don't have an airspeed sensor. You may also want to set up multiple screens, I use a potentiometer to switch between the four different screens of the OSD:
2021-01-07 16:49:18 -05:00
- One with everything on (for debugging), which is also set as the `OSD_ARM_SCR`/`OSD_DSARM_SCR`.
- One with the artificial horizon, system messages and some basic info like RSSI, battery, ground speed and altitude.
- A minimal screen with just system messages and battery/RSSI/speed/altitude.
- A screen with just system messages, for when I want to enjoy the scenery.
2021-03-03 19:24:46 -05:00
2021-01-07 16:49:18 -05:00
## Radio-related
- [ ] Set your radio channels to AETR and run the radio calibration in the calibration section of ArduPilot.
2021-03-13 12:06:12 -05:00
- [ ] Add a killswitch to the radio that overrides the mode to manual and the throttle to 0.
This way it's really easy to kill the motor right away, but you still need to go through the arming procedure to get the motor running (thanks to Michel Pastor for this great idea).
2021-01-07 17:02:38 -05:00
- [ ] Set up modes, possibly having switches override the mode channel to the mode you want.
What I do is set a given channel as the mode channel, and make that channel always output -100% on the radio. Then, I set up channel overrides for each switch, keeping in mind that overrides in OpenTX are executed in order (so the bottom override has the highest priority).
2021-03-07 14:27:40 -05:00
That way, I set MANUAL/ACRO/FBWA to be lowest priority (on the same switch), then CRUISE to override those, then LOITER, RTL in that order. Finally, I add AUTO to a switch on its own channel.
Keep in mind that whatever mode you have on its own channel might be overridden if you flick a different switch.
2021-03-13 12:06:12 -05:00
Unfortunately, the way the mode system in AP works, there's no good way to have a list of prioritized modes, which would be ideal though now I have opened a PR to extend the modes to 12, which solves this).
2021-01-07 16:49:18 -05:00
## Auto modes
- [ ] Set `SERVO_AUTO_TRIM=1` so the aircraft trims itself while flying.
- [ ] Set `FS_SHORT_ACTN`/`FS_SHORT_TIMEOUT`/`FS_LONG_ACTN`/`FS_LONG_TIMEOUT`. I tend to disable the short action and set long to RTL.
- [ ] Set `RTL_CLIMB_MIN=30` so the aircraft climbs first before starting to return to home.
- [ ] Set `ACRO_LOCKING=1` to avoid drifting when you aren't moving the sticks.
- [ ] Change `AUTOTUNE_LEVEL` according to how aggressive you want the tune.
2021-01-07 20:03:07 -05:00
- [ ] Set `ACRO_PITCH_RATE`/`ACRO_ROLL_RATE` according to your craft.
2021-01-08 12:49:20 -05:00
- [ ] Set `THR_PASS_STAB=1` so you have total throttle control in ACRO/FBWA/STABILIZE.
2021-03-05 15:05:33 -05:00
- [ ] Set `ARSPD_FBW_MIN`/`ARSPD_FBW_MAX` to the minimum and maximum airspeed you want auto modes to fly (see the TECS tuning guide below for details).
2021-01-24 10:33:00 -05:00
- [ ] Set `MIN_GNDSPD_CM` so the craft makes an effort to return even under high winds. WARNING: Might make throttle pulse or have other unwanted side-effects.
2021-01-07 20:03:07 -05:00
## Auto takeoff
- [ ] Change `TKOFF_THR_MAX` to the desired max takeoff throttle.
- [ ] Change `TKOFF_ALT` to the altitude you want takeoff to reach.
2021-01-16 15:34:47 -05:00
- [ ] Set `THR_SUPP_MAN=1` so you can manually set the autolaunch "idle" throttle (before the throw).
2021-01-07 20:37:34 -05:00
- [ ] Set `TKOFF_THR_MINACC=18` for the takeoff throw to activate takeoff with a minimum of 2g.
- [ ] set `TKOFF_LVL_PITCH` to your desired angle (20 is a good value).
- [ ] Set `TKOFF_THR_DELAY` to the number of deciseconds that you want the motor to wait before it starts up.
- [ ] Potentially set `TKOFF_THR_SLEW=127` to make the throttle spin up to full faster (within 0.8 sec).
2021-01-07 16:49:18 -05:00
2021-03-03 19:24:46 -05:00
## In the field
- [ ] Run an autotune.
- [ ] Fly in FBWA and see if you're gaining/losing altitude. Pitch up/down to fly level, check the pitch on the OSD, and use the formula `old_value+pitch*π/180` to get the new value (in radians).
2021-01-07 16:49:18 -05:00
## Tuning the TECS
2021-03-05 15:05:33 -05:00
To tune the TECS, a helpful resource is the [TECS tuning guide](https://ardupilot.org/plane/docs/tecs-total-energy-control-system-for-speed-height-tuning-guide.html).
Make sure you have run an autotune beforehand, and continue with the tuning below.
2021-01-07 16:49:18 -05:00
2021-03-05 15:05:33 -05:00
In tuning, there are two stages:
2021-01-07 16:49:18 -05:00
2021-03-05 15:05:33 -05:00
- Take measurements in the field.
- Set parameters on the bench, based on your measurements.
### In the field
You should perform the measurements in four stages, all in the FBWA mode:
#### Fly straight
Fly straight and note down:
- [ ] A comfortable cruise speed (in km/h).
- [ ] The throttle percentage at that cruise speed.
- [ ] The maximum speed you want to be flying at (in km/h).
- [ ] The throttle percentage at that maximum speed.
- [ ] Start a turn at the maximum bank angle (full roll deflection to one side) and note the slowest speed you can fly at without stalling.
2021-03-05 16:48:15 -05:00
- [ ] Turn throttle to 0 and pitch down a bit so you don't stall.
Note the minimum amount of down-pitch required to keep you from stalling (this should only be in the 1-3 degree ballpark).
2021-03-05 15:05:33 -05:00
#### Fly up
Set the throttle to the maximum throttle percentage from the previous step and start slowly pulling back on pitch until your airspeed equals your "comfortable cruise speed" from the previous step.
Note down:
- [ ] The pitch angle (in degrees).
- [ ] The vertical speed from the variometer (in m/s).
#### Fly down
Set the throttle to 0 and start pushing on the pitch stick until your airspeed equals your "comfortable cruise speed" from the previous step.
Note down:
- [ ] The pitch angle (in degrees).
- [ ] The vertical speed from the variometer (in m/s).
#### Fly down more
Keep the throttle at 0 and pitch down until you reach your desired maximum speed from step 1.
Note down:
- [ ] The pitch angle (in degrees).
- [ ] The vertical speed from the variometer (in m/s).
You're done with this step.
### On the bench
After you have the above measurements, you're ready to tune things.
For the level flight measurements:
- [ ] Set `TRIM_ARSPD_CM` to your "comfortable cruise speed".
- [ ] Set `TRIM_THROTTLE` to your cruise throttle percentage.
- [ ] Set `ARSPD_FBW_MAX` to something a bit less than the maximum airspeed you achieved in level flight.
- [ ] Set `THR_MAX` to the throttle percentage at max speed.
- [ ] Set `ARSPD_FBW_MIN` to the slowest speed you could turn at without stalling (maybe go a bit higher for some margin).
2021-03-05 16:48:15 -05:00
- [ ] Set `STAB_PITCH_DOWN` to the pitch angle that keeps you from stalling.
2021-03-05 15:05:33 -05:00
For the ascent measurements:
- [ ] Set `TECS_PITCH_MAX` to the pitch angle you measured.
- [ ] Set `TECS_CLMB_MAX` to the climb rate you measured.
For the descent measurements:
- [ ] Set `TECS_SINK_MIN` to the descent rate you measured.
For the max descent measurements:
- [ ] Set `TECS_PITCH_MIN` to the pitch angle you measured.
- [ ] Set `TECS_SINK_MAX` to the descent rate you measured.
Afterwards:
- [ ] Set `LIM_PITCH_MAX` to something higher than `TECS_PITCH_MAX`.
This is the maximum pitch you'll be achieving in FBWA.
- [ ] Set `LIM_PITCH_MIN` to something lower than `TECS_PITCH_MIN`.
This is the minimum pitch you'll be achieving in FBWA.
That's it!
2021-01-07 16:49:18 -05:00
_(Many thanks to Michel Pastor for his help with everything in this note.)_
* * *
<p style="font-size:80%; font-style: italic">
2021-04-17 18:40:15 -04:00
Last updated on April 10, 2021. For any questions/feedback,
2021-01-07 16:49:18 -05:00
email me at <a href="mailto:hi@stavros.io">hi@stavros.io</a>.
</p>