Skip to content

Commit

Permalink
Plane: Enabled roll navigation in mode TAKEOFF during climb
Browse files Browse the repository at this point in the history
- Fixed lack of heading control during TAKEOFF climb.
- Also now the TAKEOFF loiter waypoint is set by the bearing of the
aircraft while on TKOFF_LVL_ALT, as in the last stable release, instead
of TKOFF_ALT.
  • Loading branch information
Georacer committed Aug 8, 2024
1 parent 33e81d9 commit 968fc1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ArduPlane/ArduPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void Plane::update_GPS_10Hz(void)
*/
void Plane::update_control_mode(void)
{
if (control_mode != &mode_auto) {
if ((control_mode != &mode_auto) && (control_mode != &mode_takeoff)) {
// hold_course is only used in takeoff and landing
steer_state.hold_course_cd = -1;
}
Expand Down
32 changes: 19 additions & 13 deletions ArduPlane/mode_takeoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void ModeTakeoff::update()
plane.set_flight_stage(AP_FixedWing::FlightStage::NORMAL);
} else {
gcs().send_text(MAV_SEVERITY_INFO, "Climbing to TKOFF alt then loitering");
start_loc = plane.current_loc;
plane.next_WP_loc = plane.current_loc;
plane.next_WP_loc.alt += ((alt - altitude) *100);
plane.next_WP_loc.offset_bearing(direction, dist);
Expand All @@ -119,32 +120,37 @@ void ModeTakeoff::update()
alt, dist, direction);
plane.takeoff_state.start_time_ms = millis();
takeoff_mode_setup = true;

plane.steer_state.hold_course_cd = wrap_360_cd(direction*100); // Necessary to allow Plane::takeoff_calc_roll() to function.
}
}
}
// check for optional takeoff timeout
if (plane.check_takeoff_timeout()) {
plane.set_flight_stage(AP_FixedWing::FlightStage::NORMAL);
takeoff_mode_setup = false;

}

// we finish the initial level takeoff if we climb past
// TKOFF_LVL_ALT or we pass the target location. The check for
// target location prevents us flying forever if we can't climb
// reset the loiter waypoint target to be correct bearing and dist
// from starting location in case original yaw used to set it was off due to EKF
// reset or compass interference from max throttle

// We update the waypoint to follow once we're past TKOFF_LVL_ALT.
// This will correct any yaw estimation errors (caused by EKF reset
// or compass interference from max throttle), since it's using position bearing.
const float altitude_cm = plane.current_loc.alt - start_loc.alt;
if (plane.flight_stage == AP_FixedWing::FlightStage::TAKEOFF &&
(altitude_cm >= (alt*100 - 200) ||
start_loc.get_distance(plane.current_loc) >= dist)) {
// reset the target loiter waypoint using current yaw which should be close to correct starting heading
if (plane.flight_stage == AP_FixedWing::FlightStage::TAKEOFF
&& plane.steer_state.hold_course_cd == -1 // This is the enter-once flag.
&& altitude_cm >= level_alt
) {
const float direction = start_loc.get_bearing_to(plane.current_loc) * 0.01;
plane.next_WP_loc = start_loc;
plane.next_WP_loc.offset_bearing(direction, dist);
plane.next_WP_loc.alt += alt*100.0;
plane.steer_state.hold_course_cd = wrap_360_cd(direction*100); // Necessary to allow Plane::takeoff_calc_roll() to function.
}

// We finish the initial level takeoff if we climb past
// TKOFF_ALT or we pass the target location. The check for
// target location prevents us flying forever if we can't climb.
if (plane.flight_stage == AP_FixedWing::FlightStage::TAKEOFF &&
(altitude_cm >= (alt*100 - 200) ||
start_loc.get_distance(plane.current_loc) >= dist)) {
plane.set_flight_stage(AP_FixedWing::FlightStage::NORMAL);
}

Expand Down

0 comments on commit 968fc1d

Please sign in to comment.