AnimatLab  2
Test
LengthTensionGain.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 "Gain.h"
13 #include "LengthTensionGain.h"
14 
15 namespace AnimatSim
16 {
17  namespace Gains
18  {
19 
27 {
29  m_fltTLwidth = 0;
30  m_fltTLc = 0;
34  m_fltMinPeLength = 0;
35 }
36 
44 {
45 
46 try
47 {
48 }
49 catch(...)
50 {Std_TraceMsg(0, "Caught Error in desctructor of LengthTensionGain\r\n", "", -1, false, true);}
51 }
52 
53 
54 float LengthTensionGain::RestingLength() {return m_fltRestingLength;}
55 
56 void LengthTensionGain::RestingLength(float fltVal)
57 {
58  Std_IsAboveMin((float) 0, fltVal, true, "RestingLength");
59  m_fltRestingLength = fltVal;
62 }
63 
64 float LengthTensionGain::TLwidth() {return m_fltTLwidth;}
65 
66 void LengthTensionGain::TLwidth(float fltVal)
67 {
68  Std_IsAboveMin((float) 0, fltVal, true, "TLwidth");
69  m_fltTLwidth = fltVal;
70  m_fltTLc = pow(m_fltTLwidth, 2);
71 }
72 
73 float LengthTensionGain::TLc() {return m_fltTLc;}
74 
75 float LengthTensionGain::CalculateGain(float fltInput)
76 {
77  float fltLceNorm = fltInput - m_fltRestingLength;
78  float fltTl = (-(pow(fltLceNorm, 2)/m_fltTLc) + 1);
79  if(fltTl<0) fltTl = 0;
80  return fltTl;
81 }
91 
101 {
102  //We need to scale it because this comes in as 0-100, but we need it in 0-1.
103  fltVal = fltVal/100;
104 
105  Std_InValidRange((float) 0, (float) 1, fltVal, true, "PeLengthPercentage");
106  m_fltPeLengthPercentage = fltVal;
108 }
109 
119 
129 {
130  //We need to scale it because this comes in as 0-100, but we need it in 0-1.
131  fltVal = fltVal/100;
132 
133  Std_InValidRange((float) 0, m_fltPeLengthPercentage, fltVal, true, "MinPeLengthPercentage");
136 }
137 
147 
157 
158 void LengthTensionGain::Copy(CStdSerialize *lpSource)
159 {
160  Gain::Copy(lpSource);
161 
162  LengthTensionGain *lpOrig = dynamic_cast<LengthTensionGain *>(lpSource);
163 
165  m_fltTLwidth = lpOrig->m_fltTLwidth;
166  m_fltTLc = lpOrig->m_fltTLc;
171 }
172 
173 CStdSerialize *LengthTensionGain::Clone()
174 {
175  CStdSerialize *lpClone = new LengthTensionGain();
176  lpClone->Copy(this);
177  return lpClone;
178 }
179 
180 bool LengthTensionGain::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
181 {
182  if(Gain::SetData(strDataType, strValue, false))
183  return true;
184 
185  if(strDataType == "RESTINGLENGTH")
186  {
187  RestingLength((float) atof(strValue.c_str()));
188  return true;
189  }
190 
191  if(strDataType == "LWIDTH")
192  {
193  TLwidth((float) atof(strValue.c_str()));
194  return true;
195  }
196 
197  if(strDataType == "PELENGTHPERCENTAGE")
198  {
199  PeLengthPercentage((float) atof(strValue.c_str()));
200  return true;
201  }
202 
203  if(strDataType == "MINPELENGTHPERCENTAGE")
204  {
205  MinPeLengthPercentage((float) atof(strValue.c_str()));
206  return true;
207  }
208 
209  //If it was not one of those above then we have a problem.
210  if(bThrowError)
211  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
212 
213  return false;
214 }
215 
216 void LengthTensionGain::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
217 {
218  Gain::QueryProperties(aryProperties);
219 
220  aryProperties.Add(new TypeProperty("RestingLength", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
221  aryProperties.Add(new TypeProperty("Lwidth", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
222  aryProperties.Add(new TypeProperty("PeLengthPercentage", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
223  aryProperties.Add(new TypeProperty("MinPeLengthPercentage", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
224 }
225 
226 void LengthTensionGain::Load(CStdXml &oXml)
227 {
228  Gain::Load(oXml);
229 
230  oXml.IntoElem(); //Into Adapter Element
231 
232  RestingLength(oXml.GetChildFloat("RestingLength"));
233  TLwidth(oXml.GetChildFloat("Lwidth"));
234  PeLengthPercentage(oXml.GetChildFloat("PeLength"));
235  MinPeLengthPercentage(oXml.GetChildFloat("MinPeLength"));
236 
237  oXml.OutOfElem(); //OutOf Adapter Element
238 }
239 
240  } //Gains
241 } //AnimatSim
float m_fltRestingLength
The resting length of the muscle.
Base class file for all Animat simulation objects.
virtual float MinPeLength()
Gets the minimum pe length.
Root namespace for the base simulation library for AnimatLab.
Length-Tension muscle gain.
float m_fltPeLengthPercentage
The percentage of the muscle length that is the Pe portion.
float m_fltTLc
precalculated value used in the determination of the length-tension curve.
virtual float MinPeLengthPercentage()
Gets the minimum pe length percentage.
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
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_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
Declares the gain base class.
LengthTensionGain()
Default constructor.
virtual float SeRestLength()
Gets the se rest length.
virtual float CalculateGain(float fltInput)
Calculates the gain.
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 an inverted quadratic gain class used to calculate length-tension relationship for muscle...
float m_fltTLwidth
The width parameter of the curve.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual float PeLengthPercentage()
Gets the pe length percentage.
float m_fltSeRestLength
Resting length of the se portion of the muscle. Used to calculate SE and PE lengths.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Gain.cpp:232
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: Gain.cpp:190