NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgUnidirComprSprActuatorInfo.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 (are these included from the superclass?...)
31 //#include "core/tgBulletCompressionSpring.h"
33 #include "core/tgCast.h"
34 
35 // Include the new type of spring
37 
42 {
43  // Debugging
44  #if (0)
45  std::cout << "tgUnidirComprSprActuatorInfo constructor. Direction is:" << std::endl;
46  std::cout << "(" << m_config.direction->x() << ",";
47  std::cout << m_config.direction->y() << ",";
48  std::cout << m_config.direction->z() << ")" << std::endl;
49  #endif
50 }
51 
58 m_config(config),
60 {
61  // call the helper function for the constructors
63 }
64 
66 m_config(config),
68 {
69  // call the helper function for the constructors
71 }
72 
74 m_config(config),
76 {
77  // call the helper function for the constructors
79 }
80 
82 {
83  return new tgUnidirComprSprActuatorInfo(m_config, pair);
84 }
85 
87 {
88  // Note: tgBulletUnidirComprSpr holds pointers to things
89  // in the world, but it doesn't actually have any in-world representation.
90  // Remember that m_bulletCompressionSpring is held in the superclass.
92 }
93 
95 {
96  // Don't have to do anything in the world for a tgBulletCompressionSpring...
97  // @todo: set the name based on joined tags, or remove name from the model...
98  //std::cout << "tgUnidirComprSprActuatorInfo::createModel" << std::endl;
99 
100  // ensure connector has been initialized
102 
103  // Here, we have to cast the compression spring to the type that's used in this
104  // class. Casting from the superclass (tgBulletCompressionSpring) to the
105  // subclass tgBulletUnidirComprSpr.
106  // Rememeber that m_bulletCompressionSpring is a pointer to
107  // a bulletCompressionSpring.
108  return new tgUnidirComprSprActuator(
109  tgCast::cast<tgBulletCompressionSpring, tgBulletUnidirComprSpr>(m_bulletCompressionSpring), getTags(), m_config);
110 }
111 
113 {
114  // @TO-DO: make this more object-oriented. Currently, there is code re-use
115  // between this method and the create compression spring method in
116  // the parent class.
117  // @todo: need to check somewhere that the rigid bodies have been set...
118  btRigidBody* fromBody = getFromRigidBody();
119  btRigidBody* toBody = getToRigidBody();
120 
121  // This method can create the spring-cable either at the node location
122  // as specified, or it can automatically re-locate either anchor end
123  // to the edge of a rigid body.
124  btVector3 from;
125  btVector3 to;
126 
127  // Choose either the node location (as given by the tgConnectorInfo's point),
128  // or the point returned by the attached rigid body's getConnectorInfo method.
129 
130  // Point "A" is the "From" point, the first btVector3 in the pair.
131  if( m_config.moveCablePointAToEdge ){
132  from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo());
133  }
134  else {
135  // The getFrom method is inherited from tgConnectorInfo.
136  from = getFrom();
137  }
138  // Point "B" is the "To" point, the second btVector3 in the pair.
139  if( m_config.moveCablePointBToEdge ){
140  to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom());
141  }
142  else {
143  // The getTo method is inherited from tgConnectorInfo.
144  to = getTo();
145  }
146 
147  // Note that even though this object is definitely not a SpringCable,
148  // and does not inherit from that class at all, it's still more useful
149  // to re-use the spring cable version of anchor.
150  // No need to re-create the exact same object, just to name it differently.
151  // This should work, since tgBulletSpringCableAnchor actually has
152  // no tie-ins to either tgBulletSpringCable or tgSpringCable.
153  std::vector<tgBulletSpringCableAnchor*> anchorList;
154 
155  // add the anchors from these two rigid bodies to the list of anchors that
156  // will reside within the tgBulletCompressionSpring.
157  tgBulletSpringCableAnchor* anchor1 =
158  new tgBulletSpringCableAnchor(fromBody, from);
159  anchorList.push_back(anchor1);
160 
161  tgBulletSpringCableAnchor* anchor2 =
162  new tgBulletSpringCableAnchor(toBody, to);
163  anchorList.push_back(anchor2);
164 
165  // call the constructor for tgBulletUnidirComprSpr.
166  // Unlike the spring-cable, it makes more sense to state the rest length
167  // of a compression spring. That way, it's easy to only apply a force
168  // if the total distance between the two anchors is less than restLength.
169  return new tgBulletUnidirComprSpr(anchorList,
170  m_config.isFreeEndAttached, m_config.stiffness, m_config.damping,
171  m_config.restLength, m_config.direction);
172 }
173 
tgBulletCompressionSpring * m_bulletCompressionSpring
Definitions of class tgBulletUnidirComprSpr, a version of tgBulletCompressionSpring that only applies...
Utility class for class casting and filtering collections by type.
virtual tgModel * createModel(tgWorld &world)
tgBulletUnidirComprSpr * createTgBulletUnidirComprSpr()
virtual tgConnectorInfo * createConnectorInfo(const tgPair &pair)
virtual void initConnector(tgWorld &world)
Definition: tgPair.h:48
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
Definition of class tgUnidirComprSprActuatorInfo, used to create a tgBulletUnidirComprSpr.
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint) const =0
tgUnidirComprSprActuatorInfo(const tgUnidirComprSprActuator::Config &config)
Definition: tgTags.h:44