Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Wing: Compensate minimum sink rate based on weight ratio and air density #22049

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions src/modules/fw_pos_control/FixedwingPositionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,21 @@ FixedwingPositionControl::init()
return true;
}

float FixedwingPositionControl::getMaximumClimbRate()
float FixedwingPositionControl::getWeightRatio()
{

float weight_factor = 1.0f;

if (_param_weight_base.get() > 0.0f && _param_weight_gross.get() > 0.0f) {
weight_factor = math::constrain(_param_weight_base.get() / _param_weight_gross.get(), MIN_WEIGHT_RATIO,
if (_param_weight_base.get() > FLT_EPSILON && _param_weight_gross.get() > FLT_EPSILON) {
weight_factor = math::constrain(_param_weight_gross.get() / _param_weight_base.get(), MIN_WEIGHT_RATIO,
MAX_WEIGHT_RATIO);
}

return weight_factor;
}

float FixedwingPositionControl::getMaximumClimbRate()
{
float climbrate_max = _param_fw_t_clmb_max.get();

const float density_min = _param_density_min.get();
Expand All @@ -116,7 +121,12 @@ float FixedwingPositionControl::getMaximumClimbRate()
climbrate_max = _param_fw_t_clmb_max.get() + density_gradient * delta_rho;
}

return climbrate_max * weight_factor;
return climbrate_max / getWeightRatio();
}

float FixedwingPositionControl::getMinimumSinkRate()
{
return _param_fw_t_sink_min.get() * sqrtf(getWeightRatio() * CONSTANTS_AIR_DENSITY_SEA_LEVEL_15C / _air_density);
}

int
Expand Down Expand Up @@ -147,7 +157,7 @@ FixedwingPositionControl::parameters_update()

// TECS parameters
_tecs.set_max_climb_rate(getMaximumClimbRate());
_tecs.set_max_sink_rate(_param_fw_t_sink_max.get());
_tecs.set_max_sink_rate(getMinimumSinkRate());
_tecs.set_min_sink_rate(_param_fw_t_sink_min.get());
_tecs.set_speed_weight(_param_fw_t_spdweight.get());
_tecs.set_equivalent_airspeed_trim(_param_fw_airspd_trim.get());
Expand Down Expand Up @@ -451,19 +461,12 @@ FixedwingPositionControl::adapt_airspeed_setpoint(const float control_interval,
load_factor_from_bank_angle = 1.0f / cosf(_att_sp.roll_body);
}

float weight_ratio = 1.0f;

if (_param_weight_base.get() > FLT_EPSILON && _param_weight_gross.get() > FLT_EPSILON) {
weight_ratio = math::constrain(_param_weight_gross.get() / _param_weight_base.get(), MIN_WEIGHT_RATIO,
MAX_WEIGHT_RATIO);
}

// Here we make sure that the set minimum airspeed is automatically adapted to the current load factor.
// The minimum airspeed is the controller limit (FW_AIRSPD_MIN, unless either in takeoff or landing) that should
// resemble the vehicles stall speed (CAS) with a 1g load plus some safety margin (as no controller tracks perfectly).
// Stall speed increases with the square root of the load factor: V_stall ~ sqrt(load_factor).
// The load_factor is composed of a term from the bank angle and a term from the weight ratio.
calibrated_min_airspeed *= sqrtf(load_factor_from_bank_angle * weight_ratio);
calibrated_min_airspeed *= sqrtf(load_factor_from_bank_angle * getWeightRatio());

// Aditional option to increase the min airspeed setpoint based on wind estimate for more stability in higher winds.
if (_airspeed_valid && _wind_valid && _param_fw_wind_arsp_sc.get() > FLT_EPSILON) {
Expand Down Expand Up @@ -2292,6 +2295,7 @@ FixedwingPositionControl::Run()
if (_vehicle_air_data_sub.update(&air_data)) {
_air_density = PX4_ISFINITE(air_data.rho) ? air_data.rho : _air_density;
_tecs.set_max_climb_rate(getMaximumClimbRate());
_tecs.set_min_sink_rate(getMinimumSinkRate());
}

if (_vehicle_land_detected_sub.updated()) {
Expand Down Expand Up @@ -2508,13 +2512,6 @@ float FixedwingPositionControl::calculateTrimThrottle(float throttle_min,
throttle_trim = _param_fw_thr_trim.get() + slope_above_trim * (airspeed_sp - _param_fw_airspd_trim.get());
}

float weight_ratio = 1.0f;

if (_param_weight_base.get() > FLT_EPSILON && _param_weight_gross.get() > FLT_EPSILON) {
weight_ratio = math::constrain(_param_weight_gross.get() / _param_weight_base.get(), MIN_WEIGHT_RATIO,
MAX_WEIGHT_RATIO);
}

float air_density_throttle_scale = 1.0f;

if (PX4_ISFINITE(_air_density)) {
Expand All @@ -2525,7 +2522,8 @@ float FixedwingPositionControl::calculateTrimThrottle(float throttle_min,
}

// compensate trim throttle for both weight and air density
return math::constrain(throttle_trim * sqrtf(weight_ratio) * air_density_throttle_scale, throttle_min, throttle_max);
return math::constrain(throttle_trim * sqrtf(getWeightRatio()) * air_density_throttle_scale, throttle_min,
throttle_max);
}

void
Expand Down
17 changes: 17 additions & 0 deletions src/modules/fw_pos_control/FixedwingPositionControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,24 @@ class FixedwingPositionControl final : public ModuleBase<FixedwingPositionContro
*/
float get_terrain_altitude_takeoff(float takeoff_alt);

/**
* @brief Return the maximum climb rate achievable given the estimated air density and the vehicle weight.
* @return Maximum climbrate [m/s].
*/
float getMaximumClimbRate();

/**
* @brief Return the minimum sink rate achievable given the estimated air density and the vehicle weight.
* @return Minimum sink rate [m/s].
*/
float getMinimumSinkRate();

/**
* @brief Return the ratio of actual vehicle weight to vehicle base weight.
* @return Weight ratio.
*/
float getWeightRatio();

/**
* @brief Maps the manual control setpoint (pilot sticks) to height rate commands
*
Expand Down