6 #include "IMovableItemCallback.h"
7 #include "ISimGUICallback.h"
12 #include "IPhysicsMovableItem.h"
13 #include "IPhysicsBody.h"
15 #include "MovableItem.h"
48 #include "InverseMuscleCurrent.h"
52 namespace ExternalStimuli
59 InverseMuscleCurrent::InverseMuscleCurrent()
61 m_lpTargetNode = NULL;
62 m_lpExternalCurrent = NULL;
73 m_fltConductance = 100e-9f;
74 m_fltRestPotential = -100e-3f;
77 InverseMuscleCurrent::~InverseMuscleCurrent()
82 m_lpExternalCurrent = NULL;
84 m_aryTime.RemoveAll();
85 m_aryLength.RemoveAll();
86 m_aryVelocity.RemoveAll();
89 {
Std_TraceMsg(0,
"Caught Error in desctructor of InverseMuscleCurrent\r\n",
"", -1,
false,
true);}
93 void InverseMuscleCurrent::RestPotential(
float fltV)
97 m_fltRestPotential = fltV;
100 float InverseMuscleCurrent::RestPotential() {
return m_fltRestPotential;}
102 void InverseMuscleCurrent::Conductance(
float fltG)
106 m_fltConductance = fltG;
109 float InverseMuscleCurrent::Conductance() {
return m_fltConductance;}
111 void InverseMuscleCurrent::MuscleID(std::string strID)
113 m_strMuscleID = strID;
121 std::string InverseMuscleCurrent::MuscleID() {
return m_strMuscleID;}
125 void InverseMuscleCurrent::MuscleLengthData(std::string strFilename)
127 m_strMuscleLengthData = strFilename;
129 m_aryTime.RemoveAll();
130 m_aryLength.RemoveAll();
131 m_aryVelocity.RemoveAll();
136 m_strMuscleLengthData = AnimatSim::GetFilePath(
m_lpSim->
ProjectPath(), m_strMuscleLengthData);
137 LoadMuscleData(m_strMuscleLengthData);
139 if(m_aryTime.GetSize() < 2)
140 THROW_PARAM_ERROR(Al_Err_lMuscleLengthDataEmpty, Al_Err_strMuscleLengthDataEmpty,
"File", m_strMuscleLengthData);
143 float fltStep = m_aryTime[1] - m_aryTime[0];
146 THROW_TEXT_ERROR(Al_Err_lMuscleLengthTimeStep, Al_Err_strMuscleLengthTimeStep,
" File Time Step: " + STR(fltStep) +
" Physics Time Step: " + STR(
m_lpSim->
PhysicsTimeStep()) );
158 std::string InverseMuscleCurrent::MuscleLengthData() {
return m_strMuscleLengthData;}
160 void InverseMuscleCurrent::TargetNodeID(std::string strID)
163 THROW_TEXT_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank,
"Muscle ID is missing.");
165 m_strTargetNodeID = strID;
168 std::string InverseMuscleCurrent::TargetNodeID() {
return m_strTargetNodeID;}
170 Node *InverseMuscleCurrent::TargetNode() {
return m_lpTargetNode;}
179 THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound,
"ID: ", m_strTargetNodeID);
181 m_lpExternalCurrent = m_lpTargetNode->
GetDataPointer(
"ExternalCurrent");
183 if(!m_lpExternalCurrent)
184 THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound,
185 (
"Stimulus: " +
m_strID +
"Node: " + m_strTargetNodeID +
" DataType: ExternalCurrent"));
194 m_lpMuscle = dynamic_cast<LinearHillMuscle *>(
m_lpSim->
FindByID(m_strMuscleID));
203 m_fltPrevCurrent = 0;
221 m_fltT = m_lpMuscle->
Tension();
227 if(m_lpMuscle && m_iIndex < m_aryTime.GetSize())
229 float fltTime = m_aryTime[m_iIndex];
235 m_fltLength = m_aryLength[m_iIndex];
236 m_fltVelocity = m_aryVelocity[m_iIndex];
240 m_fltVm = m_fltVm - m_fltRestPotential;
242 m_fltPrevCurrent = m_fltCurrent;
243 m_fltCurrent = m_fltVm*m_fltConductance;
244 m_fltOffset = m_fltCurrent - m_fltPrevCurrent;
246 *m_lpExternalCurrent = *m_lpExternalCurrent + m_fltOffset;
258 *m_lpExternalCurrent = *m_lpExternalCurrent - m_fltCurrent;
268 else if(strType ==
"VM")
270 else if(strType ==
"CURRENT")
271 lpData = &m_fltCurrent;
273 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"StimulusName: " + STR(
m_strName) +
" DataType: " + strDataType);
283 if(strDataType ==
"RESTPOTENTIAL")
285 RestPotential((
float) atof(strValue.c_str()));
289 if(strDataType ==
"CONDUCTANCE")
291 Conductance((
float) atof(strValue.c_str()));
295 if(strDataType ==
"MUSCLEID")
301 if(strDataType ==
"MUSCLELENGTHDATA")
303 MuscleLengthData(strValue);
309 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
318 aryProperties.Add(
new TypeProperty(
"A", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
319 aryProperties.Add(
new TypeProperty(
"Vm", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
320 aryProperties.Add(
new TypeProperty(
"Current", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
322 aryProperties.Add(
new TypeProperty(
"RestPotential", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
323 aryProperties.Add(
new TypeProperty(
"Conductance", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
324 aryProperties.Add(
new TypeProperty(
"MuscleID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
325 aryProperties.Add(
new TypeProperty(
"MuscleLengthData", AnimatPropertyType::String, AnimatPropertyDirection::Set));
328 void InverseMuscleCurrent::Load(
CStdXml &oXml)
336 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
348 Conductance(oXml.
GetChildFloat(
"Conductance", m_fltConductance));
349 RestPotential(oXml.
GetChildFloat(
"RestPotential", m_fltRestPotential));
354 void InverseMuscleCurrent::LoadMuscleData(std::string strFilename)
356 std::ifstream fsFile(strFilename.c_str());
359 THROW_TEXT_ERROR(Al_Err_lOpenFile, Al_Err_strOpenFile,
"File: " + strFilename);
362 CStdArray<std::string> aryParts;
364 fsFile.getline(sLine, 300);
367 if(aryParts.GetSize() != 3)
368 THROW_PARAM_ERROR(Al_Err_lInvalidMuscleLengthCols, Al_Err_strInvalidMuscleLengthCols,
"Col Size", aryParts.GetSize());
370 float fltTime=0, fltLength=0, fltVelocity=0;
373 fsFile.getline(sLine, 300);
377 if(aryParts.GetSize() == 3)
379 fltTime = atof(aryParts[0].c_str());
380 fltLength = atof(aryParts[1].c_str());
381 fltVelocity = atof(aryParts[2].c_str());
383 m_aryTime.Add(fltTime);
384 m_aryLength.Add(fltLength);
385 m_aryVelocity.Add(fltVelocity);
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
virtual void CalculateInverseDynamics(float fltLength, float fltVelocity, float fltT, float &fltVm, float &fltA)
Calculates the activation needed for a given tension value.
Declares the nervous system class.
virtual void PhysicsTimeStep(float fltVal)
Sets the integration time step for the physics engine.
virtual void Activate()
Activates this item.
Declares the simulation recorder class.
long m_lEndSlice
The time slice where this item is deactived.
Root namespace for the base simulation library for AnimatLab.
Declares the sigmoid gain class.
Declares the body part class.
virtual void Deactivate()
Deactivates this item.
Simulator * m_lpSim
The pointer to a Simulation.
virtual bool Enabled()
Gets whether the item is enabled or not.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Class that stores information about types for QueryProperty information.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the link base class.
int Std_Split(const std::string &input, const std::string &delimiter, CStdArray< std::string > &results)
Splits a string into an array of subparts based on a delimiter.
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.
std::string m_strID
The unique Id for this object.
Declares the activated item class.
virtual float TimeStep()
Gets the smallest integration time step used within the simulation.
float Tension()
Gets the tension of the muscle.
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Declares the linear hill muscle class.
Declares the line base class.
virtual std::string ProjectPath()
Gets the project path.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
virtual void StepSimulation()
Step the simulation for this object.
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 bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Base class for body parts and neural network nodes.
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.
virtual void Deactivate()
Deactivates this item.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
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.
A muscle that is connected between two attachment points.
Declares the structure class.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Declares the simulator class.
Declares the neural module class.
virtual float Time()
Gets the current simulation time in seconds.
Declares the activated item manager class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the external stimuli manager class.
virtual void Initialize()
Initializes this object.
bool m_bAlwaysActive
Determines whether this item is always active during simulation.
virtual void AddToObjectList(AnimatBase *lpItem)
Adds an object to the list of all simulation objects.
virtual bool AlwaysActive()
Gets whether this item is always active.
long m_lStartSlice
The time slice where this item becomes active.
Declares the receptive field class.
std::string m_strName
The name for this object.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
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 float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual void Activate()
Activates this item.