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

Plane: Move navigation functions into flight mode classes. #14959

Merged
merged 4 commits into from Aug 20, 2020

Conversation

samuelctabor
Copy link
Collaborator

After discussing with @magicrub this should be a step in the right direction. I'm planning to flight test this soon.

Copy link
Contributor

@magicrub magicrub left a 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 !!!

@magicrub
Copy link
Contributor

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.

@samuelctabor
Copy link
Collaborator Author

Good stuff, I will rebase tomorrow. All tests pass on my local branch.

Copy link
Contributor

@peterbarker peterbarker left a 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 :-)

@@ -11,3 +11,8 @@ void ModeAvoidADSB::update()
plane.mode_guided.update();
}

void ModeAvoidADSB::_navigate()
{
plane.mode_loiter.navigate();
Copy link
Contributor

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.

*/
plane.set_mode(plane.mode_qrtl, ModeReason::UNKNOWN);
return;
} else if (plane.g.rtl_autoland == 1 &&
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@samuelctabor
Copy link
Collaborator Author

Rebased and removed the extra "else".

@samuelctabor
Copy link
Collaborator Author

Any other changes required before this can be merged or taken to the dev call?

@peterbarker
Copy link
Contributor

@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.

// nothing to do
break;
}
control_mode->navigate();
Copy link
Contributor

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?

Copy link
Contributor

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

@tridge tridge self-requested a review August 10, 2020 23:25
@rmackay9
Copy link
Contributor

As discussed on the dev call, @magicrub and @tridge will do a detailed inspection of this before merging.

@@ -11,3 +11,8 @@ void ModeAvoidADSB::update()
plane.mode_guided.update();
}

void ModeAvoidADSB::_navigate()
{
plane.mode_loiter.navigate();
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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().

@tridge
Copy link
Contributor

tridge commented Aug 11, 2020

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

@samuelctabor
Copy link
Collaborator Author

Checked:

  • correct circle radius and location in takeoff, guided and loiter
  • auto mission works
  • flying around in cruise works
  • RTL works correctly with various RTL_AUTOLAND settings

ToDo:

  • having some trouble with avoid ADSB, I'll check with Tom tomorrow
  • RTL with quadplane

@samuelctabor
Copy link
Collaborator Author

  • RTL with quadplane works correctly
  • ADSB avoidance has other issues but this PR doesn't change them

@samuelctabor
Copy link
Collaborator Author

Perhaps we could discuss this on the EU dev call?

@rmackay9
Copy link
Contributor

Added the DevCallEU at @samuelctabor's request.

Copy link
Contributor

@tridge tridge left a 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

@samuelctabor samuelctabor force-pushed the pr/navigation-flight-modes branch 2 times, most recently from b30793f to e795a7f Compare August 19, 2020 09:22
@peterbarker
Copy link
Contributor

Rebased this on top of CI problem fixes.

@samuelctabor
Copy link
Collaborator Author

Thanks Peter, I did the same a few seconds later before I saw your comment :-)

@peterbarker peterbarker merged commit 334fd4a into ArduPilot:master Aug 20, 2020
@peterbarker
Copy link
Contributor

Merged, thanks!

@samuelctabor samuelctabor deleted the pr/navigation-flight-modes branch August 20, 2020 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants