Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
pfeedbackloop.h
Go to the documentation of this file.
1
#ifndef Math_PFEEDBACKLOOP_H
2
#define Math_PFEEDBACKLOOP_H
3
//------------------------------------------------------------------------------
20
#include "
core/types.h
"
21
#include "
timing/time.h
"
22
23
namespace
Math
24
{
25
//------------------------------------------------------------------------------
26
template
<
class
TYPE>
class
PFeedbackLoop
27
{
28
public
:
30
PFeedbackLoop
();
32
void
Reset
(
Timing::Time
time
,
float
stepSize
,
float
gain
,
const
TYPE& curState);
34
void
SetGain
(
float
g);
36
float
GetGain
()
const
;
38
void
SetGoal
(
const
TYPE& c);
40
const
TYPE&
GetGoal
()
const
;
42
void
SetState
(
const
TYPE& s);
44
const
TYPE&
GetState
()
const
;
46
void
Update
(
Timing::Time
time
);
47
48
private
:
49
Timing::Time
time
;
// the time at which the simulation is
50
float
stepSize
;
51
float
gain
;
52
TYPE
goal
;
53
TYPE
state
;
54
};
55
56
//------------------------------------------------------------------------------
59
template
<
class
TYPE>
60
PFeedbackLoop<TYPE>::PFeedbackLoop
() :
61
time
(0.0),
62
stepSize
(0.001f),
63
gain
(-1.0f)
64
{
65
// empty
66
}
67
68
//------------------------------------------------------------------------------
71
template
<
class
TYPE>
72
void
73
PFeedbackLoop<TYPE>::Reset
(
Timing::Time
t,
float
s,
float
g,
const
TYPE& curState)
74
{
75
this->
time
= t;
76
this->
stepSize
= s;
77
this->
gain
= g;
78
this->
state
= curState;
79
this->
goal
= curState;
80
}
81
82
//------------------------------------------------------------------------------
85
template
<
class
TYPE>
86
void
87
PFeedbackLoop<TYPE>::SetGain
(
float
g)
88
{
89
this->
gain
= g;
90
}
91
92
//------------------------------------------------------------------------------
95
template
<
class
TYPE>
96
float
97
PFeedbackLoop<TYPE>::GetGain
()
const
98
{
99
return
this->
gain
;
100
}
101
102
//------------------------------------------------------------------------------
105
template
<
class
TYPE>
106
void
107
PFeedbackLoop<TYPE>::SetGoal
(
const
TYPE& g)
108
{
109
this->
goal
= g;
110
}
111
112
//------------------------------------------------------------------------------
115
template
<
class
TYPE>
116
const
TYPE&
117
PFeedbackLoop<TYPE>::GetGoal
()
const
118
{
119
return
this->
goal
;
120
}
121
122
//------------------------------------------------------------------------------
125
template
<
class
TYPE>
126
void
127
PFeedbackLoop<TYPE>::SetState
(
const
TYPE& s)
128
{
129
this->
state
= s;
130
}
131
132
//------------------------------------------------------------------------------
135
template
<
class
TYPE>
136
const
TYPE&
137
PFeedbackLoop<TYPE>::GetState
()
const
138
{
139
return
this->
state
;
140
}
141
142
//------------------------------------------------------------------------------
145
template
<
class
TYPE>
146
void
147
PFeedbackLoop<TYPE>::Update
(
Timing::Time
curTime)
148
{
149
Timing::Time
dt = curTime - this->
time
;
150
151
// catch time exceptions
152
if
(dt < 0.0)
153
{
154
this->time = curTime;
155
}
156
else
if
(dt > 0.5)
157
{
158
this->time = curTime - 0.5;
159
}
160
161
while
(this->time < curTime)
162
{
163
this->
state
= this->
state
+ (this->
state
- this->
goal
) * this->
gain
* this->
stepSize
;
164
this->time += this->
stepSize
;
165
}
166
}
167
}
// namespace Math
168
//------------------------------------------------------------------------------
169
#endif
Math::PFeedbackLoop::state
TYPE state
Definition
pfeedbackloop.h:53
Math::PFeedbackLoop::goal
TYPE goal
Definition
pfeedbackloop.h:52
Math::PFeedbackLoop::GetState
const TYPE & GetState() const
get the current state the system is in
Definition
pfeedbackloop.h:137
Math::PFeedbackLoop::SetState
void SetState(const TYPE &s)
set the current state directly
Definition
pfeedbackloop.h:127
Math::PFeedbackLoop::GetGoal
const TYPE & GetGoal() const
get the goal
Definition
pfeedbackloop.h:117
Math::PFeedbackLoop::stepSize
float stepSize
Definition
pfeedbackloop.h:50
Math::PFeedbackLoop::Reset
void Reset(Timing::Time time, float stepSize, float gain, const TYPE &curState)
reset the time
Definition
pfeedbackloop.h:73
Math::PFeedbackLoop::time
Timing::Time time
Definition
pfeedbackloop.h:49
Math::PFeedbackLoop::PFeedbackLoop
PFeedbackLoop()
constructor
Definition
pfeedbackloop.h:60
Math::PFeedbackLoop::SetGain
void SetGain(float g)
set the gain
Definition
pfeedbackloop.h:87
Math::PFeedbackLoop::SetGoal
void SetGoal(const TYPE &c)
set the goal
Definition
pfeedbackloop.h:107
Math::PFeedbackLoop::gain
float gain
Definition
pfeedbackloop.h:51
Math::PFeedbackLoop::GetGain
float GetGain() const
get the gain
Definition
pfeedbackloop.h:97
Math::PFeedbackLoop::Update
void Update(Timing::Time time)
update the object, return new state
Definition
pfeedbackloop.h:147
Math
Different curves.
Definition
angularpfeedbackloop.h:17
Timing::Time
double Time
the time datatype
Definition
time.h:18
time.h
Typedefs for the Timing subsystem.
types.h
code
foundation
math
pfeedbackloop.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.