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){
103 void BigPuppySymmetricSpiral2::addRodsLeg(
tgStructure& s){
117 void BigPuppySymmetricSpiral2::addNodesHip(
tgStructure& s,
double r){
124 void BigPuppySymmetricSpiral2::addRodsHip(
tgStructure& s){
130 void BigPuppySymmetricSpiral2::addNodesVertebra(
tgStructure& s,
double r){
138 void BigPuppySymmetricSpiral2::addRodsVertebra(
tgStructure& s){
146 const double offsetDist = r+1;
147 const double offsetDist2 = offsetDist*6;
148 const double offsetDist3 = offsetDist2+2;
149 const double yOffset_leg = -(2*r+1);
150 const double yOffset_foot = -(2*r+6);
153 btVector3 offset(offsetDist,0.0,0);
155 btVector3 offset1(offsetDist*2,0.0,offsetDist);
156 btVector3 offset2(offsetDist2,0.0,offsetDist);
157 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
158 btVector3 offset4(offsetDist2,0.0,-offsetDist);
160 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
161 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
162 btVector3 offset7(r*2,yOffset_leg,offsetDist);
163 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
165 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
166 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
167 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
168 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
170 for(std::size_t i = 0; i < m_segments; i++) {
172 t->addTags(
tgString(
"spine segment num", i + 1));
173 t->move((i + 1)*offset);
177 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
182 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
189 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
191 t->addTags(
tgString(
"segment num", i + 1));
195 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
200 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
206 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
208 t->addTags(
tgString(
"segment num", i + 1));
221 for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {
223 t->addTags(
tgString(
"segment num", i + 1));
227 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
232 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
241 for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {
243 t->addTags(
tgString(
"segment num", i + 1));
247 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
252 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
293 void BigPuppySymmetricSpiral2::addMuscles(
tgStructure& puppy){
295 std::vector<tgStructure*> children = puppy.
getChildren();
296 for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
298 tgNodes n0 = children[i-2]->getNodes();
299 tgNodes n1 = children[i-1]->getNodes();
300 tgNodes n2 = children[i]->getNodes();
355 if (i >= 2 && i < 7){
389 tgNodes n0 = children[0]->getNodes();
390 tgNodes n1 = children[1]->getNodes();
391 tgNodes n2 = children[2]->getNodes();
392 tgNodes n3 = children[3]->getNodes();
393 tgNodes n4 = children[4]->getNodes();
394 tgNodes n5 = children[5]->getNodes();
395 tgNodes n6 = children[6]->getNodes();
396 tgNodes n7 = children[7]->getNodes();
397 tgNodes n8 = children[8]->getNodes();
398 tgNodes n9 = children[9]->getNodes();
399 tgNodes n10 = children[10]->getNodes();
400 tgNodes n11 = children[11]->getNodes();
401 tgNodes n12 = children[12]->getNodes();
402 tgNodes n13 = children[13]->getNodes();
403 tgNodes n14 = children[14]->getNodes();
470 puppy.
addPair(n11[4], n1[4],
tgString(
"right_front_leg front abdomen connection muscle seg", 10) +
tgString(
" seg", 1));
471 puppy.
addPair(n11[3], n1[1],
tgString(
"right_front_leg front abdomen connection muscle3 seg", 11) +
tgString(
" seg", 5));
472 puppy.
addPair(n11[2], n1[4],
tgString(
"right_front_leg abdomen connection muscle3 seg", 11) +
tgString(
" seg", 5));
477 puppy.
addPair(n11[2], n7[3],
tgString(
"right_front_leg outer front tricep muscle seg", 10) +
tgString(
" seg", 6));
478 puppy.
addPair(n11[2], n7[2],
tgString(
"right_front_leg inner front tricep muscle seg", 10) +
tgString(
" seg", 6));
489 puppy.
addPair(n13[4], n1[3],
tgString(
"left_front_leg front abdomen connection muscle seg", 12) +
tgString(
" seg", 1));
490 puppy.
addPair(n13[3], n1[2],
tgString(
"left_front_leg front abdomen connection muscle3 seg", 13) +
tgString(
" seg", 5));
491 puppy.
addPair(n13[2], n1[3],
tgString(
"left_front_leg abdomen connection muscle3 seg", 13) +
tgString(
" seg", 5));
496 puppy.
addPair(n13[2], n9[3],
tgString(
"left_front_leg outer front tricep muscle seg", 12) +
tgString(
" seg", 8));
497 puppy.
addPair(n13[2], n9[2],
tgString(
"left_front_leg inner front tricep muscle seg", 12) +
tgString(
" seg", 8));
509 puppy.
addPair(n12[4], n3[1],
tgString(
"right_hind_leg rear abdomen connection muscle seg", 11) +
tgString(
" seg", 3));
510 puppy.
addPair(n12[3], n5[1],
tgString(
"right_hind_leg rear abdomen connection muscle3 seg", 11) +
tgString(
" seg", 5));
511 puppy.
addPair(n12[2], n5[4],
tgString(
"right_hind_leg rear abdomen connection muscle3 seg", 11) +
tgString(
" seg", 5));
516 puppy.
addPair(n12[2], n8[3],
tgString(
"right_hind_leg outer front calf muscle seg", 11) +
tgString(
" seg", 7));
517 puppy.
addPair(n12[2], n8[2],
tgString(
"right_hind_leg inner front calf muscle seg", 11) +
tgString(
" seg", 7));
530 puppy.
addPair(n14[4], n3[2],
tgString(
"left_hind_leg rear abdomen connection muscle seg", 13) +
tgString(
" seg", 3));
531 puppy.
addPair(n14[3], n5[2],
tgString(
"left_hind_leg rear abdomen connection muscle3 seg", 13) +
tgString(
" seg", 5));
532 puppy.
addPair(n14[2], n5[3],
tgString(
"left_hind_leg rear abdomen connection muscle3 seg", 13) +
tgString(
" seg", 5));
537 puppy.
addPair(n14[2], n10[3],
tgString(
"left_hind_leg outer front calf muscle seg", 13) +
tgString(
" seg", 9));
538 puppy.
addPair(n14[2], n10[2],
tgString(
"left_hind_leg inner front calf muscle seg", 13) +
tgString(
" seg", 9));
552 puppy.
addPair(n6[3], n11[0],
tgString(
"right front leg_to spine middle muscleAct seg", 11) +
tgString(
" seg", 7));
553 puppy.
addPair(n0[2], n12[0],
tgString(
"right hind leg_to spine middle muscleAct seg", 11) +
tgString(
" seg", 7));
554 puppy.
addPair(n6[3], n13[0],
tgString(
"left front leg_to spine middle muscleAct seg", 11) +
tgString(
" seg", 7));
555 puppy.
addPair(n0[2], n14[0],
tgString(
"left hind leg_to spine middle muscleAct seg", 11) +
tgString(
" seg", 7));
560 puppy.
addPair(n11[5], n7[2],
tgString(
"right front leg_to inner extra muscleAct seg", 11) +
tgString(
" seg", 7));
561 puppy.
addPair(n11[5], n7[3],
tgString(
"right front leg_to inner extra muscleAct seg", 11) +
tgString(
" seg", 7));
606 const double density = 4.2/300.0;
607 const double radius = 0.5;
608 const double rod_space = 10.0;
609 const double rod_space2 = 8.0;
610 const double friction = 1;
611 const double rollFriction = 0.0;
612 const double restitution = 0.0;
614 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
616 const double stiffness = 1000.0;
617 const double stiffnessPassive = 2000.0;
618 const double stiffnessPassive2 = 10000.0;
619 const double damping = .01*stiffness;
620 const double pretension = 0.0;
621 const bool history =
true;
622 const double maxTens = 10000000.0;
623 const double maxSpeed = 1000000.0;
625 const double passivePretension = 1000;
626 const double passivePretension2 = 1000;
627 const double passivePretension3 = 3500;
628 const double passivePretension4 = 4000;
632 const double mRad = 1.0;
633 const double motorFriction = 10.0;
634 const double motorInertia = 1.0;
635 const bool backDrivable =
false;
636 #ifdef PASSIVE_STRUCTURE
638 mRad, motorFriction, motorInertia, backDrivable,
639 history, maxTens, maxSpeed);
642 mRad, motorFriction, motorInertia, backDrivable,
643 history, maxTens, maxSpeed);
646 mRad, motorFriction, motorInertia, backDrivable,
647 history, maxTens, maxSpeed);
649 mRad, motorFriction, motorInertia, backDrivable,
650 history, maxTens, maxSpeed);
653 mRad, motorFriction, motorInertia, backDrivable,
654 history, maxTens, maxSpeed);
657 mRad, motorFriction, motorInertia, backDrivable,
658 history, maxTens, maxSpeed);
661 mRad, motorFriction, motorInertia, backDrivable,
662 history, maxTens, maxSpeed);
664 mRad, motorFriction, motorInertia, backDrivable,
665 history, maxTens, maxSpeed);
670 #ifdef PASSIVE_STRUCTURE
688 addNodesFoot(foot,rod_space,rod_space2);
693 addNodesLeg(leg,rod_space);
698 addNodesVertebra(vertebra,rod_space);
699 addRodsVertebra(vertebra);
703 addNodesHip(hip,rod_space);
709 const double yOffset_foot = -(2*rod_space+6);
711 addSegments(puppy,vertebra,hip,leg,rod_space);
713 puppy.move(btVector3(0.0,-yOffset_foot+2,0.0));
718 std::vector<tgStructure*> children = puppy.
getChildren();
722 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
726 #ifdef PASSIVE_STRUCTURE
740 #ifdef PASSIVE_STRUCTURE
760 structureInfo.buildInto(*
this, world);
764 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
766 m_allSegments = this->find<tgModel> (
"spine segment");
779 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="")