NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBasicActuatorInfo.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 #include "tgBasicActuatorInfo.h"
28 
31 
33 m_config(config),
35 {}
36 
38 m_config(config),
39 tgConnectorInfo(tags)
40 {}
41 
43 m_config(config),
44 tgConnectorInfo(pair)
45 {}
46 
47 
49 {
50  return new tgBasicActuatorInfo(m_config, pair);
51 }
52 
53 void tgBasicActuatorInfo::initConnector(tgWorld& world)
54 {
55  // Note: tgBulletSpringCable holds pointers to things in the world, but it doesn't actually have any in-world representation.
56  m_bulletSpringCable = createTgBulletSpringCable();
57 }
58 
59 tgModel* tgBasicActuatorInfo::createModel(tgWorld& world)
60 {
61  // Don't have to do anything in the world for a tgBulletSpringCable...
62  // @todo: set the name based on joined tags, or remove name from the model...
63  //std::cout << "tgBasicActuatorInfo::createModel" << std::endl;
64 
65  // ensure connector has been initialized
66  assert(m_bulletSpringCable);
67  return new tgBasicActuator(m_bulletSpringCable, getTags(), m_config);
68 }
69 
70 double tgBasicActuatorInfo::getMass()
71 {
72  // @todo: calculate a mass? tgBulletSpringCable doesn't have physics...
73  return 0;
74 }
75 
76 
77 tgBulletSpringCable* tgBasicActuatorInfo::createTgBulletSpringCable()
78 {
79 
80  // @todo: need to check somewhere that the rigid bodies have been set...
81  btRigidBody* fromBody = getFromRigidBody();
82  btRigidBody* toBody = getToRigidBody();
83 
84  // This method can create the spring-cable either at the node location
85  // as specified, or it can automatically re-locate either anchor end
86  // to the edge of a rigid body.
87  btVector3 from;
88  btVector3 to;
89 
90  // Choose either the node location (as given by the tgConnectorInfo's point),
91  // or the point returned by the attached rigid body's getConnectorInfo method.
92 
93  // Point "A" is the "From" point, the first btVector3 in the pair.
94  if( m_config.moveCablePointAToEdge ){
95  from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo(),
96  m_config.rotation);
97  }
98  else {
99  // The getFrom method is inherited from tgConnectorInfo.
100  from = getFrom();
101  }
102  // Point "B" is the "To" point, the second btVector3 in the pair.
103  if( m_config.moveCablePointBToEdge ){
104  to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom(),
105  m_config.rotation);
106  }
107  else {
108  // The getTo method is inherited from tgConnectorInfo.
109  to = getTo();
110  }
111 
112  // Older version of this code: always relocate the anchors.
113  //btVector3 from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo(), m_config.rotation);
114  //btVector3 to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom(), m_config.rotation);
115 
116  std::vector<tgBulletSpringCableAnchor*> anchorList;
117 
118  tgBulletSpringCableAnchor* anchor1 = new tgBulletSpringCableAnchor(fromBody, from);
119  anchorList.push_back(anchor1);
120 
121  tgBulletSpringCableAnchor* anchor2 = new tgBulletSpringCableAnchor(toBody, to);
122  anchorList.push_back(anchor2);
123 
124  return new tgBulletSpringCable(anchorList, m_config.stiffness, m_config.damping, m_config.pretension);
125 }
126 
tgBasicActuatorInfo(const tgBasicActuator::Config &config)
virtual tgConnectorInfo * createConnectorInfo(const tgPair &pair)
Definition of class tgBasicActuatorInfo.
Definition: tgPair.h:48
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint) const =0
Definitions of classes tgBulletSpringCable $Id$.
Definition: tgTags.h:44