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/AC_AttitudeControl/AC_AttitudeControl_Sub.h
Views: 1798
1
#pragma once
2
3
/// @file AC_AttitudeControl_Sub.h
4
/// @brief ArduSub attitude control library
5
6
#include "AC_AttitudeControl.h"
7
#include <AP_Motors/AP_MotorsMulticopter.h>
8
9
// default angle controller PID gains
10
// (Sub-specific defaults for parent class)
11
#define AC_ATC_SUB_ANGLE_P 6.0f
12
#define AC_ATC_SUB_ACCEL_Y_MAX 110000.0f
13
14
// default rate controller PID gains
15
#define AC_ATC_SUB_RATE_RP_P 0.135f
16
#define AC_ATC_SUB_RATE_RP_I 0.090f
17
#define AC_ATC_SUB_RATE_RP_D 0.0036f
18
#define AC_ATC_SUB_RATE_RP_IMAX 0.444f
19
#define AC_ATC_SUB_RATE_RP_FILT_HZ 30.0f
20
#define AC_ATC_SUB_RATE_YAW_P 0.180f
21
#define AC_ATC_SUB_RATE_YAW_I 0.018f
22
#define AC_ATC_SUB_RATE_YAW_D 0.0f
23
#define AC_ATC_SUB_RATE_YAW_IMAX 0.222f
24
#define AC_ATC_SUB_RATE_YAW_FILT_HZ 5.0f
25
26
#define MAX_YAW_ERROR radians(5)
27
28
class AC_AttitudeControl_Sub : public AC_AttitudeControl {
29
public:
30
AC_AttitudeControl_Sub(AP_AHRS_View &ahrs, const AP_MultiCopter &aparm, AP_MotorsMulticopter& motors);
31
32
// empty destructor to suppress compiler warning
33
virtual ~AC_AttitudeControl_Sub() {}
34
35
// pid accessors
36
AC_PID& get_rate_roll_pid() override { return _pid_rate_roll; }
37
AC_PID& get_rate_pitch_pid() override { return _pid_rate_pitch; }
38
AC_PID& get_rate_yaw_pid() override { return _pid_rate_yaw; }
39
const AC_PID& get_rate_roll_pid() const override { return _pid_rate_roll; }
40
const AC_PID& get_rate_pitch_pid() const override { return _pid_rate_pitch; }
41
const AC_PID& get_rate_yaw_pid() const override { return _pid_rate_yaw; }
42
43
// Update Alt_Hold angle maximum
44
void update_althold_lean_angle_max(float throttle_in) override;
45
46
// Set output throttle
47
void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) override;
48
49
// calculate total body frame throttle required to produce the given earth frame throttle
50
float get_throttle_boosted(float throttle_in);
51
52
// set desired throttle vs attitude mixing (actual mix is slewed towards this value over 1~2 seconds)
53
// low values favour pilot/autopilot throttle over attitude control, high values favour attitude control over throttle
54
// has no effect when throttle is above hover throttle
55
void set_throttle_mix_min() override { _throttle_rpy_mix_desired = _thr_mix_min; }
56
void set_throttle_mix_man() override { _throttle_rpy_mix_desired = _thr_mix_man; }
57
void set_throttle_mix_max(float ratio) override { _throttle_rpy_mix_desired = _thr_mix_max; }
58
59
// are we producing min throttle?
60
bool is_throttle_mix_min() const override { return (_throttle_rpy_mix < 1.25f*_thr_mix_min); }
61
62
// run lowest level body-frame rate controller and send outputs to the motors
63
void rate_controller_run() override;
64
65
// sanity check parameters. should be called once before take-off
66
void parameter_sanity_check() override;
67
68
// set the PID notch sample rates
69
void set_notch_sample_rate(float sample_rate) override;
70
71
// This function ensures that the ROV reaches the target orientation with the desired yaw rate
72
void input_euler_angle_roll_pitch_slew_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, float slew_yaw);
73
74
// user settable parameters
75
static const struct AP_Param::GroupInfo var_info[];
76
77
protected:
78
79
// update_throttle_rpy_mix - updates thr_low_comp value towards the target
80
void update_throttle_rpy_mix();
81
82
// get maximum value throttle can be raised to based on throttle vs attitude prioritisation
83
float get_throttle_avg_max(float throttle_in);
84
85
AP_MotorsMulticopter& _motors_multi;
86
87
// Roll and Pitch rate PIDs share the same defaults:
88
const AC_PID::Defaults rp_defaults {
89
AC_PID::Defaults{
90
.p = AC_ATC_SUB_RATE_RP_P,
91
.i = AC_ATC_SUB_RATE_RP_I,
92
.d = AC_ATC_SUB_RATE_RP_D,
93
.ff = 0.0f,
94
.imax = AC_ATC_SUB_RATE_RP_IMAX,
95
.filt_T_hz = AC_ATC_SUB_RATE_RP_FILT_HZ,
96
.filt_E_hz = 0.0,
97
.filt_D_hz = AC_ATC_SUB_RATE_RP_FILT_HZ,
98
.srmax = 0,
99
.srtau = 1.0
100
}
101
};
102
AC_PID _pid_rate_roll { rp_defaults };
103
AC_PID _pid_rate_pitch { rp_defaults };
104
105
AC_PID _pid_rate_yaw {
106
AC_PID::Defaults{
107
.p = AC_ATC_SUB_RATE_YAW_P,
108
.i = AC_ATC_SUB_RATE_YAW_I,
109
.d = AC_ATC_SUB_RATE_YAW_D,
110
.ff = 0.0f,
111
.imax = AC_ATC_SUB_RATE_YAW_IMAX,
112
.filt_T_hz = AC_ATC_SUB_RATE_YAW_FILT_HZ,
113
.filt_E_hz = 0.0f,
114
.filt_D_hz = AC_ATC_SUB_RATE_YAW_FILT_HZ,
115
.srmax = 0,
116
.srtau = 1.0
117
}
118
};
119
120
AP_Float _thr_mix_man; // throttle vs attitude control prioritisation used when using manual throttle (higher values mean we prioritise attitude control over throttle)
121
AP_Float _thr_mix_min; // throttle vs attitude control prioritisation used when landing (higher values mean we prioritise attitude control over throttle)
122
AP_Float _thr_mix_max; // throttle vs attitude control prioritisation used during active flight (higher values mean we prioritise attitude control over throttle)
123
};
124
125