mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 23:23:33 +08:00
fw attitude controllers: restructuring in order to allow acro flight mode
- split rate control into body rate control and euler rate control - this allows standard attitude control but also direct rate control of all three axes - allow activation/deactivation of turn compensation Signed-off-by: Roman <bapstroman@gmail.com>
This commit is contained in:
@@ -91,8 +91,8 @@ float ECL_PitchController::control_bodyrate(const struct ECL_ControlData &ctl_da
|
||||
/* Do not calculate control signal with bad inputs */
|
||||
if (!(PX4_ISFINITE(ctl_data.roll) &&
|
||||
PX4_ISFINITE(ctl_data.pitch) &&
|
||||
PX4_ISFINITE(ctl_data.pitch_rate) &&
|
||||
PX4_ISFINITE(ctl_data.yaw_rate) &&
|
||||
PX4_ISFINITE(ctl_data.body_y_rate) &&
|
||||
PX4_ISFINITE(ctl_data.body_z_rate) &&
|
||||
PX4_ISFINITE(ctl_data.yaw_rate_setpoint) &&
|
||||
PX4_ISFINITE(ctl_data.airspeed_min) &&
|
||||
PX4_ISFINITE(ctl_data.airspeed_max) &&
|
||||
@@ -112,10 +112,6 @@ float ECL_PitchController::control_bodyrate(const struct ECL_ControlData &ctl_da
|
||||
lock_integrator = true;
|
||||
}
|
||||
|
||||
/* Transform setpoint to body angular rates (jacobian) */
|
||||
_bodyrate_setpoint = cosf(ctl_data.roll) * _rate_setpoint +
|
||||
cosf(ctl_data.pitch) * sinf(ctl_data.roll) * ctl_data.yaw_rate_setpoint;
|
||||
|
||||
/* apply turning offset to desired bodyrate setpoint*/
|
||||
/* flying inverted (wings upside down)*/
|
||||
bool inverted = false;
|
||||
@@ -144,22 +140,24 @@ float ECL_PitchController::control_bodyrate(const struct ECL_ControlData &ctl_da
|
||||
/* input conditioning */
|
||||
float airspeed = constrain_airspeed(ctl_data.airspeed, ctl_data.airspeed_min, ctl_data.airspeed_max);
|
||||
|
||||
/* Calculate desired body fixed y-axis angular rate needed to compensate for roll angle.
|
||||
For reference see Automatic Control of Aircraft and Missiles by John H. Blakelock, pg. 175
|
||||
Availible on google books 8/11/2015:
|
||||
https://books.google.com/books?id=ubcczZUDCsMC&pg=PA175#v=onepage&q&f=false*/
|
||||
float body_fixed_turn_offset = (fabsf((CONSTANTS_ONE_G / airspeed) *
|
||||
tanf(constrained_roll) * sinf(constrained_roll)));
|
||||
if (ctl_data.do_turn_compensation) {
|
||||
/* Calculate desired body fixed y-axis angular rate needed to compensate for roll angle.
|
||||
For reference see Automatic Control of Aircraft and Missiles by John H. Blakelock, pg. 175
|
||||
Availible on google books 8/11/2015:
|
||||
https://books.google.com/books?id=ubcczZUDCsMC&pg=PA175#v=onepage&q&f=false*/
|
||||
float body_fixed_turn_offset = (fabsf((CONSTANTS_ONE_G / airspeed) *
|
||||
tanf(constrained_roll) * sinf(constrained_roll)));
|
||||
|
||||
if (inverted) {
|
||||
body_fixed_turn_offset = -body_fixed_turn_offset;
|
||||
if (inverted) {
|
||||
body_fixed_turn_offset = -body_fixed_turn_offset;
|
||||
}
|
||||
|
||||
/* Finally add the turn offset to your bodyrate setpoint*/
|
||||
_bodyrate_setpoint += body_fixed_turn_offset;
|
||||
}
|
||||
|
||||
/* Finally add the turn offset to your bodyrate setpoint*/
|
||||
_bodyrate_setpoint += body_fixed_turn_offset;
|
||||
|
||||
|
||||
_rate_error = _bodyrate_setpoint - ctl_data.pitch_rate;
|
||||
_rate_error = _bodyrate_setpoint - ctl_data.body_y_rate;
|
||||
|
||||
if (!lock_integrator && _k_i > 0.0f) {
|
||||
|
||||
@@ -188,7 +186,15 @@ float ECL_PitchController::control_bodyrate(const struct ECL_ControlData &ctl_da
|
||||
_last_output = _bodyrate_setpoint * _k_ff * ctl_data.scaler +
|
||||
_rate_error * _k_p * ctl_data.scaler * ctl_data.scaler
|
||||
+ integrator_constrained; //scaler is proportional to 1/airspeed
|
||||
// warnx("pitch: _integrator: %.4f, _integrator_max: %.4f, airspeed %.4f, _k_i %.4f, _k_p: %.4f", (double)_integrator, (double)_integrator_max, (double)airspeed, (double)_k_i, (double)_k_p);
|
||||
// warnx("roll: _last_output %.4f", (double)_last_output);
|
||||
|
||||
return math::constrain(_last_output, -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
float ECL_PitchController::control_euler_rate(const struct ECL_ControlData &ctl_data)
|
||||
{
|
||||
/* Transform setpoint to body angular rates (jacobian) */
|
||||
_bodyrate_setpoint = cosf(ctl_data.roll) * _rate_setpoint +
|
||||
cosf(ctl_data.pitch) * sinf(ctl_data.roll) * ctl_data.yaw_rate_setpoint;
|
||||
|
||||
return control_bodyrate(ctl_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user