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