8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
13 #include "IPhysicsMovableItem.h"
14 #include "IPhysicsBody.h"
16 #include "MovableItem.h"
76 {
Std_TraceMsg(0,
"Caught Error in desctructor of ContactSensor\r\n",
"", -1,
false,
true);}
132 int high = aryFields.GetSize(), low = -1, probe=0;
134 while (high - low > 1)
136 probe = (high + low) / 2;
137 if (aryFields[probe]->GreaterThanThan(fltX, fltY, fltZ))
148 if((probe < aryFields.GetSize() && aryFields[probe]->Equals(fltX, fltY, fltZ))
149 || (low > -1 && low < aryFields.GetSize() && aryFields[low]->Equals(fltX, fltY, fltZ))
150 || (high < aryFields.GetSize() && aryFields[high]->Equals(fltX, fltY, fltZ)))
171 float fltDist = 0, fltMinDist = 0;
172 float fltXMin, fltYMin, fltZMin;
175 for(
int iIndex=0; iIndex<iSize; iIndex++)
179 fltDist = sqrt( pow((fltX-lpField->
m_vVertex[0]), 2) + pow((fltY-lpField->
m_vVertex[1]), 2) + pow((fltZ-lpField->
m_vVertex[2]), 2) );
181 if(iMinIndex<0 || fltDist < fltMinDist)
183 fltMinDist = fltDist;
232 int iSize = aryFields.GetSize();
233 for(
int iV=0; iV<iSize; iV++)
235 std::ostringstream oss;
236 aryFields[iV]->Trace(oss);
238 Std_TraceMsg(StdLogDebug, oss.str(),
"", -1, STD_TRACE_TO_FILE,
false);
242 void ContactSensor::AddReceptiveField(std::string strXml)
252 void ContactSensor::RemoveReceptiveField(std::string strID,
bool bThrowError)
254 int iPos = FindReceptiveFieldListPos(strID, bThrowError);
258 int ContactSensor::FindReceptiveFieldListPos(std::string strID,
bool bThrowError)
263 for(
int iIndex=0; iIndex<iCount; iIndex++)
268 THROW_TEXT_ERROR(Al_Err_lReceptiveFieldIDNotFound, Al_Err_strReceptiveFieldIDNotFound,
"ID");
282 for(
int iField=0; iField<iSize; iField++)
304 float fltDist, fltFieldGain, fltForce, fltCurrent;
308 for(
int iField=0; iField<iSize; iField++)
313 fltForce = fltForceMagnitude*fltFieldGain;
323 bool ContactSensor::AddItem(
const std::string &strItemType,
const std::string &strXml,
bool bThrowError,
bool bDoNotInit)
327 if(strType ==
"RECEPTIVEFIELD")
329 AddReceptiveField(strXml);
335 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
344 if(strType ==
"RECEPTIVEFIELD")
346 RemoveReceptiveField(strID);
352 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
358 void ContactSensor::Load(
CStdXml &oXml)
365 std::string strModuleName = oXml.
GetChildString(
"ModuleName",
"");
371 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"FieldGain");
383 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"FieldGain");
397 for(
int iIndex=0; iIndex<iCount; iIndex++)
430 if(lpField)
delete lpField;
435 if(lpField)
delete lpField;
436 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Root namespace for the base simulation library for AnimatLab.
Declares the bell gain class.
bool UseLimits()
Tells whether limits should be used.
Declares the body part class.
StdVector3 m_vVertex
The vertex of the center of the receptive field in global coordinates.
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Simulator * m_lpSim
The pointer to a Simulation.
Information about the standard error.
virtual std::string ID()
Gets the unique GUID ID of this object.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
float UpperLimit()
Gets the upper limit.
virtual void DistanceUnits(std::string strUnits)
Sets the distance units.
Declares the key frame class.
bool Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
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...
std::string Std_Trim(std::string strVal)
Trims a string.
Declares the activated item class.
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
float m_fltCurrent
The accumulated current for this receptive field.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
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 int NumberOfChildren()
Gets the number of children of the current element.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Declares the data chart manager class.
Declares the rigid body class.
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
virtual float CalculateGain(float fltInput)=0
Calculates the gain.
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 simulator class.
virtual bool FindChildByIndex(int iIndex, bool bThrowError=true)
Finds a child element by index.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
Declares the activated item manager class.
Declares the external stimuli manager class.
Receptive field that generates current based on the amount of contact force, and how close it is to t...
Declares the receptive field class.