AnimatLab  2
Test
ConstraintFriction.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_fltCoefficient = 1;
50  m_fltMaxForce = 10;
51  m_fltLoss = 0;
52  m_bEnabled = true;
53  m_bProportional = true;
55 }
56 
64 {
65 }
66 
78 {return m_bEnabled;}
79 
91 {
92  m_bEnabled = bVal;
93  SetFrictionProperties();
94 }
95 
105 
115 {
116  Std_IsAboveMin((float) 0, fltVal, true, "Coefficient", true);
117 
118  m_fltCoefficient = fltVal;
119  SetFrictionProperties();
120 }
121 
131 
141 void ConstraintFriction::MaxForce(float fltVal, bool bUseScaling)
142 {
143  Std_IsAboveMin((float) 0, fltVal, true, "MaxForce", true);
144 
145  if(bUseScaling)
146  fltVal *= (m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits()); //This is a force.
147 
148  m_fltMaxForce = fltVal;
149  SetFrictionProperties();
150 }
151 
163 
175 void ConstraintFriction::Loss(float fltVal, bool bUseScaling)
176 {
177  Std_IsAboveMin((float) 0, fltVal, true, "Loss", true);
178 
179  if(bUseScaling)
180  fltVal *= m_lpSim->MassUnits(); //Slip units are s/Kg
181 
182  m_fltLoss = fltVal;
183  SetFrictionProperties();
184 }
185 
195 
205 {
206  m_bProportional = bVal;
207  SetFrictionProperties();
208 }
209 
219 
229 {
230  Std_IsAboveMin((float) 0, fltVal, true, "StaticFrictionScale", true);
231 
232  m_fltStaticFrictionScale = fltVal;
233  SetFrictionProperties();
234 }
235 
244 {
245  m_fltCoefficient = 1;
246  m_fltMaxForce = 10;
247  m_fltLoss = 0;
248  m_bProportional = true;
249  m_bEnabled = true;
251 
252  //scale the varios units to be consistent
253  //Friction coefficients are unitless
255  m_fltLoss *= m_lpSim->MassUnits(); //Slip units are s/Kg
256 }
257 
258 bool ConstraintFriction::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
259 {
260  std::string strType = Std_CheckString(strDataType);
261 
262  if(AnimatBase::SetData(strType, strValue, false))
263  return true;
264 
265  if(strType == "COEFFICIENT")
266  {
267  Coefficient((float) atof(strValue.c_str()));
268  return true;
269  }
270 
271  if(strType == "MAXFORCE")
272  {
273  MaxForce((float) atof(strValue.c_str()));
274  return true;
275  }
276 
277  if(strType == "LOSS")
278  {
279  Loss((float) atof(strValue.c_str()));
280  return true;
281  }
282 
283  if(strType == "PROPORTIONAL")
284  {
285  Proportional(Std_ToBool(strValue));
286  return true;
287  }
288 
289  if(strType == "ENABLED")
290  {
291  Enabled(Std_ToBool(strValue));
292  return true;
293  }
294 
295  if(strType == "STATICFRICTIONSCALE")
296  {
297  StaticFrictionScale((float) atof(strValue.c_str()));
298  return true;
299  }
300 
301  //If it was not one of those above then we have a problem.
302  if(bThrowError)
303  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
304 
305  return false;
306 }
307 
308 void ConstraintFriction::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
309 {
310  AnimatBase::QueryProperties(aryProperties);
311 
312  aryProperties.Add(new TypeProperty("Coefficient", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
313  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
314  aryProperties.Add(new TypeProperty("MaxForce", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
315  aryProperties.Add(new TypeProperty("Loss", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
316  aryProperties.Add(new TypeProperty("Proportional", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
317  aryProperties.Add(new TypeProperty("StaticFrictionScale", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
318 }
319 
320 void ConstraintFriction::Load(CStdXml &oXml)
321 {
322  AnimatBase::Load(oXml);
323 
324  oXml.IntoElem(); //Into ConstraintFriction Element
325 
326  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
327  Coefficient(oXml.GetChildFloat("Coefficient", m_fltCoefficient));
328  MaxForce(oXml.GetChildFloat("MaxForce", m_fltMaxForce));
329  Loss(oXml.GetChildFloat("Loss", m_fltLoss));
330  Proportional(oXml.GetChildBool("Proportional", m_bProportional));
331  StaticFrictionScale(oXml.GetChildFloat("StaticFrictionScale", m_fltStaticFrictionScale));
332 
333  oXml.OutOfElem(); //OutOf ConstraintFriction Element
334 
335 }
336 
337  } // Visualization
338 } //VortexAnimatSim
virtual float MaxForce()
Gets the MaxForce the friction can apply.
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
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.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual float Coefficient()
Gets the Coefficient of friction for this constraint.
virtual void CreateDefaultUnits()
This takes the default values defined in the constructor and scales them according to the distance an...
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.
virtual float StaticFrictionScale()
Gets the ratio between static and dynamic friction coefficients.
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 m_fltStaticFrictionScale
The scale ration of static to dynamic friction.
Declares a light object.
virtual void MassUnits(std::string strUnits)
Sets the mass units.
Definition: Simulator.cpp:1772
Declares the activated item class.
Declares a light manager object.
virtual float Loss()
Gets the velocity loss for this constraint.
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
float m_fltCoefficient
The friction coefficient for this constraint.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
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
bool m_bProportional
Tells if the friction force should be scaled based on the force applied to the joint.
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
float m_fltMaxForce
The maximum force for this constraint.
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.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the sensor class.
Declares the data chart manager class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
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.
virtual bool Proportional()
Gets whether the friction force should be scaled based on the amount of force applied to the joint...
Declares the odor type class.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
Definition: Simulator.cpp:1742
Declares the odor class.
Declares the simulator class.
Declares the activated item manager class.
float m_fltLoss
The velocity loss for this constraint.
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