NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgCompressionSpringActuatorInfo.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 
27 // This class
29 
30 // Other classes from core
33 
35 m_config(config),
37 {}
38 
40 m_config(config),
41 tgConnectorInfo(tags)
42 {}
43 
45 m_config(config),
46 tgConnectorInfo(pair)
47 {}
48 
50 {
51  return new tgCompressionSpringActuatorInfo(m_config, pair);
52 }
53 
55 {
56  // Note: tgBulletCompressionSpring holds pointers to things in the world, but it doesn't actually have any in-world representation.
58 }
59 
61 {
62  // Don't have to do anything in the world for a tgBulletCompressionSpring...
63  // @todo: set the name based on joined tags, or remove name from the model...
64  //std::cout << "tgCompressionSpringActuatorInfo::createModel" << std::endl;
65 
66  // ensure connector has been initialized
68  return new tgCompressionSpringActuator(m_bulletCompressionSpring, getTags(), m_config);
69 }
70 
71 double tgCompressionSpringActuatorInfo::getMass()
72 {
73  // @todo: this should never be called, unless we wanted to model the mass of
74  // a compression spring at some point. For now, maybe throw an error?
75  return 0;
76 }
77 
78 
80 {
81 
82  // @todo: need to check somewhere that the rigid bodies have been set...
83  btRigidBody* fromBody = getFromRigidBody();
84  btRigidBody* toBody = getToRigidBody();
85 
86  // This method can create the spring-cable either at the node location
87  // as specified, or it can automatically re-locate either anchor end
88  // to the edge of a rigid body.
89  btVector3 from;
90  btVector3 to;
91 
92  // Choose either the node location (as given by the tgConnectorInfo's point),
93  // or the point returned by the attached rigid body's getConnectorInfo method.
94 
95  // Point "A" is the "From" point, the first btVector3 in the pair.
96  if( m_config.moveCablePointAToEdge ){
97  from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo());
98  }
99  else {
100  // The getFrom method is inherited from tgConnectorInfo.
101  from = getFrom();
102  }
103  // Point "B" is the "To" point, the second btVector3 in the pair.
104  if( m_config.moveCablePointBToEdge ){
105  to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom());
106  }
107  else {
108  // The getTo method is inherited from tgConnectorInfo.
109  to = getTo();
110  }
111 
112  // Note that even though this object is definitely not a SpringCable,
113  // and does not inherit from that class at all, it's still more useful
114  // to re-use the spring cable version of anchor.
115  // No need to re-create the exact same object, just to name it differently.
116  // This should work, since tgBulletSpringCableAnchor actually has
117  // no tie-ins to either tgBulletSpringCable or tgSpringCable.
118  std::vector<tgBulletSpringCableAnchor*> anchorList;
119 
120  // add the anchors from these two rigid bodies to the list of anchors that
121  // will reside within the tgBulletCompressionSpring.
122  tgBulletSpringCableAnchor* anchor1 =
123  new tgBulletSpringCableAnchor(fromBody, from);
124  anchorList.push_back(anchor1);
125 
126  tgBulletSpringCableAnchor* anchor2 =
127  new tgBulletSpringCableAnchor(toBody, to);
128  anchorList.push_back(anchor2);
129 
130  // call the constructor for tgBulletCompressionSpring.
131  // Unlike the spring-cable, it makes more sense to state the rest
132  // length of a compression spring. That way, it's easy to only apply
133  // a force if the total distance between the two anchors is less than restLength.
134  return new tgBulletCompressionSpring(anchorList, m_config.isFreeEndAttached,
135  m_config.stiffness, m_config.damping, m_config.restLength);
136 }
137 
tgBulletCompressionSpring * m_bulletCompressionSpring
tgBulletCompressionSpring * createTgBulletCompressionSpring()
virtual tgModel * createModel(tgWorld &world)
tgCompressionSpringActuatorInfo(const tgCompressionSpringActuator::Config &config)
virtual tgConnectorInfo * createConnectorInfo(const tgPair &pair)
Definition of class tgCompressionSpringActuatorInfo, used to create a tgBulletCompressionSpring.
Definition: tgPair.h:48
Definitions of class tgBulletCompressionSpring.
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint) const =0
Definition: tgTags.h:44