AnimatLab  2
Test
SigmoidGain.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 "SigmoidGain.h"
14 
15 namespace AnimatSim
16 {
17  namespace Gains
18  {
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 SigmoidGain\r\n", "", -1, false, true);}
48 }
49 
58 float SigmoidGain::A() {return m_fltA;}
59 
68 void SigmoidGain::A(float fltVal) {m_fltA = fltVal;}
69 
78 float SigmoidGain::B() {return m_fltB;}
79 
88 void SigmoidGain::B(float fltVal) {m_fltB = fltVal;}
89 
98 float SigmoidGain::C() {return m_fltC;}
99 
108 void SigmoidGain::C(float fltVal) {m_fltC = fltVal;}
109 
118 float SigmoidGain::D() {return m_fltD;}
119 
128 void SigmoidGain::D(float fltVal) {m_fltD = fltVal;}
129 
130 void SigmoidGain::Copy(CStdSerialize *lpSource)
131 {
132  Gain::Copy(lpSource);
133 
134  SigmoidGain *lpOrig = dynamic_cast<SigmoidGain *>(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 *SigmoidGain::Clone()
143 {
144  CStdSerialize *lpClone = new SigmoidGain();
145  lpClone->Copy(this);
146  return lpClone;
147 }
148 
149 float SigmoidGain::CalculateGain(float fltInput)
150 {
151  if(InLimits(fltInput))
152  return ((m_fltB/(1+exp(m_fltC*(m_fltA-fltInput)))) + m_fltD);
153  else
154  return CalculateLimitOutput(fltInput);
155 }
156 
157 
158 bool SigmoidGain::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 SigmoidGain::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 SigmoidGain::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
Base class file for all Animat simulation objects.
Root namespace for the base simulation library for AnimatLab.
Declares the sigmoid gain class.
float m_fltA
The A parameter of the gain.
Definition: SigmoidGain.h:25
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
float m_fltB
The B parameter of the gain.
Definition: SigmoidGain.h:28
bool InLimits(float fltInput)
Tells whether the input value is within the defined limit ranges.
Definition: Gain.h:63
float m_fltC
The C parameter of the gain.
Definition: SigmoidGain.h:31
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the gain base class.
float C()
Gets C parameter of sigmoidal eqation: Out = D+(B/(1+e^(C*(A-In))))
Definition: SigmoidGain.cpp:98
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 m_fltD
The D parameter of the gain.
Definition: SigmoidGain.h:34
float D()
Sets D parameter of sigmoidal eqation: Out = D+(B/(1+e^(C*(A-In))))
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.
virtual ~SigmoidGain()
Destructor.
Definition: SigmoidGain.cpp:40
float B()
Gets B parameter of sigmoidal eqation: Out = D+(B/(1+e^(C*(A-In))))
Definition: SigmoidGain.cpp:78
float CalculateLimitOutput(float fltInput)
Calculates the output when the input is outside of the limit ranges.
Definition: Gain.h:81
float A()
Gets A parameter of sigmoidal eqation: Out = D+(B/(1+e^(C*(A-In))))
Definition: SigmoidGain.cpp:58
SigmoidGain()
Default constructor.
Definition: SigmoidGain.cpp:26
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 float CalculateGain(float fltInput)
Calculates the gain.