NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
StructureTestModel.h
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 CONNECTOR_TEST_MODEL_H
20 #define CONNECTOR_TEST_MODEL_H
21 
22 #include "core/tgModel.h"
23 #include "core/tgBasicActuator.h"
24 
25 #include "core/tgSubject.h"
26 #include "core/tgModelVisitor.h"
27 
28 #include "btBulletDynamicsCommon.h"
29 #include <iostream>
30 #include <set>
31 
32 #include "tgcreator/tgRodInfo.h"
35 #include "tgcreator/tgBuildSpec.h"
36 
37 #include "tgcreator/tgStructure.h"
39 
40 
41 class StructureTestModel: public tgSubject<StructureTestModel>, public tgModel
42 {
43 public:
44 
45  StructureTestModel(std::string name) : tgModel(name)
46  {
47 
48  }
49 
51  {
52  }
53 
55  virtual void setup(tgWorld& world)
56  {
57  // This is basically a manual setup of a model. There are things that do this for us (@todo: reference the things that do this for us)
58 
59  const double density = 0.9;
60  const double radius = 0.3;
61  const tgRod::Config rodConfig(radius, density);
62 
63  double stiffness = 100000;
64  double dampening = stiffness * 0.001;
65 
66  tgBasicActuator::Config muscleConfig(stiffness, dampening);
67 
68  tgStructure structure;
69 
70  structure.addNode(0,0,0);
71  structure.addNode(0,3,0);
72  structure.addNode(2,5,0);
73  structure.addNode(-2,5,0);
74 
75  structure.addNode(0, 10, 0);
76  structure.addNode(0, 7, 0);
77  structure.addNode(0, 5, 2);
78  structure.addNode(0, 5,-2);
79 
80  structure.addPair(0, 1, "rod");
81  structure.addPair(1, 2, "rod");
82  structure.addPair(1, 3, "rod");
83 
84  structure.addPair(4, 5, "rod");
85  structure.addPair(5, 6, "rod");
86  structure.addPair(5, 7, "rod");
87 
88  structure.addPair(2, 6, "muscle");
89  structure.addPair(3, 7, "muscle");
90  structure.addPair(2, 7, "muscle");
91  structure.addPair(3, 6, "muscle");
92 
93  tgBuildSpec spec;
94  spec.addBuilder("rod", new tgRodInfo(rodConfig));
95  spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig));
96 
97  tgStructureInfo structureInfo(structure, spec);
98  structureInfo.buildInto(*this, world);
99 
100 
101  // Note: all these steps are done for you by structureInfo.buildInto()
102  /*
103  structureInfo.initRigidInfo();
104  structureInfo.autoCompoundRigids();
105 
106  structureInfo.initConnectorInfo();
107  structureInfo.chooseConnectorRigids();
108 
109  structureInfo.initRigidBodies(world);
110  structureInfo.initConnectors(world); // Note: Muscle2Ps won't show up yet -- they need to be part of a model to have rendering...
111  */
112 
113 
114  //structureInfo.createRigidModels(world);
115  //structureInfo.createConnectorModels(world);
116 
117  std::cout << "StructureInfo:" << std::endl;
118  std::cout << structureInfo << std::endl;
119 
120  }
121 
122  virtual void step(double dt)
123  {
124  //btTransform trans;
125  //m_rod->getRigidBody()->getMotionState()->getWorldTransform(trans);
126  //std::cout << "rod height: " << trans.getOrigin().getY() << std::endl;
127 
128  // Notify observers (controllers) of the step so that they can take action
129  notifyStep(dt);
130 
131  tgModel::step(dt); // Step any children
132  }
133 
134  virtual void onVisit(tgModelVisitor& r)
135  {
136  // Example: m_rod->getRigidBody()->dosomething()...
137 
138  //m_testString->onRender(r);
139 
140  tgModel::onVisit(r);
141  //std::cout << " StructureTestModel has special rendering requirements!" << std::endl;
142  }
143 
144  //Does this make myModel an observer as well??
145  void changeMuscle (double length)
146  {
147  //Do we need error checking here too?
148  //newString->setRestLength(length); // commented out for testing
149  }
150 
151 private:
152  tgRodInfo* m_rod;
153  tgRodInfo* m_rod2;
154 
155  //tgBasicActuator* newString;
156  tgModel* m_testString;
157 };
158 
159 #endif
Definition of class tgRodInfo.
Definition of tgSubject class.
virtual void step(double dt)
Definition: tgModel.cpp:84
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
Definition: tgModel.cpp:107
Contains the definition of class tgModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
Contains the definition of interface class tgModelVisitor.
tgModel()
Definition: tgModel.cpp:33
Contains the definition of class tgBasicActuator.
Definition of class tgStructure.
Definition of class tgStructureInfo.
virtual void setup(tgWorld &world)
virtual void step(double dt)
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70