37 #include "LinearMath/btVector3.h"
45 const int rodNumbersPerNode[13]={0,0,1,1,2,2,3,3,4,4,5,5,6};
48 const int otherEndOfTheRod[13]={6,7,8,4,3,11,0,1,2,10,9,5,12};
53 const int parallelNode[13]={1,0,5,9,10,2,7,6,11,3,4,8,12};
76 double stiffness_passive;
77 double stiffness_active;
87 double targetVelocity;
120 const double half_length = c.rod_length / 2;
122 nodePositions.push_back(btVector3(-c.rod_space, -half_length, 0));
123 nodePositions.push_back(btVector3(-c.rod_space, half_length, 0));
124 nodePositions.push_back(btVector3( c.rod_space, -half_length, 0));
125 nodePositions.push_back(btVector3( c.rod_space, half_length, 0));
126 nodePositions.push_back(btVector3(0, -c.rod_space, -half_length));
127 nodePositions.push_back(btVector3(0, -c.rod_space, half_length));
128 nodePositions.push_back(btVector3(0, c.rod_space, -half_length));
129 nodePositions.push_back(btVector3(0, c.rod_space, half_length));
130 nodePositions.push_back(btVector3(-half_length, 0, c.rod_space));
131 nodePositions.push_back(btVector3( half_length, 0, c.rod_space));
132 nodePositions.push_back(btVector3(-half_length, 0, -c.rod_space));
133 nodePositions.push_back(btVector3( half_length, 0, -c.rod_space));
135 for(
int i=0;i<nodePositions.size();i++)
137 s.
addNode(nodePositions[i][0],nodePositions[i][1],nodePositions[i][2]);
152 const int nNodes = 12;
153 std::vector <tgRod*> rods=find<tgRod>(
"rod");
155 for(
int i=0;i<nNodes;i++) {
156 const btRigidBody* bt = rods[rodNumbersPerNode[i]]->getPRigidBody();
157 btTransform inverseTransform = bt->getWorldTransform().inverse();
158 btVector3 pos = inverseTransform * (nodePositions[i]);
160 this->addMarker(tmp);
168 s.
addPair(0, 4,
"muscle_active");
169 s.
addPair(0, 5,
"muscle_passive");
170 s.
addPair(0, 8,
"muscle_active");
171 s.
addPair(0, 10,
"muscle_passive");
173 s.
addPair(1, 6,
"muscle_active");
174 s.
addPair(1, 7,
"muscle_passive");
175 s.
addPair(1, 8,
"muscle_passive");
176 s.
addPair(1, 10,
"muscle_active");
178 s.
addPair(2, 4,
"muscle_passive");
179 s.
addPair(2, 5,
"muscle_active");
180 s.
addPair(2, 9,
"muscle_active");
181 s.
addPair(2, 11,
"muscle_passive");
183 s.
addPair(3, 7,
"muscle_active");
184 s.
addPair(3, 6,
"muscle_passive");
185 s.
addPair(3, 9,
"muscle_passive");
186 s.
addPair(3, 11,
"muscle_active");
188 s.
addPair(4, 10,
"muscle_active");
189 s.
addPair(4, 11,
"muscle_passive");
191 s.
addPair(5, 8,
"muscle_active");
192 s.
addPair(5, 9,
"muscle_passive");
194 s.
addPair(6, 10,
"muscle_passive");
195 s.
addPair(6, 11,
"muscle_active");
197 s.
addPair(7, 8,
"muscle_passive");
198 s.
addPair(7, 9,
"muscle_active");
205 const tgRod::Config rodConfig(c.radius, c.density, c.friction,
206 c.rollFriction, c.restitution);
209 c.maxTens, c.targetVelocity);
212 c.maxTens, c.targetVelocity);
219 s.move(btVector3(0, 10, 0));
223 btVector3 rotationPoint = btVector3(0, 0, 0);
224 btVector3 rotationAxis = btVector3(0, 1, 0);
225 double rotationAngle = M_PI/2;
226 s.
addRotation(rotationPoint, rotationAxis, rotationAngle);
230 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
238 structureInfo.buildInto(*
this, world);
242 allMuscles = tgCast::filter<tgModel, tgBasicActuator> (
getDescendants());
256 btVector3 location(0.0,28.0,0);
257 btVector3 rotation(0.0,0.6,0.8);
258 btVector3 speed(0,0,0);
259 this->moveModel(location,rotation,speed);
267 throw std::invalid_argument(
"dt is not positive");
285 std::vector <tgRod*> rods = find<tgRod>(
"rod");
286 assert(!rods.empty());
288 btVector3 ballCenterOfMass(0, 0, 0);
289 double ballMass = 0.0;
290 for (std::size_t i = 0; i < rods.size(); i++) {
291 const tgRod*
const rod = rods[i];
293 const double rodMass = rod->
mass();
295 ballCenterOfMass += rodCenterOfMass * rodMass;
299 assert(ballMass > 0.0);
300 ballCenterOfMass /= ballMass;
303 std::vector<double> result(3);
304 for (
size_t i = 0; i < 3; ++i) { result[i] = ballCenterOfMass[i]; }
317 return passiveMuscles;
322 return activeMuscles;
327 return (c.stiffness_passive/c.stiffness_active);
336 void T6Model::moveModel(btVector3 positionVector,btVector3 rotationVector,btVector3 speedVector) {
337 std::vector<tgRod *> rods=find<tgRod>(
"rod");
339 btQuaternion initialRotationQuat;
340 initialRotationQuat.setEuler(rotationVector[0],rotationVector[1],rotationVector[2]);
341 btTransform initialTransform;
342 initialTransform.setIdentity();
343 initialTransform.setRotation(initialRotationQuat);
344 initialTransform.setOrigin(positionVector);
345 for(
int i=0;i<rods.size();i++) {
346 rods[i]->getPRigidBody()->setLinearVelocity(speedVector);
347 rods[i]->getPRigidBody()->setWorldTransform(initialTransform * rods[i]->getPRigidBody()->getWorldTransform());
virtual void setup(tgWorld &world)
Definition of class tgRodInfo.
std::vector< double > getBallCOM()
virtual void step(double dt)
virtual void onVisit(tgModelVisitor &r)
Markers for specific places on a tensegrity.
virtual btVector3 centerOfMass() const
const std::vector< tgBasicActuator * > & getAllMuscles() const
const std::vector< tgBasicActuator * > & getPassiveMuscles() const
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
virtual void setup(tgWorld &world)
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Contains the definition of class tgBasicActuator.
virtual void step(double dt)
Definition of class tgStructure.
Definition of class tgStructureInfo.
virtual double mass() const
const std::vector< tgBasicActuator * > & getActiveMuscles() const
virtual const double muscleRatio()
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")