30 #include "BigPuppySymmetricSpiral2.h"
50 #include "LinearMath/btVector3.h"
56 #define PASSIVE_STRUCTURE
58 BigPuppySymmetricSpiral2::BigPuppySymmetricSpiral2(
int segments,
int hips,
int legs,
int feet) :
66 BigPuppySymmetricSpiral2::~BigPuppySymmetricSpiral2()
70 void BigPuppySymmetricSpiral2::addNodesFoot(
tgStructure& s,
double r1,
double r2){
81 void BigPuppySymmetricSpiral2::addRodsFoot(
tgStructure& s){
88 void BigPuppySymmetricSpiral2::addNodesLeg(
tgStructure& s,
double r){
97 void BigPuppySymmetricSpiral2::addRodsLeg(
tgStructure& s){
105 void BigPuppySymmetricSpiral2::addNodesHip(
tgStructure& s,
double r){
112 void BigPuppySymmetricSpiral2::addRodsHip(
tgStructure& s){
118 void BigPuppySymmetricSpiral2::addNodesVertebra(
tgStructure& s,
double r){
126 void BigPuppySymmetricSpiral2::addRodsVertebra(
tgStructure& s){
134 const double offsetDist = r+1;
135 const double offsetDist2 = offsetDist*6;
136 const double offsetDist3 = offsetDist2+2;
137 const double yOffset_leg = -(2*r+1);
138 const double yOffset_foot = -(2*r+6);
141 btVector3 offset(offsetDist,0.0,0);
143 btVector3 offset1(offsetDist*2,0.0,offsetDist);
144 btVector3 offset2(offsetDist2,0.0,offsetDist);
145 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
146 btVector3 offset4(offsetDist2,0.0,-offsetDist);
148 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
149 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
150 btVector3 offset7(r*2,yOffset_leg,offsetDist);
151 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
153 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
154 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
155 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
156 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
158 for(std::size_t i = 0; i < m_segments; i++) {
160 t->addTags(
tgString(
"spine segment num", i + 1));
161 t->move((i + 1)*offset);
165 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
170 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
177 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
179 t->addTags(
tgString(
"segment num", i + 1));
183 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
188 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
194 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
196 t->addTags(
tgString(
"segment num", i + 1));
209 for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {
211 t->addTags(
tgString(
"segment num", i + 1));
215 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
220 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
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);
281 void BigPuppySymmetricSpiral2::addMuscles(
tgStructure& puppy){
283 std::vector<tgStructure*> children = puppy.
getChildren();
284 for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
286 tgNodes n0 = children[i-2]->getNodes();
287 tgNodes n1 = children[i-1]->getNodes();
288 tgNodes n2 = children[i]->getNodes();
343 if (i >= 2 && i < 7){
377 tgNodes n0 = children[0]->getNodes();
378 tgNodes n1 = children[1]->getNodes();
379 tgNodes n2 = children[2]->getNodes();
380 tgNodes n3 = children[3]->getNodes();
381 tgNodes n4 = children[4]->getNodes();
382 tgNodes n5 = children[5]->getNodes();
383 tgNodes n6 = children[6]->getNodes();
384 tgNodes n7 = children[7]->getNodes();
385 tgNodes n8 = children[8]->getNodes();
386 tgNodes n9 = children[9]->getNodes();
387 tgNodes n10 = children[10]->getNodes();
388 tgNodes n11 = children[11]->getNodes();
389 tgNodes n12 = children[12]->getNodes();
390 tgNodes n13 = children[13]->getNodes();
391 tgNodes n14 = children[14]->getNodes();
458 puppy.
addPair(n11[4], n1[4],
tgString(
"right front leg front abdomen connection muscle seg", 10) +
tgString(
" seg", 1));
459 puppy.
addPair(n11[3], n1[1],
tgString(
"right front leg front abdomen connection muscle seg", 11) +
tgString(
" seg", 5));
460 puppy.
addPair(n11[2], n1[4],
tgString(
"right front leg abdomen connection muscle seg", 11) +
tgString(
" seg", 5));
465 puppy.
addPair(n11[2], n7[3],
tgString(
"right front leg outer front tricep muscle seg", 10) +
tgString(
" seg", 6));
466 puppy.
addPair(n11[2], n7[2],
tgString(
"right front leg inner front tricep muscle seg", 10) +
tgString(
" seg", 6));
474 puppy.
addPair(n13[4], n1[3],
tgString(
"left front leg front abdomen connection muscle seg", 12) +
tgString(
" seg", 1));
475 puppy.
addPair(n13[3], n1[2],
tgString(
"left front leg front abdomen connection muscle seg", 13) +
tgString(
" seg", 5));
476 puppy.
addPair(n13[2], n1[3],
tgString(
"left front leg front abdomen connection muscle seg", 13) +
tgString(
" seg", 5));
481 puppy.
addPair(n13[2], n9[2],
tgString(
"left front leg inner front tricep muscle seg", 12) +
tgString(
" seg", 8));
482 puppy.
addPair(n13[2], n9[3],
tgString(
"left front leg outer front tricep muscle seg", 12) +
tgString(
" seg", 8));
491 puppy.
addPair(n12[4], n3[1],
tgString(
"right hind leg rear abdomen connection muscle seg", 11) +
tgString(
" seg", 3));
492 puppy.
addPair(n12[3], n5[1],
tgString(
"right hind leg rear abdomen connection muscle seg", 11) +
tgString(
" seg", 5));
493 puppy.
addPair(n12[2], n5[4],
tgString(
"right hind leg rear abdomen connection muscle seg", 11) +
tgString(
" seg", 5));
498 puppy.
addPair(n12[2], n8[3],
tgString(
"right hind leg outer front calf muscle seg", 11) +
tgString(
" seg", 7));
499 puppy.
addPair(n12[2], n8[2],
tgString(
"right hind leg inner front calf muscle seg", 11) +
tgString(
" seg", 7));
508 puppy.
addPair(n14[4], n3[2],
tgString(
"left hind leg rear abdomen connection muscle seg", 13) +
tgString(
" seg", 3));
509 puppy.
addPair(n14[3], n5[2],
tgString(
"left hind leg rear abdomen connection muscle seg", 13) +
tgString(
" seg", 5));
510 puppy.
addPair(n14[2], n5[3],
tgString(
"left hind leg rear abdomen connection muscle seg", 13) +
tgString(
" seg", 5));
515 puppy.
addPair(n14[2], n10[2],
tgString(
"left hind leg inner front calf muscle seg", 13) +
tgString(
" seg", 9));
516 puppy.
addPair(n14[2], n10[3],
tgString(
"left hind leg outer front calf muscle seg", 13) +
tgString(
" seg", 9));
557 const double density = 4.2/300.0;
558 const double radius = 0.5;
559 const double rod_space = 10.0;
560 const double rod_space2 = 8.0;
561 const double friction = 0.5;
562 const double rollFriction = 0.0;
563 const double restitution = 0.0;
565 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
567 const double stiffness = 1000.0;
568 const double stiffnessPassive = 4000.0;
569 const double damping = .01*stiffness;
570 const double pretension = 0.0;
571 const bool history =
true;
572 const double maxTens = 7000.0;
573 const double maxSpeed = 12.0;
575 const double passivePretension = 1000;
576 const double passivePretension2 = 3500;
577 const double passivePretension3 = 3500;
581 const double mRad = 1.0;
582 const double motorFriction = 10.0;
583 const double motorInertia = 1.0;
584 const bool backDrivable =
false;
585 #ifdef PASSIVE_STRUCTURE
587 mRad, motorFriction, motorInertia, backDrivable,
588 history, maxTens, maxSpeed);
591 mRad, motorFriction, motorInertia, backDrivable,
592 history, maxTens, maxSpeed);
595 mRad, motorFriction, motorInertia, backDrivable,
596 history, maxTens, maxSpeed);
598 mRad, motorFriction, motorInertia, backDrivable,
599 history, maxTens, maxSpeed);
602 mRad, motorFriction, motorInertia, backDrivable,
603 history, maxTens, maxSpeed);
606 mRad, motorFriction, motorInertia, backDrivable,
607 history, maxTens, maxSpeed);
610 mRad, motorFriction, motorInertia, backDrivable,
611 history, maxTens, maxSpeed);
613 mRad, motorFriction, motorInertia, backDrivable,
614 history, maxTens, maxSpeed);
619 #ifdef PASSIVE_STRUCTURE
637 addNodesFoot(foot,rod_space,rod_space2);
642 addNodesLeg(leg,rod_space);
647 addNodesVertebra(vertebra,rod_space);
648 addRodsVertebra(vertebra);
652 addNodesHip(hip,rod_space);
658 const double yOffset_foot = -(2*rod_space+6);
660 addSegments(puppy,vertebra,hip,leg,rod_space);
662 puppy.move(btVector3(0.0,-yOffset_foot,0.0));
667 std::vector<tgStructure*> children = puppy.
getChildren();
671 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
675 #ifdef PASSIVE_STRUCTURE
689 #ifdef PASSIVE_STRUCTURE
709 structureInfo.buildInto(*
this, world);
713 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
715 m_allSegments = this->find<tgModel> (
"spine segment");
728 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
virtual void step(double dt)
Convenience function for combining strings with ints, mostly for naming structures.
virtual void setup(tgWorld &world)
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.
Contains the definition of class tgSimView.
Definition of class tgKinematicActuatorInfo.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
virtual void step(double dt)
virtual void setup(tgWorld &world)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")