30 #include "examples/learningSpines/tgSCASineControl.h"
44 #include "LinearMath/btVector3.h"
64 double triangle_length;
65 double triangle_height;
83 useKinematic(kinematic),
90 for(std::size_t i = 0; i < m_tgSCASineControllers.size(); i++)
92 delete m_tgSCASineControllers[i];
94 m_tgSCASineControllers.clear();
120 void pidTestRig::setupControl()
123 assert(allMuscles.size() > 0);
125 const double controlStep = 0.01;
128 const double amplitude = 0.0;
129 const double frequency = 0.2;
130 const double phase = 0.0;
131 const double offset = 0.0;
134 for (std::size_t i = 0; i < allMuscles.size(); i++)
136 tgKinematicActuator* kinString = tgCast::cast<tgSpringCableActuator, tgKinematicActuator>(allMuscles[i]);
147 kinString->
attach(sineController);
149 m_tgSCASineControllers.push_back(sineController);
173 s.move(btVector3(0, 5, 0));
178 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
179 spec.addBuilder(
"rod2",
new tgRodInfo(rodConfig2));
201 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
213 std::vector<tgBaseRigid*> myRigids = tgCast::filter<tgModel, tgBaseRigid> (
getDescendants());
215 for (
int i =0; i < myRigids.size(); i++)
217 std::cout << myRigids[i]->mass() <<
" " <<myRigids[i]->getPRigidBody() << std::endl;
221 std::cout <<
"Starting Length: " << allMuscles[0]->getCurrentLength() << std::endl;
222 std::cout <<
"Starting Rest Length: " << allMuscles[0]->getRestLength() << std::endl;
233 throw std::invalid_argument(
"dt is not positive");
242 if (allMuscles[0]->getRestLength() <= 5.0 && !reached)
244 std::cout <<
"Rest length below 5.0 at: " << totalTime << std::endl;
267 std::vector<tgSpringCableActuator* > tmpStrings = this->
getAllMuscles();
273 double dt = totalTime / (double)histSize;
275 double totalEnergySpent = 0;
278 std::cout <<
"Ending Length: " << allMuscles[0]->getCurrentLength() << std::endl;
279 std::cout <<
"Ending Rest Length: " << allMuscles[0]->getRestLength() << std::endl;
280 std::cout <<
"Ending Tension: " <<allMuscles[0]->getTension() << std::endl;
282 std::vector<tgBaseRigid*> myRigids = tgCast::filter<tgModel, tgBaseRigid> (
getDescendants());
284 btRigidBody* body0 = myRigids[0]->getPRigidBody();
286 btVector3 velocity = body0->getLinearVelocity();
288 std::cout <<
"Final Velocity: " << velocity.length() << std::endl;
295 const double previousLength = stringHist.
restLengths[j-1];
296 const double currentLength = stringHist.
restLengths[j];
298 double motorSpeed = (currentLength-previousLength);
301 const double workDone = previousTension * motorSpeed;
302 totalEnergySpent += workDone;
306 for(std::size_t j=0; j < histSize; j++)
311 const double workDone = previousTension * motorSpeed * dt;
312 totalEnergySpent += workDone;
316 std::cout <<
"Motor Speed " << stringHist.
lastVelocities[histSize - 1] << std::endl;
318 std::cout <<
"Energy Spent: " << totalEnergySpent << std::endl;
Contains the definition of class ImpedanceControl. $Id$.
pidTestRig(bool kinematic=true)
virtual void setup(tgWorld &world)
Definition of class tgRodInfo.
std::deque< double > tensionHistory
const std::vector< tgSpringCableActuator * > & getAllMuscles() const
virtual void onVisit(tgModelVisitor &r)
std::deque< double > restLengths
virtual void step(double dt)
std::deque< double > lastVelocities
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
virtual void setup(tgWorld &world)
Contains the definition of class tgBasicActuator.
Definition of class tgStructure.
Definition of class tgStructureInfo.
Defines a 3 strut 9 string tensegrity model.
Contains the definition of class tgKinematicActuator.
Definition of class tgKinematicActuatorInfo.
virtual void step(double dt)
Contains the definition of class tgRod.
void attach(tgObserver< T > *pObserver)
Definition of class tgBuildSpec.
Definition of the tgPIDController class.
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="")