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_Vehicle/AP_Vehicle.h>
|
2021-11-25 03:00:38 -04:00
|
|
|
#include <AC_PID/AC_PID.h>
|
2021-11-25 04:41:55 -04:00
|
|
|
#include "AP_AutoTune.h"
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
class AP_YawController
|
|
|
|
{
|
2017-08-30 15:10:44 -03:00
|
|
|
public:
|
2021-11-25 04:41:55 -04:00
|
|
|
AP_YawController(const AP_Vehicle::FixedWing &parms);
|
2017-08-30 15:10:44 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_YawController(const AP_YawController &other) = delete;
|
|
|
|
AP_YawController &operator=(const AP_YawController&) = delete;
|
2012-12-12 17:41:12 -04:00
|
|
|
|
2021-11-25 03:00:38 -04:00
|
|
|
// return true if rate control is enabled
|
|
|
|
bool rate_control_enabled(void) const { return _rate_enable != 0; }
|
|
|
|
|
|
|
|
// get actuator output for sideslip and yaw damping control
|
2021-11-25 01:23:42 -04:00
|
|
|
int32_t get_servo_out(float scaler, bool disable_integrator);
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-11-25 03:00:38 -04:00
|
|
|
// get actuator output for direct rate control
|
|
|
|
// desired_rate is in deg/sec. scaler is the surface speed scaler
|
|
|
|
float get_rate_out(float desired_rate, float scaler, bool disable_integrator);
|
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
void reset_I();
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2022-09-15 00:51:06 -03:00
|
|
|
void reset_rate_PID();
|
|
|
|
|
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;
|
|
|
|
}
|
2015-06-22 00:28:08 -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-11-25 04:41:55 -04:00
|
|
|
// start/stop auto tuner
|
|
|
|
void autotune_start(void);
|
|
|
|
void autotune_restore(void);
|
2022-09-15 00:51:06 -03:00
|
|
|
|
2021-11-25 04:41:55 -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
|
|
|
|
|
|
|
private:
|
2017-08-30 15:10:44 -03:00
|
|
|
const AP_Vehicle::FixedWing &aparm;
|
2021-11-25 01:23:42 -04:00
|
|
|
AP_Float _K_A;
|
|
|
|
AP_Float _K_I;
|
|
|
|
AP_Float _K_D;
|
|
|
|
AP_Float _K_FF;
|
2013-07-15 20:42:54 -03:00
|
|
|
AP_Int16 _imax;
|
2021-11-25 03:00:38 -04:00
|
|
|
AP_Int8 _rate_enable;
|
2022-11-30 01:24:18 -04:00
|
|
|
AC_PID rate_pid{0.04, 0.15, 0, 0.15, 0.666, 3, 0, 12, 150, 1};
|
2021-11-25 03:00:38 -04:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
uint32_t _last_t;
|
|
|
|
float _last_out;
|
|
|
|
float _last_rate_hp_out;
|
|
|
|
float _last_rate_hp_in;
|
|
|
|
float _K_D_last;
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-11-25 01:23:42 -04:00
|
|
|
float _integrator;
|
2012-08-21 23:08:14 -03:00
|
|
|
|
2021-11-25 04:41:55 -04:00
|
|
|
AP_AutoTune::ATGains gains;
|
|
|
|
AP_AutoTune *autotune;
|
|
|
|
bool failed_autotune_alloc;
|
|
|
|
|
2022-03-03 23:29:47 -04:00
|
|
|
AP_PIDInfo _pid_info;
|
2012-08-21 23:08:14 -03:00
|
|
|
};
|