-
Notifications
You must be signed in to change notification settings - Fork 20.8k
ArduPlane: enable soaring in LOITER and GUIDED modes #32034
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
| bool ModeLoiter::_enter() | ||
| { | ||
| #if HAL_SOARING_ENABLED | ||
| plane.g2.soaring_controller.init_cruising(); | ||
| #endif // HAL_SOARING_ENABLED | ||
|
|
||
| plane.do_loiter_at_location(); | ||
| plane.setup_terrain_target_alt(plane.next_WP_loc); | ||
|
|
||
|
|
@@ -25,6 +29,15 @@ void ModeLoiter::update() | |
| plane.update_fbwb_speed_height(); | ||
| } else { | ||
| plane.calc_nav_pitch(); | ||
| #if HAL_SOARING_ENABLED | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy/paste problem - make a method in the base class
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved as much logic as I can to the Now the function has considerably more complicated return value, but it's documented at declaration and all call sites. |
||
| if (plane.set_soaring_altitude()) { | ||
| // Just stopped soaring in this mode | ||
|
|
||
| // Return to loitering at target point with current altitude | ||
| plane.set_target_altitude_current(); | ||
| plane.next_WP_loc.set_alt_cm(plane.target_altitude.amsl_cm, Location::AltFrame::ABSOLUTE); | ||
|
Comment on lines
+37
to
+38
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will work correctly if terrain following is enabled? I see we follow the same pattern for nav-scripting, but that might well be wrong too. To test make sure that terrain following works before and after soaring kicks in.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't done any work with terrain following, I will familiarise myself with this feature and test/autotest it, thanks for the hint |
||
| } | ||
| #endif // HAL_SOARING_ENABLED | ||
| plane.calc_throttle(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -430,15 +430,11 @@ void Plane::update_fbwb_speed_height(void) | |
| change_target_altitude(alt_change_cm); | ||
|
|
||
| #if HAL_SOARING_ENABLED | ||
| if (g2.soaring_controller.is_active()) { | ||
| if (g2.soaring_controller.get_throttle_suppressed()) { | ||
| // we're in soaring mode with throttle suppressed | ||
| set_target_altitude_current(); | ||
| } else { | ||
| // we're in soaring mode climbing back to altitude. Set target to SOAR_ALT_CUTOFF plus 10m to ensure we positively climb | ||
| // through SOAR_ALT_CUTOFF, thus triggering throttle suppression and return to glide. | ||
| target_altitude.amsl_cm = 100*plane.g2.soaring_controller.get_alt_cutoff() + 1000 + AP::ahrs().get_home().alt; | ||
| } | ||
| if (plane.set_soaring_altitude()) { | ||
| // Just stopped soaring in this mode | ||
|
|
||
| // Continue flying with current altitude | ||
| plane.set_target_altitude_current(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me see if I get this right. Before:
Now:
It's a bit complicated, but right now I don't have an alternative at hand.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We would actually let the aircraft glide down, since throttle is suppressed.
This code was moved to I know this call site got a bit more involved, but on the request of @peterbarker now the switching logic is provided from only one place. The return value of the function is there to allow the mode calling it to know "we just ended soaring". I couldn't do the "maintain current altitude" feature from soaring itself, because it's a bit different for each supported flight mode. Most importantly, the behaviour is not complicated from end user's perspective:
I feel that this is easy to understand, but also makes sense that we don't lose all the energy we saved on powered climb to what FBWB happened to be flying before a thermal was detected.
Completely agree, and I think it would be fair to introduce "Merge on wiki completion" policy for user-facing features. But that's a discussion for another day :) |
||
| } | ||
| #endif | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,4 +58,25 @@ void Plane::update_soaring() { | |
| g2.soaring_controller.set_throttle_suppressed(false); | ||
| } | ||
|
|
||
| bool Plane::set_soaring_altitude() | ||
| { | ||
| if (!g2.soaring_controller.is_active()) { | ||
| // Notify the calling mode that we're exiting soaring and it needs to reset altitude | ||
| bool previous = soaring_was_active; | ||
| soaring_was_active = false; | ||
| return previous; | ||
| } | ||
|
|
||
| if (g2.soaring_controller.get_throttle_suppressed()) { | ||
| // we're in soaring mode with throttle suppressed | ||
| set_target_altitude_current(); | ||
| } else { | ||
| // we're in soaring mode climbing back to altitude. Set target to SOAR_ALT_CUTOFF plus 10m to ensure we positively climb | ||
| // through SOAR_ALT_CUTOFF, thus triggering throttle suppression and return to glide. | ||
| target_altitude.amsl_cm = 100 * (plane.g2.soaring_controller.get_alt_cutoff() + 10) + AP::ahrs().get_home().alt; | ||
| } | ||
| soaring_was_active = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag is only kept upto date in the new modes, it needs to be cleared when changing to a mode that does not support soaring. Maybe clear it in the |
||
| return false; | ||
| } | ||
|
|
||
| #endif // SOARING_ENABLED | ||
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 a bit hesitant with this. In FBWB and CRUISE the pilot files VLOS or at least VLOS.
But with LOITER and GUIDED, terrain becomes an issue. How will this play nice with a terrain where ALT_CUTOFF+10+<home_alt> is still lower than the terrain elevation?
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.
Perhaps an answer to my question would be "the same way this is treated in AUTO".
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.
All altitudes SOAR_ALT_MIN, SOAR_ALT_CUTOFF and SOAR_ALT_MAX are relative to home. Currently there no exceptions to that, including AUTO mode.
If we were to support a terrain height check, I think we should make it follow the present Terrain Following feature. Add another bit to TERRAIN_FOLLOW for Soaring and then check SOAR_ALT_MIN against terrain instead of home if that bit is set. But I think that both regarding code and user experience that is a separate feature that we can discuss in a separate Issue/PR if you think it's a requirement for GUIDED