51 #include "LinearMath/btVector3.h"
59 MountainGoat::MountainGoat(
int segments,
int hips,
int legs) :
63 m_subStructures = segments + hips + legs;
66 MountainGoat::~MountainGoat()
70 void MountainGoat::addNodesLeg(
tgStructure& s,
double r){
99 void MountainGoat::addNodesHip(
tgStructure& s,
double r){
112 void MountainGoat::addNodesVertebra(
tgStructure& s,
double r){
120 void MountainGoat::addRodsVertebra(
tgStructure& s){
128 const double offsetDist = r+1;
129 const double offsetDist2 = offsetDist*6;
130 const double offsetDist3 = offsetDist2+2;
131 const double yOffset_leg = -(2*r+1);
132 const double yOffset_foot = -(2*r+6);
135 btVector3 offset(offsetDist,0.0,0);
137 btVector3 offset1(offsetDist*2,0.0,offsetDist);
138 btVector3 offset2(offsetDist2,0.0,offsetDist);
139 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
140 btVector3 offset4(offsetDist2,0.0,-offsetDist);
142 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
143 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
144 btVector3 offset7(r*2,yOffset_leg,offsetDist);
145 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
147 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
148 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
149 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
150 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
152 for(std::size_t i = 0; i < m_segments; i++) {
154 t->addTags(
tgString(
"spine segment num", i + 1));
155 t->move((i + 1)*offset);
159 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
164 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
171 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
173 t->addTags(
tgString(
"segment num", i + 1));
177 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
182 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
188 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
190 t->addTags(
tgString(
"segment num", i + 1));
203 for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {
205 t->addTags(
tgString(
"segment num", i + 1));
209 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
214 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
223 for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {
225 t->addTags(
tgString(
"segment num", i + 1));
229 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
234 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
246 std::vector<tgStructure*> children = goat.
getChildren();
247 for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
249 tgNodes n0 = children[i-2]->getNodes();
250 tgNodes n1 = children[i-1]->getNodes();
251 tgNodes n2 = children[i]->getNodes();
256 goat.
addPair(n0[3], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
257 goat.
addPair(n0[3], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
259 goat.
addPair(n0[4], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
260 goat.
addPair(n0[4], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
268 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
269 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
270 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
271 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
274 goat.
addPair(n0[1], n1[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
275 goat.
addPair(n0[1], n1[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
276 goat.
addPair(n0[2], n1[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-2) +
tgString(
" seg", i-1));
277 goat.
addPair(n0[2], n1[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-2) +
tgString(
" seg", i-1));
293 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main rear upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
294 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main rear lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
295 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main rear upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
296 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main rear lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
300 goat.
addPair(n1[1], n2[3],
tgString(
"spine all main front lower right muscleAct2 seg", i-1) +
tgString(
" seg", i));
301 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main front lower left muscleAct2 seg", i-1) +
tgString(
" seg", i));
302 goat.
addPair(n1[2], n2[3],
tgString(
"spine all main front upper right muscleAct1 seg", i-1) +
tgString(
" seg", i));
303 goat.
addPair(n1[2], n2[4],
tgString(
"spine all main front upper left muscleAct1 seg", i-1) +
tgString(
" seg", i));
306 if (i >= 2 && i < 7){
324 tgNodes n0 = children[0]->getNodes();
325 tgNodes n1 = children[1]->getNodes();
326 tgNodes n2 = children[2]->getNodes();
327 tgNodes n3 = children[3]->getNodes();
328 tgNodes n4 = children[4]->getNodes();
329 tgNodes n5 = children[5]->getNodes();
330 tgNodes n6 = children[6]->getNodes();
331 tgNodes n7 = children[7]->getNodes();
332 tgNodes n8 = children[8]->getNodes();
333 tgNodes n9 = children[9]->getNodes();
334 tgNodes n10 = children[10]->getNodes();
335 tgNodes n11 = children[11]->getNodes();
336 tgNodes n12 = children[12]->getNodes();
337 tgNodes n13 = children[13]->getNodes();
338 tgNodes n14 = children[14]->getNodes();
347 goat.
addPair(n7[1], n1[1],
tgString(
"all left_shoulder hip rear upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
348 goat.
addPair(n7[1], n1[4],
tgString(
"all left_shoulder hip front upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
349 goat.
addPair(n7[1], n0[2],
tgString(
"all left_shoulder hip front top muscleAct1 seg", 7) +
tgString(
" seg", 0));
350 goat.
addPair(n7[1], n2[3],
tgString(
"all left_shoulder hip rear top muscleAct1 seg", 7) +
tgString(
" seg", 2));
352 goat.
addPair(n7[3], n1[1],
tgString(
"all left_shoulder hip rear lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
353 goat.
addPair(n7[3], n1[4],
tgString(
"all left_shoulder hip front lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
354 goat.
addPair(n7[3], n0[1],
tgString(
"all left_shoulder front bottom muscleAct1 seg", 7) +
tgString(
" seg", 0));
355 goat.
addPair(n7[3], n2[4],
tgString(
"all left_shoulder hip rear bottom muscleAct1 seg", 7) +
tgString(
" seg", 2));
358 goat.
addPair(n7[0], n1[1],
tgString(
"all left_shoulder hip rear mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
359 goat.
addPair(n7[0], n1[4],
tgString(
"all left_shoulder hip front mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
377 goat.
addPair(n9[1], n1[2],
tgString(
"all right_shoulder hip rear upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
378 goat.
addPair(n9[1], n1[3],
tgString(
"all right_shoulder hip front upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
379 goat.
addPair(n9[1], n0[2],
tgString(
"all right_shoulder hip front top muscleAct1 seg", 9) +
tgString(
" seg", 0));
380 goat.
addPair(n9[1], n2[3],
tgString(
"all right_shoulder hip rear top muscleAct1 seg", 9) +
tgString(
" seg", 2));
382 goat.
addPair(n9[3], n1[2],
tgString(
"all right_shoulder hip rear lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
383 goat.
addPair(n9[3], n1[3],
tgString(
"all right_shoulder hip front lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
384 goat.
addPair(n9[3], n0[1],
tgString(
"all right_shoulder hip front bottom muscleAct1 seg", 9) +
tgString(
" seg", 0));
385 goat.
addPair(n9[3], n2[4],
tgString(
"all right_shoulder hip rear bottom muscleAct1 seg", 9) +
tgString(
" seg", 2));
388 goat.
addPair(n9[0], n1[2],
tgString(
"all right_shoulder hip rear mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
389 goat.
addPair(n9[0], n1[3],
tgString(
"all right_shoulder hip front mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
411 goat.
addPair(n11[4], n1[4],
tgString(
"all left_foreleg front abdomen connection muscle seg", 11) +
tgString(
" seg", 1));
412 goat.
addPair(n11[3], n1[1],
tgString(
"all left_foreleg front abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
413 goat.
addPair(n11[2], n1[4],
tgString(
"all left_foreleg rear abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
418 goat.
addPair(n11[2], n7[3],
tgString(
"all left_foreleg outer front tricep muscle seg", 11) +
tgString(
" seg", 7));
419 goat.
addPair(n11[2], n7[2],
tgString(
"all left_foreleg inner front tricep muscle seg", 11) +
tgString(
" seg", 7));
427 goat.
addPair(n13[4], n1[3],
tgString(
"all right_foreleg front abdomen connection muscle seg", 13) +
tgString(
" seg", 1));
428 goat.
addPair(n13[3], n1[2],
tgString(
"all right_foreleg front abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
429 goat.
addPair(n13[2], n1[3],
tgString(
"all right_foreleg rear abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
435 goat.
addPair(n13[2], n9[2],
tgString(
"all right_foreleg inner front tricep muscle seg", 13) +
tgString(
" seg", 9));
436 goat.
addPair(n13[2], n9[3],
tgString(
"all right_foreleg outer front tricep muscle seg", 13) +
tgString(
" seg", 9));
445 goat.
addPair(n12[4], n3[1],
tgString(
"all left_hindleg rear abdomen connection muscle seg", 12) +
tgString(
" seg", 3));
446 goat.
addPair(n12[3], n5[1],
tgString(
"all left_hindleg front abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
447 goat.
addPair(n12[2], n5[4],
tgString(
"all left_hindleg rear abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
452 goat.
addPair(n12[2], n8[3],
tgString(
"all left_hindleg outer front calf muscle seg", 12) +
tgString(
" seg", 8));
453 goat.
addPair(n12[2], n8[2],
tgString(
"all left_hindleg inner front calf muscle seg", 12) +
tgString(
" seg", 8));
462 goat.
addPair(n14[4], n3[2],
tgString(
"all right_hindleg rear abdomen connection muscle seg", 14) +
tgString(
" seg", 3));
463 goat.
addPair(n14[3], n5[2],
tgString(
"all right_hindleg front abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
464 goat.
addPair(n14[2], n5[3],
tgString(
"all right_hindleg rear abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
470 goat.
addPair(n14[2], n10[2],
tgString(
"all right_hindleg inner front calf muscle seg", 14) +
tgString(
" seg", 10));
471 goat.
addPair(n14[2], n10[3],
tgString(
"all right_hindleg outer front calf muscle seg", 14) +
tgString(
" seg", 10));
474 goat.
addPair(n14[4], n10[1],
tgString(
"all right_hindleg central thigh muscle3 seg", 14) +
tgString(
" seg", 10));
481 const double density = 4.2/300.0;
482 const double radius = 0.5;
483 const double rod_space = 10.0;
484 const double rod_space2 = 8.0;
485 const double friction = 0.5;
486 const double rollFriction = 0.0;
487 const double restitution = 0.0;
489 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
491 const double stiffness = 1000.0;
492 const double stiffnessPassive = 4000.0;
493 const double stiffnessPassive2 = 4000.0;
494 const double stiffnessPassive3 = 10000.0;
495 const double damping = .01*stiffness;
496 const double pretension = 0.0;
497 const bool history =
true;
498 const double maxTens = 7000.0;
499 const double maxSpeed = 12.0;
501 const double passivePretension = 1000;
502 const double passivePretension2 = 3500;
503 const double passivePretension3 = 3500;
504 const double passivePretension4 = 4000.0;
508 const double mRad = 1.0;
509 const double motorFriction = 10.0;
510 const double motorInertia = 1.0;
511 const bool backDrivable =
false;
512 #ifdef PASSIVE_STRUCTURE
514 mRad, motorFriction, motorInertia, backDrivable,
515 history, maxTens, maxSpeed);
517 mRad, motorFriction, motorInertia, backDrivable,
518 history, maxTens, maxSpeed);
521 mRad, motorFriction, motorInertia, backDrivable,
522 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);
536 mRad, motorFriction, motorInertia, backDrivable,
537 history, maxTens, maxSpeed);
539 mRad, motorFriction, motorInertia, backDrivable,
540 history, maxTens, maxSpeed);
545 #ifdef PASSIVE_STRUCTURE
562 addNodesLeg(leg,rod_space);
567 addNodesVertebra(vertebra,rod_space);
568 addRodsVertebra(vertebra);
572 addNodesHip(hip,rod_space);
578 const double yOffset_foot = -(2*rod_space+6);
580 addSegments(goat,vertebra,hip,leg,rod_space);
582 goat.move(btVector3(0.0,-yOffset_foot,0.0));
586 std::vector<tgStructure*> children = goat.
getChildren();
590 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
594 #ifdef PASSIVE_STRUCTURE
608 #ifdef PASSIVE_STRUCTURE
632 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
634 m_allSegments = this->find<tgModel> (
"segment");
647 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Implementing the Flemons quadruped model (roughly), but as a subclass of Brian's BaseSpineModelLearni...
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.
virtual void step(double dt)
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="")