-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[navigation][flight plan] mandate call_once for functions that should only run once #1967
Conversation
157e6fe
to
8757f4a
Compare
8757f4a
to
a9314a5
Compare
just that they can be used with `call` instead of `call_once`
This was just so that they could be called with `call`, you should use `call_once` instead. Also change some macros to static inline functions for better debugging.
a9314a5
to
b8160fa
Compare
@@ -72,7 +72,6 @@ bool nav_survey_poly_setup_towards(uint8_t FirstWP, uint8_t Size, float Sweep, i | |||
//if values passed, use it. | |||
if (Size == 0) {Size = Poly_Size;} | |||
if (Sweep == 0) {Sweep = Poly_Distance;} | |||
return nav_survey_poly_setup(FirstWP, Size, Sweep, ang); |
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.
Shouldn't this function still be called before the return ?
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.
ups, yes... good catch!
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.
fixed..
b8160fa
to
817062d
Compare
6a4295e
to
72f0a00
Compare
What do you guys think about this? |
@@ -155,7 +155,7 @@ bool nav_survey_poly_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orient | |||
CSurveyStatus = Init; | |||
|
|||
if (Size == 0) { | |||
return true; | |||
return; |
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.
here the behavior is different than before, as previously it would stay stuck in init function while now it is silently failing (at least skipping the end of init)
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.
I updated the run function to return without doing anything if the size is zero...
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.
The OK as for rotorcraft, quick glance fixedwing look OK, Thx. Note that The call_once (or call for that matter ) was discussed quite some time ago. For now to go forward i think it is fine. In future I rather see a nice non tech flightplan descriptive language and users writing flightplans should just be able to write e.g simply <SetGroundReferenceHere"/>. But that is another discussion. Yes I know, one could write a wrapper for nice flighplan language encapsulating current implementation.
BTW as for SurveySize returning if 0, well if I did not arrive at my survey area one could wish to set it's values as moving toward the survey entry point while gathering data to determine the survey or e.g. let it size depend on fuel drain along the way. With this change as far a quickly understood, one now cannot start move towards even. Anyhow if ever needed it that way myself, I'll file a new issue ;)
BTW not testflown and simmed yet, will do, with finger on TX Mode switch ;) when it lnds in master and hopefully not -20 deg C.
On the general idea, I'm fine with these changes |
The
call
primitive of the flight plan can be used to repeatedly call a function until it returns false.In most cases the function is only supposed to be called only once though...
This has led to a state where a lot of functions that are supposed to be called from the flight plan have an additional
return false
to make themcall
-able.From just looking at the flight plan it is hard to determine if a function will indeed be only called once or is actually called each time the flight plan navigation is run until it is "done" (returns false).
To make this distinction more explicit and hopefully more clear (and the code cleaner), one should use
call
only when really needed andcall_once
otherwise.This PR removes the "dummy"
return false
from a lot of functions, hence mandating thatcall_once
is used for them. Eventually we shouldn't have any cases like that anymore...All flight plans were updated accordingly.
The most common case where
call
still has to be used are navigation routines a lanav_x_run
.This should be "backwards safe" (not backwards compatible) in the sense that if you try use
call
for a function that needs to be called withcall_once
(since it now returns void), you will get an "invalid use of void expression" error: