Main Page
Namespaces
Classes
Files
File List
src
PID
PIDRegulator.py
Go to the documentation of this file.
1
# Copyright (c) 2016 The UUV Simulator Authors.
2
# All rights reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
# http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import
numpy
17
18
19
class
PIDRegulator
:
20
"""A very basic 1D PID Regulator."""
21
def
__init__
(self, p, i, d, sat):
22
self.
p
= p
23
self.
i
= i
24
self.
d
= d
25
self.
sat
= sat
26
27
self.
integral
= 0
28
self.
prev_err
= 0
29
self.
prev_t
= -1.0
30
31
def
__str__
(self):
32
msg =
'PID controller:'
33
msg +=
'\n\tp=%f'
% self.
p
34
msg +=
'\n\ti=%f'
% self.
i
35
msg +=
'\n\td=%f'
% self.
d
36
msg +=
'\n\tsat=%f'
% self.
sat
37
return
msg
38
39
def
regulate
(self, err, t):
40
derr_dt = 0.0
41
dt = t - self.
prev_t
42
if
self.
prev_t
> 0.0
and
dt > 0.0:
43
derr_dt = (err - self.
prev_err
)/dt
44
self.
integral
+= 0.5*(err + self.
prev_err
)*dt
45
46
u = self.
p
*err + self.
d
*derr_dt + self.
i
*self.
integral
47
48
self.
prev_err
= err
49
self.
prev_t
= t
50
51
if
(numpy.linalg.norm(u) > self.
sat
):
52
# controller is in saturation: limit outpt, reset integral
53
u = self.
sat
*u/numpy.linalg.norm(u)
54
self.
integral
= 0.0
55
56
return
u
PID.PIDRegulator.PIDRegulator.regulate
def regulate(self, err, t)
Definition:
PIDRegulator.py:39
PID.PIDRegulator.PIDRegulator.d
d
Definition:
PIDRegulator.py:24
PID.PIDRegulator.PIDRegulator.p
p
Definition:
PIDRegulator.py:22
PID.PIDRegulator.PIDRegulator.__init__
def __init__(self, p, i, d, sat)
Definition:
PIDRegulator.py:21
PID.PIDRegulator.PIDRegulator.i
i
Definition:
PIDRegulator.py:23
PID.PIDRegulator.PIDRegulator.__str__
def __str__(self)
Definition:
PIDRegulator.py:31
PID.PIDRegulator.PIDRegulator.integral
integral
Definition:
PIDRegulator.py:27
PID.PIDRegulator.PIDRegulator
Definition:
PIDRegulator.py:19
PID.PIDRegulator.PIDRegulator.sat
sat
Definition:
PIDRegulator.py:25
PID.PIDRegulator.PIDRegulator.prev_t
prev_t
Definition:
PIDRegulator.py:29
PID.PIDRegulator.PIDRegulator.prev_err
prev_err
Definition:
PIDRegulator.py:28
uuv_control_cascaded_pids
Author(s): Musa Morena Marcusso Manhaes
, Sebastian Scherer
, Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:10