Nebula
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
16namespace Math
17{
18
19//------------------------------------------------------------------------------
21{
22public:
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;
42 Timing::Time GetTime() const;
43
44private:
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//------------------------------------------------------------------------------
55inline
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//------------------------------------------------------------------------------
69inline
70void
71AngularPFeedbackLoop::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//------------------------------------------------------------------------------
82inline
83void
85{
86 this->gain = g;
87}
88
89//------------------------------------------------------------------------------
92inline
93float
95{
96 return this->gain;
97}
98
99//------------------------------------------------------------------------------
102inline
103void
105{
106 this->goal = g;
107}
108
109//------------------------------------------------------------------------------
112inline
113float
115{
116 return this->goal;
117}
118
119//------------------------------------------------------------------------------
122inline
123void
125{
126 this->state = s;
127}
128
129//------------------------------------------------------------------------------
132inline
133float
135{
136 return this->state;
137}
138
139//------------------------------------------------------------------------------
142inline
145{
146 return this->time;
147}
148
149//------------------------------------------------------------------------------
152inline
153void
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
A proportional feedback loop with correct angular interpolation.
Definition angularpfeedbackloop.h:21
float stepSize
Definition angularpfeedbackloop.h:46
void Update(Timing::Time time)
update the object, return new state
Definition angularpfeedbackloop.h:154
Timing::Time GetTime() const
get currrent time
Definition angularpfeedbackloop.h:144
float GetState() const
get the current state the system is in
Definition angularpfeedbackloop.h:134
float gain
Definition angularpfeedbackloop.h:47
float state
Definition angularpfeedbackloop.h:49
void Reset(Timing::Time time, float stepSize, float gain, float curState)
reset the time
Definition angularpfeedbackloop.h:71
void SetGain(float g)
set the gain
Definition angularpfeedbackloop.h:84
float GetGoal() const
get the goal
Definition angularpfeedbackloop.h:114
float goal
Definition angularpfeedbackloop.h:48
AngularPFeedbackLoop()
constructor
Definition angularpfeedbackloop.h:56
void SetState(float s)
set the current state directly
Definition angularpfeedbackloop.h:124
Timing::Time time
Definition angularpfeedbackloop.h:45
void SetGoal(float c)
set the goal
Definition angularpfeedbackloop.h:104
float GetGain() const
get the gain
Definition angularpfeedbackloop.h:94
Half precision (16 bit) float implementation.
Definition angularpfeedbackloop.h:17
__forceinline scalar abs(scalar a)
Definition scalar.h:432
double Time
the time datatype
Definition time.h:18
#define N_TINY
Definition scalar.h:43
Typedefs for the Timing subsystem.