50 #include "LinearMath/btVector3.h"
58 MountainGoatNL2::MountainGoatNL2(
int segments,
int hips,
int legs) :
62 m_subStructures = segments + hips + legs;
65 MountainGoatNL2::~MountainGoatNL2()
69 void MountainGoatNL2::addNodesLeg(
tgStructure& s,
double r){
94 void MountainGoatNL2::addNodesHip(
tgStructure& s,
double r){
109 void MountainGoatNL2::addNodesVertebra(
tgStructure& s,
double r){
117 void MountainGoatNL2::addRodsVertebra(
tgStructure& s){
125 const double offsetDist = r+1;
126 const double offsetDist2 = offsetDist*6;
127 const double offsetDist3 = offsetDist2+2;
128 const double yOffset_leg = -(r+6);
129 const double yOffset_foot = -(2*r+6);
132 btVector3 offset(offsetDist,0.0,0);
134 btVector3 offset1(offsetDist*2,0.0,offsetDist);
135 btVector3 offset2(offsetDist2,0.0,offsetDist);
136 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
137 btVector3 offset4(offsetDist2,0.0,-offsetDist);
139 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
140 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
141 btVector3 offset7(r*2,yOffset_leg,offsetDist);
142 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
144 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
145 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
146 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
147 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
149 for(std::size_t i = 0; i < m_segments; i++) {
151 t->addTags(
tgString(
"spine segment num", i + 1));
152 t->move((i + 1)*offset);
156 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
161 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
168 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
170 t->addTags(
tgString(
"segment num", i + 1));
174 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
179 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
185 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
187 t->addTags(
tgString(
"segment num", i + 1));
200 for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {
202 t->addTags(
tgString(
"segment num", i + 1));
206 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(1, 0, 0), 0);
211 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(1, 0, 0), 0);
220 for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {
222 t->addTags(
tgString(
"segment num", i + 1));
226 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(1, 0, 0), 0);
231 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(1, 0, 0), 0);
239 void MountainGoatNL2::addMuscles(
tgStructure& goat){
243 std::vector<tgStructure*> children = goat.
getChildren();
244 for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
246 tgNodes n0 = children[i-2]->getNodes();
247 tgNodes n1 = children[i-1]->getNodes();
248 tgNodes n2 = children[i]->getNodes();
253 goat.
addPair(n0[3], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
254 goat.
addPair(n0[3], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
256 goat.
addPair(n0[4], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
257 goat.
addPair(n0[4], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
265 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
266 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
267 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
268 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
271 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
272 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
273 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
274 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
290 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
291 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
292 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
293 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
297 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
298 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
299 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
300 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
303 if (i >= 2 && i < 7){
321 tgNodes n0 = children[0]->getNodes();
322 tgNodes n1 = children[1]->getNodes();
323 tgNodes n2 = children[2]->getNodes();
324 tgNodes n3 = children[3]->getNodes();
325 tgNodes n4 = children[4]->getNodes();
326 tgNodes n5 = children[5]->getNodes();
327 tgNodes n6 = children[6]->getNodes();
328 tgNodes n7 = children[7]->getNodes();
329 tgNodes n8 = children[8]->getNodes();
330 tgNodes n9 = children[9]->getNodes();
331 tgNodes n10 = children[10]->getNodes();
332 tgNodes n11 = children[11]->getNodes();
333 tgNodes n12 = children[12]->getNodes();
334 tgNodes n13 = children[13]->getNodes();
335 tgNodes n14 = children[14]->getNodes();
344 goat.
addPair(n7[1], n1[1],
tgString(
"all left_shoulder hip rear upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
345 goat.
addPair(n7[1], n1[4],
tgString(
"all left_shoulder hip front upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
346 goat.
addPair(n7[1], n0[2],
tgString(
"all left_shoulder hip front top muscleAct1 seg", 7) +
tgString(
" seg", 0));
347 goat.
addPair(n7[1], n2[3],
tgString(
"all left_shoulder hip rear top muscleAct1 seg", 7) +
tgString(
" seg", 2));
349 goat.
addPair(n7[3], n1[1],
tgString(
"all left_shoulder hip rear lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
350 goat.
addPair(n7[3], n1[4],
tgString(
"all left_shoulder hip front lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
351 goat.
addPair(n7[3], n0[1],
tgString(
"all left_shoulder front bottom muscleAct1 seg", 7) +
tgString(
" seg", 0));
352 goat.
addPair(n7[3], n2[4],
tgString(
"all left_shoulder hip rear bottom muscleAct1 seg", 7) +
tgString(
" seg", 2));
355 goat.
addPair(n7[0], n1[1],
tgString(
"all left_shoulder hip rear mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
356 goat.
addPair(n7[0], n1[4],
tgString(
"all left_shoulder hip front mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
374 goat.
addPair(n9[1], n1[2],
tgString(
"all right_shoulder hip rear upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
375 goat.
addPair(n9[1], n1[3],
tgString(
"all right_shoulder hip front upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
376 goat.
addPair(n9[1], n0[2],
tgString(
"all right_shoulder hip front top muscleAct1 seg", 9) +
tgString(
" seg", 0));
377 goat.
addPair(n9[1], n2[3],
tgString(
"all right_shoulder hip rear top muscleAct1 seg", 9) +
tgString(
" seg", 2));
379 goat.
addPair(n9[3], n1[2],
tgString(
"all right_shoulder hip rear lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
380 goat.
addPair(n9[3], n1[3],
tgString(
"all right_shoulder hip front lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
381 goat.
addPair(n9[3], n0[1],
tgString(
"all right_shoulder hip front bottom muscleAct1 seg", 9) +
tgString(
" seg", 0));
382 goat.
addPair(n9[3], n2[4],
tgString(
"all right_shoulder hip rear bottom muscleAct1 seg", 9) +
tgString(
" seg", 2));
385 goat.
addPair(n9[0], n1[2],
tgString(
"all right_shoulder hip rear mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
386 goat.
addPair(n9[0], n1[3],
tgString(
"all right_shoulder hip front mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
477 const double density = 4.2/300.0;
478 const double radius = 0.5;
479 const double rod_space = 10.0;
480 const double rod_space2 = 8.0;
481 const double friction = 0.5;
482 const double rollFriction = 0.0;
483 const double restitution = 0.0;
485 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
487 const double stiffness = 1000.0;
488 const double stiffnessPassive = 4000.0;
489 const double stiffnessPassive2 = 4000.0;
490 const double stiffnessPassive3 = 10000.0;
491 const double damping = .01*stiffness;
492 const double pretension = 0.0;
493 const bool history =
true;
494 const double maxTens = 7000.0;
495 const double maxSpeed = 12.0;
497 const double passivePretension = 1000;
498 const double passivePretension2 = 3500;
499 const double passivePretension3 = 3500;
500 const double passivePretension4 = 4000.0;
504 const double mRad = 1.0;
505 const double motorFriction = 10.0;
506 const double motorInertia = 1.0;
507 const bool backDrivable =
false;
508 #ifdef PASSIVE_STRUCTURE
510 mRad, motorFriction, motorInertia, backDrivable,
511 history, maxTens, maxSpeed);
513 mRad, motorFriction, motorInertia, backDrivable,
514 history, maxTens, maxSpeed);
517 mRad, motorFriction, motorInertia, backDrivable,
518 history, maxTens, maxSpeed);
520 mRad, motorFriction, motorInertia, backDrivable,
521 history, maxTens, maxSpeed);
524 mRad, motorFriction, motorInertia, backDrivable,
525 history, maxTens, maxSpeed);
528 mRad, motorFriction, motorInertia, backDrivable,
529 history, maxTens, maxSpeed);
532 mRad, motorFriction, motorInertia, backDrivable,
533 history, maxTens, maxSpeed);
535 mRad, motorFriction, motorInertia, backDrivable,
536 history, maxTens, maxSpeed);
541 #ifdef PASSIVE_STRUCTURE
558 addNodesLeg(leg,rod_space);
563 addNodesVertebra(vertebra,rod_space);
564 addRodsVertebra(vertebra);
568 addNodesHip(hip,rod_space);
574 const double yOffset_foot = -(2*rod_space+6);
576 addSegments(goat,vertebra,hip,leg,rod_space);
578 goat.move(btVector3(0.0,-yOffset_foot+7,0.0));
582 std::vector<tgStructure*> children = goat.
getChildren();
586 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
590 #ifdef PASSIVE_STRUCTURE
604 #ifdef PASSIVE_STRUCTURE
628 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
630 m_allSegments = this->find<tgModel> (
"segment");
643 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
virtual void setup(tgWorld &world)
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
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="")
Contains the definition of class tgSimViewGraphics.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Contains the definition of class tgBasicActuator.
std::string tgString(std::string s, int i)
Contains the definition of class tgWorld $Id$.
Definition of class tgStructure.
Definition of class tgStructureInfo.
Trying out some new legs for MountainGoat.
Contains the definition of class tgSimView.
Definition of class tgKinematicActuatorInfo.
Contains the definition of class tgRod.
virtual void step(double dt)
Definition of class tgBuildSpec.
virtual void setup(tgWorld &world)
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")