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_PID/AC_P.h
Views: 1798
1
#pragma once
2
3
/// @file AC_PD.h
4
/// @brief Generic P controller with EEPROM-backed storage of constants.
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 that saves its settings to EEPROM
17
///
18
/// @note PIs must be named to avoid either multiple parameters with the
19
/// same name, or an overly complex constructor.
20
///
21
/// @param initial_p Initial value for the P term.
22
///
23
AC_P(const float &initial_p = 0.0f) :
24
default_kp(initial_p)
25
{
26
AP_Param::setup_object_defaults(this, var_info);
27
}
28
29
CLASS_NO_COPY(AC_P);
30
31
/// Iterate the P controller, return the new control value
32
///
33
/// Positive error produces positive output.
34
///
35
/// @param error The measured error value
36
/// @param dt The time delta in milliseconds (note
37
/// that update interval cannot be more
38
/// than 65.535 seconds due to limited range
39
/// of the data type).
40
///
41
/// @returns The updated control output.
42
///
43
float get_p(float error) const;
44
45
/// Load gain properties
46
///
47
void load_gains();
48
49
/// Save gain properties
50
///
51
void save_gains();
52
53
/// @name parameter accessors
54
//@{
55
56
// accessors
57
AP_Float &kP() { return _kp; }
58
const AP_Float &kP() const { return _kp; }
59
void set_kP(const float v) { _kp.set(v); }
60
61
static const struct AP_Param::GroupInfo var_info[];
62
63
private:
64
AP_Float _kp;
65
66
const float default_kp;
67
};
68
69