Nebula
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
23namespace Math
24{
25//------------------------------------------------------------------------------
26template<class TYPE> class PFeedbackLoop
27{
28public:
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;
47
48private:
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//------------------------------------------------------------------------------
59template<class TYPE>
61 time(0.0),
62 stepSize(0.001f),
63 gain(-1.0f)
64{
65 // empty
66}
67
68//------------------------------------------------------------------------------
71template<class TYPE>
72void
73PFeedbackLoop<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//------------------------------------------------------------------------------
85template<class TYPE>
86void
88{
89 this->gain = g;
90}
91
92//------------------------------------------------------------------------------
95template<class TYPE>
96float
98{
99 return this->gain;
100}
101
102//------------------------------------------------------------------------------
105template<class TYPE>
106void
108{
109 this->goal = g;
110}
111
112//------------------------------------------------------------------------------
115template<class TYPE>
116const TYPE&
118{
119 return this->goal;
120}
121
122//------------------------------------------------------------------------------
125template<class TYPE>
126void
128{
129 this->state = s;
130}
131
132//------------------------------------------------------------------------------
135template<class TYPE>
136const TYPE&
138{
139 return this->state;
140}
141
142//------------------------------------------------------------------------------
145template<class TYPE>
146void
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
A P feedback loop (proportional feedback loop) is a simple object which moves a system's current stat...
Definition pfeedbackloop.h:27
TYPE state
Definition pfeedbackloop.h:53
TYPE goal
Definition pfeedbackloop.h:52
const TYPE & GetState() const
get the current state the system is in
Definition pfeedbackloop.h:137
void SetState(const TYPE &s)
set the current state directly
Definition pfeedbackloop.h:127
const TYPE & GetGoal() const
get the goal
Definition pfeedbackloop.h:117
float stepSize
Definition pfeedbackloop.h:50
void Reset(Timing::Time time, float stepSize, float gain, const TYPE &curState)
reset the time
Definition pfeedbackloop.h:73
Timing::Time time
Definition pfeedbackloop.h:49
PFeedbackLoop()
constructor
Definition pfeedbackloop.h:60
void SetGain(float g)
set the gain
Definition pfeedbackloop.h:87
void SetGoal(const TYPE &c)
set the goal
Definition pfeedbackloop.h:107
float gain
Definition pfeedbackloop.h:51
float GetGain() const
get the gain
Definition pfeedbackloop.h:97
void Update(Timing::Time time)
update the object, return new state
Definition pfeedbackloop.h:147
Different curves.
Definition angularpfeedbackloop.h:17
double Time
the time datatype
Definition time.h:18
Typedefs for the Timing subsystem.