AnimatLab  2
Test
BellGain.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 #include "Gain.h"
12 #include "BellGain.h"
13 
14 
15 namespace AnimatSim
16 {
17  namespace Gains
18  {
26 {
27  m_fltA = 0;
28  m_fltB = 0;
29  m_fltC = 0;
30  m_fltD = 0;
31 }
32 
40 {
41 
42 try
43 {
44 }
45 catch(...)
46 {Std_TraceMsg(0, "Caught Error in desctructor of BellGain\r\n", "", -1, false, true);}
47 }
48 
57 float BellGain::A() {return m_fltA;}
58 
67 void BellGain::A(float fltVal) {m_fltA = fltVal;}
68 
77 float BellGain::B() {return m_fltB;}
78 
87 void BellGain::B(float fltVal) {m_fltB = fltVal;}
88 
97 float BellGain::C() {return m_fltC;}
98 
107 void BellGain::C(float fltVal) {m_fltC = fltVal;}
108 
117 float BellGain::D() {return m_fltD;}
118 
127 void BellGain::D(float fltVal) {m_fltD = fltVal;}
128 
129 void BellGain::Copy(CStdSerialize *lpSource)
130 {
131  Gain::Copy(lpSource);
132 
133  BellGain *lpOrig = dynamic_cast<BellGain *>(lpSource);
134 
135  m_fltA = lpOrig->m_fltA;
136  m_fltB = lpOrig->m_fltB;
137  m_fltC = lpOrig->m_fltC;
138  m_fltD = lpOrig->m_fltD;
139 }
140 
141 CStdSerialize *BellGain::Clone()
142 {
143  CStdSerialize *lpClone = new BellGain();
144  lpClone->Copy(this);
145  return lpClone;
146 }
147 
148 float BellGain::CalculateGain(float fltInput)
149 {
150  float fltVal = 0;
151 
152  if(InLimits(fltInput))
153  {
154  if(m_fltB)
155  {
156  fltVal = pow((float) (fltInput-m_fltA), (float) 2.0);
157  fltVal = exp(-m_fltC * fltVal);
158  fltVal = (m_fltB * fltVal) + m_fltD;
159  }
160  }
161  else
162  fltVal = CalculateLimitOutput(fltInput);
163 
164  return fltVal;
165 }
166 
167 bool BellGain::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
168 {
169  if(Gain::SetData(strDataType, strValue, false))
170  return true;
171 
172  if(strDataType == "A")
173  {
174  A((float) atof(strValue.c_str()));
175  return true;
176  }
177 
178  if(strDataType == "B")
179  {
180  B((float) atof(strValue.c_str()));
181  return true;
182  }
183 
184  if(strDataType == "C")
185  {
186  C((float) atof(strValue.c_str()));
187  return true;
188  }
189 
190  if(strDataType == "D")
191  {
192  D((float) atof(strValue.c_str()));
193  return true;
194  }
195 
196  //If it was not one of those above then we have a problem.
197  if(bThrowError)
198  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
199 
200  return false;
201 }
202 
203 void BellGain::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
204 {
205  Gain::QueryProperties(aryProperties);
206 
207  aryProperties.Add(new TypeProperty("A", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
208  aryProperties.Add(new TypeProperty("B", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
209  aryProperties.Add(new TypeProperty("C", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
210  aryProperties.Add(new TypeProperty("D", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
211 }
212 
213 void BellGain::Load(CStdXml &oXml)
214 {
215  Gain::Load(oXml);
216 
217  oXml.IntoElem(); //Into Adapter Element
218 
219  A(oXml.GetChildFloat("A"));
220  B(oXml.GetChildFloat("B"));
221  C(oXml.GetChildFloat("C"));
222  D(oXml.GetChildFloat("D"));
223 
224  oXml.OutOfElem(); //OutOf Adapter Element
225 }
226 
227 
228  } //Gains
229 } //AnimatSim
Base class file for all Animat simulation objects.
virtual float CalculateGain(float fltInput)
Calculates the gain.
Definition: BellGain.cpp:148
Root namespace for the base simulation library for AnimatLab.
Declares the bell gain class.
float B()
Gets B parameter of bell eqation: Out = B*e^(-C*(In-A)^2)+D.
Definition: BellGain.cpp:77
float m_fltB
The B parameter of the gain.
Definition: BellGain.h:28
float m_fltA
The A parameter of the gain.
Definition: BellGain.h:25
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
float A()
Gets A parameter of bell eqation: Out = B*e^(-C*(In-A)^2)+D.
Definition: BellGain.cpp:57
bool InLimits(float fltInput)
Tells whether the input value is within the defined limit ranges.
Definition: Gain.h:63
virtual ~BellGain()
Destructor.
Definition: BellGain.cpp:39
float D()
Sets D parameter of bell eqation: Out = B*e^(-C*(In-A)^2)+D.
Definition: BellGain.cpp:117
Declares the gain base class.
float m_fltD
The D parameter of the gain.
Definition: BellGain.h:34
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
float m_fltC
The C parameter of the gain.
Definition: BellGain.h:31
float C()
Gets C parameter of bell eqation: Out = B*e^(-C*(In-A)^2)+D.
Definition: BellGain.cpp:97
float CalculateLimitOutput(float fltInput)
Calculates the output when the input is outside of the limit ranges.
Definition: Gain.h:81
Bell gain class.
Definition: BellGain.h:21
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: BellGain.cpp:167
BellGain()
Default constructor.
Definition: BellGain.cpp:25
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Gain.cpp:232
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: Gain.cpp:190
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: BellGain.cpp:203