Line data Source code
1 : #pragma once 2 : 3 : /// @file AC_PD.h 4 : /// @brief Single-axis P controller with EEPROM-backed gain storage. 5 : 6 : #include <AP_Common/AP_Common.h> 7 : #include <AP_Param/AP_Param.h> 8 : #include <stdlib.h> 9 : #include <cmath> 10 : 11 : /// @class AC_P 12 : /// @brief Object managing one P controller 13 : class AC_P { 14 : public: 15 : 16 : /// Constructor for P controller with EEPROM-backed gain. 17 : /// Parameters are initialized from defaults or EEPROM at runtime. 18 : /// 19 : /// @note PIs must be named to avoid either multiple parameters with the 20 : /// same name, or an overly complex constructor. 21 : /// 22 : /// @param initial_p Initial value for the P term. 23 : /// 24 6207 : AC_P(const float &initial_p = 0.0f) : 25 6207 : default_kp(initial_p) 26 : { 27 6207 : AP_Param::setup_object_defaults(this, var_info); 28 6207 : } 29 : 30 : CLASS_NO_COPY(AC_P); 31 : 32 : /// Iterate the P controller, return the new control value 33 : /// 34 : /// Positive error produces positive output. 35 : /// 36 : /// @param error The measured error value 37 : /// @returns The updated control output. 38 : /// 39 : float get_p(float error) const; 40 : 41 : // Loads controller configuration from EEPROM, including gains and filter frequencies. (not used) 42 : void load_gains(); 43 : 44 : // Saves controller configuration from EEPROM. Used by autotune to save gains before tuning. 45 : void save_gains(); 46 : 47 : /// @name parameter accessors 48 : //@{ 49 : 50 : // accessors 51 99810266 : AP_Float &kP() { return _kp; } 52 65929148 : const AP_Float &kP() const { return _kp; } 53 7366 : void set_kP(const float v) { _kp.set(v); } 54 : 55 : static const struct AP_Param::GroupInfo var_info[]; 56 : 57 : private: 58 : AP_Float _kp; 59 : 60 : const float default_kp; 61 : };