51 #include "LinearMath/btVector3.h"
59 MountainGoatAchilles::MountainGoatAchilles(
int segments,
int hips,
int legs) :
63 m_subStructures = segments + hips + legs;
66 MountainGoatAchilles::~MountainGoatAchilles()
70 void MountainGoatAchilles::addNodesLeg(
tgStructure& s,
double r){
85 void MountainGoatAchilles::addRodsLeg(
tgStructure& s){
105 void MountainGoatAchilles::addNodesHip(
tgStructure& s,
double r){
113 void MountainGoatAchilles::addRodsHip(
tgStructure& s){
120 void MountainGoatAchilles::addNodesVertebra(
tgStructure& s,
double r){
128 void MountainGoatAchilles::addRodsVertebra(
tgStructure& s){
136 const double offsetDist = r+1;
137 const double offsetDist2 = offsetDist*6;
138 const double offsetDist3 = offsetDist2+2;
139 const double yOffset_leg = -(2*r+1);
140 const double yOffset_foot = -(2*r+6);
143 btVector3 offset(offsetDist,0.0,0);
145 btVector3 offset1(offsetDist*2,0.0,offsetDist);
146 btVector3 offset2(offsetDist2,0.0,offsetDist);
147 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
148 btVector3 offset4(offsetDist2,0.0,-offsetDist);
150 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
151 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
152 btVector3 offset7(r*2,yOffset_leg,offsetDist);
153 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
155 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
156 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
157 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
158 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
160 for(std::size_t i = 0; i < m_segments; i++) {
162 t->addTags(
tgString(
"spine segment num", i + 1));
163 t->move((i + 1)*offset);
167 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
172 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
179 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
181 t->addTags(
tgString(
"segment num", i + 1));
185 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
190 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
196 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
198 t->addTags(
tgString(
"segment num", i + 1));
211 for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {
213 t->addTags(
tgString(
"segment num", i + 1));
217 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), 0);
222 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), 0);
229 for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {
231 t->addTags(
tgString(
"segment num", i + 1));
235 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
240 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
248 void MountainGoatAchilles::addMuscles(
tgStructure& goat){
252 std::vector<tgStructure*> children = goat.
getChildren();
253 for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
255 tgNodes n0 = children[i-2]->getNodes();
256 tgNodes n1 = children[i-1]->getNodes();
257 tgNodes n2 = children[i]->getNodes();
262 goat.
addPair(n0[3], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
263 goat.
addPair(n0[3], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
265 goat.
addPair(n0[4], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
266 goat.
addPair(n0[4], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
274 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
275 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
276 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
277 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
280 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
281 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
282 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
283 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
299 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
300 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
301 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
302 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
306 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
307 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
308 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
309 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
312 if (i >= 2 && i < 7){
330 tgNodes n0 = children[0]->getNodes();
331 tgNodes n1 = children[1]->getNodes();
332 tgNodes n2 = children[2]->getNodes();
333 tgNodes n3 = children[3]->getNodes();
334 tgNodes n4 = children[4]->getNodes();
335 tgNodes n5 = children[5]->getNodes();
336 tgNodes n6 = children[6]->getNodes();
337 tgNodes n7 = children[7]->getNodes();
338 tgNodes n8 = children[8]->getNodes();
339 tgNodes n9 = children[9]->getNodes();
340 tgNodes n10 = children[10]->getNodes();
341 tgNodes n11 = children[11]->getNodes();
342 tgNodes n12 = children[12]->getNodes();
343 tgNodes n13 = children[13]->getNodes();
344 tgNodes n14 = children[14]->getNodes();
353 goat.
addPair(n7[1], n1[1],
tgString(
"all left_shoulder hip rear upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
354 goat.
addPair(n7[1], n1[4],
tgString(
"all left_shoulder hip front upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
358 goat.
addPair(n7[3], n1[1],
tgString(
"all left_shoulder hip rear lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
359 goat.
addPair(n7[3], n1[4],
tgString(
"all left_shoulder hip front lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
364 goat.
addPair(n7[0], n1[1],
tgString(
"all left_shoulder hip rear mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
365 goat.
addPair(n7[0], n1[4],
tgString(
"all left_shoulder hip front mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
383 goat.
addPair(n9[1], n1[2],
tgString(
"all right_shoulder hip rear upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
384 goat.
addPair(n9[1], n1[3],
tgString(
"all right_shoulder hip front upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
388 goat.
addPair(n9[3], n1[2],
tgString(
"all right_shoulder hip rear lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
389 goat.
addPair(n9[3], n1[3],
tgString(
"all right_shoulder hip front lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
394 goat.
addPair(n9[0], n1[2],
tgString(
"all right_shoulder hip rear mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
395 goat.
addPair(n9[0], n1[3],
tgString(
"all right_shoulder hip front mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
417 goat.
addPair(n11[4], n1[4],
tgString(
"all left_foreleg front_horizontal abdomen connection muscle seg", 11) +
tgString(
" seg", 1));
418 goat.
addPair(n11[4], n1[1],
tgString(
"all left_foreleg rear_horizontal abdomen connection muscle seg", 11) +
tgString(
" seg", 1));
419 goat.
addPair(n11[2], n1[1],
tgString(
"all left_foreleg front abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
420 goat.
addPair(n11[3], n1[4],
tgString(
"all left_foreleg rear abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
432 goat.
addPair(n11[8], n7[4],
tgString(
"all left_front_achilles_tendon only muscle seg", 11) +
tgString(
" seg", 7));
433 goat.
addPair(n11[9], n7[4],
tgString(
"all left_front_achilles_tendon only muscle seg", 11) +
tgString(
" seg", 7));
439 goat.
addPair(n13[4], n1[3],
tgString(
"all right_foreleg front_horizontal abdomen connection muscle seg", 13) +
tgString(
" seg", 1));
440 goat.
addPair(n13[4], n1[2],
tgString(
"all right_foreleg rear_horizontal abdomen connection muscle seg", 13) +
tgString(
" seg", 1));
441 goat.
addPair(n13[3], n1[2],
tgString(
"all right_foreleg front abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
442 goat.
addPair(n13[2], n1[3],
tgString(
"all right_foreleg rear abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
455 goat.
addPair(n13[8], n9[4],
tgString(
"all right_front_achilles_tendon only muscle seg", 13) +
tgString(
" seg", 9));
456 goat.
addPair(n13[9], n9[4],
tgString(
"all right_front_achilles_tendon only muscle seg", 13) +
tgString(
" seg", 9));
462 goat.
addPair(n12[4], n3[1],
tgString(
"all left_hindleg front_horizontal abdomen connection muscle seg", 12) +
tgString(
" seg", 3));
463 goat.
addPair(n12[4], n5[1],
tgString(
"all left_hindleg rear_horizontal abdomen connection muscle seg", 12) +
tgString(
" seg", 3));
464 goat.
addPair(n12[2], n5[1],
tgString(
"all left_hindleg front abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
465 goat.
addPair(n12[3], n5[4],
tgString(
"all left_hindleg rear abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
477 goat.
addPair(n12[8], n8[4],
tgString(
"all left_rear_achilles_tendon only muscle seg", 12) +
tgString(
" seg", 8));
478 goat.
addPair(n12[9], n8[4],
tgString(
"all left_rear_achilles_tendon only muscle seg", 12) +
tgString(
" seg", 8));
484 goat.
addPair(n14[4], n3[2],
tgString(
"all right_hindleg front_horizontal abdomen connection muscle seg", 14) +
tgString(
" seg", 3));
485 goat.
addPair(n14[4], n5[2],
tgString(
"all right_hindleg rear_horizontal abdomen connection muscle seg", 14) +
tgString(
" seg", 3));
486 goat.
addPair(n14[3], n5[2],
tgString(
"all right_hindleg front abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
487 goat.
addPair(n14[2], n5[3],
tgString(
"all right_hindleg rear abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
497 goat.
addPair(n14[4], n10[1],
tgString(
"all right_hindleg central thigh muscle3 seg", 14) +
tgString(
" seg", 10));
500 goat.
addPair(n14[8], n10[4],
tgString(
"all right_rear_achilles_tendon only muscle seg", 14) +
tgString(
" seg", 10));
501 goat.
addPair(n14[9], n10[4],
tgString(
"all right_rear_achilles_tendon only muscle seg", 14) +
tgString(
" seg", 10));
509 const double density = 4.2/300.0;
511 const double density2 = 4.2/300.0;
513 const double radius = 0.5;
514 const double rod_space = 10.0;
515 const double rod_space2 = 8.0;
516 const double friction = 0.5;
517 const double rollFriction = 0.0;
518 const double restitution = 0.0;
520 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
521 const tgRod::Config rodConfig2(radius, density2, friction, rollFriction, restitution);
524 const double stiffness = 1000.0;
525 const double stiffnessPassive = 4000.0;
526 const double stiffnessPassive2 = 4000.0;
527 const double stiffnessPassive3 = 10000.0;
528 const double damping = .01*stiffness;
529 const double pretension = 0.0;
530 const bool history =
true;
531 const double maxTens = 10000.0;
532 const double maxSpeed = 12.0;
534 const double maxTens2 = 1000000.0;
535 const double maxSpeed2 = 20.0;
537 const double passivePretension = 1000;
538 const double passivePretension2 = 3500;
539 const double passivePretension3 = 3500;
540 const double passivePretension4 = 5000.0;
544 const double mRad = 1.0;
545 const double motorFriction = 10.0;
546 const double motorInertia = 1.0;
547 const bool backDrivable =
false;
548 #ifdef PASSIVE_STRUCTURE
550 mRad, motorFriction, motorInertia, backDrivable,
551 history, maxTens, maxSpeed);
553 mRad, motorFriction, motorInertia, backDrivable,
554 history, maxTens, maxSpeed);
557 mRad, motorFriction, motorInertia, backDrivable,
558 history, maxTens, maxSpeed);
560 mRad, motorFriction, motorInertia, backDrivable,
561 history, maxTens, maxSpeed);
564 mRad, motorFriction, motorInertia, backDrivable,
565 history, maxTens, maxSpeed);
568 mRad, motorFriction, motorInertia, backDrivable,
569 history, maxTens, maxSpeed);
572 mRad, motorFriction, motorInertia, backDrivable,
573 history, maxTens, maxSpeed);
575 mRad, motorFriction, motorInertia, backDrivable,
576 history, maxTens, maxSpeed);
581 #ifdef PASSIVE_STRUCTURE
598 addNodesLeg(leg,rod_space);
603 addNodesVertebra(vertebra,rod_space);
604 addRodsVertebra(vertebra);
608 addNodesHip(hip,rod_space);
614 const double yOffset_foot = -(2*rod_space+6);
616 addSegments(goat,vertebra,hip,leg,rod_space);
618 goat.move(btVector3(0.0,-yOffset_foot,0.0));
622 std::vector<tgStructure*> children = goat.
getChildren();
626 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
627 spec.addBuilder(
"rod2",
new tgRodInfo(rodConfig2));
631 #ifdef PASSIVE_STRUCTURE
645 #ifdef PASSIVE_STRUCTURE
669 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
671 m_allSegments = this->find<tgModel> (
"segment");
684 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.
Trying a longer achilles tendon muscle on the MountainGoat. Trying to stiffen up the legs more...
virtual void step(double dt)
std::string tgString(std::string s, int i)
Contains the definition of class tgWorld $Id$.
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class tgSimView.
Definition of class tgKinematicActuatorInfo.
virtual void setup(tgWorld &world)
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")