NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgSpringCable.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
25 // This module
26 #include "tgSpringCable.h"
27 #include "tgSpringCableAnchor.h"
28 
29 #include <iostream>
30 #include <stdexcept>
31 #include <cassert>
32 
33 tgSpringCable::tgSpringCable( const std::vector<tgSpringCableAnchor*>& anchors,
34  double coefK,
35  double dampingCoefficient,
36  double pretension) :
37 m_damping(0.0),
38 m_velocity(0.0),
39 m_coefK (coefK),
40 m_dampingCoefficient(dampingCoefficient)
41 {
42  // Anchors will be stored in child classes
43  assert(anchors.size() >= 2);
44  assert(coefK > 0.0);
45  assert(dampingCoefficient >= 0.0);
46 
47  std::size_t n = anchors.size();
48 
49  btVector3 pos1 = anchors[0]->getWorldPosition();
50  btVector3 pos2 = anchors[n - 1]->getWorldPosition();
51 
52  m_restLength = pos1.distance(pos2) - pretension / coefK;
53 
54  if (m_restLength <= 0.0)
55  {
56  throw std::invalid_argument("Pretension causes string to shorten past rest length!");
57  }
58 
60 }
61 
63 {
64 }
65 
66 const double tgSpringCable::getRestLength() const
67 {
68  return m_restLength;
69 }
70 
71 void tgSpringCable::setRestLength( const double newRestLength)
72 {
73  // Assume we've already put this through a motor model
74  // But check anyway
75  assert(newRestLength > 0.0);
76 
77  m_restLength = newRestLength;
78 }
virtual void setRestLength(const double newRestLength)
Definitions of class tgSpringCable.
virtual const double getRestLength() const
virtual ~tgSpringCable()
tgSpringCable(const std::vector< tgSpringCableAnchor * > &anchors, double coefK, double dampingCoefficient, double pretension=0.0)
double m_restLength
Definitions of class tgSpringCableAnchor.
double m_prevLength