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

AP_Mount: Only save converted mount parameter if mount was previously set in the first place #27109

Conversation

joshanne
Copy link
Contributor

The mount library force configures the mount type on conversion, even if the mount was never configured in the first place.

@rmackay9
Copy link
Contributor

Hi @joshanne,

Thanks for this. Have you noticed any issue with this save? This is actually done on purpose so that we don't run the parameter conversion on each boot.

@joshanne
Copy link
Contributor Author

joshanne commented May 20, 2024

Thanks for this. Have you noticed any issue with this save? This is actually done on purpose so that we don't run the parameter conversion on each boot.

If you flash the flight controller then boot, the parameter is immediately considered configured. So if you update to software with a configured defaults.parm the default mount is not reflected.

The conversion probably should only occur if the old MNT_TYPE parameter is non zero and the current mount is not configured && the current mount type is non-zero.

ie. Do not run the conversion if:

  • if a defaults file is used then the new parameter is unconfigured but non-zero.
  • if a defaults file is not used, and the parameter is non-zero.

What we want to achieve is don't trample the user config if updating from an old version of software.

@joshanne
Copy link
Contributor Author

joshanne commented May 20, 2024

At the very least the conversion should only occur if the old mount type is set to a non-zero mount type.

The underlying problem is this conversion runs and writes that mount parameter even if the flight controller only ever saw a later version of software.

…e first place

The mount library force configures the mount type on conversion, even if the mount was never configured in the first place
@joshanne joshanne force-pushed the pr/only-save-converted-mount-if-mount-was-previously-set branch from 402839b to 10f1731 Compare May 21, 2024 21:25
}
_params[0].type.set_and_save(mnt_type);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving this inside the else ensures that we only write a value to MNT1_TYPE if the previous MNT_TYPE was set to a non zero value.

ie. don't set MNT1_TYPE to a configured value of zero, as this is no longer "default".

@joshanne
Copy link
Contributor Author

@rmackay9 - updated the changes, comments added to both source and PR.

@joshanne
Copy link
Contributor Author

I still lean toward the initial commit, because upgrading of the other mount parameters could be perfectly valid if the mount type was not set at the time of the upgrade.

@rmackay9
Copy link
Contributor

rmackay9 commented May 22, 2024

@joshanne,

OK, thanks. The existing code is a very common pattern though so I think we should discuss with @tridge (and perhaps others) at the EU dev call later today.

I think the ideal change would actually be to set the MNT1_TYPE parameter to the default value of the parameter instead of 0. I think that would maintain the current behaviour and give you what you want. As far as I know we don't have an easy way to retrieve what the default of a parameter is.

if (mnt_type > 0) {
if (mnt_type == 0) {
// if the mount was not previously set, no need to perform the upgrade logic
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the old MNT_TYPE value is zero, it is not configured, and upgrade is not required - so bail.

@tridge tridge merged commit a5e1191 into ArduPilot:master May 22, 2024
91 checks passed
@joshanne joshanne deleted the pr/only-save-converted-mount-if-mount-was-previously-set branch May 22, 2024 07:20
@IamPete1 IamPete1 removed the DevCallEU label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants