AnimatLab  2
Test
Gain.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 <sys/types.h>
13 #include <sys/stat.h>
14 #include "Gain.h"
15 #include "Node.h"
16 #include "Link.h"
17 #include "IPhysicsMovableItem.h"
18 #include "IPhysicsBody.h"
19 #include "BoundingBox.h"
20 #include "MovableItem.h"
21 #include "BodyPart.h"
22 #include "Joint.h"
23 #include "ReceptiveField.h"
24 #include "ContactSensor.h"
25 #include "RigidBody.h"
26 #include "Structure.h"
27 #include "NeuralModule.h"
28 #include "Adapter.h"
29 #include "NervousSystem.h"
30 #include "Organism.h"
31 #include "ActivatedItem.h"
32 #include "ActivatedItemMgr.h"
33 #include "DataChartMgr.h"
34 #include "ExternalStimuliMgr.h"
35 #include "KeyFrame.h"
36 #include "SimulationRecorder.h"
37 #include "OdorType.h"
38 #include "Odor.h"
39 #include "Light.h"
40 #include "LightManager.h"
41 #include "Simulator.h"
42 
43 
44 namespace AnimatSim
45 {
46  namespace Gains
47  {
55 {
56  m_bUseLimits = false;
57  m_fltLowerLimit = 0;
58  m_fltLowerOutput = 0;
59  m_fltUpperLimit = 0;
60  m_fltUpperOutput = 0;
61 }
62 
70 {
71 
72 try
73 {
74 }
75 catch(...)
76 {Std_TraceMsg(0, "Caught Error in desctructor of Gain\r\n", "", -1, false, true);}
77 }
78 
87 bool Gain::UseLimits() {return m_bUseLimits;}
88 
97 void Gain::UseLimits(bool bVal) {m_bUseLimits = bVal;}
98 
108 
117 void Gain::LowerLimit(float fltVal)
118 {
119  Std_IsAboveMin(fltVal, m_fltUpperLimit, true, "LowerLimit");
120  m_fltLowerLimit = fltVal;
121 }
122 
132 
141 void Gain::UpperLimit(float fltVal)
142 {
143  Std_IsAboveMin(m_fltLowerLimit, fltVal, true, "UpperLimit");
144  m_fltUpperLimit = fltVal;
145 }
146 
156 
165 void Gain::LowerOutput(float fltVal) {m_fltLowerOutput = fltVal;}
166 
176 
177 void Gain::Copy(CStdSerialize *lpSource)
178 {
179  AnimatBase::Copy(lpSource);
180 
181  Gain *lpOrig = dynamic_cast<Gain *>(lpSource);
182 
183  m_bUseLimits = lpOrig->m_bUseLimits;
188 }
189 
190 bool Gain::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
191 {
192  if(AnimatBase::SetData(strDataType, strValue, false))
193  return true;
194 
195  if(strDataType == "USELIMITS")
196  {
197  UseLimits(Std_ToBool(strValue));
198  return true;
199  }
200 
201  if(strDataType == "LOWERLIMIT")
202  {
203  LowerLimit((float) atof(strValue.c_str()));
204  return true;
205  }
206 
207  if(strDataType == "LOWEROUTPUT")
208  {
209  LowerOutput((float) atof(strValue.c_str()));
210  return true;
211  }
212 
213  if(strDataType == "UPPERLIMIT")
214  {
215  UpperLimit((float) atof(strValue.c_str()));
216  return true;
217  }
218 
219  if(strDataType == "UPPEROUTPUT")
220  {
221  UpperOutput((float) atof(strValue.c_str()));
222  return true;
223  }
224 
225  //If it was not one of those above then we have a problem.
226  if(bThrowError)
227  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
228 
229  return false;
230 }
231 
232 void Gain::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
233 {
234  AnimatBase::QueryProperties(aryProperties);
235 
236  aryProperties.Add(new TypeProperty("UseLimits", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
237  aryProperties.Add(new TypeProperty("LowerLimit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
238  aryProperties.Add(new TypeProperty("LowerOutput", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
239  aryProperties.Add(new TypeProperty("UpperLimit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
240  aryProperties.Add(new TypeProperty("UpperOutput", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
241 }
242 
251 void Gain::UpperOutput(float fltVal) {m_fltUpperOutput = fltVal;}
252 
253 void Gain::Load(CStdXml &oXml)
254 {
255  AnimatBase::Load(oXml);
256 
257  oXml.IntoElem(); //Into Adapter Element
258 
259  UseLimits(oXml.GetChildBool("UseLimits", m_bUseLimits));
260 
261  if(m_bUseLimits)
262  {
263  m_fltLowerLimit = oXml.GetChildFloat("LowerLimit");
264  m_fltUpperLimit = oXml.GetChildFloat("UpperLimit");
265  m_fltLowerOutput = oXml.GetChildFloat("LowerOutput");
266  m_fltUpperOutput = oXml.GetChildFloat("UpperOutput");
267 
268  Std_IsAboveMin(m_fltLowerLimit, m_fltUpperLimit, true, "UpperLimit");
269  }
270 
271  oXml.OutOfElem(); //OutOf Adapter Element
272 }
273 
287 Gain ANIMAT_PORT *LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
288 {
289  Gain *lpGain = NULL;
290 
291  try
292  {
293  //Now lets load this Current Graph object.
294  oXml.IntoChildElement(strName);
295  std::string strModuleName = oXml.GetChildString("ModuleName", "");
296  std::string strType = oXml.GetChildString("Type");
297  oXml.OutOfElem(); //OutOf Gain Element
298 
299  Gain *lpGain = dynamic_cast<AnimatSim::Gains::Gain *>(lpSim->CreateObject(strModuleName, "Gain", strType));
300  if(!lpGain)
301  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "CurrentGraph");
302 
303  lpGain->SetSystemPointers(lpSim, NULL, NULL, NULL, true);
304  lpGain->Load(oXml);
305 
306  return lpGain;
307  }
308  catch(CStdErrorInfo oError)
309  {
310  if(lpGain)
311  delete lpGain;
312  THROW_ERROR(oError.m_lError, oError.m_strError);
313  return NULL;
314  }
315 }
316 
317  } //Gains
318 } //AnimatSim
Gain()
Default constructor.
Definition: Gain.cpp:54
Base class file for all Animat simulation objects.
Declares the nervous system class.
Declares the simulation recorder class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
Simulates the entire environment.
Definition: Simulator.h:31
Root namespace for the base simulation library for AnimatLab.
bool UseLimits()
Tells whether limits should be used.
Definition: Gain.cpp:87
Declares the body part class.
float m_fltUpperLimit
The upper limit value that is checked if UseLimits is true.
Definition: Gain.h:48
std::string m_strError
The error message.
Definition: StdErrorInfo.h:26
Information about the standard error.
Definition: StdErrorInfo.h:19
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
long m_lError
The error number.
Definition: StdErrorInfo.h:23
The Gain base class.
Definition: Gain.h:35
float UpperLimit()
Gets the upper limit.
Definition: Gain.cpp:131
Declares the key frame class.
Declares the joint class.
Declares the organism class.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
float LowerOutput()
Gets the lower output.
Definition: Gain.cpp:155
Declares a light object.
Declares the activated item class.
float m_fltLowerLimit
The lower limit value that is checked if UseLimits is true.
Definition: Gain.h:42
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
Definition: Simulator.cpp:3440
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
float UpperOutput()
Gets the upper output.
Definition: Gain.cpp:175
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: AnimatBase.cpp:447
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
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 bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
float m_fltLowerOutput
The lower limit output that is used if UseLimits is true and the input is below the lower limit...
Definition: Gain.h:45
float LowerLimit()
Gets the lower limit.
Definition: Gain.cpp:107
virtual ~Gain()
Destructor.
Definition: Gain.cpp:69
Declares the data chart manager class.
Declares the rigid body class.
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
Definition: StdXml.cpp:278
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
float m_fltUpperOutput
The upper limit output that is used if UseLimits is true and the input is above the upper limit...
Definition: Gain.h:51
Declares the structure class.
Declares the odor type class.
Standard serialize class.
Definition: StdSerialize.h:20
Declares the odor class.
Declares the simulator class.
Declares the neural module class.
bool m_bUseLimits
Determines whether or not the gain uses upper and lower limits during its calculations.
Definition: Gain.h:39
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
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: AnimatBase.cpp:371
Gain * LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
Loads a gain object.
Definition: Gain.cpp:287
Declares the receptive field class.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617