Main Page
Classes
Files
File List
File Members
src
pid.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
ros/ros.h
>
4
5
class
PID
6
{
7
public
:
8
PID
(
9
float
kp,
10
float
kd,
11
float
ki
,
12
float
minOutput,
13
float
maxOutput,
14
float
integratorMin,
15
float
integratorMax,
16
const
std::string& name)
17
:
m_kp
(kp)
18
,
m_kd
(kd)
19
,
m_ki
(ki)
20
,
m_minOutput
(minOutput)
21
,
m_maxOutput
(maxOutput)
22
,
m_integratorMin
(integratorMin)
23
,
m_integratorMax
(integratorMax)
24
,
m_integral
(0)
25
,
m_previousError
(0)
26
,
m_previousTime
(
ros
::Time::now())
27
{
28
}
29
30
void
reset
()
31
{
32
m_integral
= 0;
33
m_previousError
= 0;
34
m_previousTime
=
ros::Time::now
();
35
}
36
37
void
setIntegral
(
float
integral)
38
{
39
m_integral
= integral;
40
}
41
42
float
ki
()
const
43
{
44
return
m_ki
;
45
}
46
47
float
update
(
float
value,
float
targetValue)
48
{
49
ros::Time
time =
ros::Time::now
();
50
float
dt = time.
toSec
() -
m_previousTime
.
toSec
();
51
float
error = targetValue - value;
52
m_integral
+= error * dt;
53
m_integral
= std::max(std::min(
m_integral
,
m_integratorMax
),
m_integratorMin
);
54
float
p =
m_kp
* error;
55
float
d
= 0;
56
if
(dt > 0)
57
{
58
d =
m_kd
* (error -
m_previousError
) / dt;
59
}
60
float
i =
m_ki
*
m_integral
;
61
float
output = p + d + i;
62
m_previousError
= error;
63
m_previousTime
= time;
64
// self.pubOutput.publish(output)
65
// self.pubError.publish(error)
66
// self.pubP.publish(p)
67
// self.pubD.publish(d)
68
// self.pubI.publish(i)
69
return
std::max(std::min(output,
m_maxOutput
),
m_minOutput
);
70
}
71
72
private
:
73
float
m_kp
;
74
float
m_kd
;
75
float
m_ki
;
76
float
m_minOutput
;
77
float
m_maxOutput
;
78
float
m_integratorMin
;
79
float
m_integratorMax
;
80
float
m_integral
;
81
float
m_previousError
;
82
ros::Time
m_previousTime
;
83
};
PID::m_ki
float m_ki
Definition:
pid.hpp:75
d
d
PID::m_integratorMax
float m_integratorMax
Definition:
pid.hpp:79
ros::Time
PID::update
float update(float value, float targetValue)
Definition:
pid.hpp:47
PID::m_minOutput
float m_minOutput
Definition:
pid.hpp:76
PID::PID
PID(float kp, float kd, float ki, float minOutput, float maxOutput, float integratorMin, float integratorMax, const std::string &name)
Definition:
pid.hpp:8
PID
Definition:
pid.hpp:5
PID::reset
void reset()
Definition:
pid.hpp:30
PID::m_previousTime
ros::Time m_previousTime
Definition:
pid.hpp:82
ros
ros.h
PID::m_kp
float m_kp
Definition:
pid.hpp:73
PID::m_kd
float m_kd
Definition:
pid.hpp:74
PID::m_maxOutput
float m_maxOutput
Definition:
pid.hpp:77
PID::m_previousError
float m_previousError
Definition:
pid.hpp:81
ros::Time::now
static Time now()
PID::ki
float ki() const
Definition:
pid.hpp:42
PID::m_integratorMin
float m_integratorMin
Definition:
pid.hpp:78
TimeBase< Time, Duration >::toSec
double toSec() const
PID::setIntegral
void setIntegral(float integral)
Definition:
pid.hpp:37
PID::m_integral
float m_integral
Definition:
pid.hpp:80
crazyflie_controller
Author(s): Wolfgang Hoenig
autogenerated on Mon Sep 28 2020 03:40:09