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_AutoTune/AC_AutoTune_Multi.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
/*
16
support for autotune of multirotors. Based on original autotune code from ArduCopter, written by Leonard Hall
17
Converted to a library by Andrew Tridgell
18
*/
19
20
#pragma once
21
22
#include "AC_AutoTune_config.h"
23
24
#if AC_AUTOTUNE_ENABLED
25
26
#include "AC_AutoTune.h"
27
28
class AC_AutoTune_Multi : public AC_AutoTune
29
{
30
public:
31
// constructor
32
AC_AutoTune_Multi();
33
34
// save gained, called on disarm
35
void save_tuning_gains() override;
36
37
// var_info for holding Parameter information
38
static const struct AP_Param::GroupInfo var_info[];
39
40
protected:
41
//
42
// methods to load and save gains
43
//
44
45
// backup original gains and prepare for start of tuning
46
void backup_gains_and_initialise() override;
47
48
// switch to use original gains
49
void load_orig_gains() override;
50
51
// switch to gains found by last successful autotune
52
void load_tuned_gains() override;
53
54
// load gains used between tests. called during testing mode's update-gains step to set gains ahead of return-to-level step
55
void load_intra_test_gains() override;
56
57
// load test gains
58
void load_test_gains() override;
59
60
// reset the test variables for multi
61
void reset_vehicle_test_variables() override {};
62
63
// reset the update gain variables for multi
64
void reset_update_gain_variables() override {};
65
66
float target_angle_max_rp_cd() const override;
67
68
float target_angle_max_y_cd() const override;
69
70
float target_angle_min_rp_cd() const override;
71
72
float target_angle_min_y_cd() const override;
73
74
float angle_lim_max_rp_cd() const override;
75
76
float angle_lim_neg_rpy_cd() const override;
77
78
void test_init() override;
79
void test_run(AxisType test_axis, const float dir_sign) override;
80
81
// send intermittent updates to user on status of tune
82
void do_gcs_announcements() override;
83
84
// send post test updates to user
85
void do_post_test_gcs_announcements() override {};
86
87
// report final gains for a given axis to GCS
88
void report_final_gains(AxisType test_axis) const override;
89
90
// update gains for the rate P up tune type
91
void updating_rate_p_up_all(AxisType test_axis) override;
92
93
// update gains for the rate D up tune type
94
void updating_rate_d_up_all(AxisType test_axis) override;
95
96
// update gains for the rate D down tune type
97
void updating_rate_d_down_all(AxisType test_axis) override;
98
99
// update gains for the rate ff up tune type
100
void updating_rate_ff_up_all(AxisType test_axis) override {
101
// this should never happen
102
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
103
}
104
105
// update gains for the angle P up tune type
106
void updating_angle_p_up_all(AxisType test_axis) override;
107
108
// update gains for the angle P down tune type
109
void updating_angle_p_down_all(AxisType test_axis) override;
110
111
// update gains for the max gain tune type
112
void updating_max_gains_all(AxisType test_axis) override {
113
// this should never happen
114
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
115
}
116
117
// set gains post tune for the tune type
118
void set_gains_post_tune(AxisType test_axis) override;
119
120
// reverse direction for twitch test
121
bool twitch_reverse_direction() override { return !positive_direction; }
122
123
#if HAL_LOGGING_ENABLED
124
void Log_AutoTune() override;
125
void Log_AutoTuneDetails() override;
126
void Log_AutoTuneSweep() override {
127
// this should never happen
128
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
129
}
130
void Log_Write_AutoTune(AxisType axis, uint8_t tune_step, float meas_target, float meas_min, float meas_max, float new_gain_rp, float new_gain_rd, float new_gain_sp, float new_ddt);
131
void Log_Write_AutoTuneDetails(float angle_cd, float rate_cds);
132
#endif
133
134
void set_tune_sequence() override {
135
tune_seq[0] = RD_UP;
136
tune_seq[1] = RD_DOWN;
137
tune_seq[2] = RP_UP;
138
tune_seq[3] = SP_DOWN;
139
tune_seq[4] = SP_UP;
140
tune_seq[5] = TUNE_COMPLETE;
141
}
142
143
// get_axis_bitmask accessor
144
uint8_t get_axis_bitmask() const override { return axis_bitmask; }
145
146
// get_testing_step_timeout_ms accessor
147
uint32_t get_testing_step_timeout_ms() const override;
148
149
private:
150
// twitch test functions for multicopter
151
void twitch_test_init();
152
void twitch_test_run(AxisType test_axis, const float dir_sign);
153
154
void twitching_test_rate(float angle, float rate, float rate_target, float &meas_rate_min, float &meas_rate_max, float &meas_angle_min);
155
void twitching_abort_rate(float angle, float rate, float angle_max, float meas_rate_min, float angle_min);
156
void twitching_test_angle(float angle, float rate, float angle_target, float &meas_angle_min, float &meas_angle_max, float &meas_rate_min, float &meas_rate_max);
157
158
// measure acceleration during twitch test
159
void twitching_measure_acceleration(float &accel_average, float rate, float &rate_max) const;
160
161
// updating_rate_d_up - increase D and adjust P to optimize the D term for a little bounce back
162
// optimize D term while keeping the maximum just below the target by adjusting P
163
void updating_rate_d_up(float &tune_d, float tune_d_min, float tune_d_max, float tune_d_step_ratio, float &tune_p, float tune_p_min, float tune_p_max, float tune_p_step_ratio, float rate_target, float meas_rate_min, float meas_rate_max);
164
165
// updating_rate_d_down - decrease D and adjust P to optimize the D term for no bounce back
166
// optimize D term while keeping the maximum just below the target by adjusting P
167
void updating_rate_d_down(float &tune_d, float tune_d_min, float tune_d_step_ratio, float &tune_p, float tune_p_min, float tune_p_max, float tune_p_step_ratio, float rate_target, float meas_rate_min, float meas_rate_max);
168
169
// updating_rate_p_up_d_down - increase P to ensure the target is reached while checking bounce back isn't increasing
170
// P is increased until we achieve our target within a reasonable time while reducing D if bounce back increases above the threshold
171
void updating_rate_p_up_d_down(float &tune_d, float tune_d_min, float tune_d_step_ratio, float &tune_p, float tune_p_min, float tune_p_max, float tune_p_step_ratio, float rate_target, float meas_rate_min, float meas_rate_max, bool fail_min_d = true);
172
173
// updating_angle_p_down - decrease P until we don't reach the target before time out
174
// P is decreased to ensure we are not overshooting the target
175
void updating_angle_p_down(float &tune_p, float tune_p_min, float tune_p_step_ratio, float angle_target, float meas_angle_max, float meas_rate_min, float meas_rate_max);
176
177
// updating_angle_p_up - increase P to ensure the target is reached
178
// P is increased until we achieve our target within a reasonable time
179
void updating_angle_p_up(float &tune_p, float tune_p_max, float tune_p_step_ratio, float angle_target, float meas_angle_max, float meas_rate_min, float meas_rate_max);
180
181
// report gain formatting helper
182
void report_axis_gains(const char* axis_string, float rate_P, float rate_I, float rate_D, float angle_P, float max_accel) const;
183
184
// parameters
185
AP_Int8 axis_bitmask; // axes to be tuned
186
AP_Float aggressiveness; // aircraft response aggressiveness to be tuned
187
AP_Float min_d; // minimum rate d gain allowed during tuning
188
bool ignore_next; // ignore the results of the next test when true
189
float target_angle; // target angle for the test
190
float target_rate; // target rate for the test
191
float angle_abort; // Angle that test is aborted
192
float test_rate_min; // the minimum angular rate achieved during TESTING_RATE
193
float test_rate_max; // the maximum angular rate achieved during TESTING_RATE
194
float test_angle_min; // the minimum angle achieved during TESTING_ANGLE
195
float test_angle_max; // the maximum angle achieved during TESTING_ANGLE
196
float accel_measure_rate_max; // the maximum rate used to measure average acceleration during twitch
197
};
198
199
#endif // AC_AUTOTUNE_ENABLED
200
201