NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
Muscle2P.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 NTRT_MUSCLE2P_H_
20 #define NTRT_MUSCLE2P_H_
21 
29 // The Bullet Physics library
30 #include "LinearMath/btScalar.h"
31 #include "LinearMath/btVector3.h"
32 // The C++ Standard Library
33 
34 #include <string>
35 
36 // Forward references
37 class btRigidBody;
38 class muscleAnchor;
39 
40 class Muscle2P
41 {
42 public:
43  Muscle2P(btRigidBody * body1,
44  btVector3 pos1,
45  btRigidBody * body2,
46  btVector3 pos2,
47  double coefK,
48  double dampingCoefficient);
49 
50  virtual ~Muscle2P();
51 
52  // Called by tensegrity class update function for each muscle2p
53  virtual btVector3 calculateAndApplyForce(double dt);
54 
55  void setName(std::string a) { name = a; }
56 
57  const double getRestLength() const;
58 
59  void setRestLength( const double newRestLength);
60 
61  const btScalar getActualLength() const;
62 
63  const double getTension() const;
64 
65  const double getCoefK() const
66  {
67  return m_coefK;
68  }
69 
70  const double getVelocity() const
71  {
72  return m_velocity;
73  }
74 
75  const double getDamping() const
76  {
77  return m_damping;
78  }
79 
80  const std::string& getName() const {
81  return name;
82  }
83 
84  muscleAnchor * anchor1;
85 
86  muscleAnchor * anchor2;
87 
88  std::string name;
89 
90  bool recordHistory;
91 
92 
93  private:
94  // Necessary for computations
95  double m_restLength;
96 
97  double m_prevLength;
98 
99  // So we can get it without passing a dt
100  double m_damping;
101 
102  double m_velocity;
103 
104  // Should be const for the lifetime of a muscle
105  const btScalar m_dampingCoefficient;
106 
107  const btScalar m_coefK;
108 
109  bool invariant(void) const;
110 };
111 
113 {
114 public:
115  muscleAnchor();
116 
117  muscleAnchor(btRigidBody *body, btVector3 pos);
118 
119  ~muscleAnchor();
120 
121  btVector3 getWorldPosition();
122 
123  // Relative to the body
124  btVector3 getRelativePosition();
125 
126  btRigidBody * attachedBody;
127 
128  // Relative to the body when it is first constructed
129  btVector3 attachedRelativeOriginalPosition;
130 
131  btScalar height;
132  private:
133 };
134 
135 #endif // NTRT_MUSCLE2P_H_