AnimatLab  2
Test
Hinge.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMotorizedJoint.h"
9 #include "IMovableItemCallback.h"
10 #include "ISimGUICallback.h"
11 #include "AnimatBase.h"
12 
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 "MotorizedJoint.h"
21 #include "ReceptiveField.h"
22 #include "ContactSensor.h"
23 #include "RigidBody.h"
24 #include "ConstraintLimit.h"
25 #include "Hinge.h"
26 #include "Structure.h"
27 #include "Organism.h"
28 #include "ActivatedItem.h"
29 #include "ActivatedItemMgr.h"
30 #include "DataChartMgr.h"
31 #include "ExternalStimuliMgr.h"
32 #include "KeyFrame.h"
33 #include "SimulationRecorder.h"
34 #include "OdorType.h"
35 #include "Odor.h"
36 #include "Light.h"
37 #include "LightManager.h"
38 #include "Simulator.h"
39 
40 namespace AnimatSim
41 {
42  namespace Environment
43  {
44  namespace Joints
45  {
53 {
54  m_lpUpperLimit = NULL;
55  m_lpLowerLimit = NULL;
56  m_lpPosFlap = NULL;
57  m_fltRotationDeg = 0;
59 }
60 
68 {
69 try
70 {
71  if(m_lpUpperLimit)
72  {
73  delete m_lpUpperLimit;
74  m_lpUpperLimit = NULL;
75  }
76 
77  if(m_lpLowerLimit)
78  {
79  delete m_lpLowerLimit;
80  m_lpLowerLimit = NULL;
81  }
82 
83  if(m_lpPosFlap)
84  {
85  delete m_lpPosFlap;
86  m_lpPosFlap = NULL;
87  }
88 }
89 catch(...)
90 {Std_TraceMsg(0, "Caught Error in desctructor of Hinge\r\n", "", -1, false, true);}
91 }
92 
102 {
103  return m_fltSize * 0.25f;
104 };
105 
115 {
116  return m_fltSize;
117 };
118 
128 {
129  return m_fltSize * 0.05f;
130 };
131 
132 void Hinge::Enabled(bool bValue)
133 {
135  m_bEnabled = bValue;
136 }
137 
147 
157 
159 {
160  if(m_bEnableLimits)
161  {
162  if(fltPos>m_lpUpperLimit->LimitPos())
163  fltPos = m_lpUpperLimit->LimitPos();
164  if(fltPos<m_lpLowerLimit->LimitPos())
165  fltPos = m_lpLowerLimit->LimitPos();
166  }
167 
168  return fltPos;
169 }
170 
172 {
173  if(m_bEnableLimits)
175  else
176  return -1;
177 }
178 
179 bool Hinge::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
180 {
181  std::string strType = Std_CheckString(strDataType);
182 
183  if(MotorizedJoint::SetData(strType, strValue, false))
184  return true;
185 
186  //If it was not one of those above then we have a problem.
187  if(bThrowError)
188  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
189 
190  return false;
191 }
192 
193 int Hinge::GetTargetDataTypeIndex(const std::string &strDataType)
194 {
195  std::string strType = Std_CheckString(strDataType);
196 
197  if(strType == "DESIREDPOSITION")
198  return DESIRED_POSITION_TYPE;
199  else
200  return DESIRED_VELOCITY_TYPE;
201 
202 }
203 
204 void Hinge::AddExternalNodeInput(int iTargetDataType, float fltInput)
205 {
206  if(iTargetDataType == DESIRED_POSITION_TYPE)
207  m_fltDesiredPosition += fltInput;
208  else
209  m_fltDesiredVelocity += fltInput;
210 }
211 
213 {
215  m_fltRotationDeg = 0;
217 }
218 
220 {
222  m_fltRotationDeg = ((m_fltPosition/STD_PI)*180);
224 }
225 
226 void Hinge::Load(CStdXml &oXml)
227 {
228  MotorizedJoint::Load(oXml);
229 
230  oXml.IntoElem(); //Into Joint Element
231 
232  m_lpUpperLimit->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, true);
233  m_lpLowerLimit->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, true);
234  m_lpPosFlap->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, JointPosition());
235 
236  m_lpUpperLimit->Load(oXml, "UpperLimit");
237  m_lpLowerLimit->Load(oXml, "LowerLimit");
238 
239  oXml.OutOfElem(); //OutOf Joint Element
240 }
241 
242  } //Joints
243  } //Environment
244 } //AnimatSim
float CylinderHeight()
Gets the height of the cylinder used to display the hinge in the environment.
Definition: Hinge.cpp:114
Base class file for all Animat simulation objects.
virtual float GetLimitRange()
Gets the entire range of movement within the limits. If limits are not enabled then it returns -1...
Definition: Hinge.cpp:171
Declares the simulation recorder class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Root namespace for the base simulation library for AnimatLab.
Declares the hinge class.
virtual float LimitPos()
Gets the limit position.
virtual void UpdateData()
Called to collect any body data for this part.
Definition: BodyPart.cpp:80
Declares the body part class.
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
ConstraintLimit * m_lpUpperLimit
Upper limit constring pointer.
Definition: Hinge.h:43
virtual int GetTargetDataTypeIndex(const std::string &strDataType)
Used to convert a string target data type into an integer index.
Definition: Hinge.cpp:193
Declares the key frame class.
Declares the joint class.
Declares the organism class.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
Declares a light object.
Declares the activated item class.
float m_fltRotationDeg
The rotation of the hinge in degrees.
Definition: Hinge.h:52
Declares a light manager object.
float CylinderRadius()
Gets the radius cylinder of the cylinder used to display the hinge in the environment.
Definition: Hinge.cpp:101
virtual float GetPositionWithinLimits(float fltPos)
Gets a position value within the constraint limits.
Definition: Hinge.cpp:158
Declares the bounding box class.
float m_fltDesiredPositionDeg
The desired rotation of the hinge in degrees.
Definition: Hinge.h:55
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)
Adds an external node input.
Definition: Hinge.cpp:204
A standard xml manipulation class.
Definition: StdXml.h:19
virtual bool EnableMotor()
Tells if the motor is enabled.
Declares the node class.
bool m_bEnableLimits
If true then any ConstraintLimits for this joint are enabled.
Definition: Joint.h:47
ConstraintLimit * m_lpLowerLimit
Lower limit constring pointer.
Definition: Hinge.h:46
Hinge()
Default constructor.
Definition: Hinge.cpp:52
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.
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_fltSize
Scales the size of the graphics for this joint.
Definition: Joint.h:61
virtual ConstraintLimit * UpperLimit()
Gets a pointer to the upper limit ConstraintLimit.
Definition: Hinge.cpp:146
ConstraintLimit * m_lpPosFlap
Pointer to a constraint that is used to represent the position flap.
Definition: Hinge.h:49
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual float JointPosition()
Gets the joint position.
Definition: Joint.cpp:532
Declares the data chart manager class.
virtual ~Hinge()
Destructor.
Definition: Hinge.cpp:67
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Hinge.cpp:212
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the constraint limit class.
virtual ConstraintLimit * LowerLimit()
Gets a pointer to the lower limit ConstraintLimit.
Definition: Hinge.cpp:156
Declares the structure class.
Declares the odor type class.
float FlapWidth()
Gets the width of the flaps used to display the hinge in the environment.
Definition: Hinge.cpp:127
Declares the odor class.
Declares the simulator class.
virtual void UpdateData()
Called to collect any body data for this part.
Definition: Hinge.cpp:219
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.