Automatic MOT_THST_EXPO estimation lua script


I’m after volunteers to test a new lua script which can automaticaly find the right MOT_THST_EXPO for a copter, saving the need to use a thrust stand setup.
Finding the right expo for your motors/prop/ESC combination is an important part of getting a good tune for ArduPilot, but the only method we have had so far is to do a full thrust stand test, which is quite time consuming and thrust stands can be quite expensive, especially for coaxial propeller setups (on an X8 multirotor you need a dual-prop thrust stand to do it properly).
I’ve developed a new lua script which runs a series of pulse tests to find the expo automatically with a couple of minutes of flying. You can see the pattern of pulses it uses in the above graph, which shows the throttle in green and the acceleration produced in red.
I need volunteers so we can test this script on a wide variety of vehicles and make sure it performs reliably.
To test you will need an updated firmware which adds a new lua binding from this PR:

if you are not comfortable building yourself then you can ask me to build the firmware for you if you tell me what build you need (what board and any special options such as bdshot).
Once you have the firmware loaded then you will need to load this lua script:

Then refresh parameters and set the parameter EXPO_ENABLE to 1.
Then setup an RCn_OPTION to be 300 for some 3 position switch. The 3 switch positions are:

  • low: disable tuning
  • mid: enable tuning
  • high: save tune

To run the test takeoff and hover at about 10 meters over the ground, and switch to GUIDED mode (or takeoff in GUIDED mode). Then move the 3 position switch to the mid position.
The copter will do a series of thrust tests, pulsing the throttle up and down by 25% while measuring the acceleration. After each pair of tests it will send a text message with the adjustment to the expo, like this:
image
the convergence criteria is still being improved, so if it hasn’t finished after about 3 minutes then you can abort and send me the log.
Please fly with LOG_BITMASK=65535 so I can see the PIDs.
There is more documentation here:

For discussion on discord see the thread “automatic MOT_THST_EXPO estimation” under the copter dev channel.
When you send me logs, if you also have thrust stand test data then please send that as well, and also let me what what prop/ESC/motor you are using and the weight of the copter is.
Note that this is for copter only for now. I will extend it to quadplanes soon.
Thanks!

13 Likes

I’ll contribute Tridge. Can you please send me a build for a Matek H743-bdshot? I have 2 different quads I can test that on.

@dkemxr thanks!
firmware is here: http://uav.tridgell.net/ExpoTest/copter-MatekH743-bdshot-expo-test3.apj
lua script here:
ardupilot/VTOL-expo.lua at pr-expo-estimator · tridge/ardupilot · GitHub
instructions here:
ardupilot/VTOL-expo.md at pr-expo-estimator · tridge/ardupilot · GitHub

OK! The 3 -position switch is a typical Low/Mid/High PWM mix?

yes. You can also use the AUX function buttons in MissionPlanner

just pushed a bug fix thanks to testing by @rmackay9 - please use latest lua from link

1 Like

Just tested it on a Foxtech hybrid 56kg hexa. Worked nicely!

1 Like

Hey @tridge, I’ll test this on my Y6 if you like. I dorked my build environment up yesterday but if you could build copter master with this PR I’ll happily test… MatekH743. I’ll fix my build env again tomorrow or this weekend…

Here’s a Google Drive folder with builds for KakuteH7Mini-Nand, MatekH743, MatekH743-bdshot, CubeOrange-bdshot, and CubeOrangePlus-bdshot, up to date with Tridge’s fork/branch as of a few minutes ago.

https://drive.google.com/drive/folders/1QzJJyZJZVrbIRXbgCltVvMDEOfQETgUL?usp=share_link

If there are further commits, I will update (or remove) the files.

I plan to test on 3 Copters this week as well.

2 Likes

I see the EXPO_PULSE_TIME is set to 1.5s at default and the guide states .25. I’m trying it 1st on a 5" with a high thrust/weight. Which is best to try 1st?

1.5s is correct, I will fix the guide

I’d appreciate if some of the tests are done with both MOT_OPTIONS=0 and MOT_OPTIONS=1. The new MOT_OPTIONS=1 setting uses the raw battery voltage for thrust compensation which I think will produce a more accurate result, but I’d like to see how much difference it makes.

1 Like

Hi Tridge,
For that Foxtech Hybrid have you got the before and after expo values plus related parameters , MOT_PWM_MIN and MOT_PWM_MAX
And what Props, motors and ESCs does it have?

I’m watching this all with interest and very curious to see how the new real-world MOT_THST_EXPO fits in with our calculated values.

@xfacta sure.
The original estimate from the expo curve in the wiki was 0.83. I changed that to 0.75 based on past conversations with @Leonardthall that such high expos are unlikely even with big props.
The tune did this:

2023-05-11 18:27:10.081 Expo: starting tune with expo=0.75
2023-05-11 18:27:17.918 Expo: 0.72 accel=(-2.16,2.47) err=-0.133
2023-05-11 18:27:27.570 Expo: 0.69 accel=(-2.26,2.46) err=-0.095
2023-05-11 18:27:37.850 Expo: 0.67 accel=(-2.13,2.51) err=-0.128
2023-05-11 18:27:47.865 Expo: 0.68 accel=(-2.35,2.64) err=0.040
2023-05-11 18:27:57.716 Expo: 0.68 accel=(-2.25,2.64) err=-0.003
2023-05-11 18:27:57.716 Expo: finished tune 0.68
2023-05-11 18:28:11.882 Expo: saved at 0.68

so it got 0.68 after 50 seconds tuning.
One thing of note is they had MOT_OPTIONS=0. That means thrust compensation uses resting voltage calculation, but resulting voltage is quite bad for sudden thrust changes. This is what happens in a pulse:


so the resting voltage went in the wrong direction. This will impact the expo, although I think on this vehicle the difference would have been small as the voltage difference as a percentage of total voltage is about 3%, so correct expo may in fact be 0.70 instead of 0.68.

they had 1000 to 2000 PWM range. It uses X9Plus motor/ESC with 36" props.

Highly interesting! Thanks for the info.
Regarding the high expo and large props, I have been thinking of altering the calcs in the Initial Params to suit a maximum value of around 0.8 since I also noticed Leonard mentioned that.
EDIT - what I mean is change the curve, formula, a bit rather than just setting a hard maximum - this new estimation script will be great info for that, so I’m holding off until I know more.

I like the informative output from the script too - nice!

You might have to get the Foxtech Hybrid owner to run that test again, not just with
MOT_OPTIONS,1
but also that motor ESC combo is supposed to use

MOT_PWM_MIN,1100
MOT_PWM_MAX,1940

which will affect the expo and also

MOT_SPIN_ARM
MOT_SPIN_MIN

so they will need to use MissionPlanner motor test to check for new values of MOT_SPIN_ARM and MIN
and hover thrust will need a bit of time to relearn (but maybe it wont be too different and they wont notice)

I’m not trying to tell you anything you wouldn’t already know, just putting down all my thoughts :slight_smile: and maybe it will help others too.

1 Like

interesting, where did you find that info? I can ask them if they re-calibrated the ESCs.
they had MOT_SPIN_ARM=0.1 and MOT_SPIN_MIN=0.15

ahh, found this on hobbywing site:

Yes that’s it - and the indication is they dont calibrate either. I’ve seen them before…
Using the default MOT_PWM_MIN/MAX can clearly work, but I prefer to see the correct values and know that only valid values could be commanded - and all the MOT_SPIN_ARM/MIN and EXPO values would be reasonable and not skewed.

EDIT:
For those following - making any changes to a working Foxtech Hybrid shouldnt be taken lightly - it can be hard enough to get these flying nice and stable. And they are big, heavy and expensive. I’m sure the owner would be acutely aware

thanks Shawn. In this case I’m working directly with Foxtech helping them tune the Thor210 for initial release as part of support in the ArduPilot partners program. They forward mavlink to me via support.ardupilot.org and I monitor the tuning remotely. I have asked them about the PWM range.

The script ran fine. Sent you a couple logs for a sub 250g 5"
I’ll give a 7" a go next.