AnimatLab  2
Test
MuscleBase.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 <math.h>
13 #include "Node.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
16 #include "BoundingBox.h"
17 #include "MovableItem.h"
18 #include "BodyPart.h"
19 #include "Joint.h"
20 #include "ReceptiveField.h"
21 #include "ContactSensor.h"
22 #include "RigidBody.h"
23 #include "Sensor.h"
24 #include "Attachment.h"
25 #include "Structure.h"
26 #include "Organism.h"
27 #include "ActivatedItem.h"
28 #include "ActivatedItemMgr.h"
29 #include "DataChartMgr.h"
30 #include "ExternalStimuliMgr.h"
31 #include "KeyFrame.h"
32 #include "SimulationRecorder.h"
33 #include "OdorType.h"
34 #include "Odor.h"
35 #include "Light.h"
36 #include "LightManager.h"
37 #include "Simulator.h"
38 
39 #include "ExternalStimulus.h"
40 
41 #include "LineBase.h"
42 #include "Gain.h"
43 #include "SigmoidGain.h"
44 #include "LengthTensionGain.h"
45 #include "MuscleBase.h"
46 
47 namespace AnimatSim
48 {
49  namespace Environment
50  {
51  namespace Bodies
52  {
53 
61 {
62  m_fltMaxTension = 0;
63  m_fltVm = (float) -0.15;
64  m_fltTdot = 0;
65  m_fltTension = 0;
66  m_fltPrevTension = 0;
67 }
68 
76 {
77  try
78  {
79  }
80  catch(...)
81  {Std_TraceMsg(0, "Caught Error in desctructor of MuscleBase\r\n", "", -1, false, true);}
82 }
83 
93 
103 void MuscleBase::Tension(float fltVal)
104 {
105  if(fltVal < 0)
106  THROW_PARAM_ERROR(Al_Err_lForceLessThanZero, Al_Err_strForceLessThanZero, "MuscleID", m_strName);
107 
108  m_fltTension = fltVal;
109 }
110 
120 
130 void MuscleBase::MaxTension(float fltVal)
131 {
132  Std_IsAboveMin((float) 0, fltVal, true, "Max Tension");
133  m_fltMaxTension = fltVal;
134 }
135 
144 float MuscleBase::Vm() {return m_fltVm;}
145 
154 float MuscleBase::Tdot() {return m_fltTdot;}
155 
165 
175 
184 void MuscleBase::Enabled(bool bVal)
185 {
186  LineBase::Enabled(bVal);
187 
188  if(!bVal)
189  {
190  m_fltTdot = 0;
191  m_fltTension = 0;
192  }
193 }
194 
195 SigmoidGain *MuscleBase::StimTension() {return &m_gainStimTension;}
196 
197 
198 
206 void MuscleBase::StimTension(std::string strXml)
207 {
208  CStdXml oXml;
209  oXml.Deserialize(strXml);
210  oXml.FindElement("Root");
211  oXml.FindChildElement("Gain");
212  m_gainStimTension.Load(oXml);
213 }
214 
215 LengthTensionGain *MuscleBase::LengthTension() {return &m_gainLengthTension;}
216 
224 void MuscleBase::LengthTension(std::string strXml)
225 {
226  CStdXml oXml;
227  oXml.Deserialize(strXml);
228  oXml.FindElement("Root");
229  oXml.FindChildElement("Gain");
230  m_gainLengthTension.Load(oXml);
231 }
232 
233 void MuscleBase::AddExternalNodeInput(int iTargetDataType, float fltInput)
234 {
235  //We are changing this. It is now really driven by the membrane voltage of the non-spiking neuron. Integration from
236  //different motor neurons takes place in the non-spiking neuron and we get that here instead of frequency and use that
237  //to calculate the max isometric tension from the stim-tension curve.
238  m_fltVm=fltInput;
239 }
240 
242 {
244 
245  m_fltVm = 0;
246  m_fltTdot = 0;
247  m_fltTension = 0;
248  m_fltPrevTension = 0;
249 }
250 
251 #pragma region DataAccesMethods
252 
253 void MuscleBase::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
254 {
255  m_gainStimTension.SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
256  m_gainLengthTension.SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
257  LineBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
258 }
259 
261 {
265 }
266 
267 float *MuscleBase::GetDataPointer(const std::string &strDataType)
268 {
269  std::string strType = Std_CheckString(strDataType);
270 
271  float *lpData = NULL;
272 
273  if(strType == "TENSION")
274  lpData = &m_fltTension;
275  else if(strType == "TDOT")
276  lpData = &m_fltTdot;
277  else if(strType == "MEMBRANEVOLTAGE")
278  lpData = &m_fltVm;
279  else
280  lpData = LineBase::GetDataPointer(strDataType);
281 
282  return lpData;
283 }
284 
285 bool MuscleBase::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
286 {
287  if(LineBase::SetData(strDataType, strValue, false))
288  return true;
289 
290  if(strDataType == "MAXTENSION")
291  {
292  MaxTension((float) atof(strValue.c_str()));
293  return true;
294  }
295 
296  if(strDataType == "STIMULUSTENSION")
297  {
298  StimTension(strValue);
299  return true;
300  }
301 
302  if(strDataType == "LENGTHTENSION")
303  {
304  LengthTension(strValue);
305  return true;
306  }
307 
308  //If it was not one of those above then we have a problem.
309  if(bThrowError)
310  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
311 
312  return false;
313 }
314 
315 void MuscleBase::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
316 {
317  LineBase::QueryProperties(aryProperties);
318 
319  aryProperties.Add(new TypeProperty("Tension", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
320  aryProperties.Add(new TypeProperty("Tdot", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
321  aryProperties.Add(new TypeProperty("MembraneVoltage", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
322 
323  aryProperties.Add(new TypeProperty("MaxTension", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
324  aryProperties.Add(new TypeProperty("StimTension", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
325  aryProperties.Add(new TypeProperty("LengthTension", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
326 }
327 
328 #pragma endregion
329 
330 void MuscleBase::Load(CStdXml &oXml)
331 {
332  if(!m_lpParent)
333  THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
334 
335  LineBase::Load(oXml);
336 
337  oXml.IntoElem(); //Into RigidBody Element
338 
339  m_fltMaxTension = oXml.GetChildFloat("MaximumTension", m_fltMaxTension);
340 
341  if(oXml.FindChildElement("StimulusTension"))
342  m_gainStimTension.Load(oXml);
343 
344  if(oXml.FindChildElement("LengthTension"))
345  m_gainLengthTension.Load(oXml);
346 
347  oXml.OutOfElem(); //OutOf RigidBody Element
348 }
349 
350  } //Bodies
351  } //Environment
352 } //AnimatSim
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
float Tdot()
Gets the derivative of the tension.
Definition: MuscleBase.cpp:154
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: MuscleBase.cpp:241
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
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
Root namespace for the base simulation library for AnimatLab.
Length-Tension muscle gain.
Declares the sigmoid gain class.
Declares the body part class.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)
Adds an external node input.
Definition: MuscleBase.cpp:233
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: RigidBody.cpp:1473
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Definition: StdXml.cpp:179
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
Declares the key frame class.
Declares the muscle base 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.
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
Declares a light object.
SigmoidGain m_gainStimTension
The stimulus-tension gain.
Definition: MuscleBase.h:45
Declares the activated item class.
float Vm()
Gets the total stimulation applied to the muscle.
Definition: MuscleBase.cpp:144
float Tension()
Gets the tension of the muscle.
Definition: MuscleBase.cpp:92
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
A "static" structure in the simulation.
Definition: Structure.h:84
Declares the node class.
float m_fltPrevTension
Tension of the muscle in the last time slice.
Definition: MuscleBase.h:42
float m_fltMaxTension
The maximum tension that this muscle can ever generate. This is an upper limit to prevent unrealistic...
Definition: MuscleBase.h:28
Declares the line base 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.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: MuscleBase.cpp:260
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
Base class for body parts and neural network nodes.
Definition: Node.h:25
float m_fltTension
Tension of the muscle.
Definition: MuscleBase.h:39
Declares an inverted quadratic gain class used to calculate length-tension relationship for muscle...
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the sensor class.
virtual bool Enabled()
Gets whether the muscle is enabled.
Definition: MuscleBase.cpp:174
Declares the data chart manager class.
Declares the rigid body class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: Node.cpp:171
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
float MaxTension()
Gets the maximum tension.
Definition: MuscleBase.cpp:119
LengthTensionGain m_gainLengthTension
The length-tension gain.
Definition: MuscleBase.h:48
Declares the structure class.
Declares the odor type class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: AnimatBase.cpp:315
Declares the odor class.
Declares the simulator class.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
float m_fltTdot
The derivative of tension at the current time step.
Definition: MuscleBase.h:36
Declares the attachment class.
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617
float PrevTension()
Gets the previous tension.
Definition: MuscleBase.cpp:164