37 #include "LinearMath/btVector3.h"
69 double targetVelocity;
102 const int rodNumbersPerNode[13]={0,1,2,3,3,4,0,1,2,5,5,4,6};
105 const int otherEndOfTheRod[13]={6,7,8,4,3,11,0,1,2,10,9,5,12};
110 const int parallelNode[13]={1,0,5,9,10,2,7,6,11,3,4,8,12};
138 const double half_length = c.rod_length / 2;
140 nodePositions.push_back(btVector3(-half_length, c.rod_space, 0));
141 nodePositions.push_back(btVector3( half_length, c.rod_space, 0));
142 nodePositions.push_back(btVector3(0, half_length, -c.rod_space));
143 nodePositions.push_back(btVector3(-c.rod_space, 0, -half_length));
144 nodePositions.push_back(btVector3( c.rod_space, 0, -half_length));
145 nodePositions.push_back(btVector3(0, -half_length, -c.rod_space));
146 nodePositions.push_back(btVector3(-half_length, -c.rod_space, 0));
147 nodePositions.push_back(btVector3( half_length, -c.rod_space, 0));
148 nodePositions.push_back(btVector3(0, half_length, c.rod_space));
149 nodePositions.push_back(btVector3(-c.rod_space, 0, half_length));
150 nodePositions.push_back(btVector3( c.rod_space, 0, half_length));
151 nodePositions.push_back(btVector3(0, -half_length, c.rod_space));
153 for(
int i=0;i<12;i++)
155 s.
addNode(nodePositions[i][0],nodePositions[i][1],nodePositions[i][2]);
171 void T12SuperBallPayload::addMarkers(
tgStructure &s)
173 std::vector<tgRod *> rods=find<tgRod>(
"rod");
175 for(
int i=0;i<12;i++)
177 const btRigidBody* bt = rods[rodNumbersPerNode[i]]->getPRigidBody();
178 btTransform inverseTransform = bt->getWorldTransform().inverse();
179 btVector3 pos = inverseTransform * (nodePositions[i]);
181 this->addMarker(tmp);
185 void T12SuperBallPayload::addMuscles(
tgStructure& s)
188 int muscleConnections[13][13];
189 musclesPerNodes.resize(13);
190 for(
int i=0;i<13;i++)
192 musclesPerNodes[i].resize(13);
193 for(
int j=0;j<13;j++)
194 musclesPerNodes[i][j]=NULL;
196 for(
int i=0;i<13;i++)
197 for(
int j=0;j<13;j++)
198 muscleConnections[i][j]=-1;
200 muscleConnections[0][3]=0;
201 muscleConnections[3][2]=0;
202 muscleConnections[2][0]=0;
203 muscleConnections[4][5]=0;
204 muscleConnections[5][7]=0;
205 muscleConnections[7][4]=0;
206 muscleConnections[1][8]=0;
207 muscleConnections[8][10]=0;
208 muscleConnections[10][1]=0;
209 muscleConnections[9][11]=0;
210 muscleConnections[11][6]=0;
211 muscleConnections[6][9]=0;
212 muscleConnections[1][2]=1;
213 muscleConnections[2][4]=1;
214 muscleConnections[4][1]=1;
215 muscleConnections[3][5]=1;
216 muscleConnections[5][6]=1;
217 muscleConnections[6][3]=1;
218 muscleConnections[0][8]=1;
219 muscleConnections[8][9]=1;
220 muscleConnections[9][0]=1;
221 muscleConnections[11][7]=1;
222 muscleConnections[7][10]=1;
223 muscleConnections[10][11]=1;
225 for(
int i=0;i<13;i++)
227 for(
int j=0;j<13;j++)
229 if(muscleConnections[i][j]>=0)
231 std::stringstream tag;
232 tag<<
"muscle-"<<i<<
"-"<<j;
244 const tgRod::Config rodConfig(c.radius, c.density, c.friction,
245 c.rollFriction, c.restitution);
248 c.history, c.maxTens, c.targetVelocity);
267 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
278 allMuscles = tgCast::filter<tgModel, tgBasicActuator> (
getDescendants());
289 btVector3 location(0,10.0,0);
290 btVector3 rotation(0.0,0.6,0.8);
291 btVector3 speed(0,20,100);
292 this->moveModel(location,rotation,speed);
300 throw std::invalid_argument(
"dt is not positive");
325 void T12SuperBallPayload::moveModel(btVector3 positionVector,btVector3 rotationVector,btVector3 speedVector)
327 std::vector<tgRod *> rods=find<tgRod>(
"rod");
329 btQuaternion initialRotationQuat;
330 initialRotationQuat.setEuler(rotationVector[0],rotationVector[1],rotationVector[2]);
331 btTransform initialTransform;
332 initialTransform.setIdentity();
333 initialTransform.setRotation(initialRotationQuat);
334 initialTransform.setOrigin(positionVector);
335 for(
int i=0;i<rods.size();i++)
337 rods[i]->getPRigidBody()->setLinearVelocity(speedVector);
338 rods[i]->getPRigidBody()->setWorldTransform(initialTransform * rods[i]->getPRigidBody()->getWorldTransform());
virtual void setup(tgWorld &world)
Definition of class tgRodInfo.
Contains the definition of class T12SuperBallPayload. $Id$.
virtual void step(double dt)
virtual ~T12SuperBallPayload()
Markers for specific places on a tensegrity.
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of class tgBasicActuator.
Definition of class tgStructure.
Definition of class tgStructureInfo.
virtual void onVisit(tgModelVisitor &r)
virtual void step(double dt)
virtual void setup(tgWorld &world)
const std::vector< tgBasicActuator * > & getAllMuscles() const
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")