Skip to content

Commit

Permalink
add land cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Hwurzburg committed Nov 24, 2024
1 parent a1defd0 commit 3a47dc2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ArduPlane/ArduPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,13 @@ void Plane::update_flight_stage(void)
}
#endif
set_flight_stage(AP_FixedWing::FlightStage::NORMAL);
} else if (control_mode != &mode_takeoff) {
} else if ((control_mode != &mode_takeoff) && (control_mode != &mode_autoland)) {
// If not in AUTO then assume normal operation for normal TECS operation.
// This prevents TECS from being stuck in the wrong stage if you switch from
// AUTO to, say, FBWB during a landing, an aborted landing or takeoff.
set_flight_stage(AP_FixedWing::FlightStage::NORMAL);
} else if (control_mode == &mode_autoland) {
set_flight_stage(AP_FixedWing::FlightStage::LAND);
}
return;
}
Expand Down
2 changes: 2 additions & 0 deletions ArduPlane/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ class ModeAutoLand: public Mode

protected:
bool _enter() override;
AP_Mission::Mission_Command cmd {};
bool land_started;


private:
Expand Down
16 changes: 15 additions & 1 deletion ArduPlane/mode_autoland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ bool ModeAutoLand::_enter()
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;
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location = plane.next_WP_loc;
land_started = false;
return true;
}

Expand All @@ -56,5 +59,16 @@ void ModeAutoLand::update()

void ModeAutoLand::navigate()
{
plane.nav_controller->update_waypoint(plane.prev_WP_loc, plane.next_WP_loc);
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.start_command(cmd);
}
return;
} else {
plane.verify_command(cmd);
}
}

0 comments on commit 3a47dc2

Please sign in to comment.