Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Cloning Instructions (tested on Linux):
It is assumed that you have a working development environment:
git  clone  https://bitbucket.org/TheOtherCliff/librepilot.git  autotune
cd  autotune
git  checkout  theothercliff/LP-76_Port_Autotune_from_dRonin
git  checkout   theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code
make  build_sdk_install  install   (I avoid this by sym linking my global downloads and tools directories into this directory, so whatever you need to do for downloads and tools)
nice -n15 make  -j4  gcs  revolution  revonano     (the 4 is however many real CPU cores you have to keep all of them busy, it still works even if it is wrong)  (gcs might take 30 minutes to build)  (or remove 'nice -n15' which says to run it at low priority in case you want to do something else with the computer while it is making the software)
./build/librepilot-gcs_release/bin/librepilot-gcs  gcs   (runs the GCS that you just built) (in Linux that is ./b <tab> l (lower case L) <tab> b <tab> <tab>)

Updating an old clone (tested on Linux)

With GCS running and firmware built, go to the Firmware page, press Halt.  Wait about 15 seconds for the Flash button to appear.  Also, it should automatically select firmware that matches your flight controller.  Press Flash.  You will also have to erase settings and run the setup wizard again.  With that complete, you need to do your calibrations before anything else.

Flight Mode Switch setup:
Note that when AutoTune is complete, it writes the calculated PIDs into the destination stabilization (PID) bank which by default is configured to be bank 2.  The standard procedure has you flying the AutoTune mode on bank 1 and writing the new PIDs to bank 2.

The recommended setup for running AutoTune uses a 3 position Flight Mode Switch.  With this, you can take off and fly Attitude mode with default PIDs, run AutoTune with default PIDs and fly Attitude mode with new PIDs, all without using the GCS:
Pos#1 - Attitude mode using bank 1
Pos#2 - AutoTune using bank 1 with SystemIdentSettings.DestinationPidBank set to 2 (that is the default)
Pos#3 - Attitude mode using bank 2 (bank 2 is where the tuned PIDs are written by default)
PID bank 1 should have default PIDs or something that is at least known to fly without oscillations.
This setup can all be done at home, and everything else can be done at the flying field, without using the GCS.

With this FMS (Flight Mode Switch) setup, you always have Pos#1 to fall back on.  Use Pos#1 to recover from any bad situation or to start over and run AutoTune again.

 An alternate FMS setup for a 2 position FMS removes the ability to fly with default PIDs once you have run AutoTune:
Pos#1 - Attitude mode using bank 2 (bank 2 is where the tuned PIDs are written by default)
Pos#2 - AutoTune using bank 1 with SystemIdentSettings.DestinationPidBank set to 2 (that is the default)
PID bank 1 should have default PIDs or something that is at least known to fly without oscillations.
PID bank 2 start out with the same PIDs as bank 1, but the PIDs will be changed by AutoTune.

It is possible to arm in Pos#1, then switch to Pos#2 and immediately take off before the AutoTune shaking starts, if your tuned PIDs don't work and you want to retune.

Remove anything that is expensive or fragile (e.g. cameras and antennas, but understand that transmitters must remain unpowered any time they don't have an antenna attached) from the multicopter if this is your first experience with AutoTune on this multicopter.  Be aware though, that you eventually need to tune in "flight trim".  Things like cameras and FPV gear that even moderately affect the total weight of the copter should be mounted to get a good tune.

Arm and take off in Pos#1 which is Attitude mode with default (or other known-good) PIDs.  These PIDs must not oscillate for the tuning to work.  Switch to Pos#2 which is AutoTune mode which is also configured to use default (or other known-good) PIDs.  After a few seconds the copter begins to shake.  Fly it smoothly.  Don't let the copter touch anything (such as the ground) while tuning is running.  60 seconds after that, the shaking stops and the tuning is complete.  The PIDs have already been written to the destination PID bank, but are only stored in RAM memory at this point.  The standard procedure is to land and disarm which writes the PIDs to permanent storage.  The PIDs will be written to permanent settings if you disarm before powering off.  The PIDs will be discarded if the copter is powered off without disarming it.

Switch to Pos#3 (Pos#1 for the 2 position FMS) which now holds the tuned PIDs.  Cautiously take off, and be ready to immediately cut power to zero if there is any problem.  You are now flying tuned PIDs.  If for some reason you want to run AutoTune again, just switch to Pos#2 as before.

That covers the basics of AutoTune.  If you don't want to use additional AutoTune features, you can remove AutoTune from your FMS at this point.  Enhanced functionality, further tweaks, and safety issues are discussed below.

Further Information follows:
Any time after tuning is complete, you can switch to Pos#3 which is Attitude mode using the tuned PIDs to test them.  Use caution!  It's recommended that when tuning completes you land and disarm, but if you were to switch to Pos#3, even without landing, you would be flying the new PIDs.  If you have time and access to a GCS at this point and understand what reasonable PID values look like, you could examine the new PIDs before you fly them.

To test fly your new PIDs, switch to Pos#3 (Attitude with tuned PIDs), arm, and cautiously take off.  Beginners beware: a slow increase in motor power for takeoff is not recommended as it causes PID windup.  It is best to start with motors off and immediately jump up the smallest amount you can to barely get off the ground and stay off.  You can learn the correct amount of throttle by starting with small blips and giving bigger and bigger blips until you learn how much throttle it takes to take off.  Before you take off, mentally prepare yourself to immediately apply zero throttle if something doesn't feel right.  A fall from 3 feet / 1 meter generally causes little or no damage.

You can simply retune by running AutoTune again if you want to.  The use of Attitude mode when testing the new PIDs is recommended (but not required), even for experts.  AutoTune mode itself is a modified form of Attitude mode and it doesn't matter what other modes you have as far as the tune is concerned.

In the worst case scenario where you don't have your FMS set up as recommended, oscillation may cause it to climb, and the only way to get down is to cut power for short periods and let if fall.  Automatic leveling in that case is very desirable.  This isn't an issue if you have the FMS set up as recommended.  In that case, just switch to Pos#1.

Tricopters are a special issue.  They may or may not tune correctly.  An assumption is made that the control delay is the same for roll pitch and yaw.  This is not true for tricopters which use a servo for yaw, but use motor thrust for roll / pitch.

If you intend to fly this copter both with and without a significant payload attached (like a camera) or with different batteries (weight, cell count) then ideally you would tune each case separately and store them in different PID banks.  Probably the easiest way to handle the simple case of with/without a camera is to tune with the camera, copy bank2 to bank3, retune without the camera and leave that in bank 2.  Then remove AutoTune from your FMS and add flight modes that include both bank 2 (without camera) and bank 3 (with camera).  Note that the lighter total weight has smaller PIDs.  Smaller PIDs will work when carrying an extra load that wasn't there when tuning (it is a bit mushy), but if you use the larger PIDs that come from tuning with a camera mounted when the camera is not mounted, you may get some minor oscillations.

It won't arm:
 It won't arm if you
- try to arm it in AutoTune mode
-
have put SystemIdent stabilization on Thrust on any FMS switch position
- use GPS Assist with AutoTune
- enable it on a vehicle that is not a multicopter

SmoothQuick:
There is a virtual slider called SmoothQuick, and the PIDs you get by default are in the middle of the slider.  At one end of the virtual slider are smooth PIDs which may be preferred for photography.  At the other end are quick PIDs which may be preferred for racing.  Once you have run the tuning, the FC will always remember the tuning and allow you to change PIDs along this sliding scale at any time in the future.  Starting the AutoTune process by staying in AutoTune mode for over 2 seconds while armed will erase the old settings and start a new tuning.  If you accidentally start an unwanted new tuning you can just power it off without disarming and it will forget the new tuning rather than making it permanent.  To use the SmoothQuick virtual slider, you need to attach a real slider (or knob or FMS 3x toggle) to it.  SmoothQuick works in real time, even while you are flying the tuned/destination PID bank if you want.

SystemIdentSettings -> SmoothQuickSource is where you attach a real slider.  SmoothQuickSource = 0 disables SmoothQuick entirely.  The default of 25 says to access the next of a set of 5 equally spaced points on the slider by toggling the Flight Mode Switch (starting outside of AutoTune) into AutoTune and back out, 3 times, in less than 2 seconds, but only if armed.  If you think of the SmoothQuick slider as a scale from -100 to +100, with smoothest being -100 and quickest being +100, then you start out in the middle at 0.  The first time you do the fast FMS 3x double toggle it will move you to +50 on the slider, then +100, then -100, then -50, then back to 0, etc.  If you do the fast FMS 3x toggle while disarmed, it will always set it to 0.  You can do that to set it to a known value if you forget.  SmoothQuickSource = 23, 25, and 27 give you 3, 5, and 7 equally spaced stops on the SmoothQuick slider.  25 is the default and gives you positions at -100, -50, 0, 50, and 100.

You can also set SmoothQuickSource to be a number from 10 to 13 which corresponds to using Accessory0 to Accessory3 to directly adjust the slider.  This requires that you have an available knob or slider on your transmitter, that you already have your transmitter configured to send it out as a separate channel, that the FC has been configured to attach that RC channel to one of the four FC Accessory channels, and that that FC Accessory is not being used by another FC function.

AutoTune / SmoothQuick 'data' is stored permanently.  Once you have run AutoTune once, you can use SmoothQuick with this stored data to produce smoother or quicker PIDs any time in the future.  You don't have to run AutoTune again, but you may want to if you change something, like props or weight or motors or cell count.

Using SmoothQuick semi-permanently:
It isn't necessary to manually enable the AutoTune module because it will be enabled each time the FC boots with AutoTune in the FMS.

If you do enable the AutoTune module manually then it will always be running, even if there is no AutoTune flight mode in your FMS.  In that case your SmoothQuick Accessory knob (or FMS 3x toggle) is always active to change the PIDs in the destination PID bank (default 2) and you can adjust PIDs from smooth to quick any time you need it.

AutoTune data:
The settings used by SmoothQuick are all stored permanently in SystemIdentSettings.  They are Tau, GyroReadTimeAverage, the 3 Beta values, and SmoothQuickSetting.  'Complete' must also be True.  SmoothQuickSetting is only important if you use the 3x FMS toggle method to select how smooth or quick you want your PIDs.  It stores the current value of the toggle as a number from -1 to +1.

If you erase settings or build a copy of your tuned model, you can copy the settings by hand if you know what they are.  They are stored as text in an exported uav file, or you can make a screen capture when they are visible on your computer screen.

AutoTune tries to produce results that make the tuning flight correctly tuned.  That does not take into account the non-linearity of thrust response.  To remove high thrust oscillations (or increase stability during descent), use TPS to decrease PIDs at high thrust (and if necessary, increase PIDs at low thrust).  Typically you want the TPS curve/line to cross the horizontal axis at the point (thrust value) where the copter hovers.  Examine SystemIdentState -> HoverThrottle after tuning and before you power off (:
This branch has recently been rebased onto next and uploaded with push -f.  That means you will have problems if you originally started from the version before the rebase.  One easy way around that is to delete the old directory and clone again, but that means you will re-download the whole thing again.  Another way (assumes origin is https://bitbucket.org/TheOtherCliff/librepilot.git) is to:
git merge --abort
git checkout next
git branch -D theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code
git fetch origin
git checkout -t origin/theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code
make all_clean

make  build_sdk_install   (I avoid this by sym linking my global downloads and tools directories into this directory, so whatever you need to do for downloads and tools)
nice -n15 make  -j4  gcs  revolution  revonano   (the 4 is however many real CPU cores you have to keep all of them busy, it still works even if it is wrong)  (gcs might take 30 minutes to build)  (or remove 'nice -n15' which says to run it at low priority in case you want to do something else with the computer while it is making the software)
./build/librepilot-gcs_release/bin/librepilot-gcs   (runs the GCS that you just built) (in Linux that is ./b <tab> l (lower case L) <tab> b <tab> <tab>)

With GCS running and firmware built, go to the Firmware page, press Halt.  Wait about 15 seconds for the Flash button to appear.  Also, it should automatically select firmware that matches your flight controller.  Press Flash.  You will also have to erase settings and run the setup wizard again.  With that complete, you need to do your calibrations before anything else.

Flight Mode Switch setup:
Note that when AutoTune is complete, it writes the calculated PIDs into the destination stabilization (PID) bank which by default is configured to be bank 2.  The standard procedure has you flying the AutoTune mode on bank 1 and writing the new PIDs to bank 2.

The recommended setup for running AutoTune uses a 3 position Flight Mode Switch.  With this, you can take off and fly Attitude mode with default PIDs, run AutoTune with default PIDs and fly Attitude mode with new PIDs, all without using the GCS:
Pos#1 - Attitude mode using bank 1
Pos#2 - AutoTune using bank 1 with SystemIdentSettings.DestinationPidBank set to 2 (that is the default)
Pos#3 - Attitude mode using bank 2 (bank 2 is where the tuned PIDs are written by default)
PID bank 1 should have default PIDs or something that is at least known to fly without oscillations.
This setup can all be done at home, and everything else can be done at the flying field, without using the GCS.

With this FMS (Flight Mode Switch) setup, you always have Pos#1 to fall back on.  Use Pos#1 to recover from any bad situation or to start over and run AutoTune again.

 An alternate FMS setup for a 2 position FMS removes the ability to fly with default PIDs once you have run AutoTune:
Pos#1 - Attitude mode using bank 2 (bank 2 is where the tuned PIDs are written by default)
Pos#2 - AutoTune using bank 1 with SystemIdentSettings.DestinationPidBank set to 2 (that is the default)
PID bank 1 should have default PIDs or something that is at least known to fly without oscillations.
PID bank 2 start out with the same PIDs as bank 1, but the PIDs will be changed by AutoTune.

It is possible to arm in Pos#1, then switch to Pos#2 and immediately take off before the AutoTune shaking starts, if your tuned PIDs don't work and you want to retune.

Remove anything that is expensive or fragile (e.g. cameras and antennas, but understand that transmitters must remain unpowered any time they don't have an antenna attached) from the multicopter if this is your first experience with AutoTune on this multicopter.  Be aware though, that you eventually need to tune in "flight trim".  Things like cameras and FPV gear that even moderately affect the total weight of the copter should be mounted to get a good tune.

Arm and take off in Pos#1 which is Attitude mode with default (or other known-good) PIDs.  These PIDs must not oscillate for the tuning to work.  Switch to Pos#2 which is AutoTune mode which is also configured to use default (or other known-good) PIDs.  After a few seconds the copter begins to shake.  Fly it smoothly.  Don't let the copter touch anything (such as the ground) while tuning is running.  60 seconds after that, the shaking stops and the tuning is complete.  The PIDs have already been written to the destination PID bank, but are only stored in RAM memory at this point.  The standard procedure is to land and disarm which writes the PIDs to permanent storage.  The PIDs will be written to permanent settings if you disarm before powering off.  The PIDs will be discarded if the copter is powered off without disarming it.

Switch to Pos#3 (Pos#1 for the 2 position FMS) which now holds the tuned PIDs.  Cautiously take off, and be ready to immediately cut power to zero if there is any problem.  You are now flying tuned PIDs.  If for some reason you want to run AutoTune again, just switch to Pos#2 as before.

That covers the basics of AutoTune.  If you don't want to use additional AutoTune features, you can remove AutoTune from your FMS at this point.  Enhanced functionality, further tweaks, and safety issues are discussed below.

Further Information follows:
Any time after tuning is complete, you can switch to Pos#3 which is Attitude mode using the tuned PIDs to test them.  Use caution!  It's recommended that when tuning completes you land and disarm, but if you were to switch to Pos#3, even without landing, you would be flying the new PIDs.  If you have time and access to a GCS at this point and understand what reasonable PID values look like, you could examine the new PIDs before you fly them.

To test fly your new PIDs, switch to Pos#3 (Attitude with tuned PIDs), arm, and cautiously take off.  Beginners beware: a slow increase in motor power for takeoff is not recommended as it causes PID windup.  It is best to start with motors off and immediately jump up the smallest amount you can to barely get off the ground and stay off.  You can learn the correct amount of throttle by starting with small blips and giving bigger and bigger blips until you learn how much throttle it takes to take off.  Before you take off, mentally prepare yourself to immediately apply zero throttle if something doesn't feel right.  A fall from 3 feet / 1 meter generally causes little or no damage.

You can simply retune by running AutoTune again if you want to.  The use of Attitude mode when testing the new PIDs is recommended (but not required), even for experts.  AutoTune mode itself is a modified form of Attitude mode and it doesn't matter what other modes you have as far as the tune is concerned.

In the worst case scenario where you don't have your FMS set up as recommended, oscillation may cause it to climb, and the only way to get down is to cut power for short periods and let if fall.  Automatic leveling in that case is very desirable.  This isn't an issue if you have the FMS set up as recommended.  In that case, just switch to Pos#1.

Tricopters are a special issue.  They may or may not tune correctly.  An assumption is made that the control delay is the same for roll pitch and yaw.  This is not true for tricopters which use a servo for yaw, but use motor thrust for roll / pitch.

If you intend to fly this copter both with and without a significant payload attached (like a camera) or with different batteries (weight, cell count) then ideally you would tune each case separately and store them in different PID banks.  Probably the easiest way to handle the simple case of with/without a camera is to tune with the camera, copy bank2 to bank3, retune without the camera and leave that in bank 2.  Then remove AutoTune from your FMS and add flight modes that include both bank 2 (without camera) and bank 3 (with camera).  Note that the lighter total weight has smaller PIDs.  Smaller PIDs will work when carrying an extra load that wasn't there when tuning (it is a bit mushy), but if you use the larger PIDs that come from tuning with a camera mounted when the camera is not mounted, you may get some minor oscillations.

It won't arm:
 It won't arm if you
- try to arm it in AutoTune mode
-
have put SystemIdent stabilization on Thrust on any FMS switch position
- use GPS Assist with AutoTune
- enable it on a vehicle that is not a multicopter

SmoothQuick:
There is a virtual slider called SmoothQuick, and the PIDs you get by default are in the middle of the slider.  At one end of the virtual slider are smooth PIDs which may be preferred for photography.  At the other end are quick PIDs which may be preferred for racing.  Once you have run the tuning, the FC will always remember the tuning and allow you to change PIDs along this sliding scale at any time in the future.  Starting the AutoTune process by staying in AutoTune mode for over 2 seconds while armed will erase the old settings and start a new tuning.  If you accidentally start an unwanted new tuning you can just power it off without disarming and it will forget the new tuning rather than making it permanent.  To use the SmoothQuick virtual slider, you need to attach a real slider (or knob or FMS 3x toggle) to it.  SmoothQuick works in real time, even while you are flying the tuned/destination PID bank if you want.

SystemIdentSettings -> SmoothQuickSource is where you attach a real slider.  SmoothQuickSource = 0 disables SmoothQuick entirely.  The default of 25 says to access the next of a set of 5 equally spaced points on the slider by toggling the Flight Mode Switch (starting outside of AutoTune) into AutoTune and back out, 3 times, in less than 2 seconds, but only if armed.  If you think of the SmoothQuick slider as a scale from -100 to +100, with smoothest being -100 and quickest being +100, then you start out in the middle at 0.  The first time you do the fast FMS 3x double toggle it will move you to +50 on the slider, then +100, then -100, then -50, then back to 0, etc.  If you do the fast FMS 3x toggle while disarmed, it will always set it to 0.  You can do that to set it to a known value if you forget.  SmoothQuickSource = 23, 25, and 27 give you 3, 5, and 7 equally spaced stops on the SmoothQuick slider.  25 is the default and gives you positions at -100, -50, 0, 50, and 100.

You can also set SmoothQuickSource to be a number from 10 to 13 which corresponds to using Accessory0 to Accessory3 to directly adjust the slider.  This requires that you have an available knob or slider on your transmitter, that you already have your transmitter configured to send it out as a separate channel, that the FC has been configured to attach that RC channel to one of the four FC Accessory channels, and that that FC Accessory is not being used by another FC function.

AutoTune / SmoothQuick 'data' is stored permanently.  Once you have run AutoTune once, you can use SmoothQuick with this stored data to produce smoother or quicker PIDs any time in the future.  You don't have to run AutoTune again, but you may want to if you change something, like props or weight or motors or cell count.

Using SmoothQuick semi-permanently:
It isn't necessary to manually enable the AutoTune module because it will be enabled each time the FC boots with AutoTune in the FMS.

If you do enable the AutoTune module manually then it will always be running, even if there is no AutoTune flight mode in your FMS.  In that case your SmoothQuick Accessory knob (or FMS 3x toggle) is always active to change the PIDs in the destination PID bank (default 2) and you can adjust PIDs from smooth to quick any time you need it.

AutoTune data:
The settings used by SmoothQuick are all stored permanently in SystemIdentSettings.  They are Tau, GyroReadTimeAverage, the 3 Beta values, and SmoothQuickSetting.  'Complete' must also be True.  SmoothQuickSetting is only important if you use the 3x FMS toggle method to select how smooth or quick you want your PIDs.  It stores the current value of the toggle as a number from -1 to +1.

If you erase settings or build a copy of your tuned model, you can copy the settings by hand if you know what they are.  They are stored as text in an exported uav file, or you can make a screen capture when they are visible on your computer screen.

AutoTune tries to produce results that make the tuning flight correctly tuned.  That does not take into account the non-linearity of thrust response.  To remove high thrust oscillations (or increase stability during descent), use TPS to decrease PIDs at high thrust (and if necessary, increase PIDs at low thrust).  Typically you want the TPS curve/line to cross the horizontal axis at the point (thrust value) where the copter hovers.  Examine SystemIdentState -> HoverThrottle after tuning and before you power off (not saved) to see what your hover thrust is.  Beware of throttle bloom that happens when slow responding ESC's make a copter climb just because of the fast RPY controls.

...

DataObjects.SystemIdentState
- Is not stored permanently (Goes away when power is removed)
- Is logged
- HoverThrottle is the average throttle used during tuning.  It is a reasonable value to use in Settings.AltitudeHoldSettings.ThrustLimits.Neutral although it is usually a little smaller than it should be due to throttle bloom during shaking.
- The 3 values in Noise tell you how much vibration you have on the 3 axes.  Normal values range from about 100 to about 1000.  For high values, or jittery response to the PIDs created, you may want to increase Settings.StabilizationSettings.GyroTau (found in the GCS GUI at Configuration -> Stabilization -> Expert -> GyroNoiseFiltering) and retune.  Now you know how much vibration you actually have.
- Contains fields that may be useful if debugging problems with AutoTune
- Contains copies of some fields from System.SystemIdentSettingsvibration you actually have.
- Contains fields that may be useful if debugging problems with AutoTune
- Contains copies of some fields from System.SystemIdentSettings

iMac-di-Paolo:autotune340 paolo$ git merge --abort
iMac-di-Paolo:autotune340 paolo$ git checkout next
Switched to branch 'next'
Your branch is behind 'origin/next' by 255 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
iMac-di-Paolo:autotune340 paolo$ git branch -D theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code
Deleted branch theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code (was b5890b9).
iMac-di-Paolo:autotune340 paolo$ git fetch origin
iMac-di-Paolo:autotune340 paolo$ git checkout -t origin/theothercliff/LP-340_AutoTune_fix_some_time_measurement_issues_in_original_code