Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autotune: Add switch to test gains after tune is complete #27754

Merged
merged 5 commits into from
Aug 12, 2024

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Aug 5, 2024

This adds a switch allowing the user to test gains in any mode once the autotune has been completed. If the user has used the switch they can then disarm in any mode and the gains will be saved if they are active. If the user does not use the switch then they must disarm in autotune to save gains per the current behavior.

This allows easy testing of the tune in any mode and makes the procedure to save a little simpler.

The load test gains functions have been updated to ensure they use the same criteria as the saving of gains for the load. Currently they were not checking if a axis had completed, only that the axis was enabled.

@Hwurzburg Hwurzburg added the WikiNeeded needs wiki update label Aug 5, 2024
Copy link
Collaborator

@andyp1per andyp1per left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@lthall lthall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. However I think one of my previous PR's may have introduced a bug that keeps ddt zero. I will find this problem and report back.

update_gcs(AUTOTUNE_MESSAGE_TESTING_END);
break;
case RC_Channel::AuxSwitchPos::MIDDLE:
// Middle position is unused for now
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we could change to mode AutoTune if the tune has not been completed.

********* For Discussion *********

@lthall
Copy link
Contributor

lthall commented Aug 5, 2024

Confirmed that this showed a problem in master :)

Copy link
Contributor

@rmackay9 rmackay9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides the slight switch name question

@rmackay9
Copy link
Contributor

rmackay9 commented Aug 6, 2024

We decided to wait for @bnsgeyer to test this

Copy link
Contributor

@bnsgeyer bnsgeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in SITL on heli. LGTM.

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a bug in the ordering of the hal.util->set_soft_armed(false); and the copter.mode_autotune.save_tuning_gains(); as otherwise AP_Param will only save the first 30 gains as we queue parameters when soft_armed is true, and queue length is 30 - we probably get away with it for now, but if autotune changed 32 params, only 30 would save
randy has asked the fix to be in a separate PR, does need fixing

tridge
tridge previously requested changes Aug 7, 2024
const bool tune_complete_no_testing = !have_pilot_testing_command && in_autotune_mode;

if (tune_complete_no_testing || testing_tuned) {
save_tuning_gains();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you intend to save_tuning_gains() if switch is in lower position so we currently have the old gains loaded?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have used the switch to test the gains and you have the switch in the "original gains" position then it should not save the tuned gains.

If you have not used the switch to test the gains and are in AutoTune mode then it will save the gains. The is should be the same as the current behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to better suggestions but I could not think of anything else while preserving the current behaviour, we can't make it a requirement that everyone must setup the new switch to run autotune.

Now we can send aux functions from the gcs we can't really check if the user has setup a switch until they first trigger it.

Copy link
Contributor

@timtuxworth timtuxworth Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about reverse the switch?

  • low = new gains (test/save on disarm),
  • high = original gains (discard)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that is less confusing, the pattern (there are one or two exceptions) for functions is that high is to take some action. In this case the action is the thing we have added namely the ability to test gains in any mode. Original gains and discarding in other modes is the existing behavior, it would be abit odd to require the user to flip a switch to high for that.

Don't forget that aux functions are edge triggered, it does not matter where the switch is until autotune has completed, only changes after that (and before you disarm) will do anything.

@tridge tridge removed the DevCallEU label Aug 7, 2024
@tridge tridge dismissed their stale review August 12, 2024 23:57

will be fixed in another PR

@rmackay9 rmackay9 merged commit 698f8fb into ArduPilot:master Aug 12, 2024
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WikiNeeded needs wiki update
Projects
None yet
Development

Successfully merging this pull request may close these issues.