AnimatLab  2
Test
ConstraintRelaxation.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 "IPhysicsMovableItem.h"
14 #include "IPhysicsBody.h"
15 #include "BoundingBox.h"
16 #include "MovableItem.h"
17 #include "BodyPart.h"
18 #include "Joint.h"
19 #include "ReceptiveField.h"
20 #include "ContactSensor.h"
21 #include "RigidBody.h"
22 #include "Sensor.h"
23 #include "Structure.h"
24 #include "Organism.h"
25 #include "ActivatedItem.h"
26 #include "ActivatedItemMgr.h"
27 #include "DataChartMgr.h"
28 #include "ExternalStimuliMgr.h"
29 #include "KeyFrame.h"
30 #include "SimulationRecorder.h"
31 #include "OdorType.h"
32 #include "Odor.h"
33 #include "Light.h"
34 #include "LightManager.h"
35 #include "Simulator.h"
36 
37 namespace AnimatSim
38 {
39  namespace Environment
40  {
48 {
49  m_iCoordinateID = 0;
50  m_fltStiffness = 1000e3;
51  m_fltDamping = 500;
52  m_bEnabled = false;
53 }
54 
62 {
63 }
64 
76 {return m_bEnabled;}
77 
89 {
90  m_bEnabled = bVal;
91  SetRelaxationProperties();
92 }
93 
103 {return m_iCoordinateID;}
104 
116 {
117  Std_IsAboveMin((int) 0, iVal, true, "CoordinateID", true);
118 
119  m_iCoordinateID = iVal;
120  SetRelaxationProperties();
121 }
122 
132 
142 void ConstraintRelaxation::Stiffness(float fltVal, bool bUseScaling)
143 {
144  Std_IsAboveMin((float) 0, fltVal, true, "Stiffness", true);
145 
146  if(bUseScaling)
147  fltVal *= m_lpSim->InverseMassUnits();
148 
149  m_fltStiffness = fltVal;
150  SetRelaxationProperties();
151 }
152 
162 
172 void ConstraintRelaxation::Damping(float fltVal, bool bUseScaling)
173 {
174  Std_IsAboveMin((float) 0, fltVal, true, "Damping", true);
175 
176  if(bUseScaling)
177  fltVal = fltVal/m_lpSim->DisplayMassUnits();
178 
179  m_fltDamping = fltVal;
180  SetRelaxationProperties();
181 }
182 
191 {
192  m_fltStiffness = 1e-7f;
193  m_fltDamping = 5e4f;
194 
195  //scale the varios units to be consistent
196  //Friction coefficients are unitless
199 }
200 
201 bool ConstraintRelaxation::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
202 {
203  std::string strType = Std_CheckString(strDataType);
204 
205  if(AnimatBase::SetData(strType, strValue, false))
206  return true;
207 
208  if(strType == "COORDINATEID")
209  {
210  CoordinateID(atoi(strValue.c_str()));
211  return true;
212  }
213 
214  if(strType == "STIFFNESS")
215  {
216  Stiffness((float) atof(strValue.c_str()));
217  return true;
218  }
219 
220  if(strType == "DAMPING")
221  {
222  Damping((float) atof(strValue.c_str()));
223  return true;
224  }
225 
226  if(strType == "ENABLED")
227  {
228  Enabled(Std_ToBool(strValue));
229  return true;
230  }
231 
232  //If it was not one of those above then we have a problem.
233  if(bThrowError)
234  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
235 
236  return false;
237 }
238 
239 void ConstraintRelaxation::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
240 {
241  AnimatBase::QueryProperties(aryProperties);
242 
243  aryProperties.Add(new TypeProperty("CoordinateID", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
244  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
245  aryProperties.Add(new TypeProperty("Damping", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
246  aryProperties.Add(new TypeProperty("Stiffness", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
247 }
248 
249 void ConstraintRelaxation::Load(CStdXml &oXml)
250 {
251  AnimatBase::Load(oXml);
252 
253  oXml.IntoElem(); //Into ConstraintRelaxation Element
254 
255  CoordinateID(oXml.GetChildInt("CoordinateID", m_iCoordinateID));
256  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
257  Stiffness(oXml.GetChildFloat("Stiffness", m_fltStiffness));
258  Damping(oXml.GetChildFloat("Damping", m_fltDamping));
259 
260  oXml.OutOfElem(); //OutOf ConstraintRelaxation Element
261 
262 }
263 
264  } // Visualization
265 } //VortexAnimatSim
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual int CoordinateID()
Gets the ID of the coordiante that this relaxation is associated with.
Root namespace for the base simulation library for AnimatLab.
virtual float InverseMassUnits()
Gets the inverse mass units.
Definition: Simulator.cpp:1797
Declares the body part class.
virtual float Stiffness()
Gets the Stiffness for collisions between RigidBodies with these two materials.
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 void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
int m_iCoordinateID
The constraint coordinate ID.
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 joint class.
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
Definition: StdXml.cpp:456
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
float m_fltDamping
The damping of the collision between those two materials.
float m_fltStiffness
The compliance of the collision between those two materials.
Declares a light object.
Declares the activated item class.
virtual float DisplayMassUnits()
Gets the density mass units.
Definition: Simulator.cpp:1810
Declares a light manager object.
Declares the bounding box class.
virtual bool Enabled()
Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications.
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: AnimatBase.cpp:447
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
virtual bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
virtual float Damping()
Gets the damping for collisions between RigidBodies with these two materials.
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
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual void CreateDefaultUnits()
This takes the default values defined in the constructor and scales them according to the distance an...
Declares the sensor class.
Declares the data chart manager class.
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the structure class.
Declares the odor type class.
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.
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
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