NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBulletCompressionSpring.h
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 
19 #ifndef SRC_CORE_TG_BULLET_COMPRESSION_SPRING_H_
20 #define SRC_CORE_TG_BULLET_COMPRESSION_SPRING_H_
21 
30 // The Bullet Physics library
31 #include "LinearMath/btVector3.h"
32 // The C++ Standard Library
33 #include <vector>
34 
35 // Forward references
36 // Note that even though this object is not a tgSpringCable,
37 // we're still using tgSpringCableAnchor as a convenience.
38 // This works because there actually don't seem to be any references
39 // to tgSpringCable in tgSpringCableAnchor or tgBulletSpringCableAnchor.
40 class btRigidBody;
43 
49 {
50 public:
65  tgBulletCompressionSpring( const std::vector<tgBulletSpringCableAnchor*>& anchors,
66  bool isFreeEndAttached,
67  double coefK,
68  double coefD,
69  double restLength);
70 
76 
81  virtual void step(double dt);
82 
87  virtual const double getCurrentAnchorDistance() const;
88 
93  virtual const double getCurrentSpringLength() const;
94 
98  virtual const btVector3 getAnchorDirectionUnitVector() const;
99 
105  virtual const btVector3 getSpringEndpoint() const;
106 
107 
111  virtual const double getSpringForce() const;
112 
116  virtual const double getCoefK() const
117  {
118  return m_coefK;
119  }
120 
124  virtual const double getCoefD() const
125  {
126  return m_coefD;
127  }
128 
132  virtual const double getVelocity() const
133  {
134  return m_velocity;
135  }
136 
140  virtual const double getDampingForce() const
141  {
142  return m_dampingForce;
143  }
144 
149  virtual const double getRestLength() const
150  {
151  return m_restLength;
152  }
153 
157  virtual const bool isFreeEndAttached() const
158  {
159  return m_isFreeEndAttached;
160  }
161 
168  virtual const std::vector<const tgSpringCableAnchor*> getAnchors() const;
169 
170 
171 protected:
172 
180  std::vector<tgBulletSpringCableAnchor*> m_anchors;
181 
187 
192 
198 
203  double m_velocity;
204 
209 
215  const double m_coefK;
216 
222  const double m_coefD;
223 
227  double m_restLength;
228 
233  double m_prevLength;
234 
240  virtual void calculateAndApplyForce(double dt);
241 
242 private:
244  bool invariant(void) const;
245 };
246 
247 #endif // SRC_CORE_TG_BULLET_SPRING_CABLE_H_
virtual const double getVelocity() const
virtual const double getDampingForce() const
virtual const double getSpringForce() const
tgBulletSpringCableAnchor *const anchor1
virtual const bool isFreeEndAttached() const
tgBulletCompressionSpring(const std::vector< tgBulletSpringCableAnchor * > &anchors, bool isFreeEndAttached, double coefK, double coefD, double restLength)
virtual const btVector3 getSpringEndpoint() const
tgBulletSpringCableAnchor *const anchor2
std::vector< tgBulletSpringCableAnchor * > m_anchors
virtual const double getCoefK() const
virtual const double getCurrentSpringLength() const
virtual const double getCoefD() const
virtual const std::vector< const tgSpringCableAnchor * > getAnchors() const
virtual void calculateAndApplyForce(double dt)
virtual const btVector3 getAnchorDirectionUnitVector() const
virtual const double getCurrentAnchorDistance() const
virtual const double getRestLength() const