2016-02-17 21:25:08 -04:00
|
|
|
#pragma once
|
2014-02-14 02:53:23 -04:00
|
|
|
|
|
|
|
/// @file AC_PD.h
|
2020-01-04 02:25:34 -04:00
|
|
|
/// @brief Generic P controller with EEPROM-backed storage of constants.
|
2014-02-14 02:53:23 -04:00
|
|
|
|
2015-08-11 03:28:41 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2014-02-14 02:53:23 -04:00
|
|
|
#include <stdlib.h>
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2014-02-14 02:53:23 -04:00
|
|
|
|
|
|
|
/// @class AC_P
|
|
|
|
/// @brief Object managing one P controller
|
|
|
|
class AC_P {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor for P that saves its settings to EEPROM
|
|
|
|
///
|
|
|
|
/// @note PIs must be named to avoid either multiple parameters with the
|
|
|
|
/// same name, or an overly complex constructor.
|
|
|
|
///
|
|
|
|
/// @param initial_p Initial value for the P term.
|
|
|
|
///
|
2023-01-03 13:22:36 -04:00
|
|
|
AC_P(const float &initial_p = 0.0f) :
|
|
|
|
default_kp(initial_p)
|
2014-02-14 02:53:23 -04:00
|
|
|
{
|
2023-01-03 13:22:36 -04:00
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2014-02-14 02:53:23 -04:00
|
|
|
}
|
|
|
|
|
2021-06-06 05:33:35 -03:00
|
|
|
CLASS_NO_COPY(AC_P);
|
|
|
|
|
2014-02-14 02:53:23 -04:00
|
|
|
/// Iterate the P controller, return the new control value
|
|
|
|
///
|
|
|
|
/// Positive error produces positive output.
|
|
|
|
///
|
|
|
|
/// @param error The measured error value
|
|
|
|
/// @param dt The time delta in milliseconds (note
|
|
|
|
/// that update interval cannot be more
|
|
|
|
/// than 65.535 seconds due to limited range
|
|
|
|
/// of the data type).
|
|
|
|
///
|
|
|
|
/// @returns The updated control output.
|
|
|
|
///
|
|
|
|
float get_p(float error) const;
|
|
|
|
|
|
|
|
/// Load gain properties
|
|
|
|
///
|
|
|
|
void load_gains();
|
|
|
|
|
|
|
|
/// Save gain properties
|
|
|
|
///
|
|
|
|
void save_gains();
|
|
|
|
|
|
|
|
/// @name parameter accessors
|
|
|
|
//@{
|
|
|
|
|
|
|
|
// accessors
|
2016-05-06 01:43:12 -03:00
|
|
|
AP_Float &kP() { return _kp; }
|
2017-11-20 22:34:12 -04:00
|
|
|
const AP_Float &kP() const { return _kp; }
|
2014-02-14 02:53:23 -04:00
|
|
|
void kP(const float v) { _kp.set(v); }
|
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
|
|
|
AP_Float _kp;
|
2023-01-03 13:22:36 -04:00
|
|
|
|
|
|
|
const float default_kp;
|
2014-02-14 02:53:23 -04:00
|
|
|
};
|