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
Plane: Move navigation functions into flight mode classes. #14959
Plane: Move navigation functions into flight mode classes. #14959
Conversation
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 wrote up some comments about not using the indirect _navigate() but after seeing that copter does a very similar thing with run_autopilot() I'm ok with this as-is. Wonderful abstraction, thanks for the help @samuelctabor on the onion v2 !!!
This needs a rebase but otherwise is a straightforward refactor. Sadly, refactors like this don't last long in master without a conflict so lets take a look at this one again after the rebase and get it in. It looks like a low-risk refactor, no behavior change. |
Good stuff, I will rebase tomorrow. All tests pass on my local branch. |
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.
This is a nice cleanup.
That fallthrough-to-loiter-from-RTL was kinda nasty, and narrowing the scope of radius a qrtl_radius is cool.
Same as @magicrub I noted the indirect navigate() calling _navigate() - but it seems to be a trend in Plane :-)
ArduPlane/mode_avoidADSB.cpp
Outdated
@@ -11,3 +11,8 @@ void ModeAvoidADSB::update() | |||
plane.mode_guided.update(); | |||
} | |||
|
|||
void ModeAvoidADSB::_navigate() | |||
{ | |||
plane.mode_loiter.navigate(); |
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'm not sure these things should be calling into mode_loiter to do stuff. They could call update_loiter themselves.
On the Copter side we've often factored out the functionality - land_run_vertical
/ land_run_horizontal
, for example. That's not universal - for example, mode-auto uses mode-rtl for RTL'ing and mode-guided for guided'ing....
It's a minor point and doesn't need to be addressed, really.
ArduPlane/mode_rtl.cpp
Outdated
*/ | ||
plane.set_mode(plane.mode_qrtl, ModeReason::UNKNOWN); | ||
return; | ||
} else if (plane.g.rtl_autoland == 1 && |
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.
Don't need the else here.
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
8bf9258
to
598c4b1
Compare
Rebased and removed the extra "else". |
Any other changes required before this can be merged or taken to the dev call? |
@samuelctabor fine as far as I can see. Needs to be merged by a Plane maintainer IMO, 'though - and that's not me :-) I'll mark it DevCall so you have a deadline at least. |
ArduPlane/ArduPlane.cpp
Outdated
// nothing to do | ||
break; | ||
} | ||
control_mode->navigate(); |
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.
Why retain this wrapper at all? It's only called once from Plane::navigate
so this is adding an indirection that isn't needed, and makes it harder to follow?
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 agree, it is clearer without it
ArduPlane/mode_avoidADSB.cpp
Outdated
@@ -11,3 +11,8 @@ void ModeAvoidADSB::update() | |||
plane.mode_guided.update(); | |||
} | |||
|
|||
void ModeAvoidADSB::_navigate() | |||
{ | |||
plane.mode_loiter.navigate(); |
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'd like them to call plane.update_loiter() instead. The problem with calling into mode_loiter is it means we're calling a member function on a class wirthout ever calling the init function on the class. Right now this is safe, but if someone changes mode_loiter it could break other modes.
In general I don't like calls into non-static functions on a mode class without the class enter function having been called
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.
yes, I totally agree with Tridge's comment.
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.
Changed to call into plane.update_loiter().
I've checked for copy&paste errors and it looks good. I'd like someone to test all affected flight modes to look for correct behaviour in a manual SITL run |
Checked:
ToDo:
|
|
Perhaps we could discuss this on the EU dev call? |
Added the DevCallEU at @samuelctabor's request. |
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.
just remove the extra level of indirection, so plane.update_loiter() is called directly by the mode navigate functions, then can be merged when passes CI
b30793f
to
e795a7f
Compare
e795a7f
to
9bced62
Compare
Rebased this on top of CI problem fixes. |
9bced62
to
a300997
Compare
Thanks Peter, I did the same a few seconds later before I saw your comment :-) |
Merged, thanks! |
After discussing with @magicrub this should be a step in the right direction. I'm planning to flight test this soon.