39 #include "BulletDynamics/Dynamics/btRigidBody.h"
53 const double rodDensity = 1;
54 const double rodRadius = 0.25;
57 const tgBox::Config boxConfig(rodRadius, rodRadius, rodDensity);
81 s.move(btVector3(0, 0, 0));
85 s.move(btVector3(0, 0, 0));
86 s.
addRotation(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 1.0, 0.0), M_PI/4);
92 spec.addBuilder(
"rod2",
new tgRodInfo(rodConfig2));
93 spec.addBuilder(
"box",
new tgBoxInfo(boxConfig));
94 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
100 structureInfo.buildInto(*
this, world);
105 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
106 allRods = tgCast::filter<tgModel, tgBaseRigid> (
getDescendants());
108 btRigidBody* body = allRods[0]->getPRigidBody();
109 btRigidBody* body2 = allRods[1]->getPRigidBody();
112 btVector3 impulse(0.5, 0.0, 0.5);
113 body->applyCentralImpulse(impulse);
114 body2->applyCentralImpulse(impulse);
116 btRigidBody* body3 = allRods[2]->getPRigidBody();
118 std::cout << body3->getCenterOfMassTransform () << std::endl;
136 btVector3 vCom(0, 0, 0);
139 for (std::size_t i = 0; i < allRods.size(); i++)
143 btVector3 localVel = body->getLinearVelocity();
144 vCom += localVel * ri.
mass();
145 energy += localVel.length2() * ri.
mass();
149 btVector3 forceSum(0.0, 0.0, 0.0);
151 const std::vector<const tgSpringCableAnchor*>& anchorList = allMuscles[0]->getSpringCable()->getAnchors();
152 int n = anchorList.size();
153 for (std::size_t i = 0; i < n; i++)
155 forceSum += anchorList[i]->getForce();
159 std::cout <<
"Time " << totalTime << std::endl;
160 std::cout <<
"Momentum " << vCom << std::endl;
161 std::cout <<
"Energy " << energy << std::endl;
162 std::cout <<
"Other Momentum " <<
getMomentum() << std::endl;
163 std::cout <<
"Force sum " << forceSum << std::endl;
164 std::cout <<
"Length " << allMuscles[0]->getCurrentLength();
165 std::cout <<
" Dist " << (anchorList[0]->getWorldPosition() - anchorList[n-1]->getWorldPosition()).length() << std::endl;
166 std::cout <<
"Anchors: " << n << std::endl;
169 std::cout <<
"Here!" << std::endl;
188 for (std::size_t i = 0; i < allRods.size(); i++)
192 btVector3 localVel = body->getLinearVelocity();
193 energy += localVel.length2() * ri->
mass();
202 btVector3 vCom(0, 0, 0);
205 for (std::size_t i = 0; i < allRods.size(); i++)
209 btVector3 localVel = body->getLinearVelocity();
210 vCom += localVel * ri->
mass();
217 btVector3 MuscleNPCons::getVelocityOfBody(
int body_num)
const
219 assert(body_num < allRods.size() && body_num >= 0);
221 btRigidBody* body = ri->getPRigidBody();
223 return body->getLinearVelocity();
virtual btVector3 getMomentum() const
virtual double getEnergy() const
Create a box shape as an obstacle or add it to your tensegrity.
virtual void setup(tgWorld &world)
Definition of class tgRodInfo.
Create a box shape as an obstacle or add it to your tensegrity.
virtual void setup(tgWorld &world)
virtual void step(double dt)
virtual void onVisit(const tgModelVisitor &r) const
Class that interfaces with Bullet to build the boxes.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
virtual void render(const tgRod &rod) const
Contains the definition of interface class tgModelVisitor.
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBulletUtil.
Definition of class tgStructure.
virtual btRigidBody * getPRigidBody()
Definition of class tgStructureInfo.
virtual double mass() const
virtual void step(double dt)
Definitions of class tgSpringCableAnchor.
Definitions of classes tgBulletSpringCable $Id$.
virtual void onVisit(const tgModelVisitor &r) const
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
std::vector< tgModel * > getDescendants() const
For testing MuscleNP contacts.
void addNode(double x, double y, double z, std::string tags="")