NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
ContactTestModel.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 CONTACT_TEST_MODEL_H
20 #define CONTACT_TEST_MODEL_H
21 
22 #include "core/tgModel.h"
23 #include "core/tgLinearString.h"
24 
25 #include "core/tgSubject.h"
26 
27 #include "btBulletDynamicsCommon.h"
28 #include <iostream>
29 #include <set>
30 
31 #include "tgcreator/tgRodInfo.h"
32 #include "core/tgLinearString.h"
33 #include "dev/btietz/tgRBString.h"
34 #include "tgcreator/tgLinearStringInfo.h"
37 #include "tgcreator/tgBuildSpec.h"
38 
39 #include "tgcreator/tgStructure.h"
41 #include "tgcreator/tgUtil.h"
42 #include "core/tgString.h"
43 
44 //#include <tgmath.h>
48 class ContactTestModel : public tgSubject<ContactTestModel>, public tgModel
49 {
50 public:
51 
53  {
54  }
55 
56  virtual ~ContactTestModel()
57  {}
58 
60  virtual void setup(tgWorld& world)
61  {
62 
63  // Config for rods that are a part of RB Strings
64  const double radius = 0.15;
65  const double density = 4; // Note: This needs to be high enough or things fly apart...
66  const tgRod::Config rodConfig(radius, density);
67 
68  const double stiffness = 10000.0;
69  const double damping = .01*stiffness;
70  const int segments = 16;
71  const tgLinearString::Config stringConfig(stiffness, damping);
72  const tgRBString::Config rbConfig(segments, rodConfig, stringConfig, 8.0);
73 
74  // Config for the other rods
75  const double bigRadius = 1.0;
76  const double massLess = 0;
77  const double massive = 1.0;
78 
79  const tgRod::Config masslessRod(bigRadius, massLess);
80  const tgRod::Config massiveRod(bigRadius, massive);
81 
82  double length = 10.0;
83  double height = 20.0;
84 
85  tgStructure s;
86 
87  s.addNode(0, height, 0); // 0
88  s.addNode(length, height, 0); // 1
89  s.addNode(0, height + 10.0, 0); // 2
90  s.addNode(length, height + 10.0, 0); // 3
91 
92  // Rods
93  s.addPair( 0, 1, "massive rod");
94  s.addPair( 2, 3, "massless rod");
95 
96 
97  // Muscles
98  s.addPair(0, 2, "muscle");
99  s.addPair(1, 3, "muscle");
100 
101  //s.move(btVector3(0, 10, 0));
102 
103  // Create the build spec that uses tags to turn the structure into a real model
104  tgBuildSpec spec;
105  spec.addBuilder("massive", new tgRodInfo(massiveRod));
106  spec.addBuilder("massless", new tgRodInfo(masslessRod));
107  spec.addBuilder("muscle", new tgRBStringInfo(rbConfig));
108 
109  // Create your structureInfo
110  tgStructureInfo structureInfo(s, spec);
111 
112  // Use the structureInfo to build ourselves
113  structureInfo.buildInto(*this, world);
114 
115  // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) that we want to control.
116  allMuscles = tgCast::filter<tgModel, tgRBString> (getDescendants());
117 
118  // Debug printing
119  std::cout << "StructureInfo:" << std::endl;
120  std::cout << structureInfo << std::endl;
121 
122  std::cout << "Model: " << std::endl;
123  std::cout << *this << std::endl;
124 
125  // Actually setup the children
126  tgModel::setup(world);
127 
128  std::cout << "Finished Setup!" << std::endl;
129 
130  }
131 
132  // @todo: Is there a way that we can get rid of the need to override this function in subclasses of tgModel?
133  // comment_BRT: only if we can somehow make tgModel a template class,
134  // we need to know what class we're notifying
135  virtual void step(double dt)
136  {
137  // Notify observers (controllers) of the step so that they can take action
138  notifyStep(dt);
139 
140  tgModel::step(dt); // Step any children
141 
142  }
143 
144  void teardown()
145  {
147  }
148 
149  std::vector <tgRBString*>& getAllMuscles ()
150  {
151  return allMuscles;
152  }
153 
154 private:
155  std::vector<tgRBString*> allMuscles;
156 };
157 
158 #endif
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
Definition of class tgRodInfo.
Definition of tgSubject class.
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Definition: tgModel.cpp:84
virtual void step(double dt)
Contains the definition of class tgModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
tgModel()
Definition: tgModel.cpp:33
virtual void setup(tgWorld &world)
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class tgRBString. A string with small rigid bodies to create contact dynam...
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:170
Contains the definition of class tgRBStringInfo. A string with small rigid bodies to create contact d...
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70