NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
hillyMuscleNP.cpp
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 #include "hillyMuscleNP.h"
20 #include "core/tgModelVisitor.h"
21 #include "core/tgBulletUtil.h"
22 #include "core/tgWorld.h"
25 #include "core/tgRod.h"
26 #include "core/tgBox.h"
27 #include "tgcreator/tgBuildSpec.h"
28 #include "tgcreator/tgRodInfo.h"
29 #include "tgcreator/tgBoxInfo.h"
30 #include "tgcreator/tgStructure.h"
34 {
35 }
36 
38 {
39 }
40 
42 {
43 
44 
45  const double rodDensity = 1; // Note: This needs to be high enough or things fly apart...
46  const double rodRadius = 0.25;
47  const tgRod::Config rodConfig(rodRadius, rodDensity);
48  const tgRod::Config rodConfig2(rodRadius, 0.0);
49  const tgBox::Config boxConfig(rodRadius, rodRadius, 0.0);
50 
51  tgStructure s;
52 
53 #if (0)
54  s.addNode(-2, 2.1, 0);
55  s.addNode(0, 2.1, 0);
56  s.addNode(10, 2.1, 0);
57  s.addNode(12, 2.1, 0);
58  s.addNode(22, 2.1, 0);
59  s.addNode(24, 2.1, 0);
60 
61  s.addPair(0, 1, "rod2");
62  s.addPair(2, 3, "rod2");
63  s.addPair(4, 5, "rod2");
64 
65  s.addPair(1, 2, "muscle");
66  s.addPair(3, 4, "muscle");
67  s.move(btVector3(0, 0, 0));
68 #else
69  s.addNode(0, 5, 2);
70  s.addNode(0, 5, 0);
71  s.addNode(20, 5, 2);
72  s.addNode(20, 5, 0);
73  s.addNode(5, 2, -5);
74  s.addNode(5, 2, 5);
75 
76  s.addPair(0, 1, "rod");
77  s.addPair(2, 3, "rod");
78 
79  s.addPair(0, 2, "muscle");
80  s.addPair(1, 3, "muscle");
81  //s.addPair(3, 4, "muscle");
82  s.move(btVector3(0, 0, 0));
83 #endif
84 
85 
86  // Move the structure so it doesn't start in the ground
87  s.move(btVector3(0, 0, 0));
88  //s.addRotation(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 1.0, 0.0), M_PI_2);
89  tgSpringCableActuator::Config muscleConfig(1000, 10, 0.0, false, 600000000);
90 
91  // Create the build spec that uses tags to turn the structure into a real model
92  tgBuildSpec spec;
93  spec.addBuilder("rod", new tgRodInfo(rodConfig));
94  spec.addBuilder("rod2", new tgRodInfo(rodConfig2));
95  spec.addBuilder("box", new tgBoxInfo(boxConfig));
96  spec.addBuilder("muscle", new tgBasicContactCableInfo(muscleConfig));
97 
98  // Create your structureInfo
99  tgStructureInfo structureInfo(s, spec);
100  // Use the structureInfo to build ourselves
101  structureInfo.buildInto(*this, world);
102  // We could now use tgCast::filter or similar to pull out the
103  // models (e.g. muscles) that we want to control.
104  allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants());
105  allRods = tgCast::filter<tgModel, tgRod> (getDescendants());
106 
107  notifySetup();
108  totalTime = 0.0;
109  tgModel::setup(world);
110 }
111 
113 {
115 }
116 
117 void hillyMuscleNP::step(double dt)
118 {
119  totalTime += dt;
120 
121  //allMuscles[0]->setRestLength(11, dt);
122 // allMuscles[1]->setRestLength(11, dt);
123 
124  btVector3 com(0, 0, 0);
125  btScalar mass = 0;
126 #if (0)
127  btScalar energy = 0;
128 #endif // Supress compiler warning
129  for (std::size_t i = 0; i < allRods.size(); i++)
130  {
131  tgRod& ri = *(allRods[i]);
132  com += ri.centerOfMass() * ri.mass();
133  mass += ri.mass();
134  }
135 
136  //std::cout << allMuscles[0]->getTension() << std::endl;
137  tgModel::step(dt);
138 }
139 
145 {
146  r.render(*this);
147  tgModel::onVisit(r);
148 }
Create a box shape as an obstacle or add it to your tensegrity.
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
Definition of class tgRodInfo.
virtual ~hillyMuscleNP()
virtual void step(double dt)
Definition: tgModel.cpp:84
virtual void setup(tgWorld &world)
virtual btVector3 centerOfMass() const
Definition: tgBaseRigid.cpp:74
virtual void step(double dt)
virtual void teardown()
virtual void onVisit(const tgModelVisitor &r) const
Definition: tgModel.cpp:107
Class that interfaces with Bullet to build the boxes.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
virtual void render(const tgRod &rod) const
Contains the definition of interface class tgModelVisitor.
Definition of class tgBasicContactCableInfo.
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBulletUtil.
Definition of class tgStructure.
Definition of class tgStructureInfo.
virtual double mass() const
Definition: tgBaseRigid.h:65
For testing MuscleNP contacts.
virtual void onVisit(const tgModelVisitor &r) const
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
Definition: tgRod.h:43
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:170
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70