Robotics Library
0.6.2
rl
math
Pid.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009, Markus Rickert
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
//
8
// * Redistributions of source code must retain the above copyright notice,
9
// this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above copyright notice,
11
// this list of conditions and the following disclaimer in the documentation
12
// and/or other materials provided with the distribution.
13
//
14
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
// POSSIBILITY OF SUCH DAMAGE.
25
//
26
27
#ifndef _RL_MATH_PID_H_
28
#define _RL_MATH_PID_H_
29
30
#include "
Real.h
"
31
32
namespace
rl
33
{
34
namespace
math
35
{
39
template
<
typename
T >
40
class
Pid
41
{
42
public
:
43
Pid
() :
44
e
(0),
45
kd
(0),
46
ki
(0),
47
kp
(0),
48
i
(0)
49
{
50
51
}
52
53
virtual
~Pid
()
54
{
55
56
}
57
63
T
operator()
(
const
T&
x
,
const
Real
& dt)
64
{
65
T
e
= this->x -
x
;
66
T p = this->
kp
*
e
;
67
this->
i
+= this->
ki
* e * dt;
68
T d = this->
kd
* (e - this->
e
) / dt;
69
this->e =
e
;
70
return
x
+ p + this->
i
+ d;
71
}
72
73
void
reset
()
74
{
75
this->
e
= 0;
76
this->
i
= 0;
77
}
78
80
T
kd
;
81
83
T
ki
;
84
86
T
kp
;
87
89
T
x
;
90
91
protected
:
92
93
private
:
95
T
e
;
96
98
T
i
;
99
};
100
}
101
}
102
103
#endif // _RL_MATH_PID_H_
rl::math::Pid::i
T i
Integral output .
Definition:
Pid.h:98
rl::math::Pid
Proportional-Integral-Derivative controller.
Definition:
Pid.h:41
rl::math::Pid::e
T e
Previous error.
Definition:
Pid.h:95
rl::math::Pid::kd
T kd
Derivative gain .
Definition:
Pid.h:80
rl::math::Pid::Pid
Pid()
Definition:
Pid.h:43
rl::math::Pid::reset
void reset()
Definition:
Pid.h:73
rl::math::Pid::~Pid
virtual ~Pid()
Definition:
Pid.h:53
rl::math::Pid::ki
T ki
Integral gain .
Definition:
Pid.h:83
rl::math::Pid::x
T x
Setpoint.
Definition:
Pid.h:89
rl::math::Pid::operator()
T operator()(const T &x, const Real &dt)
Definition:
Pid.h:63
Real.h
rl::math::Pid::kp
T kp
Proportional gain .
Definition:
Pid.h:86
rl::math::Real
double Real
Definition:
Real.h:34
rl
Definition:
Ati.cpp:35
Generated by
1.8.20