|
|
|
@ -4,6 +4,11 @@ Mode::_TakeOff Mode::takeoff;
@@ -4,6 +4,11 @@ Mode::_TakeOff Mode::takeoff;
|
|
|
|
|
|
|
|
|
|
bool Mode::auto_takeoff_no_nav_active = false; |
|
|
|
|
float Mode::auto_takeoff_no_nav_alt_cm = 0; |
|
|
|
|
float Mode::auto_take_off_start_alt_cm = 0; |
|
|
|
|
float Mode::auto_take_off_complete_alt_cm = 0; |
|
|
|
|
bool Mode::auto_takeoff_terrain_alt = false; |
|
|
|
|
bool Mode::auto_takeoff_complete = false; |
|
|
|
|
Vector3p Mode::auto_takeoff_complete_pos; |
|
|
|
|
|
|
|
|
|
// This file contains the high-level takeoff logic for Loiter, PosHold, AltHold, Sport modes.
|
|
|
|
|
// The take-off can be initiated from a GCS NAV_TAKEOFF command which includes a takeoff altitude
|
|
|
|
@ -93,13 +98,21 @@ void Mode::_TakeOff::do_pilot_takeoff(float& pilot_climb_rate_cm)
@@ -93,13 +98,21 @@ void Mode::_TakeOff::do_pilot_takeoff(float& pilot_climb_rate_cm)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// auto_takeoff_run - controls the vertical position controller during the process of taking off in auto modes
|
|
|
|
|
// auto_takeoff_complete set to true when target altitude is within 10% of the take off altitude and less than 50% max climb rate
|
|
|
|
|
void Mode::auto_takeoff_run() |
|
|
|
|
{ |
|
|
|
|
// if not armed set throttle to zero and exit immediately
|
|
|
|
|
if (!motors->armed() || !copter.ap.auto_armed) { |
|
|
|
|
// do not spool down tradheli when on the ground with motor interlock enabled
|
|
|
|
|
make_safe_ground_handling(copter.is_tradheli() && motors->get_interlock()); |
|
|
|
|
wp_nav->shift_wp_origin_and_destination_to_current_pos_xy(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// get terrain offset
|
|
|
|
|
float terr_offset = 0.0f; |
|
|
|
|
if (auto_takeoff_terrain_alt && !wp_nav->get_terrain_offset(terr_offset)) { |
|
|
|
|
gcs().send_text(MAV_SEVERITY_CRITICAL, "auto takeoff: failed to get terrain offset"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -116,17 +129,18 @@ void Mode::auto_takeoff_run()
@@ -116,17 +129,18 @@ void Mode::auto_takeoff_run()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// aircraft stays in landed state until rotor speed runup has finished
|
|
|
|
|
// aircraft stays in landed state until rotor speed run up has finished
|
|
|
|
|
if (motors->get_spool_state() == AP_Motors::SpoolState::THROTTLE_UNLIMITED) { |
|
|
|
|
set_land_complete(false); |
|
|
|
|
} else { |
|
|
|
|
// motors have not completed spool up yet so relax navigation and position controllers
|
|
|
|
|
wp_nav->shift_wp_origin_and_destination_to_current_pos_xy(); |
|
|
|
|
pos_control->relax_velocity_controller_xy(); |
|
|
|
|
pos_control->update_xy_controller(); |
|
|
|
|
pos_control->relax_z_controller(0.0f); // forces throttle output to decay to zero
|
|
|
|
|
pos_control->update_z_controller(); |
|
|
|
|
attitude_control->reset_yaw_target_and_rate(); |
|
|
|
|
attitude_control->reset_rate_controller_I_terms(); |
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw(0.0f, 0.0f, 0.0f); |
|
|
|
|
attitude_control->input_thrust_vector_rate_heading(pos_control->get_thrust_vector(), auto_yaw.rate_cds()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -135,51 +149,74 @@ void Mode::auto_takeoff_run()
@@ -135,51 +149,74 @@ void Mode::auto_takeoff_run()
|
|
|
|
|
// check if vehicle has reached no_nav_alt threshold
|
|
|
|
|
if (inertial_nav.get_position_z_up_cm() >= auto_takeoff_no_nav_alt_cm) { |
|
|
|
|
auto_takeoff_no_nav_active = false; |
|
|
|
|
wp_nav->shift_wp_origin_and_destination_to_stopping_point_xy(); |
|
|
|
|
} else { |
|
|
|
|
// shift the navigation target horizontally to our current position
|
|
|
|
|
wp_nav->shift_wp_origin_and_destination_to_current_pos_xy(); |
|
|
|
|
} |
|
|
|
|
// tell the position controller that we have limited roll/pitch demand to prevent integrator buildup
|
|
|
|
|
pos_control->set_externally_limited_xy(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// run waypoint controller
|
|
|
|
|
copter.failsafe_terrain_set_status(wp_nav->update_wpnav()); |
|
|
|
|
|
|
|
|
|
Vector3f thrustvector{0, 0, -GRAVITY_MSS * 100.0f}; |
|
|
|
|
if (!auto_takeoff_no_nav_active) { |
|
|
|
|
thrustvector = wp_nav->get_thrust_vector(); |
|
|
|
|
pos_control->relax_velocity_controller_xy(); |
|
|
|
|
} else { |
|
|
|
|
Vector2f vel; |
|
|
|
|
Vector2f accel; |
|
|
|
|
pos_control->input_vel_accel_xy(vel, accel); |
|
|
|
|
} |
|
|
|
|
pos_control->update_xy_controller(); |
|
|
|
|
|
|
|
|
|
// WP_Nav has set the vertical position control targets
|
|
|
|
|
// command the aircraft to the take off altitude
|
|
|
|
|
float pos_z = auto_take_off_complete_alt_cm + terr_offset; |
|
|
|
|
float vel_z = 0.0; |
|
|
|
|
copter.pos_control->input_pos_vel_accel_z(pos_z, vel_z, 0.0); |
|
|
|
|
|
|
|
|
|
// run the vertical position controller and set output throttle
|
|
|
|
|
copter.pos_control->update_z_controller(); |
|
|
|
|
pos_control->update_z_controller(); |
|
|
|
|
|
|
|
|
|
// call attitude controller
|
|
|
|
|
if (auto_yaw.mode() == AUTO_YAW_HOLD) { |
|
|
|
|
// roll & pitch from position controller, yaw rate from pilot
|
|
|
|
|
attitude_control->input_thrust_vector_rate_heading(thrustvector, target_yaw_rate); |
|
|
|
|
attitude_control->input_thrust_vector_rate_heading(pos_control->get_thrust_vector(), target_yaw_rate); |
|
|
|
|
} else if (auto_yaw.mode() == AUTO_YAW_RATE) { |
|
|
|
|
// roll & pitch from position controller, yaw rate from mavlink command or mission item
|
|
|
|
|
attitude_control->input_thrust_vector_rate_heading(thrustvector, auto_yaw.rate_cds()); |
|
|
|
|
attitude_control->input_thrust_vector_rate_heading(pos_control->get_thrust_vector(), auto_yaw.rate_cds()); |
|
|
|
|
} else { |
|
|
|
|
// roll & pitch from position controller, yaw heading from GCS or auto_heading()
|
|
|
|
|
attitude_control->input_thrust_vector_heading(thrustvector, auto_yaw.yaw(), auto_yaw.rate_cds()); |
|
|
|
|
attitude_control->input_thrust_vector_heading(pos_control->get_thrust_vector(), auto_yaw.yaw(), auto_yaw.rate_cds()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// handle takeoff completion
|
|
|
|
|
bool reached_altitude = (copter.pos_control->get_pos_target_z_cm() - auto_take_off_start_alt_cm) >= ((auto_take_off_complete_alt_cm - auto_take_off_start_alt_cm) * 0.90); |
|
|
|
|
bool reached_climb_rate = copter.pos_control->get_vel_desired_cms().z < copter.pos_control->get_max_speed_up_cms() * 0.5; |
|
|
|
|
auto_takeoff_complete = reached_altitude && reached_climb_rate; |
|
|
|
|
|
|
|
|
|
// calculate completion for location in case it is needed for a smooth transition to wp_nav
|
|
|
|
|
if (auto_takeoff_complete) { |
|
|
|
|
const Vector3p& complete_pos = copter.pos_control->get_pos_target_cm(); |
|
|
|
|
auto_takeoff_complete_pos = Vector3p{complete_pos.x, complete_pos.y, pos_z}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Mode::auto_takeoff_set_start_alt(void) |
|
|
|
|
void Mode::auto_takeoff_start(float complete_alt_cm, bool terrain_alt) |
|
|
|
|
{ |
|
|
|
|
auto_take_off_start_alt_cm = inertial_nav.get_position_z_up_cm(); |
|
|
|
|
auto_take_off_complete_alt_cm = complete_alt_cm; |
|
|
|
|
auto_takeoff_terrain_alt = terrain_alt; |
|
|
|
|
auto_takeoff_complete = false; |
|
|
|
|
if ((g2.wp_navalt_min > 0) && (is_disarmed_or_landed() || !motors->get_interlock())) { |
|
|
|
|
// we are not flying, climb with no navigation to current alt-above-ekf-origin + wp_navalt_min
|
|
|
|
|
auto_takeoff_no_nav_alt_cm = inertial_nav.get_position_z_up_cm() + g2.wp_navalt_min * 100; |
|
|
|
|
auto_takeoff_no_nav_alt_cm = auto_take_off_start_alt_cm + g2.wp_navalt_min * 100; |
|
|
|
|
auto_takeoff_no_nav_active = true; |
|
|
|
|
} else { |
|
|
|
|
auto_takeoff_no_nav_active = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// return takeoff final position if takeoff has completed successfully
|
|
|
|
|
bool Mode::auto_takeoff_get_position(Vector3p& complete_pos) |
|
|
|
|
{ |
|
|
|
|
// only provide location if takeoff has completed
|
|
|
|
|
if (!auto_takeoff_complete) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
complete_pos = auto_takeoff_complete_pos; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Mode::is_taking_off() const |
|
|
|
|
{ |
|
|
|
|
if (!has_user_takeoff(false)) { |
|
|
|
|