41 #include "btBulletDynamicsCommon.h"
106 double vertebra_separation;
107 double base_vertical_offset;
123 double targetVelocity;
148 std::cout << std::endl <<
"StructureInfo Trace:" << std::endl
149 << structureInfo << std::endl
150 <<
"Model: " << std::endl
151 << model << std::endl;
158 void VerticalSpineModel::trace(
const tgStructure& structure,
161 std::cout << std::endl <<
"Structure Trace inside VerticalSpineModel:" << std::endl
162 << structure << std::endl
163 << std::endl <<
"StructureInfo Trace inside VerticalSpineModel:" << std::endl
164 << structureInfo << std::endl
165 << std::endl <<
"tgModel Trace inside VerticalSpineModel: " << std::endl
166 << model << std::endl;
173 vertebra.
addNode( getEdgeLength(conf_vertebra) / 2.0, 0, 0);
175 vertebra.
addNode( -getEdgeLength(conf_vertebra) / 2.0, 0, 0);
177 vertebra.
addNode(0, conf_vertebra.height, -getEdgeLength(conf_vertebra) / 2.0);
179 vertebra.
addNode(0, conf_vertebra.height, getEdgeLength(conf_vertebra) / 2.0);
181 vertebra.
addNode(0, conf_vertebra.height/2, 0);
185 double VerticalSpineModel::getDensity(
ConfigVertebra& conf_vertebra)
191 double volume = num_rods * M_PI * pow(conf_vertebra.radius, 2) * conf_vertebra.leg_length;
192 double density = conf_vertebra.mass / volume;
196 double VerticalSpineModel::getEdgeLength(
ConfigVertebra& conf_vertebra)
200 double edge = 2 * sqrt( pow(conf_vertebra.leg_length, 2) - pow( conf_vertebra.height / 2, 2) );
206 vertebra.
addPair(0, 4,
"rod_" + conf_vertebra.vertebra_name);
207 vertebra.
addPair(1, 4,
"rod_" + conf_vertebra.vertebra_name);
208 vertebra.
addPair(2, 4,
"rod_" + conf_vertebra.vertebra_name);
209 vertebra.
addPair(3, 4,
"rod_" + conf_vertebra.vertebra_name);
214 double edge,
size_t segment_count)
218 const btVector3 offset(0, conf_spine.vertebra_separation, 0);
220 for (
size_t i = 1; i < segment_count; i++)
225 new_vertebra -> addTags(
tgString(
"segment", i + 1));
227 new_vertebra -> move((i + 1) * offset);
234 void VerticalSpineModel::addVertebra(
tgStructure& spine,
236 size_t vertebra_number)
241 std::vector<tgStructure*> spine_vertebrae = spine.
getChildren();
251 addNodes( *new_vertebra, conf_vertebra);
252 addRodPairs( *new_vertebra, conf_vertebra);
256 new_vertebra -> move( btVector3(0.0,
257 (vertebra_number - 1) * conf_spine.vertebra_separation, 0.0) );
260 new_vertebra -> addTags(
tgString(
"segment", vertebra_number) );
267 void VerticalSpineModel::addMuscles(
tgStructure& spine)
269 const std::vector<tgStructure*> children = spine.
getChildren();
270 for (
size_t i = 1; i < children.size(); i++)
272 tgNodes n0 = children[i-1]->getNodes();
273 tgNodes n1 = children[i ]->getNodes();
276 spine.
addPair(n0[0], n1[0],
"vertical muscle a");
277 spine.
addPair(n0[1], n1[1],
"vertical muscle b");
278 spine.
addPair(n0[2], n1[2],
"vertical muscle c");
279 spine.
addPair(n0[3], n1[3],
"vertical muscle d");
290 tgModel& model,
size_t segmentCount)
301 for (
size_t i = 1; i < segmentCount ; i++)
320 std::cout <<
"passive vertebra height: " << conf_passive_vertebra.height
322 std::cout <<
"passive vertebra edge length: " <<
323 getEdgeLength(conf_passive_vertebra) << std::endl;
333 addNodes(base_vertebra, conf_base_vertebra);
334 addRodPairs(base_vertebra, conf_base_vertebra);
338 base_vertebra.move(btVector3(0.0, conf_spine.base_vertical_offset, 0));
341 base_vertebra.addTags(
tgString(
"segment", 1));
348 addVertebra(spine, conf_active_vertebra, 2);
349 addVertebra(spine, conf_passive_vertebra, 3);
350 addVertebra(spine, conf_active_vertebra, 4);
351 addVertebra(spine, conf_passive_vertebra, 5);
362 getDensity(conf_base_vertebra),
363 conf_base_vertebra.friction,
364 conf_base_vertebra.rollFriction,
365 conf_base_vertebra.restitution);
368 const tgRod::Config rodConfigPassive(conf_passive_vertebra.radius,
369 getDensity(conf_passive_vertebra),
370 conf_passive_vertebra.friction,
371 conf_passive_vertebra.rollFriction,
372 conf_passive_vertebra.restitution);
375 const tgRod::Config rodConfigActive(conf_active_vertebra.radius,
376 getDensity(conf_active_vertebra),
377 conf_active_vertebra.friction,
378 conf_active_vertebra.rollFriction,
379 conf_active_vertebra.restitution);
383 spec.addBuilder(
"rod_" + conf_base_vertebra.vertebra_name,
385 spec.addBuilder(
"rod_" + conf_passive_vertebra.vertebra_name,
387 spec.addBuilder(
"rod_" + conf_active_vertebra.vertebra_name,
394 c.hist, c.maxTens, c.targetVelocity);
403 trace(spine, structureInfo, *
this);
410 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
411 mapMuscles(muscleMap, *
this, m_segments);
416 std::vector<tgBaseRigid*> all_tgBaseRigid = tgCast::filter<tgModel, tgBaseRigid>(all_children);
438 throw std::invalid_argument(
"dt is not positive");
449 const std::vector<tgSpringCableActuator*>&
452 const MuscleMap::const_iterator it = muscleMap.
find(key);
453 if (it == muscleMap.end())
455 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
const std::vector< tgStructure * > & getChildren() const
virtual void step(const double dt)
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
Definition of class tgRodInfo.
const std::vector< tgSpringCableActuator * > & getMuscles(const std::string &key) const
virtual void setup(tgWorld &world)
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Utility class for class casting and filtering collections by type.
Contains the definition of class VerticalSpineModel.
VerticalSpineModel(size_t segments)
Definition of class tgBasicActuatorInfo.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
std::map< std::string, std::vector< tgSpringCableActuator * > > MuscleMap
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
const std::vector< tgSpringCableActuator * > & getAllMuscles() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")