Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
z
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
z
Classes
Class List
Class Hierarchy
Class Members
All
:
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
Enumerations
a
b
c
d
e
f
h
i
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Properties
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Related Functions
:
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
z
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
grpc
src
core
lib
transport
pid_controller.cc
Go to the documentation of this file.
1
/*
2
*
3
* Copyright 2016 gRPC authors.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*/
18
19
#include <
grpc/support/port_platform.h
>
20
21
#include "
src/core/lib/transport/pid_controller.h
"
22
23
#include "
src/core/lib/gpr/useful.h
"
24
25
namespace
grpc_core
{
26
27
PidController::PidController
(
const
Args
&
args
)
28
: last_control_value_(
args
.initial_control_value()),
args_
(
args
) {}
29
30
double
PidController::Update
(
double
error
,
double
dt) {
31
if
(dt <= 0)
return
last_control_value_
;
32
/* integrate error using the trapezoid rule */
33
error_integral_
+= dt * (
last_error_
+
error
) * 0.5;
34
error_integral_
=
35
Clamp
(
error_integral_
, -
args_
.
integral_range
(),
args_
.
integral_range
());
36
double
diff_error = (
error
-
last_error_
) / dt;
37
/* calculate derivative of control value vs time */
38
double
dc_dt =
args_
.
gain_p
() *
error
+
args_
.
gain_i
() *
error_integral_
+
39
args_
.
gain_d
() * diff_error;
40
/* and perform trapezoidal integration */
41
double
new_control_value =
42
last_control_value_
+ dt * (
last_dc_dt_
+ dc_dt) * 0.5;
43
new_control_value =
Clamp
(new_control_value,
args_
.
min_control_value
(),
44
args_
.
max_control_value
());
45
last_error_
=
error
;
46
last_dc_dt_
= dc_dt;
47
last_control_value_
= new_control_value;
48
return
new_control_value;
49
}
50
51
}
// namespace grpc_core
grpc_core::PidController::PidController
PidController(const Args &args)
Definition:
pid_controller.cc:27
grpc_core::PidController::args_
const Args args_
Definition:
pid_controller.h:111
grpc_core::PidController::Args::min_control_value
double min_control_value() const
Definition:
pid_controller.h:43
grpc_core
Definition:
call_metric_recorder.h:31
useful.h
error
grpc_error_handle error
Definition:
retry_filter.cc:499
args_
grpc_channel_args * args_
Definition:
grpclb.cc:513
grpc_core::PidController::Args::gain_p
double gain_p() const
Definition:
pid_controller.h:39
asyncio_get_stats.args
args
Definition:
asyncio_get_stats.py:40
grpc_core::PidController::Args
Definition:
pid_controller.h:37
grpc_core::PidController::Args::max_control_value
double max_control_value() const
Definition:
pid_controller.h:44
grpc_core::PidController::last_control_value_
double last_control_value_
Definition:
pid_controller.h:109
grpc_core::Clamp
T Clamp(T val, T min, T max)
Definition:
useful.h:31
grpc_core::PidController::Args::integral_range
double integral_range() const
Definition:
pid_controller.h:45
grpc_core::PidController::Update
double Update(double error, double dt)
Definition:
pid_controller.cc:30
grpc_core::PidController::Args::gain_i
double gain_i() const
Definition:
pid_controller.h:40
grpc_core::PidController::error_integral_
double error_integral_
Definition:
pid_controller.h:108
pid_controller.h
grpc_core::PidController::last_dc_dt_
double last_dc_dt_
Definition:
pid_controller.h:110
grpc_core::PidController::Args::gain_d
double gain_d() const
Definition:
pid_controller.h:41
grpc_core::PidController::last_error_
double last_error_
Definition:
pid_controller.h:107
port_platform.h
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:52