NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPrismaticInfo.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 "tgPrismaticInfo.h"
28 
29 #include "btBulletDynamicsCommon.h"
30 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
31 #include "LinearMath/btVector3.h"
32 #include "LinearMath/btTransform.h"
33 
34 #include <iostream>
35 
36 #include "tgcreator/tgNode.h"
38 
39 tgPrismaticInfo::tgPrismaticInfo(const tgPrismatic::Config& config) :
40  m_config(config),
42 {
43 }
44 
45 tgPrismaticInfo::tgPrismaticInfo(const tgPrismatic::Config& config, tgTags tags) :
46  m_config(config),
47  tgConnectorInfo(tags)
48 {}
49 
50 tgPrismaticInfo::tgPrismaticInfo(const tgPrismatic::Config& config, const tgPair& pair) :
51  m_config(config),
52  tgConnectorInfo(pair)
53 {}
54 
55 tgPrismaticInfo::~tgPrismaticInfo()
56 {
57 }
58 
60 {
61  return new tgPrismaticInfo(m_config, pair);
62 }
63 
64 void tgPrismaticInfo::initConnector(tgWorld& world)
65 {
66 }
67 
68 btSliderConstraint* tgPrismaticInfo::createSlider()
69 {
70  btRigidBody* fromBody = getFromRigidBody();
71  btVector3 from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo(), 0);//m_config.rotation);
72  btTransform transATop;
73  transATop.setIdentity();
74  transATop.setOrigin(fromBody->getWorldTransform().inverse() * from);
75  transATop.setRotation(btQuaternion(btVector3(0,0,1),M_PI/2));
76 
77  btRigidBody* toBody = getToRigidBody();
78  btVector3 to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom(), 0);//m_config.rotation);
79  btTransform transBTop;
80  transBTop.setIdentity();
81  transBTop.setOrigin(toBody->getWorldTransform().inverse() * to);
82  transBTop.setRotation(btQuaternion(btVector3(0,0,1),M_PI/2));
83 
84  btSliderConstraint* slider = new btSliderConstraint(*fromBody, *toBody, transATop, transBTop, true);
85 
86  return slider;
87 }
88 
89 tgModel* tgPrismaticInfo::createModel(tgWorld& world)
90 {
91  tgNode startNode = this->getFrom();
92  tgNode endNode = this->getTo();
93 
94  btVector3 buildVec = (endNode - startNode);
95  double m_startLength = buildVec.length();
96 
97 // m_config.m_minLength = m_startLength;
98 
99  btSliderConstraint* slider = createSlider();
100 
101  tgPrismatic* prism = new tgPrismatic(slider, getTags(), m_config);
102  prism->setup(world);
103  return prism;
104 }
105 
106 double tgPrismaticInfo::getMass()
107 {
108  // @todo: add up the rigid bodies
109  return 0;
110 }
virtual void setup(tgWorld &world)
Definition: tgPrismatic.cpp:94
Definition of class tgNode.
Definition: tgPair.h:48
Definition: tgNode.h:45
Definition of class tgStructureInfo.
Contains the definition of class tgPrismaticInfo. A prismatic actuator builder.
virtual tgConnectorInfo * createConnectorInfo(const tgPair &pair)
Definition: tgTags.h:44