Skip to content

Minor pid.c refactoring #12722

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

Merged
merged 6 commits into from
May 11, 2023

Conversation

ctzsnooze
Copy link
Member

Small changes, perhaps a little more efficient.

  • refactor pid[F] to avoid conditionals
  • only perform the multiply needed for a debug when that specific debug is active
  • don't break the declaration of delta
  • adjust whitespace before major code blocks

@github-actions

This comment has been minimized.

Copy link
Contributor

@ledvinap ledvinap left a comment

Choose a reason for hiding this comment

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

Looks safe.
In general, you shall concentrate on making code more readable and simpler instead of saving few cycles...

@ctzsnooze
Copy link
Member Author

ctzsnooze commented Apr 24, 2023

Thanks, @ledvinap. I agree about the desirability of keeping it readable and simple.

Though I'm confused why we would multiply the preTpaD value by '22' for logging purposes? I can't quite understand the explanatory comment.

The value being logged is simply the pre-TPA D value. Why multiply that logged value by 22? To me that makes no sense. Maybe multiply by 10 for precision perhaps... but 22?

Very tempted to change 22 to 10.

@@ -245,7 +245,7 @@ void pgResetFn_pidProfiles(pidProfile_t *pidProfiles)

// Scale factors to make best use of range with D_LPF debugging, aiming for max +/-16K as debug values are 16 bit
#define D_LPF_RAW_SCALE 25
#define D_LPF_FILT_SCALE 22
#define DEBUG_D_PRE_TPA_SCALE 10
Copy link
Member Author

@ctzsnooze ctzsnooze Apr 24, 2023

Choose a reason for hiding this comment

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

Makes no sense to log a pre-TPA D value that is multiplied by 22, when the following, normal, D value is not multiplied by anything.

A multiply by 10 makes the logged values much easier to compare, numerically, and does enhance precision of the logged value.

Copy link
Member

Choose a reason for hiding this comment

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

Does this need coordination with the blackbox viewer?

Copy link
Member

Choose a reason for hiding this comment

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

bbe:

$ grep -Iirn D_LPF ./js
./js/flightlog_fields_presenter.js:846:        'D_LPF' : {
./js/flightlog_fields_presenter.js:847:            'debug[all]':'D-Term [D_LPF]',
./js/flightlog_fielddefs.js:337:        "D_LPF",

upon skim-read, i do not see any SCALE nor static 22 associated.
may need to add translation (flightlog_parser.js:358), but unsure 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

See 4361d32

Copy link
Member Author

@ctzsnooze ctzsnooze May 11, 2023

Choose a reason for hiding this comment

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

@KarateBrot

Does this need coordination with the blackbox viewer?

No, it is easier to compare with DTerm when the multiplier is 10.
BlackBox viewer needs quite a lot of updating :-(

Copy link
Member

@KarateBrot KarateBrot May 11, 2023

Choose a reason for hiding this comment

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

@ctzsnooze You're giving me mixed signals here 😀 Do we need to update the corresponding debug channel in the blackbox viewer or not (to make this perfectly comparable to the D-term)?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this change improves the blackbox scaling so that the D_LPF Debug is easier to interpret.

There are many other debugs which require attention, including the D_LPF debug. The D_LPF debug from memory requires attention in some of its other channels.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, gotcha

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@blckmn
Copy link
Member

blckmn commented Apr 24, 2023

AUTOMERGE: (FAIL)

  • github identifies PR as mergeable -> FAIL
  • assigned to a milestone -> PASS
  • cooling off period lapsed -> PASS
  • commit count less or equal to three -> PASS
  • Don't merge label NOT found -> PASS
  • at least one RN: label found -> PASS
  • Tested label found -> FAIL
  • assigned to an approver -> PASS
  • approver count at least three -> FAIL

@nerdCopter

This comment was marked as outdated.

@ctzsnooze ctzsnooze force-pushed the PR-minor-pid.c--refactor branch from 03c5473 to 1f91ab5 Compare May 1, 2023 02:28
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ctzsnooze
Copy link
Member Author

@nerdCopter Thanks, I removed any two blank lines in sequence and replaced with one.

@github-actions

This comment has been minimized.

@ctzsnooze ctzsnooze force-pushed the PR-minor-pid.c--refactor branch from d9d220e to 6a8966a Compare May 11, 2023 13:56
@haslinghuis haslinghuis merged commit 68dd061 into betaflight:master May 11, 2023
haslinghuis pushed a commit to haslinghuis/betaflight that referenced this pull request May 11, 2023
* Minor pid.c refactoring

* Only calculate unfiltered gyro delta for that debug

Remove unnecessary comment
Change multiplier to factor of 10

* remove some archaic comments

* clarify name of D_LPF_PRE_TPA_SCALE, use inverse in define

* Remove some blank lines

* undo conversion to division thanks -ffast-math
AkankshaJjw pushed a commit to AkankshaJjw/betaflight that referenced this pull request May 29, 2023
* Minor pid.c refactoring

* Only calculate unfiltered gyro delta for that debug

Remove unnecessary comment
Change multiplier to factor of 10

* remove some archaic comments

* clarify name of D_LPF_PRE_TPA_SCALE, use inverse in define

* Remove some blank lines

* undo conversion to division thanks -ffast-math
davidbitton pushed a commit to davidbitton/betaflight that referenced this pull request Feb 5, 2024
* Minor pid.c refactoring

* Only calculate unfiltered gyro delta for that debug

Remove unnecessary comment
Change multiplier to factor of 10

* remove some archaic comments

* clarify name of D_LPF_PRE_TPA_SCALE, use inverse in define

* Remove some blank lines

* undo conversion to division thanks -ffast-math
@ctzsnooze ctzsnooze deleted the PR-minor-pid.c--refactor branch April 3, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

6 participants