Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/ArduCopter/baro_ground_effect.cpp
Views: 1798
#include "Copter.h"12void Copter::update_ground_effect_detector(void)3{4if(!g2.gndeffect_comp_enabled || !motors->armed()) {5// disarmed - disable ground effect and return6gndeffect_state.takeoff_expected = false;7gndeffect_state.touchdown_expected = false;8ahrs.set_takeoff_expected(gndeffect_state.takeoff_expected);9ahrs.set_touchdown_expected(gndeffect_state.touchdown_expected);10return;11}1213// variable initialization14uint32_t tnow_ms = millis();15float xy_des_speed_cms = 0.0f;16float xy_speed_cms = 0.0f;17float des_climb_rate_cms = pos_control->get_vel_desired_cms().z;1819if (pos_control->is_active_xy()) {20Vector3f vel_target = pos_control->get_vel_target_cms();21vel_target.z = 0.0f;22xy_des_speed_cms = vel_target.length();23}2425if (position_ok() || ekf_has_relative_position()) {26Vector3f vel = inertial_nav.get_velocity_neu_cms();27vel.z = 0.0f;28xy_speed_cms = vel.length();29}3031// takeoff logic3233if (flightmode->mode_number() == Mode::Number::THROW) {34// throw mode never wants the takeoff expected EKF code35gndeffect_state.takeoff_expected = false;36} else if (motors->armed() && ap.land_complete) {37// if we are armed and haven't yet taken off then we expect an imminent takeoff38gndeffect_state.takeoff_expected = true;39}4041// if we aren't taking off yet, reset the takeoff timer, altitude and complete flag42const bool throttle_up = flightmode->has_manual_throttle() && channel_throttle->get_control_in() > 0;43if (!throttle_up && ap.land_complete) {44gndeffect_state.takeoff_time_ms = tnow_ms;45gndeffect_state.takeoff_alt_cm = inertial_nav.get_position_z_up_cm();46}4748// if we are in takeoff_expected and we meet the conditions for having taken off49// end the takeoff_expected state50if (gndeffect_state.takeoff_expected && (tnow_ms-gndeffect_state.takeoff_time_ms > 5000 || inertial_nav.get_position_z_up_cm()-gndeffect_state.takeoff_alt_cm > 50.0f)) {51gndeffect_state.takeoff_expected = false;52}5354// landing logic55Vector3f angle_target_rad = attitude_control->get_att_target_euler_cd() * radians(0.01f);56bool small_angle_request = cosf(angle_target_rad.x)*cosf(angle_target_rad.y) > cosf(radians(7.5f));57bool xy_speed_low = (position_ok() || ekf_has_relative_position()) && xy_speed_cms <= 125.0f;58bool xy_speed_demand_low = pos_control->is_active_xy() && xy_des_speed_cms <= 125.0f;59bool slow_horizontal = xy_speed_demand_low || (xy_speed_low && !pos_control->is_active_xy()) || (flightmode->mode_number() == Mode::Number::ALT_HOLD && small_angle_request);6061bool descent_demanded = pos_control->is_active_z() && des_climb_rate_cms < 0.0f;62bool slow_descent_demanded = descent_demanded && des_climb_rate_cms >= -100.0f;63bool z_speed_low = fabsf(inertial_nav.get_velocity_z_up_cms()) <= 60.0f;64bool slow_descent = (slow_descent_demanded || (z_speed_low && descent_demanded));6566gndeffect_state.touchdown_expected = slow_horizontal && slow_descent;6768// Prepare the EKF for ground effect if either takeoff or touchdown is expected.69ahrs.set_takeoff_expected(gndeffect_state.takeoff_expected);70ahrs.set_touchdown_expected(gndeffect_state.touchdown_expected);71}7273// update ekf terrain height stable setting74// when set to true, this allows the EKF to stabilize the normally barometer based altitude using a rangefinder75// this is not related to terrain following76void Copter::update_ekf_terrain_height_stable()77{78// set to false if no position estimate79if (!position_ok() && !ekf_has_relative_position()) {80ahrs.set_terrain_hgt_stable(false);81return;82}8384// consider terrain height stable if vehicle is taking off or landing85ahrs.set_terrain_hgt_stable(flightmode->is_taking_off() || flightmode->is_landing());86}878889