39 void tgLinearString::constructorAux()
42 assert(m_pHistory != NULL);
46 throw std::invalid_argument(
"Pointer to Muscle2P is NULL.");
48 else if (m_config.targetVelocity < 0.0)
50 throw std::invalid_argument(
"Target velocity is negative.");
52 else if (m_config.maxAcc < 0.0)
54 throw std::invalid_argument(
"Maximum acceleration is negative.");
56 else if (m_config.minActualLength < 0.0)
58 throw std::invalid_argument(
"Minimum length is negative.");
69 tgBaseString(tags, config, muscle->getRestLength(), muscle->getActualLength())
75 assert(m_muscle == muscle);
80 std::string space_separated_tags,
85 muscle->getRestLength(),
86 muscle->getActualLength())
92 assert(m_muscle == muscle);
119 throw std::invalid_argument(
"dt is not positive.");
125 m_muscle->calculateAndApplyForce(dt);
136 void tgLinearString::logHistory()
155 const double tgLinearString::getCurrentLength()
const
157 return m_muscle->getActualLength();
160 const double tgLinearString::getTension()
const
162 return m_muscle->getTension();
165 const double tgLinearString::getRestLength()
const
167 return m_muscle->getRestLength();
170 const double tgLinearString::getVelocity()
const
172 return m_muscle->getVelocity();
179 throw std::invalid_argument(
"Rest length is negative.");
183 m_preferredLength = newLength;
186 assert(m_preferredLength == newLength);
201 const double stiffness = m_muscle->getCoefK();
203 assert(stiffness > 0.0);
210 const double actualLength = m_muscle->getActualLength();
215 if ((actualLength - m_preferredLength) * stiffness
222 const double fabsDiff = abs(diff);
228 if (abs(diff) > stepSize)
232 mostRecentVelocity) >
236 stepSize = velChange * dt;
238 m_restLength += (diff/fabsDiff)*stepSize;
242 if (abs(diff/dt - mostRecentVelocity) > velChange)
247 diff = (diff/fabsDiff) * velChange * dt;
254 diff = -(mostRecentVelocity / abs(mostRecentVelocity)) *
258 m_restLength += diff;
265 std::cout <<
"RL: " << m_restLength <<
" M2P RL: " << m_muscle->getRestLength() << std::endl;
268 std::cout <<
"RL: " << m_restLength
269 <<
" Vel: " << (m_restLength -m_muscle->getRestLength()) / dt
270 <<
" prev Vel: " << prevVel
271 <<
" force " << (actualLength - m_restLength)*stiffness << std::endl;
272 prevVel = (m_restLength -m_muscle->getRestLength()) / dt ;
274 m_muscle->setRestLength(m_restLength);
282 const double stiffness = m_muscle->getCoefK();
284 assert(stiffness > 0.0);
286 const double currentTension = m_muscle->getTension();
287 const double delta = targetTension - currentTension;
288 double diff = delta/stiffness;
289 const double currentLength = m_muscle->getRestLength();
296 std::cout <<
"m_preferred: " << m_preferredLength << std::endl;
306 bool tgLinearString::invariant()
const
309 (m_muscle != NULL) &&
314 (m_preferredLength >= 0.0);
virtual void setup(tgWorld &world)
tgLinearString(Muscle2P *muscle, const tgTags &tags, tgBaseString::Config &config)
virtual ~tgLinearString()
virtual void step(double dt)
virtual void step(double dt)
std::deque< double > lastLengths
std::deque< double > dampingHistory
std::deque< double > tensionHistory
Definitions of classes Muscle2P and MuscleAnchor.
void setRestLength(double newLength, float dt)
virtual void tensionMinLengthController(const double targetTension, float dt)
virtual void setup(tgWorld &world)
virtual void render(const tgRod &rod) const
Contains the definition of interface class tgModelVisitor.
Contains the definition of class tgLinearString.
Contains the definition of class tgWorld $Id$.
virtual void moveMotors(double dt)
BaseStringHistory *const m_pHistory
virtual void onVisit(const tgModelVisitor &r) const
std::deque< double > lastVelocities
virtual const double getStartLength() const
std::deque< double > restLengths
void notifyStep(double dt)