Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
angularpfeedbackloop.h
Go to the documentation of this file.
1
#ifndef MATH_ANGULARPFEEDBACKLOOP_H
2
#define MATH_ANGULARPFEEDBACKLOOP_H
3
//------------------------------------------------------------------------------
13
#include "
core/types.h
"
14
#include "
timing/time.h
"
15
16
namespace
Math
17
{
18
19
//------------------------------------------------------------------------------
20
class
AngularPFeedbackLoop
21
{
22
public
:
24
AngularPFeedbackLoop
();
26
void
Reset
(
Timing::Time
time
,
float
stepSize
,
float
gain
,
float
curState);
28
void
SetGain
(
float
g);
30
float
GetGain
()
const
;
32
void
SetGoal
(
float
c);
34
float
GetGoal
()
const
;
36
void
SetState
(
float
s);
38
float
GetState
()
const
;
40
void
Update
(
Timing::Time
time
);
42
Timing::Time
GetTime
()
const
;
43
44
private
:
45
Timing::Time
time
;
// the time at which the simulation is
46
float
stepSize
;
47
float
gain
;
48
float
goal
;
49
float
state
;
50
};
51
52
//------------------------------------------------------------------------------
55
inline
56
AngularPFeedbackLoop::AngularPFeedbackLoop
() :
57
time
(0.0),
58
stepSize
(0.001f),
59
gain
(-1.0f),
60
goal
(0.0f),
61
state
(0.0f)
62
{
63
// empty
64
}
65
66
//------------------------------------------------------------------------------
69
inline
70
void
71
AngularPFeedbackLoop::Reset
(
Timing::Time
t,
float
s,
float
g,
float
curState)
72
{
73
this->
time
= t;
74
this->
stepSize
= s;
75
this->
gain
= g;
76
this->
state
= curState;
77
}
78
79
//------------------------------------------------------------------------------
82
inline
83
void
84
AngularPFeedbackLoop::SetGain
(
float
g)
85
{
86
this->
gain
= g;
87
}
88
89
//------------------------------------------------------------------------------
92
inline
93
float
94
AngularPFeedbackLoop::GetGain
()
const
95
{
96
return
this->
gain
;
97
}
98
99
//------------------------------------------------------------------------------
102
inline
103
void
104
AngularPFeedbackLoop::SetGoal
(
float
g)
105
{
106
this->
goal
= g;
107
}
108
109
//------------------------------------------------------------------------------
112
inline
113
float
114
AngularPFeedbackLoop::GetGoal
()
const
115
{
116
return
this->
goal
;
117
}
118
119
//------------------------------------------------------------------------------
122
inline
123
void
124
AngularPFeedbackLoop::SetState
(
float
s)
125
{
126
this->
state
= s;
127
}
128
129
//------------------------------------------------------------------------------
132
inline
133
float
134
AngularPFeedbackLoop::GetState
()
const
135
{
136
return
this->
state
;
137
}
138
139
//------------------------------------------------------------------------------
142
inline
143
Timing::Time
144
AngularPFeedbackLoop::GetTime
()
const
145
{
146
return
this->
time
;
147
}
148
149
//------------------------------------------------------------------------------
152
inline
153
void
154
AngularPFeedbackLoop::Update
(
Timing::Time
curTime)
155
{
156
Timing::Time
dt = curTime - this->
time
;
157
158
// catch time exceptions
159
if
(dt < 0.0)
160
{
161
this->time = curTime;
162
}
163
else
if
(dt > 0.5)
164
{
165
this->time = curTime - 0.5;
166
}
167
168
while
(this->time < curTime)
169
{
170
// get angular distance error
171
float
error = n_angulardistance(this->
state
, this->
goal
);
172
if
(
Math::abs
(error) >
N_TINY
)
173
{
174
this->
state
= n_modangle(this->
state
- (error * this->
gain
* this->
stepSize
));
175
this->time += this->stepSize;
176
}
177
else
178
{
179
this->
state
= this->
goal
;
180
this->time = curTime;
181
break
;
182
}
183
}
184
}
185
186
}
// namespace Math
187
//------------------------------------------------------------------------------
188
#endif
Math::AngularPFeedbackLoop::stepSize
float stepSize
Definition
angularpfeedbackloop.h:46
Math::AngularPFeedbackLoop::Update
void Update(Timing::Time time)
update the object, return new state
Definition
angularpfeedbackloop.h:154
Math::AngularPFeedbackLoop::GetTime
Timing::Time GetTime() const
get currrent time
Definition
angularpfeedbackloop.h:144
Math::AngularPFeedbackLoop::GetState
float GetState() const
get the current state the system is in
Definition
angularpfeedbackloop.h:134
Math::AngularPFeedbackLoop::gain
float gain
Definition
angularpfeedbackloop.h:47
Math::AngularPFeedbackLoop::state
float state
Definition
angularpfeedbackloop.h:49
Math::AngularPFeedbackLoop::Reset
void Reset(Timing::Time time, float stepSize, float gain, float curState)
reset the time
Definition
angularpfeedbackloop.h:71
Math::AngularPFeedbackLoop::SetGain
void SetGain(float g)
set the gain
Definition
angularpfeedbackloop.h:84
Math::AngularPFeedbackLoop::GetGoal
float GetGoal() const
get the goal
Definition
angularpfeedbackloop.h:114
Math::AngularPFeedbackLoop::goal
float goal
Definition
angularpfeedbackloop.h:48
Math::AngularPFeedbackLoop::AngularPFeedbackLoop
AngularPFeedbackLoop()
constructor
Definition
angularpfeedbackloop.h:56
Math::AngularPFeedbackLoop::SetState
void SetState(float s)
set the current state directly
Definition
angularpfeedbackloop.h:124
Math::AngularPFeedbackLoop::time
Timing::Time time
Definition
angularpfeedbackloop.h:45
Math::AngularPFeedbackLoop::SetGoal
void SetGoal(float c)
set the goal
Definition
angularpfeedbackloop.h:104
Math::AngularPFeedbackLoop::GetGain
float GetGain() const
get the gain
Definition
angularpfeedbackloop.h:94
Math
Different curves.
Definition
angularpfeedbackloop.h:17
Math::abs
__forceinline scalar abs(scalar a)
Definition
scalar.h:451
Timing::Time
double Time
the time datatype
Definition
time.h:18
N_TINY
#define N_TINY
Definition
scalar.h:43
time.h
Typedefs for the Timing subsystem.
types.h
code
foundation
math
angularpfeedbackloop.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.