35 #include "LinearMath/btVector3.h"
49 TetraSpineStaticModel::TetraSpineStaticModel(
size_t segments) :
54 TetraSpineStaticModel::~TetraSpineStaticModel()
59 void addNodes(
tgStructure& tetra,
double edge,
double height)
63 tetra.
addNode(-edge / 2.0, 0, 0,
"base");
65 tetra.
addNode( edge / 2.0, 0, 0,
"base");
67 tetra.
addNode(0, height, 0,
"base");
69 tetra.
addNode(0, edge / 2.0 * tan(M_PI / 6.0), 25.0,
"tip");
73 tgNode nn1 = (oldNodes[0] + oldNodes[2])/2.0;
76 tgNode nn2 = (oldNodes[1] + oldNodes[2])/2.0;
80 std::cout << (oldNodes[3] - oldNodes[2]).length() << std::endl;
81 std::cout << (oldNodes[3] - oldNodes[1]).length() << std::endl;
82 std::cout << (oldNodes[3] - oldNodes[0]).length() << std::endl;
88 tetra.
addPair(0, 1,
"back bottom rod");
89 tetra.
addPair(0, 4,
"back rightBottom rod");
90 tetra.
addPair(4, 2,
"back rightTop rod");
91 tetra.
addPair(0, 3,
"front right rod");
92 tetra.
addPair(1, 5,
"back leftBottom rod");
93 tetra.
addPair(5, 2,
"back leftTop rod");
94 tetra.
addPair(1, 3,
"front left rod");
95 tetra.
addPair(2, 3,
"front top rod");
102 const btVector3 offset(0, 0, -23.0);
103 for (
size_t i = 0; i < segmentCount; ++i)
108 t->addTags(
tgString(
"segment num", i ));
110 t->move((i + 1) * offset);
121 const std::vector<tgStructure*> children = snake.
getChildren();
122 for (
size_t i = 1; i < children.size(); ++i)
124 tgNodes n0 = children[i-1]->getNodes();
125 tgNodes n1 = children[i ]->getNodes();
137 void mapMuscles(TetraSpineStaticModel::MuscleMap& muscleMap,
153 const std::vector<tgStructure*> children = structure.
getChildren();
154 tgNodes n0 = children[0]->getNodes();
157 btRigidBody* firstBody = model.getAllRigids()[0]->getPRigidBody();
159 std::vector<tgBaseRigid*> myRigids = model.getAllRigids();
161 for (
int i =0; i < myRigids.size(); i++)
163 std::cout << myRigids[i]->mass() <<
" " <<myRigids[i]->getPRigidBody() << std::endl;
167 abstractMarker marker1(firstBody, n0[3] - firstBody->getCenterOfMassPosition (), btVector3(1, 0, 0), 0);
169 model.addMarker(marker1);
171 tgNodes n1 = children[1]->getNodes();
173 btRigidBody* secondBody = model.getAllRigids()[15]->getPRigidBody();
175 abstractMarker marker2(secondBody, n1[3] - secondBody->getCenterOfMassPosition (), btVector3(1, 0, 0), 0);
177 model.addMarker(marker2);
179 abstractMarker marker3(secondBody, n1[1] - secondBody->getCenterOfMassPosition (), btVector3(1, 0, 0), 0);
181 model.addMarker(marker3);
183 abstractMarker marker4(secondBody, n1[0] - secondBody->getCenterOfMassPosition (), btVector3(1, 0, 0), 0);
185 model.addMarker(marker4);
187 tgNodes n2 = children[2]->getNodes();
189 btRigidBody* thirdBody = model.getAllRigids()[29]->getPRigidBody();
191 abstractMarker marker5(thirdBody, n2[3] - thirdBody->getCenterOfMassPosition (), btVector3(1, 0, 0), 0);
193 model.addMarker(marker5);
198 std::cout <<
"StructureInfo:" << std::endl
199 << structureInfo << std::endl
200 <<
"Model: " << std::endl
201 << model << std::endl;
203 const std::vector<tgSpringCableActuator*> outerMuscles =
205 for (
size_t i = 0; i < outerMuscles.size(); ++i)
208 assert(pMuscle != NULL);
209 std::cout <<
"Outer muscle: " << *pMuscle << std::endl;
219 const double edge = 38;
220 const double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
221 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
225 addNodes(tetra, edge, height);
230 tetra.move(btVector3(0.0, 2.0, 100.0));
234 addSegments(snake, tetra, edge, m_segments);
242 const double oldDensity = .00311;
243 const double radius = 0.635 / 2.0;
244 const double density = 0.0201 / (pow(radius, 2) * M_PI * edge);
245 const double friction = 0.25;
248 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
251 const double sphereVolume = 1000.0 * 4.0 / 3.0 * M_PI * pow(radius, 3);
253 const double baseCornerFrontD = 140.0 / sphereVolume;
254 const tgSphere::Config baseCornerFrontConfig(radius, baseCornerFrontD, friction);
255 spec.addBuilder(
"num0 base",
new tgSphereInfo(baseCornerFrontConfig));
257 const double baseCornerMidD = 180.0 / sphereVolume;
258 const tgSphere::Config baseCornerMidConfig(radius, baseCornerMidD, friction);
259 spec.addBuilder(
"num1 base",
new tgSphereInfo(baseCornerMidConfig));
261 const double baseCornerRearD = 100.0 / sphereVolume;
262 const tgSphere::Config baseCornerRearConfig(radius, baseCornerRearD, friction);
263 spec.addBuilder(
"num2 base",
new tgSphereInfo(baseCornerRearConfig));
265 const double tipCornerFrontD = 40.0 / sphereVolume;
266 const tgSphere::Config tipCornerFrontConfig(radius, tipCornerFrontD, friction);
267 spec.addBuilder(
"num0 tip",
new tgSphereInfo(tipCornerFrontConfig));
269 const double tipCornerMidD = 120.0 / sphereVolume;
271 spec.addBuilder(
"num1 tip",
new tgSphereInfo(tipCornerMidConfig));
272 spec.addBuilder(
"num2 tip",
new tgSphereInfo(tipCornerMidConfig));
274 const double PCBD = 70.0 / sphereVolume;
276 spec.addBuilder(
"PCB num0",
new tgSphereInfo(PCB_1_Config));
277 spec.addBuilder(
"PCB num1",
new tgSphereInfo(PCB_1_Config));
279 const double PCB2D = 95.0 / sphereVolume;
281 spec.addBuilder(
"PCB num2",
new tgSphereInfo(PCB_2_Config));
299 m_allMuscles = this->find<tgSpringCableActuator> (
"muscle");
300 m_allSegments = this->find<tgModel> (
"segment");
301 mapMuscles(m_muscleMap, *
this);
303 addMarkers(snake, *
this);
306 trace(structureInfo, *
this);
324 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
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.
Utility class for class casting and filtering collections by type.
Markers for specific places on a tensegrity.
virtual void setup(tgWorld &world)
const tgNodes & getNodes() const
Definition of class tgBasicActuatorInfo.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
virtual void step(double dt)
Tetraspine, configured for learning in the NTRT simulator.
virtual void step(const double dt)
virtual void setup(tgWorld &world)
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")