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_1D.h
Views: 1798
1
#pragma once
2
3
/// @file AC_P_1D.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
9
/// @class AC_P_1D
10
/// @brief Object managing one P controller
11
class AC_P_1D {
12
public:
13
14
// constructor
15
AC_P_1D(float initial_p);
16
17
CLASS_NO_COPY(AC_P_1D);
18
19
// update_all - set target and measured inputs to P controller and calculate outputs
20
// target and measurement are filtered
21
float update_all(float &target, float measurement) WARN_IF_UNUSED;
22
23
// set_limits - sets the maximum error to limit output and first and second derivative of output
24
void set_limits(float output_min, float output_max, float D_Out_max = 0.0f, float D2_Out_max = 0.0f);
25
26
// set_error_limits - reduce maximum position error to error_max
27
// to be called after setting limits
28
void set_error_limits(float error_min, float error_max);
29
30
// get_error_min - return minimum position error
31
float get_error_min() const { return _error_min; }
32
33
// get_error_max - return maximum position error
34
float get_error_max() const { return _error_max; }
35
36
// save gain to eeprom
37
void save_gains() { _kp.save(); }
38
39
// accessors
40
AP_Float &kP() WARN_IF_UNUSED { return _kp; }
41
const AP_Float &kP() const WARN_IF_UNUSED { return _kp; }
42
float get_error() const { return _error; }
43
44
// set accessors
45
void set_kP(float v) { _kp.set(v); }
46
47
// parameter var table
48
static const struct AP_Param::GroupInfo var_info[];
49
50
private:
51
52
// parameters
53
AP_Float _kp;
54
55
// internal variables
56
float _error; // time step in seconds
57
float _error_min; // error limit in negative direction
58
float _error_max; // error limit in positive direction
59
float _D1_max; // maximum first derivative of output
60
61
const float default_kp;
62
};
63
64