summaryrefslogtreecommitdiffstats
path: root/pid/ec/pid.hpp
blob: 74ad5a70155565a9a1259996f2899d5c89e39dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include <cstdint>

namespace ec
{

typedef struct
{
    double min;
    double max;
} limits_t;

/* Note: If you update these structs you need to update the copy code in
 * pid/util.cpp.
 */
typedef struct
{
    bool initialized; // has pid been initialized

    double ts;         // sample time in seconds
    double integral;   // intergal of error
    double lastOutput; // value of last output

    double proportionalCoeff; // coeff for P
    double integralCoeff;     // coeff for I
    double feedFwdOffset;     // offset coeff for feed-forward term
    double feedFwdGain;       // gain for feed-forward term

    limits_t integralLimit; // clamp of integral
    limits_t outLim;        // clamp of output
    double slewNeg;
    double slewPos;
    double positiveHysteresis;
    double negativeHysteresis;
} pid_info_t;

double pid(pid_info_t* pidinfoptr, double input, double setpoint);

/* Condensed version for use by the configuration. */
struct pidinfo
{
    double ts;                  // sample time in seconds
    double proportionalCoeff;   // coeff for P
    double integralCoeff;       // coeff for I
    double feedFwdOffset;       // offset coeff for feed-forward term
    double feedFwdGain;         // gain for feed-forward term
    ec::limits_t integralLimit; // clamp of integral
    ec::limits_t outLim;        // clamp of output
    double slewNeg;
    double slewPos;
    double positiveHysteresis;
    double negativeHysteresis;
};

} // namespace ec
OpenPOWER on IntegriCloud