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
Refactor Feedforward Angle and RC Smoothing - mashup of 12578 and 12594 #12605
Refactor Feedforward Angle and RC Smoothing - mashup of 12578 and 12594 #12605
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
cf53c55
to
626f727
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
@ctzsnooze everything works as expected again. I don't notice any difference when flying, but the logs look a bit different than usual. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only needs to update unit tests and remove comments.
0ddf592
to
3bdac20
Compare
This comment has been minimized.
This comment has been minimized.
tested again with rebased PR on ghost and frsky sbus. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix unit tests before merging
Need someone to help get the 'container' for the unit tests. I'll do the tests themselves, but I can't figure how to do them now the code is in a different place. So if not one person here can help, then we should merge the PR without the unit tests. |
@borisbstyle @haslinghuis - in this PR:
In the previous 'master' code the functions However, the In short, the old tests didn't test the code in master anyway - it 'cheated'. The 'test' only tested the code in the test, not the code we flew. At least that's how I see it. After this PR, these old functions don't exist anymore. To do the unit test entirely within the pid_unitest, we would need to get rc.c to calculate I think that to test the feedforward code itself, we would need need a test in rc.c that checks what would return for Then only test required in pid.c is to multiply a simulated feedforward value by the feedforward gain value, and check it is zero in angle mode. I have updated the pid_unittest. It now returns sensible values for feedforward for a given simulated setpointDelta value. I don't think I have the capability to write a unit test for rc.c. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5bd86dc
to
b01a6d2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@borisbstyle this should be good for now as we can improve the tests later.
@ctzsnooze thanks for reverting clang version - as I overlooked that.
Do you want to test this code? Here you have an automated build: |
@ctzsnooze here another testflight ... hope now that's the last before merge |
|
@haslinghuis Dismissing my review is not okay. We were still in the review process. Please never do this again! |
@KarateBrot Just trying to keep the project going here. Assumed your request was fixed. We always can fix upon (any) work if it doesn't turn out. As this PR was hanging and multiple requests for merging were pending and tested were positive I deemed it ready for merge. |
Sorry @KarateBrot I thought that I had addressed your comments. And I remain very grateful for the time you took to make those reviews. My error was to mark those which I thought had been addressed, as 'resolved', which I did for housekeeping purposes, so I could track which had been dealt with. I thought that this could always be reversed if we wanted to go back and check on how they were 'resolved'. Unfortunately, I now see that, on merging, all review discussions marked as 'resolved' have vanished. I didn't expect this. It would be much better that all review discussions, including those marked as 'resolved', are retained on merging. The remaining review questions that I didn't resolve are still open, eg the query about the CLI print line function. @blckmn I wonder if those review discussions can be restored somehow? Or if we can change our GitHub settings to not delete 'resolved' review discussions? Could it be that the 'squash' associated with the merge causes our review discussion to be lost? |
recommend author(s) set long-standing PR(s) as draft until truly "ready". |
we can still see some comments/unresolved via the "files changed" tab. |
…94 (betaflight#12605) * Refactor Feedforward Angle and RC Smoothing * update rc_smoothing at regular intervals * add Earth Ref to OSD, update pid and rate PG * Initialise filters correctly * refactoring to improve performance * Save 24 cycles in Horizon calculations, other optimisations At a cost of 40 bytes * save 25 cycles and 330 bytes in rc_smoothing * feedforward max rate improvements * typo fix * Karatebrot's review suggestions part one * Karatebrot's excellent suggestions part 2 * more efficient if we calculate inverse at init time Co-Authored-By: Jan Post <post@stud.tu-darmstadt.de> * Horizon delay, to ease it in when returning sticks to centre * fix unit tests after horizon changes Co-Authored-By: 4712 <4712@users.noreply.github.com> * horizon_delay_ms, default 500 * fix unit test for feedforward from setpointDelta * Final optimisations - thanks @KarateBrot for your advice * increase horizon level strength default to 75 now we have the delay * restore Makefile value which allowed local make test on mac --------- Co-authored-by: Jan Post <post@stud.tu-darmstadt.de> Co-authored-by: 4712 <4712@users.noreply.github.com>
…94 (betaflight#12605) * Refactor Feedforward Angle and RC Smoothing * update rc_smoothing at regular intervals * add Earth Ref to OSD, update pid and rate PG * Initialise filters correctly * refactoring to improve performance * Save 24 cycles in Horizon calculations, other optimisations At a cost of 40 bytes * save 25 cycles and 330 bytes in rc_smoothing * feedforward max rate improvements * typo fix * Karatebrot's review suggestions part one * Karatebrot's excellent suggestions part 2 * more efficient if we calculate inverse at init time Co-Authored-By: Jan Post <post@stud.tu-darmstadt.de> * Horizon delay, to ease it in when returning sticks to centre * fix unit tests after horizon changes Co-Authored-By: 4712 <4712@users.noreply.github.com> * horizon_delay_ms, default 500 * fix unit test for feedforward from setpointDelta * Final optimisations - thanks @KarateBrot for your advice * increase horizon level strength default to 75 now we have the delay * restore Makefile value which allowed local make test on mac --------- Co-authored-by: Jan Post <post@stud.tu-darmstadt.de> Co-authored-by: 4712 <4712@users.noreply.github.com>
This PR combines #12578 and #12594, which are now closed. Both shared a lot of common changes in pid.c and rc.c, and would be difficult to merge sequentially. It includes the current updated Angle and Horizon code.
Note: Users who want the old Angle mode behaviour should set expo to zero in their Rates, and:
Note: Horizon users should adjust the following parameters to suit their preference:
There are two functional changes that are added by this PR, on top of the changes in #12578 and #12594:
Delayed onset of levelling in Horizon when returning sticks to the centre. As suggested by @justainchoe, this adds a delay whenever the levelling strength increases in Horizon mode. Decreases in levelling strength are unaffected and happen immediately. The delay is achieved by applying a first order lowpass filter, with a time constant of 500ms by default to the horizon strength factor, where a
horizon_delay
of 50 means 500ms. The code then uses the lowest of the un-smoothed and smoothed value, where a low value means no smoothing. This results in a delay only when the horizon strength value increases. The pilot can do a flip and bring their sticks hard back to centre, and the levelling will come on relatively slowly, avoiding the previously unwelcome 'snap' due to the combination of self-levelling and the pilot bringing the sticks to a halt. It there's too much 'snap', or if you want the levelling to come in only after a longer time, increase the time constant (up to 250 or 2.5s). For more immediate levelling, as perhaps preferred by a person learning Acro via Horizon, the delay can be reduced. If set to zero, there is no delay.Small modification to
feedforward_max_rate_limit
. Now this value affects the slope of the limiting line, with zero feedforward always by the time setpoint reaches maximum, rather than moving the line left and right, while the users PID "P" value modifies the slow. Racers may preferfeedforward_max_rate_limit
at values around 100-120 to maintain full feedforward until quite late in a full stick move. Cinematic users or those with heavier quads may want a smoother, less aggressive feedforward, in which casefeedforward_max_rate_limit
could be around 50, and the RC smoothing on feedforward increased a bit (lower cutoff than default).Please refer to #12576 and #12594 for detailed notes on the other changes..
There is a lot of efficiency related refactoring, resulting in significant CPU and flash space savings.
Summary of changes:
There should be no change in feedforward or RC smoothing functionality. All quads should fly the same, just a bit more smoothly. CPU load / instability should be a bit less of a problem on marginal setups.
RC smoothing values and reported link speeds should be accurate in all circumstances. Previously when the RC smoothing calculations were in error, RC link stepping could get through to the motors via feedforward or setpoint. This shouldn't happen any more, including in Angle and Horizon mode.
The code should be able to deal with radios that change links dynamically, even in small steps. Previously there was an issue detecting change from 333 to 250hz. Now it should respond to any change greater than 1hz, and do so within a few packets.
Please also test feedforward by flying and noting normal feedforward behaviour, and log feedforward.
If you find any issues with unexpected link intervals or rc smoothing issues, please either raise an issue here on GitHub or a pre-issue on Discord.
Feedforward, when a new RC packet arrives, requires 125 cycles without averaging, jitter or transition. This increases to 170 cycles with averaging, 196 cycles when also adding jitter reduction, and 209 cycles with "the lot".
RC Smoothing requires 18 cycles while idle, about 160 cycles when a new RC packet arrives in that is not much different from the previous interval, and about 250 cycles when the interval is sufficiently different that new cutoffs are required.
Recoding for efficiency mostly involved: