Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_AutoTune/AC_AutoTune_Multi.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14/*15support for autotune of multirotors. Based on original autotune code from ArduCopter, written by Leonard Hall16Converted to a library by Andrew Tridgell17*/1819#pragma once2021#include "AC_AutoTune_config.h"2223#if AC_AUTOTUNE_ENABLED2425#include "AC_AutoTune.h"2627class AC_AutoTune_Multi : public AC_AutoTune28{29public:30// constructor31AC_AutoTune_Multi();3233// save gained, called on disarm34void save_tuning_gains() override;3536// var_info for holding Parameter information37static const struct AP_Param::GroupInfo var_info[];3839protected:40//41// methods to load and save gains42//4344// backup original gains and prepare for start of tuning45void backup_gains_and_initialise() override;4647// switch to use original gains48void load_orig_gains() override;4950// switch to gains found by last successful autotune51void load_tuned_gains() override;5253// load gains used between tests. called during testing mode's update-gains step to set gains ahead of return-to-level step54void load_intra_test_gains() override;5556// load test gains57void load_test_gains() override;5859// reset the test variables for multi60void reset_vehicle_test_variables() override {};6162// reset the update gain variables for multi63void reset_update_gain_variables() override {};6465float target_angle_max_rp_cd() const override;6667float target_angle_max_y_cd() const override;6869float target_angle_min_rp_cd() const override;7071float target_angle_min_y_cd() const override;7273float angle_lim_max_rp_cd() const override;7475float angle_lim_neg_rpy_cd() const override;7677void test_init() override;78void test_run(AxisType test_axis, const float dir_sign) override;7980// send intermittent updates to user on status of tune81void do_gcs_announcements() override;8283// send post test updates to user84void do_post_test_gcs_announcements() override {};8586// report final gains for a given axis to GCS87void report_final_gains(AxisType test_axis) const override;8889// update gains for the rate P up tune type90void updating_rate_p_up_all(AxisType test_axis) override;9192// update gains for the rate D up tune type93void updating_rate_d_up_all(AxisType test_axis) override;9495// update gains for the rate D down tune type96void updating_rate_d_down_all(AxisType test_axis) override;9798// update gains for the rate ff up tune type99void updating_rate_ff_up_all(AxisType test_axis) override {100// this should never happen101INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);102}103104// update gains for the angle P up tune type105void updating_angle_p_up_all(AxisType test_axis) override;106107// update gains for the angle P down tune type108void updating_angle_p_down_all(AxisType test_axis) override;109110// update gains for the max gain tune type111void updating_max_gains_all(AxisType test_axis) override {112// this should never happen113INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);114}115116// set gains post tune for the tune type117void set_gains_post_tune(AxisType test_axis) override;118119// reverse direction for twitch test120bool twitch_reverse_direction() override { return !positive_direction; }121122#if HAL_LOGGING_ENABLED123void Log_AutoTune() override;124void Log_AutoTuneDetails() override;125void Log_AutoTuneSweep() override {126// this should never happen127INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);128}129void 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);130void Log_Write_AutoTuneDetails(float angle_cd, float rate_cds);131#endif132133void set_tune_sequence() override {134tune_seq[0] = RD_UP;135tune_seq[1] = RD_DOWN;136tune_seq[2] = RP_UP;137tune_seq[3] = SP_DOWN;138tune_seq[4] = SP_UP;139tune_seq[5] = TUNE_COMPLETE;140}141142// get_axis_bitmask accessor143uint8_t get_axis_bitmask() const override { return axis_bitmask; }144145// get_testing_step_timeout_ms accessor146uint32_t get_testing_step_timeout_ms() const override;147148private:149// twitch test functions for multicopter150void twitch_test_init();151void twitch_test_run(AxisType test_axis, const float dir_sign);152153void twitching_test_rate(float angle, float rate, float rate_target, float &meas_rate_min, float &meas_rate_max, float &meas_angle_min);154void twitching_abort_rate(float angle, float rate, float angle_max, float meas_rate_min, float angle_min);155void 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);156157// measure acceleration during twitch test158void twitching_measure_acceleration(float &accel_average, float rate, float &rate_max) const;159160// updating_rate_d_up - increase D and adjust P to optimize the D term for a little bounce back161// optimize D term while keeping the maximum just below the target by adjusting P162void 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);163164// updating_rate_d_down - decrease D and adjust P to optimize the D term for no bounce back165// optimize D term while keeping the maximum just below the target by adjusting P166void 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);167168// updating_rate_p_up_d_down - increase P to ensure the target is reached while checking bounce back isn't increasing169// P is increased until we achieve our target within a reasonable time while reducing D if bounce back increases above the threshold170void 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);171172// updating_angle_p_down - decrease P until we don't reach the target before time out173// P is decreased to ensure we are not overshooting the target174void 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);175176// updating_angle_p_up - increase P to ensure the target is reached177// P is increased until we achieve our target within a reasonable time178void 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);179180// report gain formatting helper181void report_axis_gains(const char* axis_string, float rate_P, float rate_I, float rate_D, float angle_P, float max_accel) const;182183// parameters184AP_Int8 axis_bitmask; // axes to be tuned185AP_Float aggressiveness; // aircraft response aggressiveness to be tuned186AP_Float min_d; // minimum rate d gain allowed during tuning187bool ignore_next; // ignore the results of the next test when true188float target_angle; // target angle for the test189float target_rate; // target rate for the test190float angle_abort; // Angle that test is aborted191float test_rate_min; // the minimum angular rate achieved during TESTING_RATE192float test_rate_max; // the maximum angular rate achieved during TESTING_RATE193float test_angle_min; // the minimum angle achieved during TESTING_ANGLE194float test_angle_max; // the maximum angle achieved during TESTING_ANGLE195float accel_measure_rate_max; // the maximum rate used to measure average acceleration during twitch196};197198#endif // AC_AUTOTUNE_ENABLED199200201