2016-02-17 21:25:34 -04:00
|
|
|
#pragma once
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2015-08-11 03:28:41 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include "AP_AutoTune.h"
|
|
|
|
#include <AP_Math/AP_Math.h>
|
2020-09-18 21:29:41 -03:00
|
|
|
#include <AC_PID/AC_PID.h>
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
class AP_PitchController
|
|
|
|
{
|
2012-08-21 23:08:14 -03:00
|
|
|
public:
|
2022-09-29 20:10:40 -03:00
|
|
|
AP_PitchController(const AP_FixedWing &parms);
|
2017-08-30 15:10:44 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_PitchController);
|
2012-12-12 17:41:12 -04:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
float get_rate_out(float desired_rate, float scaler);
|
2021-10-29 07:37:15 -03:00
|
|
|
float get_servo_out(int32_t angle_err, float scaler, bool disable_integrator, bool ground_mode);
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2023-07-03 15:50:53 -03:00
|
|
|
// setup a one loop FF scale multiplier. This replaces any previous scale applied
|
|
|
|
// so should only be used when only one source of scaling is needed
|
|
|
|
void set_ff_scale(float _ff_scale) { ff_scale = _ff_scale; }
|
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
void reset_I();
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2019-07-06 22:20:49 -03:00
|
|
|
/*
|
|
|
|
reduce the integrator, used when we have a low scale factor in a quadplane hover
|
|
|
|
*/
|
2021-11-25 01:23:42 -04:00
|
|
|
void decay_I()
|
|
|
|
{
|
2019-07-06 22:20:49 -03:00
|
|
|
// this reduces integrator by 95% over 2s
|
|
|
|
_pid_info.I *= 0.995f;
|
2020-09-18 21:29:41 -03:00
|
|
|
rate_pid.set_integrator(rate_pid.get_i() * 0.995);
|
2019-07-06 22:20:49 -03:00
|
|
|
}
|
2021-11-25 01:23:42 -04:00
|
|
|
|
2021-03-31 20:42:19 -03:00
|
|
|
void autotune_start(void);
|
|
|
|
void autotune_restore(void);
|
2014-04-12 01:11:33 -03:00
|
|
|
|
2022-03-03 23:29:47 -04:00
|
|
|
const AP_PIDInfo& get_pid_info(void) const
|
2021-11-25 01:23:42 -04:00
|
|
|
{
|
|
|
|
return _pid_info;
|
|
|
|
}
|
2021-03-12 02:05:00 -04:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-02-27 05:56:41 -04:00
|
|
|
AP_Float &kP(void) { return rate_pid.kP(); }
|
|
|
|
AP_Float &kI(void) { return rate_pid.kI(); }
|
|
|
|
AP_Float &kD(void) { return rate_pid.kD(); }
|
|
|
|
AP_Float &kFF(void) { return rate_pid.ff(); }
|
2022-10-10 19:13:47 -03:00
|
|
|
AP_Float &tau(void) { return gains.tau; }
|
2017-08-30 15:10:44 -03:00
|
|
|
|
2021-02-27 05:56:41 -04:00
|
|
|
void convert_pid();
|
|
|
|
|
2012-08-21 23:08:14 -03:00
|
|
|
private:
|
2022-09-29 20:10:40 -03:00
|
|
|
const AP_FixedWing &aparm;
|
2014-04-12 01:11:33 -03:00
|
|
|
AP_AutoTune::ATGains gains;
|
2021-03-31 20:42:19 -03:00
|
|
|
AP_AutoTune *autotune;
|
|
|
|
bool failed_autotune_alloc;
|
2021-11-25 01:23:42 -04:00
|
|
|
AP_Int16 _max_rate_neg;
|
|
|
|
AP_Float _roll_ff;
|
2020-09-18 21:29:41 -03:00
|
|
|
float _last_out;
|
2022-11-30 01:24:18 -04:00
|
|
|
AC_PID rate_pid{0.04, 0.15, 0, 0.345, 0.666, 3, 0, 12, 150, 1};
|
2021-04-12 23:37:37 -03:00
|
|
|
float angle_err_deg;
|
2023-07-03 15:50:53 -03:00
|
|
|
float ff_scale = 1.0;
|
2020-09-18 21:29:41 -03:00
|
|
|
|
2022-03-03 23:29:47 -04:00
|
|
|
AP_PIDInfo _pid_info;
|
2013-07-10 10:25:06 -03:00
|
|
|
|
2021-10-29 07:37:15 -03:00
|
|
|
float _get_rate_out(float desired_rate, float scaler, bool disable_integrator, float aspeed, bool ground_mode);
|
2021-11-25 01:23:42 -04:00
|
|
|
float _get_coordination_rate_offset(float &aspeed, bool &inverted) const;
|
2012-08-21 23:08:14 -03:00
|
|
|
};
|