AnimatLab  2
Test
VoltageClamp.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 "Link.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
16 #include "BoundingBox.h"
17 #include "MovableItem.h"
18 #include "BodyPart.h"
19 #include "Gain.h"
20 #include "Adapter.h"
21 #include "Joint.h"
22 #include "ReceptiveField.h"
23 #include "ContactSensor.h"
24 #include "RigidBody.h"
25 #include "Structure.h"
26 #include "NeuralModule.h"
27 #include "NervousSystem.h"
28 #include "Organism.h"
29 #include "ActivatedItem.h"
30 #include "ActivatedItemMgr.h"
31 #include "DataChartMgr.h"
32 #include "ExternalStimuliMgr.h"
33 #include "ExternalStimulus.h"
34 #include "ExternalInputStimulus.h"
35 #include "VoltageClamp.h"
36 #include "KeyFrame.h"
37 #include "SimulationRecorder.h"
38 #include "OdorType.h"
39 #include "Odor.h"
40 #include "Light.h"
41 #include "LightManager.h"
42 #include "Simulator.h"
43 
44 namespace AnimatSim
45 {
46  namespace ExternalStimuli
47  {
55 {
56  m_lpNode = NULL;
57  m_lpExternalCurrent = NULL;
58  m_lpTotalCurrent = NULL;
59  m_lpVrest = NULL;
60  m_lpGm = NULL;
61  m_fltVtarget = -0.70f;
64 }
65 
73 {
74 
75 try
76 {
77  m_lpNode = NULL;
78  m_lpExternalCurrent = NULL;
79  m_lpTotalCurrent = NULL;
80  m_lpVrest = NULL;
81  m_lpGm = NULL;
82 }
83 catch(...)
84 {Std_TraceMsg(0, "Caught Error in desctructor of VoltageClamp\r\n", "", -1, false, true);}
85 }
86 
87 std::string VoltageClamp::Type() {return "VoltageClamp";}
88 
98 
107 void VoltageClamp::TargetNodeID(std::string strID)
108 {
109  if(Std_IsBlank(strID))
110  THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
111  m_strTargetNodeID = strID;
112 }
113 
123 
132 void VoltageClamp::Vtarget(float fltVal)
133 {
134  m_fltVtarget = fltVal;
135  if(m_lpGm)
137 }
138 
140 {
142 
143  //Lets try and get the node we will dealing with.
144  m_lpNode = dynamic_cast<Node *>(m_lpSim->FindByID(m_strTargetNodeID));
145  if(!m_lpNode)
146  THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound, "ID: ", m_strTargetNodeID);
147 
148  m_lpExternalCurrent = m_lpNode->GetDataPointer("ExternalCurrent");
149  m_lpTotalCurrent = m_lpNode->GetDataPointer("TotalCurrent");
150  m_lpVrest = m_lpNode->GetDataPointer("Vrest");
151  m_lpGm = m_lpNode->GetDataPointer("Gm");
152 
153  //Calculate the target current to keep the voltage at the target level.
155 
157  THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound,
158  ("Stimulus: " + m_strID + "Node: " + m_strTargetNodeID + " DataType: ExternalCurrent"));
159 }
160 
162 {
164 
165  m_fltActiveCurrent = m_fltTargetCurrent - (*m_lpTotalCurrent);
167 }
168 
170 {
171  m_fltActiveCurrent = m_fltTargetCurrent - (*m_lpTotalCurrent);
173 }
174 
176 {
178  //*m_lpExternalCurrent = *m_lpExternalCurrent - m_fltActiveCurrent;
179 }
180 
182 {
184 
185  m_fltActiveCurrent = 0;
186 }
187 
188 float *VoltageClamp::GetDataPointer(const std::string &strDataType)
189 {
190  float *lpData=NULL;
191  std::string strType = Std_CheckString(strDataType);
192 
193  if(strType == "CLAMPCURRENT")
194  lpData = &m_fltActiveCurrent;
195  else
196  THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "StimulusName: " + STR(m_strName) + " DataType: " + strDataType);
197 
198  return lpData;
199 }
200 
201 bool VoltageClamp::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
202 {
203  std::string strType = Std_CheckString(strDataType);
204 
205  if(ExternalStimulus::SetData(strDataType, strValue, false))
206  return true;
207 
208  if(strType == "VTARGET")
209  {
210  Vtarget((float) atof(strValue.c_str()));
211  return true;
212  }
213 
214  //If it was not one of those above then we have a problem.
215  if(bThrowError)
216  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
217 
218  return false;
219 }
220 
221 void VoltageClamp::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
222 {
223  ExternalStimulus::QueryProperties(aryProperties);
224 
225  aryProperties.Add(new TypeProperty("ClampCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
226 
227  aryProperties.Add(new TypeProperty("Vtarget", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
228 }
229 
230 void VoltageClamp::Load(CStdXml &oXml)
231 {
232  ActivatedItem::Load(oXml);
233 
234  oXml.IntoElem(); //Into Simulus Element
235 
236  TargetNodeID(oXml.GetChildString("TargetNodeID"));
237  Vtarget(oXml.GetChildFloat("Vtarget", m_fltVtarget));
238 
239  oXml.OutOfElem(); //OutOf Simulus Element
240 }
241 
242  } //ExternalStimuli
243 } //VortexAnimatSim
244 
245 
246 
247 
virtual void ResetSimulation()
Resets the simulation back to time 0.
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
Declares the nervous system class.
virtual void Activate()
Activates this item.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
float * m_lpVrest
The resting voltage data variable within the node to clamp.
Definition: VoltageClamp.h:28
Declares the body part class.
virtual std::string Type()
returns the string type name of this object.
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
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Definition: AnimatBase.cpp:340
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
float * m_lpTotalCurrent
The total current data variable within the node that is clamped.
Definition: VoltageClamp.h:25
virtual void StepSimulation()
Step the simulation for this object.
Declares the key frame class.
Declares the joint class.
Declares the organism class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
Declares a light object.
Declares the activated item class.
Declares a light manager object.
virtual void Activate()
Activates this item.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
Node * m_lpNode
The pointer to this items parent Node. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:52
virtual void ResetSimulation()
Resets the simulation back to time 0.
Declares the node class.
virtual std::string TargetNodeID()
Gets the GUID ID of the target node that will be enabled.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
float * m_lpGm
The conductance data variable within the node to clamp.
Definition: VoltageClamp.h:31
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.
Declares the voltage clamp class.
float m_fltTargetCurrent
The target current for the clamp.
Definition: VoltageClamp.h:37
float m_fltActiveCurrent
The active current is the target current - total current in the cell.
Definition: VoltageClamp.h:40
Base class for body parts and neural network nodes.
Definition: Node.h:25
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual void Deactivate()
Deactivates this item.
virtual float Vtarget()
Gets the target voltage for the clamp.
float m_fltVtarget
The target voltage for the clamp.
Definition: VoltageClamp.h:34
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.
Declares the structure class.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the odor class.
Declares the simulator class.
Declares the neural module class.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the external input stimulus class.
std::string m_strTargetNodeID
GUID ID of the node that will be clamped.
Definition: VoltageClamp.h:18
virtual void Deactivate()
Deactivates this item.
Declares the receptive field class.
virtual void Initialize()
Initializes this object.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61
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 GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.