51 #include "LinearMath/btVector3.h"
59 MountainGoatFM0::MountainGoatFM0(
int segments,
int hips,
int legs) :
63 m_subStructures = segments + hips + legs;
66 MountainGoatFM0::~MountainGoatFM0()
70 void MountainGoatFM0::addNodesLeg(
tgStructure& s,
double r){
99 void MountainGoatFM0::addNodesHip(
tgStructure& s,
double r){
112 void MountainGoatFM0::addNodesVertebra(
tgStructure& s,
double r){
120 void MountainGoatFM0::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);
242 void MountainGoatFM0::addMuscles(
tgStructure& goat){
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));
291 if(i > 0 && i < m_segments){
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 muscleAct1 seg", i-1) +
tgString(
" seg", i));
301 goat.
addPair(n1[1], n2[4],
tgString(
"spine all main front lower left muscleAct1 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 < m_segments){
313 if(i == m_segments - 1){
325 tgNodes n0 = children[0]->getNodes();
326 tgNodes n1 = children[1]->getNodes();
327 tgNodes n2 = children[2]->getNodes();
328 tgNodes n3 = children[3]->getNodes();
329 tgNodes n4 = children[4]->getNodes();
330 tgNodes n5 = children[5]->getNodes();
331 tgNodes n6 = children[6]->getNodes();
332 tgNodes n7 = children[7]->getNodes();
333 tgNodes n8 = children[8]->getNodes();
334 tgNodes n9 = children[9]->getNodes();
335 tgNodes n10 = children[10]->getNodes();
336 tgNodes n11 = children[11]->getNodes();
337 tgNodes n12 = children[12]->getNodes();
338 tgNodes n13 = children[13]->getNodes();
339 tgNodes n14 = children[14]->getNodes();
348 goat.
addPair(n7[1], n1[1],
tgString(
"all left_shoulder hip rear upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
349 goat.
addPair(n7[1], n1[4],
tgString(
"all left_shoulder hip front upper muscleAct1 seg", 7) +
tgString(
" seg", 1));
350 goat.
addPair(n7[1], n0[2],
tgString(
"all left_shoulder hip front top muscleAct1 seg", 7) +
tgString(
" seg", 0));
351 goat.
addPair(n7[1], n2[3],
tgString(
"all left_shoulder hip rear top muscleAct1 seg", 7) +
tgString(
" seg", 2));
353 goat.
addPair(n7[3], n1[1],
tgString(
"all left_shoulder hip rear lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
354 goat.
addPair(n7[3], n1[4],
tgString(
"all left_shoulder hip front lower muscleAct1 seg", 7) +
tgString(
" seg", 1));
355 goat.
addPair(n7[3], n0[1],
tgString(
"all left_shoulder front bottom muscleAct1 seg", 7) +
tgString(
" seg", 0));
356 goat.
addPair(n7[3], n2[4],
tgString(
"all left_shoulder hip rear bottom muscleAct1 seg", 7) +
tgString(
" seg", 2));
359 goat.
addPair(n7[0], n1[1],
tgString(
"all left_shoulder hip rear mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
360 goat.
addPair(n7[0], n1[4],
tgString(
"all left_shoulder hip front mid muscleAct1 seg", 7) +
tgString(
" seg", 1));
378 goat.
addPair(n9[1], n1[2],
tgString(
"all right_shoulder hip rear upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
379 goat.
addPair(n9[1], n1[3],
tgString(
"all right_shoulder hip front upper muscleAct1 seg", 9) +
tgString(
" seg", 1));
380 goat.
addPair(n9[1], n0[2],
tgString(
"all right_shoulder hip front top muscleAct1 seg", 9) +
tgString(
" seg", 0));
381 goat.
addPair(n9[1], n2[3],
tgString(
"all right_shoulder hip rear top muscleAct1 seg", 9) +
tgString(
" seg", 2));
383 goat.
addPair(n9[3], n1[2],
tgString(
"all right_shoulder hip rear lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
384 goat.
addPair(n9[3], n1[3],
tgString(
"all right_shoulder hip front lower muscleAct1 seg", 9) +
tgString(
" seg", 1));
385 goat.
addPair(n9[3], n0[1],
tgString(
"all right_shoulder hip front bottom muscleAct1 seg", 9) +
tgString(
" seg", 0));
386 goat.
addPair(n9[3], n2[4],
tgString(
"all right_shoulder hip rear bottom muscleAct1 seg", 9) +
tgString(
" seg", 2));
389 goat.
addPair(n9[0], n1[2],
tgString(
"all right_shoulder hip rear mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
390 goat.
addPair(n9[0], n1[3],
tgString(
"all right_shoulder hip front mid muscleAct1 seg", 9) +
tgString(
" seg", 1));
412 goat.
addPair(n11[4], n1[4],
tgString(
"all left_foreleg front abdomen connection muscle seg", 11) +
tgString(
" seg", 1));
413 goat.
addPair(n11[3], n1[1],
tgString(
"all left_foreleg front abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
414 goat.
addPair(n11[2], n1[4],
tgString(
"all left_foreleg rear abdomen connection muscle3 seg", 11) +
tgString(
" seg", 1));
419 goat.
addPair(n11[2], n7[3],
tgString(
"all left_foreleg outer front tricep muscle seg", 11) +
tgString(
" seg", 7));
420 goat.
addPair(n11[2], n7[2],
tgString(
"all left_foreleg inner front tricep muscle seg", 11) +
tgString(
" seg", 7));
428 goat.
addPair(n13[4], n1[3],
tgString(
"all right_foreleg front abdomen connection muscle seg", 13) +
tgString(
" seg", 1));
429 goat.
addPair(n13[3], n1[2],
tgString(
"all right_foreleg front abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
430 goat.
addPair(n13[2], n1[3],
tgString(
"all right_foreleg rear abdomen connection muscle3 seg", 13) +
tgString(
" seg", 1));
436 goat.
addPair(n13[2], n9[2],
tgString(
"all right_foreleg inner front tricep muscle seg", 13) +
tgString(
" seg", 9));
437 goat.
addPair(n13[2], n9[3],
tgString(
"all right_foreleg outer front tricep muscle seg", 13) +
tgString(
" seg", 9));
446 goat.
addPair(n12[4], n3[1],
tgString(
"all left_hindleg rear abdomen connection muscle seg", 12) +
tgString(
" seg", 3));
447 goat.
addPair(n12[3], n5[1],
tgString(
"all left_hindleg front abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
448 goat.
addPair(n12[2], n5[4],
tgString(
"all left_hindleg rear abdomen connection muscle3 seg", 12) +
tgString(
" seg", 5));
453 goat.
addPair(n12[2], n8[3],
tgString(
"all left_hindleg outer front calf muscle seg", 12) +
tgString(
" seg", 8));
454 goat.
addPair(n12[2], n8[2],
tgString(
"all left_hindleg inner front calf muscle seg", 12) +
tgString(
" seg", 8));
463 goat.
addPair(n14[4], n3[2],
tgString(
"all right_hindleg rear abdomen connection muscle seg", 14) +
tgString(
" seg", 3));
464 goat.
addPair(n14[3], n5[2],
tgString(
"all right_hindleg front abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
465 goat.
addPair(n14[2], n5[3],
tgString(
"all right_hindleg rear abdomen connection muscle3 seg", 14) +
tgString(
" seg", 5));
471 goat.
addPair(n14[2], n10[2],
tgString(
"all right_hindleg inner front calf muscle seg", 14) +
tgString(
" seg", 10));
472 goat.
addPair(n14[2], n10[3],
tgString(
"all right_hindleg outer front calf muscle seg", 14) +
tgString(
" seg", 10));
475 goat.
addPair(n14[4], n10[1],
tgString(
"all right_hindleg central thigh muscle3 seg", 14) +
tgString(
" seg", 10));
482 const double density = 4.2/300.0;
483 const double radius = 0.5;
484 const double rod_space = 10.0;
485 const double rod_space2 = 8.0;
486 const double friction = 0.5;
487 const double rollFriction = 0.0;
488 const double restitution = 0.0;
490 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
492 const double stiffness = 1000.0;
493 const double stiffnessPassive = 5000.0;
494 const double stiffnessPassive2 = 4000.0;
495 const double stiffnessPassive3 = 10000.0;
496 const double damping = .01*stiffness;
497 const double pretension = 0.0;
498 const bool history =
true;
499 const double maxTens = 7000.0;
500 const double maxSpeed = 12.0;
502 const double passivePretension = 1000;
503 const double passivePretension2 = 3500;
504 const double passivePretension3 = 3500;
505 const double passivePretension4 = 5000.0;
509 const double mRad = 1.0;
510 const double motorFriction = 10.0;
511 const double motorInertia = 1.0;
512 const bool backDrivable =
false;
513 #ifdef PASSIVE_STRUCTURE
515 mRad, motorFriction, motorInertia, backDrivable,
516 history, maxTens, maxSpeed);
518 mRad, motorFriction, motorInertia, backDrivable,
519 history, maxTens, maxSpeed);
522 mRad, motorFriction, motorInertia, backDrivable,
523 history, maxTens, maxSpeed);
525 mRad, motorFriction, motorInertia, backDrivable,
526 history, maxTens, maxSpeed);
529 mRad, motorFriction, motorInertia, backDrivable,
530 history, maxTens, maxSpeed);
533 mRad, motorFriction, motorInertia, backDrivable,
534 history, maxTens, maxSpeed);
537 mRad, motorFriction, motorInertia, backDrivable,
538 history, maxTens, maxSpeed);
540 mRad, motorFriction, motorInertia, backDrivable,
541 history, maxTens, maxSpeed);
546 #ifdef PASSIVE_STRUCTURE
563 addNodesLeg(leg,rod_space);
568 addNodesVertebra(vertebra,rod_space);
569 addRodsVertebra(vertebra);
573 addNodesHip(hip,rod_space);
579 const double yOffset_foot = -(2*rod_space+6);
581 addSegments(goat,vertebra,hip,leg,rod_space);
583 goat.move(btVector3(0.0,-yOffset_foot,0.0));
587 std::vector<tgStructure*> children = goat.
getChildren();
591 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
595 #ifdef PASSIVE_STRUCTURE
609 #ifdef PASSIVE_STRUCTURE
633 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
635 m_allSegments = this->find<tgModel> (
"segment");
648 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)
virtual void setup(tgWorld &world)
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.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
Implementing MountainGoat, but as a subclass of Brian's BaseSpineModelLearning module. Seeing what will happen when the number of actuators is reduced, and their placement has changed.
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")