50 #include "LinearMath/btVector3.h"
56 #define PASSIVE_STRUCTURE
58 BigPuppy::BigPuppy() :
67 void BigPuppy::addNodesFoot(
tgStructure& s,
double r1,
double r2){
85 void BigPuppy::addNodesLeg(
tgStructure& s,
double r){
102 void BigPuppy::addNodesHip(
tgStructure& s,
double r){
115 void BigPuppy::addNodesVertebra(
tgStructure& s,
double r){
131 double r, std::size_t segments, std::size_t hips, std::size_t legs, std::size_t feet){
132 const double offsetDist = r+1;
133 const double offsetDist2 = r*5+8;
134 const double offsetDist3 = r*6;
135 const double yOffset_leg = -(2*r+1);
136 const double yOffset_foot = -(2*r+6);
139 btVector3 offset(offsetDist,0.0,0);
141 btVector3 offset1(offsetDist*2,0.0,offsetDist);
142 btVector3 offset2(offsetDist2,0.0,offsetDist);
143 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
144 btVector3 offset4(offsetDist2,0.0,-offsetDist);
146 btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
147 btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
148 btVector3 offset7(r*2,yOffset_leg,offsetDist);
149 btVector3 offset8(r*2,yOffset_leg,-offsetDist);
151 btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
152 btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
153 btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
154 btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
156 for(std::size_t i = 0; i < segments; i++) {
158 t->addTags(
tgString(
"segment num", i + 1));
159 t->move((i + 1)*offset);
163 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
168 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
175 for(std::size_t i = segments; i < (segments + 2); i++) {
177 t->addTags(
tgString(
"segment num", i + 1));
181 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
185 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
191 for(std::size_t i = (segments + 2); i < (segments + hips); i++) {
193 t->addTags(
tgString(
"segment num", i + 1));
206 for(std::size_t i = (segments + hips); i < (segments + hips + 2); i++) {
208 t->addTags(
tgString(
"segment num", i + 1));
212 t->
addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
218 t->
addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
224 for(std::size_t i = (segments + hips + 2); i < (segments + hips + legs); i++) {
226 t->addTags(
tgString(
"segment num", i + 1));
230 t->
addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
234 t->
addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
240 for(std::size_t i = (segments + hips + legs); i < (segments + hips + legs + 2); i++) {
242 t->addTags(
tgString(
"segment num", i + 1));
246 t->
addRotation(btVector3(r*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
250 t->
addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
256 for(std::size_t i = (segments + hips + legs + 2); i < (segments + hips + legs + feet); i++) {
258 t->addTags(
tgString(
"segment num", i + 1));
262 t->
addRotation(btVector3(r*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
266 t->
addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
273 void BigPuppy::addMuscles(
tgStructure& puppy, std::size_t segments, std::size_t hips, std::size_t legs, std::size_t feet){
275 std::vector<tgStructure*> children = puppy.
getChildren();
276 for(std::size_t i = 2; i < (children.size() - (hips + legs + feet)); i++) {
278 tgNodes n0 = children[i-2]->getNodes();
279 tgNodes n1 = children[i-1]->getNodes();
280 tgNodes n2 = children[i]->getNodes();
349 tgNodes n0 = children[0]->getNodes();
350 tgNodes n1 = children[1]->getNodes();
351 tgNodes n2 = children[2]->getNodes();
352 tgNodes n3 = children[3]->getNodes();
353 tgNodes n4 = children[4]->getNodes();
354 tgNodes n5 = children[5]->getNodes();
355 tgNodes n6 = children[6]->getNodes();
356 tgNodes n7 = children[7]->getNodes();
357 tgNodes n8 = children[8]->getNodes();
358 tgNodes n9 = children[9]->getNodes();
359 tgNodes n10 = children[10]->getNodes();
360 tgNodes n11 = children[11]->getNodes();
361 tgNodes n12 = children[12]->getNodes();
362 tgNodes n13 = children[13]->getNodes();
488 for(std::size_t i = (segments + hips + legs); i < children.size(); i++) {
489 tgNodes ni = children[i]->getNodes();
490 tgNodes ni4 = children[i-4]->getNodes();
523 const double density = 4.2/300.0;
524 const double radius = 0.5;
525 const double rod_space = 10.0;
526 const double rod_space2 = 8.0;
527 const double friction = 0.5;
528 const double rollFriction = 0.0;
529 const double restitution = 0.0;
531 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
533 const double stiffness = 1000.0;
534 const double damping = .01*stiffness;
535 const double pretension = 0.0;
536 const bool history =
false;
537 const double maxTens = 7000.0;
538 const double maxSpeed = 12.0;
540 const double passivePretension = 700;
544 const double mRad = 1.0;
545 const double motorFriction = 10.0;
546 const double motorInertia = 1.0;
547 const bool backDrivable =
false;
548 #ifdef PASSIVE_STRUCTURE
550 mRad, motorFriction, motorInertia, backDrivable,
551 history, maxTens, maxSpeed);
554 mRad, motorFriction, motorInertia, backDrivable,
555 history, maxTens, maxSpeed);
560 #ifdef PASSIVE_STRUCTURE
573 addNodesFoot(foot,rod_space,rod_space2);
578 addNodesLeg(leg,rod_space);
583 addNodesVertebra(vertebra,rod_space);
584 addRodsVertebra(vertebra);
588 addNodesHip(hip,rod_space);
594 std::size_t m_segments = 6;
595 std::size_t m_hips = 4;
596 std::size_t m_legs = 4;
597 std::size_t m_feet = 4;
598 const double yOffset_foot = -(2*rod_space+6);
600 addSegments(puppy,vertebra,hip,leg,foot,rod_space,m_segments,m_hips,m_legs,m_feet);
602 puppy.move(btVector3(0.0,-yOffset_foot,0.0));
604 addMuscles(puppy,m_segments,m_hips,m_legs,m_feet);
607 std::vector<tgStructure*> children = puppy.
getChildren();
611 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
623 structureInfo.buildInto(*
this, world);
627 allActuators = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
643 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)
const std::vector< tgSpringCableActuator * > & getAllActuators() const
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.
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="")