#pragma once12/// @file AC_PD.h3/// @brief Single-axis P controller with EEPROM-backed gain storage.45#include <AP_Common/AP_Common.h>6#include <AP_Param/AP_Param.h>7#include <stdlib.h>8#include <cmath>910/// @class AC_P11/// @brief Object managing one P controller12class AC_P {13public:1415/// Constructor for P controller with EEPROM-backed gain.16/// Parameters are initialized from defaults or EEPROM at runtime.17///18/// @note PIs must be named to avoid either multiple parameters with the19/// same name, or an overly complex constructor.20///21/// @param initial_p Initial value for the P term.22///23AC_P(const float &initial_p = 0.0f) :24default_kp(initial_p)25{26AP_Param::setup_object_defaults(this, var_info);27}2829CLASS_NO_COPY(AC_P);3031/// Iterate the P controller, return the new control value32///33/// Positive error produces positive output.34///35/// @param error The measured error value36/// @returns The updated control output.37///38float get_p(float error) const;3940// Loads controller configuration from EEPROM, including gains and filter frequencies. (not used)41void load_gains();4243// Saves controller configuration from EEPROM. Used by autotune to save gains before tuning.44void save_gains();4546/// @name parameter accessors47//@{4849// accessors50AP_Float &kP() { return _kp; }51const AP_Float &kP() const { return _kp; }52void set_kP(const float v) { _kp.set(v); }5354static const struct AP_Param::GroupInfo var_info[];5556private:57AP_Float _kp;5859const float default_kp;60};616263