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);
77 s.move(btVector3(0, 0, 0));
81 s.move(btVector3(0, 0, 0));
82 s.
addRotation(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 1.0, 0.0), M_PI/4);
88 spec.addBuilder(
"rod2",
new tgRodInfo(rodConfig2));
89 spec.addBuilder(
"box",
new tgBoxInfo(boxConfig));
90 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
101 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
102 allRods = tgCast::filter<tgModel, tgBaseRigid> (
getDescendants());
104 btRigidBody* body = allRods[0]->getPRigidBody();
105 btRigidBody* body2 = allRods[1]->getPRigidBody();
108 btVector3 impulse(0.4, 0.0, 0.4);
109 body->applyCentralImpulse(impulse);
110 body2->applyCentralImpulse(impulse);
112 btRigidBody* body3 = allRods[2]->getPRigidBody();
114 std::cout << body3->getCenterOfMassTransform () << std::endl;
132 btVector3 vCom(0, 0, 0);
135 for (std::size_t i = 0; i < allRods.size(); i++)
139 btVector3 localVel = body->getLinearVelocity();
140 vCom += localVel * ri.
mass();
141 energy += localVel.length2() * ri.
mass();
145 btVector3 forceSum(0.0, 0.0, 0.0);
147 const std::vector<const tgSpringCableAnchor*>& anchorList = allMuscles[0]->getSpringCable()->getAnchors();
148 int n = anchorList.size();
149 for (std::size_t i = 0; i < n; i++)
151 forceSum += anchorList[i]->getForce();
155 std::cout <<
"Time " << totalTime << std::endl;
156 std::cout <<
"Momentum " << vCom << std::endl;
157 std::cout <<
"Energy " << energy << std::endl;
158 std::cout <<
"Other Momentum " <<
getMomentum() << std::endl;
159 std::cout <<
"Force sum " << forceSum << std::endl;
160 std::cout <<
"Length " << allMuscles[0]->getCurrentLength();
161 std::cout <<
" Dist " << (anchorList[0]->getWorldPosition() - anchorList[n-1]->getWorldPosition()).length() << std::endl;
162 std::cout <<
"Anchors: " << n << std::endl;
165 std::cout <<
"Here!" << std::endl;
184 for (std::size_t i = 0; i < allRods.size(); i++)
188 btVector3 localVel = body->getLinearVelocity();
189 energy += localVel.length2() * ri->
mass();
198 btVector3 vCom(0, 0, 0);
201 for (std::size_t i = 0; i < allRods.size(); i++)
205 btVector3 localVel = body->getLinearVelocity();
206 vCom += localVel * ri->
mass();
213 btVector3 ContactCableDemo::getVelocityOfBody(
int body_num)
const
215 assert(body_num < allRods.size() && body_num >= 0);
217 btRigidBody* body = ri->getPRigidBody();
219 return body->getLinearVelocity();
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 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
Definitions of class tgSpringCableAnchor.
Definitions of classes tgBulletSpringCable $Id$.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")