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