-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
WIP: AUTOLAND mode for Plane #28726
Closed
Closed
WIP: AUTOLAND mode for Plane #28726
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8cdda5c
Plane:capture takeoff direction
Hwurzburg 80d54fe
Plane:wip:params and framework
Hwurzburg 0bc6e5f
Plane:added final wp and fly to it
Hwurzburg 769ee2b
Plane:wip:add land cmd
Hwurzburg a9880f0
Plane:wip..add entry checks
Hwurzburg ab7eb93
Plan:wip;fix altitude slope issue
Hwurzburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include "mode.h" | ||
#include "Plane.h" | ||
#include <GCS_MAVLink/GCS.h> | ||
|
||
/* | ||
mode AutoLand parameters | ||
*/ | ||
const AP_Param::GroupInfo ModeAutoLand::var_info[] = { | ||
// @Param: WP_ALT | ||
// @DisplayName: Final approach WP altitude | ||
// @Description: This is the target altitude for final approach waypoint | ||
// @Range: 0 200 | ||
// @Increment: 1 | ||
// @Units: m | ||
// @User: Standard | ||
AP_GROUPINFO("WP_ALT", 1, ModeAutoLand, final_wp_alt, 55), | ||
|
||
// @Param: DIST | ||
// @DisplayName: Final approach WP distance | ||
// @Description: This is the distance from Home that the final approach waypoint is set. The waypoint point will be in the opposite direction of takeoff (the direction the plane is facing when the plane sets its takeoff heading) | ||
// @Range: 0 700 | ||
// @Increment: 1 | ||
// @Units: m | ||
// @User: Standard | ||
AP_GROUPINFO("WP_DIST", 2, ModeAutoLand, final_wp_dist, 400), | ||
|
||
AP_GROUPEND | ||
}; | ||
|
||
ModeAutoLand::ModeAutoLand() : | ||
Mode() | ||
{ | ||
AP_Param::setup_object_defaults(this, var_info); | ||
} | ||
|
||
bool ModeAutoLand::_enter() | ||
{ | ||
//must be flying to enter | ||
if (!plane.is_flying()) { | ||
return false; | ||
} | ||
|
||
//if do_land_start exists, jump to it | ||
if( (plane.mission.contains_item(MAV_CMD_DO_LAND_START)) && (plane.arming.is_armed())) { | ||
if (plane.have_position && plane.mission.jump_to_landing_sequence(plane.current_loc)) { | ||
// switch to AUTO | ||
plane.mission.set_force_resume(true); | ||
if (plane.set_mode(plane.mode_auto, ModeReason::FIXED_WING_AUTOLAND)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
//setup final approach waypoint | ||
plane.prev_WP_loc = plane.current_loc; | ||
const Location &home = ahrs.get_home(); | ||
plane.set_target_altitude_current(); | ||
plane.next_WP_loc = home; | ||
uint16_t bearing_cd = wrap_360((plane.takeoff_state.takeoff_initial_direction + 180)); | ||
plane.next_WP_loc.offset_bearing(bearing_cd, final_wp_dist); | ||
plane.next_WP_loc.alt = home.alt + final_wp_alt*100; | ||
|
||
// create a command to fly to final approach waypoint and start it | ||
cmd.id = MAV_CMD_NAV_WAYPOINT; | ||
cmd.content.location = plane.next_WP_loc; | ||
plane.start_command(cmd); | ||
land_started = false; | ||
|
||
return true; | ||
} | ||
|
||
void ModeAutoLand::update() | ||
{ | ||
plane.calc_nav_roll(); | ||
plane.calc_nav_pitch(); | ||
plane.set_offset_altitude_location(plane.prev_WP_loc, plane.next_WP_loc); | ||
if (plane.landing.is_throttle_suppressed()) { | ||
// if landing is considered complete throttle is never allowed, regardless of landing type | ||
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, 0.0); | ||
} else { | ||
plane.calc_throttle(); | ||
} | ||
} | ||
|
||
void ModeAutoLand::navigate() | ||
{ | ||
// check to see if if we have reached final approach waypoint, switch to NAV_LAND command and start it once if so | ||
if (!land_started){ | ||
if (plane.verify_nav_wp(cmd)){ | ||
const Location &home_loc = ahrs.get_home(); | ||
cmd.id = MAV_CMD_NAV_LAND; | ||
cmd.content.location = home_loc; | ||
land_started = true; | ||
plane.prev_WP_loc = plane.current_loc; | ||
plane.next_WP_loc = home_loc; | ||
plane.set_offset_altitude_location(plane.prev_WP_loc, plane.next_WP_loc); | ||
plane.start_command(cmd); | ||
} | ||
return; | ||
//otherwise keep flying the current command | ||
} else { | ||
plane.verify_command(cmd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're trying to move to always using a frame with an altitude. Could you use set_alt_cm()? (or set_alt_m() but since you have cm anyway ...).