mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 12:40:35 +08:00
fw att control: bugfixes for integrator
This commit is contained in:
@@ -116,8 +116,7 @@ float ECL_PitchController::control_bodyrate(float roll, float pitch,
|
||||
/* get the usual dt estimate */
|
||||
uint64_t dt_micros = ecl_elapsed_time(&_last_run);
|
||||
_last_run = ecl_absolute_time();
|
||||
|
||||
float dt = dt_micros / 1000000;
|
||||
float dt = (dt_micros > 500000) ? 0.0f : (float)dt_micros * 1e-6f;
|
||||
|
||||
/* lock integral for long intervals */
|
||||
if (dt_micros > 500000)
|
||||
@@ -142,11 +141,9 @@ float ECL_PitchController::control_bodyrate(float roll, float pitch,
|
||||
|
||||
_rate_error = _bodyrate_setpoint - pitch_bodyrate;
|
||||
|
||||
float ilimit_scaled = 0.0f;
|
||||
|
||||
if (!lock_integrator && k_i_rate > 0.0f && airspeed > 0.5f * airspeed_min) {
|
||||
|
||||
float id = _rate_error * k_i_rate * dt * scaler;
|
||||
float id = _rate_error * dt;
|
||||
|
||||
/*
|
||||
* anti-windup: do not allow integrator to increase into the
|
||||
@@ -164,9 +161,9 @@ float ECL_PitchController::control_bodyrate(float roll, float pitch,
|
||||
}
|
||||
|
||||
/* integrator limit */
|
||||
_integrator = math::constrain(_integrator, -ilimit_scaled, ilimit_scaled);
|
||||
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
|
||||
/* store non-limited output */
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator + (_rate_setpoint * k_roll_ff)) * scaler;
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator * k_i_rate * scaler + (_rate_setpoint * k_roll_ff)) * scaler;
|
||||
|
||||
return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <geo/geo.h>
|
||||
#include <ecl/ecl.h>
|
||||
#include <mathlib/mathlib.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
ECL_RollController::ECL_RollController() :
|
||||
_last_run(0),
|
||||
@@ -85,7 +86,7 @@ float ECL_RollController::control_bodyrate(float pitch,
|
||||
/* get the usual dt estimate */
|
||||
uint64_t dt_micros = ecl_elapsed_time(&_last_run);
|
||||
_last_run = ecl_absolute_time();
|
||||
float dt = (dt_micros > 500000) ? 0.0f : dt_micros / 1000000;
|
||||
float dt = (dt_micros > 500000) ? 0.0f : (float)dt_micros * 1e-6f;
|
||||
|
||||
float k_ff = math::max((_k_p - _k_i * _tc) * _tc - _k_d, 0.0f);
|
||||
float k_i_rate = _k_i * _tc;
|
||||
@@ -108,11 +109,9 @@ float ECL_RollController::control_bodyrate(float pitch,
|
||||
/* Calculate body angular rate error */
|
||||
_rate_error = _bodyrate_setpoint - roll_bodyrate; //body angular rate error
|
||||
|
||||
float ilimit_scaled = 0.0f;
|
||||
|
||||
if (!lock_integrator && k_i_rate > 0.0f && airspeed > 0.5f * airspeed_min) {
|
||||
|
||||
float id = _rate_error * k_i_rate * dt * scaler;
|
||||
float id = _rate_error * dt;
|
||||
|
||||
/*
|
||||
* anti-windup: do not allow integrator to increase into the
|
||||
@@ -130,9 +129,11 @@ float ECL_RollController::control_bodyrate(float pitch,
|
||||
}
|
||||
|
||||
/* integrator limit */
|
||||
_integrator = math::constrain(_integrator, -ilimit_scaled, ilimit_scaled);
|
||||
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
|
||||
//warnx("roll: _integrator: %.4f, _integrator_max: %.4f", (double)_integrator, (double)_integrator_max);
|
||||
|
||||
/* store non-limited output */
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator + (_rate_setpoint * k_ff)) * scaler;
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator * k_i_rate * scaler + (_rate_setpoint * k_ff)) * scaler;
|
||||
|
||||
return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <geo/geo.h>
|
||||
#include <ecl/ecl.h>
|
||||
#include <mathlib/mathlib.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
ECL_YawController::ECL_YawController() :
|
||||
_last_run(0),
|
||||
@@ -53,7 +54,8 @@ ECL_YawController::ECL_YawController() :
|
||||
_rate_error(0.0f),
|
||||
_rate_setpoint(0.0f),
|
||||
_bodyrate_setpoint(0.0f),
|
||||
_max_deflection_rad(math::radians(45.0f))
|
||||
_max_deflection_rad(math::radians(45.0f)),
|
||||
_coordinated(1.0f)
|
||||
|
||||
{
|
||||
|
||||
@@ -63,11 +65,18 @@ float ECL_YawController::control_attitude(float roll, float pitch,
|
||||
float speed_body_u, float speed_body_w,
|
||||
float roll_rate_setpoint, float pitch_rate_setpoint)
|
||||
{
|
||||
// static int counter = 0;
|
||||
/* Calculate desired yaw rate from coordinated turn constraint / (no side forces) */
|
||||
_rate_setpoint = 0.0f;
|
||||
float denumerator = (speed_body_u * cosf(roll) * cosf(pitch) + speed_body_w * sinf(pitch));
|
||||
if(denumerator != 0.0f) { //XXX: floating point comparison
|
||||
_rate_setpoint = (speed_body_w * roll_rate_setpoint + 9.81f * sinf(roll) * cosf(pitch) + speed_body_u * pitch_rate_setpoint * sinf(roll)) / denumerator;
|
||||
if (_coordinated > 0.1) {
|
||||
float denumerator = (speed_body_u * cosf(roll) * cosf(pitch) + speed_body_w * sinf(pitch));
|
||||
if(denumerator != 0.0f) { //XXX: floating point comparison
|
||||
_rate_setpoint = (speed_body_w * roll_rate_setpoint + 9.81f * sinf(roll) * cosf(pitch) + speed_body_u * pitch_rate_setpoint * sinf(roll)) / denumerator;
|
||||
}
|
||||
|
||||
// if(counter % 20 == 0) {
|
||||
// warnx("denumerator: %.4f, speed_body_u: %.4f, speed_body_w: %.4f, cosf(roll): %.4f, cosf(pitch): %.4f, sinf(pitch): %.4f", (double)denumerator, (double)speed_body_u, (double)speed_body_w, (double)cosf(roll), (double)cosf(pitch), (double)sinf(pitch));
|
||||
// }
|
||||
}
|
||||
|
||||
/* limit the rate */ //XXX: move to body angluar rates
|
||||
@@ -76,6 +85,9 @@ float ECL_YawController::control_attitude(float roll, float pitch,
|
||||
_rate_setpoint = (_rate_setpoint < -_max_rate) ? -_max_rate : _rate_setpoint;
|
||||
}
|
||||
|
||||
|
||||
// counter++;
|
||||
|
||||
return _rate_setpoint;
|
||||
}
|
||||
|
||||
@@ -87,7 +99,7 @@ float ECL_YawController::control_bodyrate(float roll, float pitch,
|
||||
/* get the usual dt estimate */
|
||||
uint64_t dt_micros = ecl_elapsed_time(&_last_run);
|
||||
_last_run = ecl_absolute_time();
|
||||
float dt = (dt_micros > 500000) ? 0.0f : dt_micros / 1000000;
|
||||
float dt = (dt_micros > 500000) ? 0.0f : (float)dt_micros * 1e-6f;
|
||||
|
||||
float k_ff = math::max((_k_p - _k_i * _tc) * _tc - _k_d, 0.0f);
|
||||
float k_i_rate = _k_i * _tc;
|
||||
@@ -110,11 +122,9 @@ float ECL_YawController::control_bodyrate(float roll, float pitch,
|
||||
/* Calculate body angular rate error */
|
||||
_rate_error = _bodyrate_setpoint - yaw_bodyrate; //body angular rate error
|
||||
|
||||
float ilimit_scaled = 0.0f;
|
||||
|
||||
if (!lock_integrator && k_i_rate > 0.0f && airspeed > 0.5f * airspeed_min) {
|
||||
|
||||
float id = _rate_error * k_i_rate * dt * scaler;
|
||||
float id = _rate_error * dt;
|
||||
|
||||
/*
|
||||
* anti-windup: do not allow integrator to increase into the
|
||||
@@ -132,9 +142,9 @@ float ECL_YawController::control_bodyrate(float roll, float pitch,
|
||||
}
|
||||
|
||||
/* integrator limit */
|
||||
_integrator = math::constrain(_integrator, -ilimit_scaled, ilimit_scaled);
|
||||
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
|
||||
/* store non-limited output */
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator + (_rate_setpoint * k_ff)) * scaler;
|
||||
_last_output = ((_rate_error * _k_d * scaler) + _integrator * k_i_rate * scaler + (_rate_setpoint * k_ff)) * scaler;
|
||||
|
||||
return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,9 @@ public:
|
||||
void set_k_roll_ff(float roll_ff) {
|
||||
_roll_ff = roll_ff;
|
||||
}
|
||||
void set_coordinated(float coordinated) {
|
||||
_coordinated = coordinated;
|
||||
}
|
||||
|
||||
|
||||
float get_rate_error() {
|
||||
@@ -115,6 +118,7 @@ private:
|
||||
float _rate_setpoint;
|
||||
float _bodyrate_setpoint;
|
||||
float _max_deflection_rad;
|
||||
float _coordinated;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ private:
|
||||
float y_d;
|
||||
float y_roll_feedforward;
|
||||
float y_integrator_max;
|
||||
float y_coordinated;
|
||||
|
||||
float airspeed_min;
|
||||
float airspeed_trim;
|
||||
@@ -181,6 +182,7 @@ private:
|
||||
param_t y_d;
|
||||
param_t y_roll_feedforward;
|
||||
param_t y_integrator_max;
|
||||
param_t y_coordinated;
|
||||
|
||||
param_t airspeed_min;
|
||||
param_t airspeed_trim;
|
||||
@@ -289,25 +291,27 @@ FixedwingAttitudeControl::FixedwingAttitudeControl() :
|
||||
_parameter_handles.p_i = param_find("FW_P_I");
|
||||
_parameter_handles.p_rmax_pos = param_find("FW_P_RMAX_POS");
|
||||
_parameter_handles.p_rmax_neg = param_find("FW_P_RMAX_NEG");
|
||||
_parameter_handles.p_integrator_max = param_find("FW_P_integrator_max");
|
||||
_parameter_handles.p_integrator_max = param_find("FW_P_IMAX");
|
||||
_parameter_handles.p_roll_feedforward = param_find("FW_P_ROLLFF");
|
||||
|
||||
_parameter_handles.r_p = param_find("FW_R_P");
|
||||
_parameter_handles.r_d = param_find("FW_R_D");
|
||||
_parameter_handles.r_i = param_find("FW_R_I");
|
||||
_parameter_handles.r_integrator_max = param_find("FW_R_integrator_max");
|
||||
_parameter_handles.r_integrator_max = param_find("FW_R_IMAX");
|
||||
_parameter_handles.r_rmax = param_find("FW_R_RMAX");
|
||||
|
||||
_parameter_handles.y_p = param_find("FW_Y_P");
|
||||
_parameter_handles.y_i = param_find("FW_Y_I");
|
||||
_parameter_handles.y_d = param_find("FW_Y_D");
|
||||
_parameter_handles.y_roll_feedforward = param_find("FW_Y_ROLLFF");
|
||||
_parameter_handles.y_integrator_max = param_find("FW_Y_integrator_max");
|
||||
_parameter_handles.y_integrator_max = param_find("FW_Y_IMAX");
|
||||
|
||||
_parameter_handles.airspeed_min = param_find("FW_AIRSPD_MIN");
|
||||
_parameter_handles.airspeed_trim = param_find("FW_AIRSPD_TRIM");
|
||||
_parameter_handles.airspeed_max = param_find("FW_AIRSPD_MAX");
|
||||
|
||||
_parameter_handles.y_coordinated = param_find("FW_Y_COORD");
|
||||
|
||||
/* fetch initial parameter values */
|
||||
parameters_update();
|
||||
}
|
||||
@@ -361,6 +365,7 @@ FixedwingAttitudeControl::parameters_update()
|
||||
param_get(_parameter_handles.y_d, &(_parameters.y_d));
|
||||
param_get(_parameter_handles.y_roll_feedforward, &(_parameters.y_roll_feedforward));
|
||||
param_get(_parameter_handles.y_integrator_max, &(_parameters.y_integrator_max));
|
||||
param_get(_parameter_handles.y_coordinated, &(_parameters.y_coordinated));
|
||||
|
||||
param_get(_parameter_handles.airspeed_min, &(_parameters.airspeed_min));
|
||||
param_get(_parameter_handles.airspeed_trim, &(_parameters.airspeed_trim));
|
||||
@@ -390,6 +395,7 @@ FixedwingAttitudeControl::parameters_update()
|
||||
_yaw_ctrl.set_k_d(math::radians(_parameters.y_d));
|
||||
_yaw_ctrl.set_k_roll_ff(math::radians(_parameters.y_roll_feedforward));
|
||||
_yaw_ctrl.set_integrator_max(math::radians(_parameters.y_integrator_max));
|
||||
_yaw_ctrl.set_coordinated(_parameters.y_coordinated);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -709,9 +715,9 @@ FixedwingAttitudeControl::task_main()
|
||||
* only once available
|
||||
*/
|
||||
vehicle_rates_setpoint_s rates_sp;
|
||||
rates_sp.roll = _roll_ctrl.get_desired_bodyrate();
|
||||
rates_sp.pitch = _pitch_ctrl.get_desired_bodyrate();
|
||||
rates_sp.yaw = _yaw_ctrl.get_desired_bodyrate();
|
||||
rates_sp.roll = _roll_ctrl.get_desired_rate();
|
||||
rates_sp.pitch = _pitch_ctrl.get_desired_rate();
|
||||
rates_sp.yaw = _yaw_ctrl.get_desired_rate();
|
||||
|
||||
rates_sp.timestamp = hrt_absolute_time();
|
||||
|
||||
|
||||
@@ -136,3 +136,4 @@ PARAM_DEFINE_FLOAT(FW_Y_ROLLFF, 0);
|
||||
PARAM_DEFINE_FLOAT(FW_AIRSPD_MIN, 9.0f);
|
||||
PARAM_DEFINE_FLOAT(FW_AIRSPD_TRIM, 12.0f);
|
||||
PARAM_DEFINE_FLOAT(FW_AIRSPD_MAX, 18.0f);
|
||||
PARAM_DEFINE_FLOAT(FW_Y_COORD, 1.0f);
|
||||
|
||||
Reference in New Issue
Block a user