Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
rtc
Stabilizer
Integrator.cpp
Go to the documentation of this file.
1
// -*- C++ -*-
2
11
#include "
Integrator.h
"
12
#include <iostream>
13
#include <iterator>
14
#include <numeric>
15
16
Integrator::Integrator
(
double
_dt,
unsigned
int
_range) {
17
setup
(_dt, _range);
18
}
19
20
Integrator::~Integrator
(
void
) {
21
}
22
23
void
Integrator::reset
(
void
) {
24
buffer
.clear();
25
first
= 0;
26
sum
= 0;
27
last
= 0;
28
init_integration_flag
=
false
;
29
return
;
30
}
31
32
void
Integrator::setup
(
double
_dt,
unsigned
int
_range) {
33
dt
= _dt;
34
range
= _range;
35
reset
();
36
return
;
37
}
38
39
void
Integrator::update
(
double
_x) {
40
41
// integration by trapezoidal rule:
42
// (1/2 * first + sum(f(x_i), 1, N-1) + 1/2 * last) * dt
43
if
(!
init_integration_flag
) {
44
first
= _x;
// update first value
45
init_integration_flag
=
true
;
46
// first value is not counted to sum
47
}
else
{
48
sum
+=
last
;
// sum is last is assumed to be 0 at first
49
last
= _x;
50
}
51
52
// if integration range is defined, use buffer
53
if
(
range
> 0) {
54
buffer
.push_back(_x);
// save values (include first)
55
if
(
buffer
.size() >
range
) {
56
buffer
.pop_front();
// remove oldest data
57
first
=
buffer
.front();
// update first value
58
sum
-=
first
;
59
}
60
}
61
62
return
;
63
}
64
65
double
Integrator::calculate
(
void
) {
66
// calc integration by trapezoidal rule
67
// sum(1/2 * (f(x_i) - f(x_(i+1))), 0, N) * dt = (1/2 * f(0) + sum(f(x_i), 1, N-1) + 1/2 * f(N)) * dt
68
return
(0.5 *
first
+
sum
+ 0.5 *
last
) *
dt
;
69
}
Integrator::calculate
double calculate(void)
Definition:
Integrator.cpp:65
Integrator::dt
double dt
Definition:
Integrator.h:27
Integrator::buffer
std::deque< double > buffer
Definition:
Integrator.h:31
Integrator::sum
double sum
Definition:
Integrator.h:28
Integrator::first
double first
Definition:
Integrator.h:28
Integrator::init_integration_flag
bool init_integration_flag
Definition:
Integrator.h:29
Integrator::~Integrator
~Integrator(void)
Definition:
Integrator.cpp:20
Integrator::range
unsigned int range
Definition:
Integrator.h:30
Integrator::setup
void setup(double _dt, unsigned int _range)
Definition:
Integrator.cpp:32
Integrator::update
void update(double _x)
Definition:
Integrator.cpp:39
Integrator::reset
void reset(void)
Definition:
Integrator.cpp:23
Integrator::last
double last
Definition:
Integrator.h:28
Integrator.h
Calcurate Integration.
Integrator::Integrator
Integrator(double _dt=0.005, unsigned int _range=0)
Definition:
Integrator.cpp:16
hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50