AnimatLab  2
Test
ExternalInputStimulus.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 "Node.h"
13 #include "Link.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
16 #include "BoundingBox.h"
17 #include "MovableItem.h"
18 #include "BodyPart.h"
19 #include "Gain.h"
20 #include "Adapter.h"
21 #include "Joint.h"
22 #include "ReceptiveField.h"
23 #include "ContactSensor.h"
24 #include "RigidBody.h"
25 #include "Structure.h"
26 #include "NeuralModule.h"
27 #include "NervousSystem.h"
28 #include "Organism.h"
29 #include "ActivatedItem.h"
30 #include "ActivatedItemMgr.h"
31 #include "DataChartMgr.h"
32 #include "ExternalStimuliMgr.h"
33 #include "ExternalStimulus.h"
34 #include "ExternalInputStimulus.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 namespace AnimatSim
44 {
45  namespace ExternalStimuli
46  {
54 {
55  m_lpNode = NULL;
56  m_lpEval = NULL;
57  m_fltInput = 0;
58 }
59 
67 {
68 
69 try
70 {
71  m_lpNode = NULL;
72  if(m_lpEval) delete m_lpEval;
73 }
74 catch(...)
75 {Std_TraceMsg(0, "Caught Error in desctructor of ExternalInputStimulus\r\n", "", -1, false, true);}
76 }
77 
78 std::string ExternalInputStimulus::Type() {return "ExternalInput";}
79 
89 
98 void ExternalInputStimulus::TargetNodeID(std::string strID)
99 {
100  if(Std_IsBlank(strID))
101  THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
102  m_strTargetNodeID = strID;
103 }
104 
114 
123 void ExternalInputStimulus::Input(float fltVal) {m_fltInput = fltVal;}
124 
134 
143 void ExternalInputStimulus::InputEquation(std::string strVal)
144 {
145  //Initialize the postfix evaluator.
146  if(m_lpEval)
147  {delete m_lpEval; m_lpEval = NULL;}
148 
150 
151  m_lpEval->AddVariable("t");
152  m_lpEval->AddVariable("x");
154 }
155 
157 {
159 
160  m_lpNode = dynamic_cast<Node *>(m_lpSim->FindByID(m_strTargetNodeID));
161  if(!m_lpNode)
162  THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound, "ID: ", m_strTargetNodeID);
163 }
164 
166 {
168 }
169 
171 {
172  try
173  {
174  m_lpEval->SetVariable("t", m_lpSim->Time());
177  }
178  catch(...)
179  {
180  LOG_ERROR("Error Occurred while setting Joint Velocity");
181  }
182 }
183 
185 {
187 }
188 
189 float *ExternalInputStimulus::GetDataPointer(const std::string &strDataType)
190 {
191  float *lpData=NULL;
192  std::string strType = Std_CheckString(strDataType);
193 
194  if(strType == "INPUT")
195  lpData = &m_fltInput;
196  else
197  THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "StimulusName: " + STR(m_strName) + " DataType: " + strDataType);
198 
199  return lpData;
200 }
201 
202 bool ExternalInputStimulus::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
203 {
204  std::string strType = Std_CheckString(strDataType);
205 
206  if(ExternalStimulus::SetData(strDataType, strValue, false))
207  return true;
208 
209  if(strType == "INPUTEQUATION")
210  {
211  InputEquation(strValue);
212  return true;
213  }
214 
215  //If it was not one of those above then we have a problem.
216  if(bThrowError)
217  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
218 
219  return false;
220 }
221 
222 void ExternalInputStimulus::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
223 {
224  ExternalStimulus::QueryProperties(aryProperties);
225 
226  aryProperties.Add(new TypeProperty("Input", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
227 
228  aryProperties.Add(new TypeProperty("InputEquation", AnimatPropertyType::String, AnimatPropertyDirection::Set));
229 }
230 
231 void ExternalInputStimulus::Load(CStdXml &oXml)
232 {
233  ActivatedItem::Load(oXml);
234 
235  oXml.IntoElem(); //Into Simulus Element
236 
237  TargetNodeID(oXml.GetChildString("NodeID"));
238  InputEquation(oXml.GetChildString("Input", "0"));
239 
240  oXml.OutOfElem(); //OutOf Simulus Element
241 }
242 
243 
244  } //ExternalStimuli
245 } //VortexAnimatSim
246 
247 
248 
249 
virtual float Input()
Gets the current input value.
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
Declares the nervous system class.
void AddVariable(std::string strVarName)
Adds a variable.
virtual void Activate()
Activates this item.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
std::string m_strInputEquation
The post-fix equation that controls the input values to the node.
virtual std::string TargetNodeID()
Gets the GUID ID of the target node that will be stimulated.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)=0
Adds an external node input.
float m_fltInput
The current input value that will be applied to the node.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
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
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual std::string Type()
returns the string type name of this object.
Declares the key frame class.
Declares the joint class.
Declares the organism class.
CStdPostFixEval * m_lpEval
Pointer to the post-fix evaluator.
Declares a light object.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
void Equation(std::string strVal)
Sets the post-fix Equation.
virtual void StepSimulation()
Step the simulation for this object.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
A standard xml manipulation class.
Definition: StdXml.h:19
Node * m_lpNode
The pointer to this items parent Node. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:52
Declares the node class.
std::string m_strTargetNodeID
GUID ID of the target node to enable.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
Standard post fix evaluation class.
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.
double Solve()
Solves the equation using the defined variable values.
void SetVariable(std::string strVarName, double dblVal)
Sets the value of a variable.
Base class for body parts and neural network nodes.
Definition: Node.h:25
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual void Deactivate()
Deactivates this item.
virtual std::string InputEquation()
Gets the post-fix input equation used for the stimulus.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
Declares the data chart manager class.
Declares the rigid body class.
virtual void Initialize()
Initializes this object.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void Deactivate()
Deactivates this item.
Declares the structure class.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
Declares the odor class.
Declares the simulator class.
Declares the neural module class.
virtual float Time()
Gets the current simulation time in seconds.
Definition: Simulator.cpp:559
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the external input stimulus class.
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.