51 #include "LinearMath/btVector3.h"
57 #define PASSIVE_STRUCTURE
59 BigPuppy::BigPuppy() :
68 void BigPuppy::addNodesFoot(
tgStructure& s,
double r1,
double r2){
86 void BigPuppy::addNodesLeg(
tgStructure& s,
double r){
103 void BigPuppy::addNodesHip(
tgStructure& s,
double r){
116 void BigPuppy::addNodesVertebra(
tgStructure& s,
double r){
132 double r, std::size_t segments, std::size_t hips, std::size_t legs, std::size_t feet){
133 const double offsetDist = r+1;
134 const double offsetDist2 = r*5+8;
135 const double offsetDist3 = r*6;
136 const double yOffset_leg = -(2*r+1);
137 const double yOffset_foot = -(2*r+6);
140 btVector3 offset(offsetDist,0.0,0);
142 btVector3 offset1(offsetDist*2,0.0,offsetDist);
143 btVector3 offset2(offsetDist2,0.0,offsetDist);
144 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
145 btVector3 offset4(offsetDist2,0.0,-offsetDist);
147 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
148 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
149 btVector3 offset7(r*2,yOffset_leg,offsetDist);
150 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
152 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
153 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
154 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
155 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
157 for(std::size_t i = 0; i < segments; i++) {
159 t->addTags(
tgString(
"segment num", i + 1));
160 t->move((i + 1)*offset);
164 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
169 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
176 for(std::size_t i = segments; i < (segments + 2); i++) {
178 t->addTags(
tgString(
"segment num", i + 1));
182 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
186 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
192 for(std::size_t i = (segments + 2); i < (segments + hips); i++) {
194 t->addTags(
tgString(
"segment num", i + 1));
207 for(std::size_t i = (segments + hips); i < (segments + hips + 2); i++) {
209 t->addTags(
tgString(
"segment num", i + 1));
213 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
219 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
225 for(std::size_t i = (segments + hips + 2); i < (segments + hips + legs); i++) {
227 t->addTags(
tgString(
"segment num", i + 1));
231 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
235 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
241 for(std::size_t i = (segments + hips + legs); i < (segments + hips + legs + 2); i++) {
243 t->addTags(
tgString(
"segment num", i + 1));
247 t->
addRotation(btVector3(r*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
251 t->
addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
257 for(std::size_t i = (segments + hips + legs + 2); i < (segments + hips + legs + feet); i++) {
259 t->addTags(
tgString(
"segment num", i + 1));
263 t->
addRotation(btVector3(r*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
267 t->
addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
274 void BigPuppy::addMuscles(
tgStructure& puppy, std::size_t segments, std::size_t hips, std::size_t legs, std::size_t feet){
276 std::vector<tgStructure*> children = puppy.
getChildren();
277 for(std::size_t i = 2; i < (children.size() - (hips + legs + feet)); i++) {
279 tgNodes n0 = children[i-2]->getNodes();
280 tgNodes n1 = children[i-1]->getNodes();
281 tgNodes n2 = children[i]->getNodes();
350 tgNodes n0 = children[0]->getNodes();
351 tgNodes n1 = children[1]->getNodes();
352 tgNodes n2 = children[2]->getNodes();
353 tgNodes n3 = children[3]->getNodes();
354 tgNodes n4 = children[4]->getNodes();
355 tgNodes n5 = children[5]->getNodes();
356 tgNodes n6 = children[6]->getNodes();
357 tgNodes n7 = children[7]->getNodes();
358 tgNodes n8 = children[8]->getNodes();
359 tgNodes n9 = children[9]->getNodes();
360 tgNodes n10 = children[10]->getNodes();
361 tgNodes n11 = children[11]->getNodes();
362 tgNodes n12 = children[12]->getNodes();
363 tgNodes n13 = children[13]->getNodes();
489 for(std::size_t i = (segments + hips + legs); i < children.size(); i++) {
490 tgNodes ni = children[i]->getNodes();
491 tgNodes ni4 = children[i-4]->getNodes();
501 puppy.
addPair(ni[4],ni[5],
tgString(
"front left upper foot muscle seg", i));
502 puppy.
addPair(ni[4],ni[7],
tgString(
"front right upper foot muscle seg", i));
503 puppy.
addPair(ni[5],ni[6],
tgString(
"rear left upper foot muscle seg", i));
504 puppy.
addPair(ni[6],ni[7],
tgString(
"rear right upper foot muscle seg", i));
524 const double density = 4.2/300.0;
525 const double radius = 0.5;
526 const double rod_space = 10.0;
527 const double rod_space2 = 8.0;
528 const double friction = 0.5;
529 const double rollFriction = 0.0;
530 const double restitution = 0.0;
532 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
534 const double stiffness = 1000.0;
535 const double damping = .01*stiffness;
536 const double pretension = 0.0;
537 const bool history =
false;
538 const double maxTens = 7000.0;
539 const double maxSpeed = 12.0;
541 const double passivePretension = 1000;
543 const double passivePretension2 = 1000;
547 const double mRad = 1.0;
548 const double motorFriction = 10.0;
549 const double motorInertia = 1.0;
550 const bool backDrivable =
false;
551 #ifdef PASSIVE_STRUCTURE
553 mRad, motorFriction, motorInertia, backDrivable,
554 history, maxTens, maxSpeed);
558 mRad, motorFriction, motorInertia, backDrivable,
559 history, maxTens, maxSpeed);
564 #ifdef PASSIVE_STRUCTURE
578 addNodesFoot(foot,rod_space,rod_space2);
583 addNodesLeg(leg,rod_space);
588 addNodesVertebra(vertebra,rod_space);
589 addRodsVertebra(vertebra);
593 addNodesHip(hip,rod_space);
599 std::size_t m_segments = 6;
600 std::size_t m_hips = 4;
601 std::size_t m_legs = 4;
602 std::size_t m_feet = 4;
603 const double yOffset_foot = -(2*rod_space+6);
605 addSegments(puppy,vertebra,hip,leg,foot,rod_space,m_segments,m_hips,m_legs,m_feet);
607 puppy.move(btVector3(0.0,-yOffset_foot,0.0));
609 addMuscles(puppy,m_segments,m_hips,m_legs,m_feet);
612 std::vector<tgStructure*> children = puppy.
getChildren();
616 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
628 structureInfo.buildInto(*
this, world);
632 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
648 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
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 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.
Contains the definition of class tgSimView.
Definition of class tgKinematicActuatorInfo.
const std::vector< tgSpringCableActuator * > & getAllMuscles() const
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
void notifyStep(double dt)
virtual void setup(tgWorld &world)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")