CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/APM_Control/AP_RollController.h
Views: 1798
1
#pragma once
2
3
#include <AP_Common/AP_Common.h>
4
#include "AP_AutoTune.h"
5
#include <AP_Math/AP_Math.h>
6
#include <AC_PID/AC_PID.h>
7
8
class AP_RollController
9
{
10
public:
11
AP_RollController(const AP_FixedWing &parms);
12
13
/* Do not allow copies */
14
CLASS_NO_COPY(AP_RollController);
15
16
float get_rate_out(float desired_rate, float scaler);
17
float get_servo_out(int32_t angle_err, float scaler, bool disable_integrator, bool ground_mode);
18
19
// setup a one loop FF scale multiplier. This replaces any previous scale applied
20
// so should only be used when only one source of scaling is needed
21
void set_ff_scale(float _ff_scale) { ff_scale = _ff_scale; }
22
23
void reset_I();
24
25
/*
26
reduce the integrator, used when we have a low scale factor in a quadplane hover
27
*/
28
void decay_I()
29
{
30
// this reduces integrator by 95% over 2s
31
_pid_info.I *= 0.995f;
32
rate_pid.set_integrator(rate_pid.get_i() * 0.995);
33
}
34
35
void autotune_start(void);
36
void autotune_restore(void);
37
38
const AP_PIDInfo& get_pid_info(void) const
39
{
40
return _pid_info;
41
}
42
43
// set the PID notch sample rates
44
void set_notch_sample_rate(float sample_rate) { rate_pid.set_notch_sample_rate(sample_rate); }
45
46
static const struct AP_Param::GroupInfo var_info[];
47
48
49
// tuning accessors
50
AP_Float &kP(void) { return rate_pid.kP(); }
51
AP_Float &kI(void) { return rate_pid.kI(); }
52
AP_Float &kD(void) { return rate_pid.kD(); }
53
AP_Float &kFF(void) { return rate_pid.ff(); }
54
AP_Float &tau(void) { return gains.tau; }
55
56
void convert_pid();
57
58
private:
59
const AP_FixedWing &aparm;
60
AP_AutoTune::ATGains gains;
61
AP_AutoTune *autotune;
62
bool failed_autotune_alloc;
63
float _last_out;
64
AC_PID rate_pid{0.08, 0.15, 0, 0.345, 0.666, 3, 0, 12, 150, 1};
65
float angle_err_deg;
66
float ff_scale = 1.0;
67
68
AP_PIDInfo _pid_info;
69
70
float _get_rate_out(float desired_rate, float scaler, bool disable_integrator, bool ground_mode);
71
};
72
73