45 #include "btBulletDynamicsCommon.h"
61 void addNodes(
tgStructure& tetra,
double edge,
double height)
64 tetra.
addNode(-edge / 2.0, 0, 0,
"heavy");
66 tetra.
addNode( edge / 2.0, 0, 0,
"heavy");
68 tetra.
addNode(0, height, -1.0 * tgUtil::round(std::sqrt(3.0) / 2.0 * height),
"light");
70 tetra.
addNode(0, height, tgUtil::round(std::sqrt(3.0) / 2.0 * height),
"heavy");
75 tetra.
addPair(0, 1,
"back bottom rod");
76 tetra.
addPair(0, 2,
"back right rod");
77 tetra.
addPair(0, 3,
"front right rod");
78 tetra.
addPair(1, 2,
"back left rod");
79 tetra.
addPair(1, 3,
"front left rod");
80 tetra.
addPair(2, 3,
"front top rod");
87 const btVector3 offset(0, 0, -edge * 2);
88 for (
size_t i = 0; i < segmentCount; ++i)
91 t->addTags(
tgString(
"segment", i + 1));
92 t->move((i + 1) * offset);
101 const std::vector<tgStructure*> children = snake.
getChildren();
102 for (
size_t i = 1; i < children.size(); ++i)
104 tgNodes n0 = children[i-1]->getNodes();
105 tgNodes n1 = children[i ]->getNodes();
107 snake.
addPair(n0[0], n1[0],
"outer right muscle");
108 snake.
addPair(n0[1], n1[1],
"outer left muscle");
109 snake.
addPair(n0[2], n1[2],
"outer top muscle");
111 snake.
addPair(n0[0], n1[3],
"inner right muscle");
112 snake.
addPair(n0[1], n1[3],
"inner left muscle");
113 snake.
addPair(n0[2], n1[3],
"inner top muscle");
132 std::cout <<
"StructureInfo:" << std::endl
133 << structureInfo << std::endl
134 <<
"Model: " << std::endl
135 << model << std::endl;
142 const double edge = 30.0;
143 const double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
144 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
148 addNodes(tetra, edge, height);
153 tetra.move(btVector3(0.0, 2.0, 100.0));
157 addSegments(snake, tetra, edge, m_segments);
162 const double density = 4.2 / 3000.0;
163 const double radius = 0.5;
164 const double h = 0.5;
167 spec.addBuilder(
"rod",
new tgBoxInfo(rodConfig));
173 spec.addBuilder(
"light",
new tgSphereInfo(sphereConfig));
176 spec.addBuilder(
"light",
new tgSphereInfo(sphereConfig2));
185 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
186 mapMuscles(muscleMap, *
this);
188 trace(structureInfo, *
this);
198 throw std::invalid_argument(
"dt is not positive");
209 const std::vector<tgSpringCableActuator*>&
212 const MuscleMap::const_iterator it = muscleMap.find(key);
213 if (it == muscleMap.end())
215 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
Create a box shape as an obstacle or add it to your tensegrity.
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Definition of class tgSphereInfo.
Convenience function for combining strings with ints, mostly for naming structures.
Contains the definition of class tgSphere.
virtual void step(double dt)
Utility class for class casting and filtering collections by type.
virtual void step(const double dt)
Definition of class tgBasicActuatorInfo.
Class that interfaces with Bullet to build the boxes.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
virtual void setup(tgWorld &world)
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
Contains the definition of class NestedBoxTestModel.
const std::vector< tgSpringCableActuator * > & getMuscles(const std::string &key) const
Rand seeding simular to the evolution and terrain classes.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
NestedBoxTestModel(size_t segments)
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
std::map< std::string, std::vector< tgSpringCableActuator * > > MuscleMap