void Plane::update_navigation() { // wp_distance is in ACTUAL meters, not the *100 meters we get from the GPS // ------------------------------------------------------------------------ uint16_t radius = 0; uint16_t qrtl_radius = abs(g.rtl_radius); if (qrtl_radius == 0) { qrtl_radius = abs(aparm.loiter_radius); } switch(control_mode) { case AUTO: if (ahrs.home_is_set()) { mission.update(); } break; case RTL: if (quadplane.available() && quadplane.rtl_mode == 1 && (nav_controller->reached_loiter_target() || location_passed_point(current_loc, prev_WP_loc, next_WP_loc) || auto_state.wp_distance < MAX(qrtl_radius, quadplane.stopping_distance())) && AP_HAL::millis() - last_mode_change_ms > 1000) { /* for a quadplane in RTL mode we switch to QRTL when we are within the maximum of the stopping distance and the RTL_RADIUS */ set_mode(QRTL, MODE_REASON_UNKNOWN); break; } else if (g.rtl_autoland == 1 && !auto_state.checked_for_autoland && reached_loiter_target() && labs(altitude_error_cm) < 1000) { // we've reached the RTL point, see if we have a landing sequence if (mission.jump_to_landing_sequence()) { // switch from RTL -> AUTO set_mode(AUTO, MODE_REASON_UNKNOWN); } // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } else if (g.rtl_autoland == 2 && !auto_state.checked_for_autoland) { // Go directly to the landing sequence if (mission.jump_to_landing_sequence()) { // switch from RTL -> AUTO set_mode(AUTO, MODE_REASON_UNKNOWN); } // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } radius = abs(g.rtl_radius); if (radius > 0) { loiter.direction = (g.rtl_radius < 0) ? -1 : 1; } // fall through to LOITER FALLTHROUGH; case LOITER: case AVOID_ADSB: case GUIDED: update_loiter(radius); break; case CRUISE: update_cruise(); break; case MANUAL: case STABILIZE: case TRAINING: case INITIALISING: case ACRO: case FLY_BY_WIRE_A: case AUTOTUNE: case FLY_BY_WIRE_B: case CIRCLE: case QSTABILIZE: case QHOVER: case QLOITER: case QLAND: case QRTL: // nothing to do break; } }
void Plane::update_navigation() { // wp_distance is in ACTUAL meters, not the *100 meters we get from the GPS // ------------------------------------------------------------------------ uint16_t radius = 0; switch(control_mode) { case AUTO: if (home_is_set != HOME_UNSET) { mission.update(); } break; case RTL: if (quadplane.available() && quadplane.rtl_mode == 1 && nav_controller->reached_loiter_target()) { set_mode(QRTL); break; } else if (g.rtl_autoland == 1 && !auto_state.checked_for_autoland && reached_loiter_target() && labs(altitude_error_cm) < 1000) { // we've reached the RTL point, see if we have a landing sequence jump_to_landing_sequence(); // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } else if (g.rtl_autoland == 2 && !auto_state.checked_for_autoland) { // Go directly to the landing sequence jump_to_landing_sequence(); // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } radius = abs(g.rtl_radius); if (radius > 0) { loiter.direction = (g.rtl_radius < 0) ? -1 : 1; } // fall through to LOITER case LOITER: case GUIDED: update_loiter(radius); break; case CRUISE: update_cruise(); break; case MANUAL: case STABILIZE: case TRAINING: case INITIALISING: case ACRO: case FLY_BY_WIRE_A: case AUTOTUNE: case FLY_BY_WIRE_B: case CIRCLE: case QSTABILIZE: case QHOVER: case QLOITER: case QLAND: case QRTL: // nothing to do break; } }
void Plane::update_navigation() { // wp_distance is in ACTUAL meters, not the *100 meters we get from the GPS // ------------------------------------------------------------------------ // distance and bearing calcs only switch(control_mode) { case AUTO: update_commands(); break; case RTL: if (g.rtl_autoland == 1 && !auto_state.checked_for_autoland && nav_controller->reached_loiter_target() && labs(altitude_error_cm) < 1000) { // we've reached the RTL point, see if we have a landing sequence jump_to_landing_sequence(); // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } else if (g.rtl_autoland == 2 && !auto_state.checked_for_autoland) { // Go directly to the landing sequence jump_to_landing_sequence(); // prevent running the expensive jump_to_landing_sequence // on every loop auto_state.checked_for_autoland = true; } // fall through to LOITER case LOITER: case GUIDED: // allow loiter direction to be changed in flight if (g.loiter_radius < 0) { loiter.direction = -1; } else { loiter.direction = 1; } update_loiter(); break; case CRUISE: update_cruise(); break; case MANUAL: case STABILIZE: case TRAINING: case INITIALISING: case ACRO: case FLY_BY_WIRE_A: case AUTOTUNE: case FLY_BY_WIRE_B: case CIRCLE: case QSTABILIZE: case QHOVER: case QLOITER: // nothing to do break; } }