NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
BigFoot.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 
29 //This application
30 #include "BigFoot.h"
31 
32 // This library
33 #include "core/tgModel.h"
34 #include "core/tgSimView.h"
35 #include "core/tgSimViewGraphics.h"
36 #include "core/tgSimulation.h"
37 #include "core/tgWorld.h"
38 #include "core/tgBasicActuator.h"
39 #include "core/tgRod.h"
41 #include "core/tgString.h"
42 #include "tgcreator/tgBuildSpec.h"
44 #include "tgcreator/tgRodInfo.h"
45 #include "tgcreator/tgStructure.h"
47 // The Bullet Physics library
48 #include "LinearMath/btVector3.h"
49 // The C++ Standard Library
50 #include <iostream>
51 #include <stdexcept>
52 
53 BigFoot::BigFoot() :
54 tgModel()
55 {
56 }
57 
58 BigFoot::~BigFoot()
59 {
60 }
61 
62 void BigFoot::setup(tgWorld& world)
63 {
64  //Rod and Muscle configuration. Todo: make into structs in a namespace block.
65 
66  const double density = 4.2/300.0; //Note: this needs to be high enough or things fly apart...
67  const double radius = 0.5;
68  const double rod_space = 10.0; //what was once v_size...
69  const double friction = 0.5;
70  const double rollFriction = 0.0;
71  const double restitution = 0.0;
72  const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
73 
74  const double radius2 = 0.15;
75  const double density2 = 1; // Note: This needs to be high enough or things fly apart...
76  const tgRod::Config rodConfig2(radius2, density2);
77 
78  const double stiffness = 1000.0;
79  const double damping = .01*stiffness;
80  const double pretension = 0.0;
81 
82  const tgSpringCableActuator::Config stringConfig(stiffness, damping, pretension, false, 7000, 24);
83 
84 
85  const double passivePretension = 700; // 5 N
86  tgSpringCableActuator::Config muscleConfig(2000, 20, passivePretension);
87 
88  tgStructure foot;
89 
90  //Nodes. Todo: make into separate function
91  foot.addNode(7,0,7);//0 : can't be less than 7, or structure spins. Weird, I know.
92  foot.addNode(7,0,-7);//1 : ditto.
93  foot.addNode(-7,0,-7);//2 : ditto.
94  foot.addNode(-7,0,7);//3 : ditto.
95  foot.addNode(2,rod_space/2,0);//4
96  foot.addNode(0,rod_space/2,-2);//5
97  foot.addNode(-2,rod_space/2,0);//6
98  foot.addNode(0,rod_space/2,2);//7
99 
100  //Rods. Todo: make into separate function
101  foot.addPair(0,6,"rod");
102  foot.addPair(1,7,"rod");
103  foot.addPair(2,4,"rod");
104  foot.addPair(3,5,"rod");
105 
106  //Muscles. Todo: make into separate function.
107  foot.addPair(0,1,"muscle");
108  foot.addPair(0,3,"muscle");
109  foot.addPair(1,2,"muscle");
110  foot.addPair(2,3,"muscle");
111  foot.addPair(0,7,"muscle");
112  foot.addPair(1,4,"muscle");
113  foot.addPair(2,5,"muscle");
114  foot.addPair(3,6,"muscle");
115  foot.addPair(4,5,"muscle");
116  foot.addPair(4,7,"muscle");
117  foot.addPair(5,6,"muscle");
118  foot.addPair(6,7,"muscle");
119 
120  // Create the build spec that uses tags to turn the structure into a real model
121  tgBuildSpec spec;
122  spec.addBuilder("rod", new tgRodInfo(rodConfig));
123  spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig));
124 
125  // Create your structureInfo
126  tgStructureInfo structureInfo(foot, spec);
127 
128  // Use the structureInfo to build ourselves
129  structureInfo.buildInto(*this, world);
130 
131  // We could now use tgCast::filter or similar to pull out the
132  // models (e.g. muscles) that we want to control.
133  allActuators = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants());
134 
135  // Notify controllers that setup has finished.
136  notifySetup();
137 
138  // Actually setup the children
139  tgModel::setup(world);
140 
141 }
142 
143 void BigFoot::step(double dt)
144 {
145  // Precondition
146  if (dt <= 0.0)
147  {
148  throw std::invalid_argument("dt is not positive");
149  }
150  else
151  {
152  // Notify observers (controllers) of the step so that they can take action
153  notifyStep(dt);
154  tgModel::step(dt); // Step any children
155  }
156 }
157 
158 const std::vector<tgSpringCableActuator*>& BigFoot::getAllActuators() const
159 {
160  return allActuators;
161 }
162 
164 {
165  notifyTeardown();
167 }
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
Definition of class tgRodInfo.
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Definition: tgModel.cpp:84
Definition of class tgBasicActuatorInfo.
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
Contains the definition of class tgSimViewGraphics.
virtual void setup(tgWorld &world)
Definition: BigFoot.cpp:62
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
A revised model for a foot.
virtual void step(double dt)
Definition: BigFoot.cpp:143
Contains the definition of class tgBasicActuator.
Contains the definition of class tgWorld $Id$.
Definition of class tgStructure.
Definition of class tgStructureInfo.
const std::vector< tgSpringCableActuator * > & getAllActuators() const
Definition: BigFoot.cpp:158
Contains the definition of class tgSimView.
virtual void teardown()
Definition: BigFoot.cpp:163
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
void notifyStep(double dt)
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