30 #include "BigPuppySpineOnly.h"
50 #include "LinearMath/btVector3.h"
58 BigPuppySpineOnly::BigPuppySpineOnly(
int segments,
int hips) :
64 BigPuppySpineOnly::~BigPuppySpineOnly()
68 void BigPuppySpineOnly::addNodesHip(
tgStructure& s,
double r){
85 void BigPuppySpineOnly::addNodesVertebra(
tgStructure& s,
double r){
93 void BigPuppySpineOnly::addRodsVertebra(
tgStructure& s){
101 const double offsetDist = r+1;
102 const double offsetDist2 = offsetDist*6;
103 const double offsetDist3 = offsetDist2+2;
106 btVector3 offset(offsetDist,0.0,0);
108 btVector3 offset1(offsetDist*2,0.0,offsetDist);
109 btVector3 offset2(offsetDist2,0.0,offsetDist);
110 btVector3 offset3(offsetDist*2,0.0,-offsetDist);
111 btVector3 offset4(offsetDist2,0.0,-offsetDist);
114 for(std::size_t i = 0; i < m_segments; i++) {
116 t->addTags(
tgString(
"spine segment num", i + 1));
117 t->move((i + 1)*offset);
121 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
126 t->
addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
133 for(std::size_t i = m_segments; i < (m_segments + 2); i++) {
135 t->addTags(
tgString(
"segment num", i + 1));
139 t->
addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
144 t->
addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
150 for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {
152 t->addTags(
tgString(
"segment num", i + 1));
166 void BigPuppySpineOnly::addMuscles(
tgStructure& puppy){
168 std::vector<tgStructure*> children = puppy.
getChildren();
169 for(std::size_t i = 2; i < (children.size() - (m_hips)); i++) {
171 tgNodes n0 = children[i-2]->getNodes();
172 tgNodes n1 = children[i-1]->getNodes();
173 tgNodes n2 = children[i]->getNodes();
240 tgNodes n0 = children[0]->getNodes();
241 tgNodes n1 = children[1]->getNodes();
242 tgNodes n2 = children[2]->getNodes();
243 tgNodes n3 = children[3]->getNodes();
244 tgNodes n4 = children[4]->getNodes();
245 tgNodes n5 = children[5]->getNodes();
246 tgNodes n6 = children[6]->getNodes();
247 tgNodes n7 = children[7]->getNodes();
248 tgNodes n8 = children[8]->getNodes();
249 tgNodes n9 = children[9]->getNodes();
250 tgNodes n10 = children[10]->getNodes();
318 const double density = 4.2/300.0;
319 const double radius = 0.5;
320 const double rod_space = 10.0;
321 const double rod_space2 = 8.0;
322 const double friction = 0.5;
323 const double rollFriction = 0.0;
324 const double restitution = 0.0;
326 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
328 const double stiffness = 1000.0;
329 const double damping = .01*stiffness;
330 const double pretension = 0.0;
331 const bool history =
true;
332 const double maxTens = 7000.0;
333 const double maxSpeed = 12.0;
335 const double passivePretension = 1000;
339 const double mRad = 1.0;
340 const double motorFriction = 10.0;
341 const double motorInertia = 1.0;
342 const bool backDrivable =
false;
343 #ifdef PASSIVE_STRUCTURE
345 mRad, motorFriction, motorInertia, backDrivable,
346 history, maxTens, maxSpeed);
349 mRad, motorFriction, motorInertia, backDrivable,
350 history, maxTens, maxSpeed);
353 mRad, motorFriction, motorInertia, backDrivable,
354 history, maxTens, maxSpeed);
359 #ifdef PASSIVE_STRUCTURE
370 addNodesVertebra(vertebra,rod_space);
371 addRodsVertebra(vertebra);
375 addNodesHip(hip,rod_space);
383 addSegments(puppy,vertebra,hip,rod_space);
385 puppy.move(btVector3(0.0,12.0,0.0));
390 std::vector<tgStructure*> children = puppy.
getChildren();
394 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
398 #ifdef PASSIVE_STRUCTURE
406 #ifdef PASSIVE_STRUCTURE
425 m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
427 m_allSegments = this->find<tgModel> (
"spine segment");
440 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Convenience function for combining strings with ints, mostly for naming structures.
virtual void setup(tgWorld &world)
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...
virtual void step(double dt)
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)
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")