40 BaseSpineModelLearning::BaseSpineModelLearning(
int segments) :
46 BaseSpineModelLearning::~BaseSpineModelLearning()
67 m_allSegments.clear();
81 const std::vector<tgSpringCableActuator*>&
82 BaseSpineModelLearning::getMuscles (
const std::string& key)
const
84 const MuscleMap::const_iterator it = m_muscleMap.find(key);
85 if (it == m_muscleMap.end())
87 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
95 const std::vector<tgSpringCableActuator*>& BaseSpineModelLearning::getAllMuscles()
100 const std::vector<tgBaseRigid*> BaseSpineModelLearning::getAllRigids()
102 if (m_allSegments.size() != m_segments)
104 throw std::runtime_error(
"Not initialized");
107 std::vector<tgBaseRigid*> p_rods;
109 for (std::size_t i = 0; i < m_allSegments.size(); i++)
111 std::vector<tgBaseRigid*> temp = tgCast::filter<tgModel, tgBaseRigid> (m_allSegments[i]->getDescendants());
112 p_rods.insert(p_rods.end(), temp.begin(), temp.end());
118 const int BaseSpineModelLearning::getSegments()
123 std::vector<double> BaseSpineModelLearning::getSegmentCOM(
const int n)
const
125 if (m_allSegments.size() != m_segments)
127 throw std::runtime_error(
"Not initialized");
131 throw std::range_error(
"Negative segment number");
133 else if (n >= m_segments)
135 throw std::range_error(
tgString(
"Segment number > ", m_segments));
138 std::vector<tgRod*> p_rods =
139 tgCast::filter<tgModel, tgRod> (m_allSegments[n]->getDescendants());
142 assert(!p_rods.empty());
144 btVector3 segmentCenterOfMass(0, 0, 0);
145 double segmentMass = 0.0;
146 for (std::size_t i = 0; i < p_rods.size(); i++)
148 const tgRod*
const pRod = p_rods[i];
149 assert(pRod != NULL);
150 const double rodMass = pRod->
mass();
153 segmentCenterOfMass += rodCenterOfMass * rodMass;
154 segmentMass += rodMass;
158 assert(segmentMass > 0.0);
160 segmentCenterOfMass /= segmentMass;
163 std::vector<double> result(3);
164 for (
size_t i = 0; i < 3; ++i) { result[i] = segmentCenterOfMass[i]; }
virtual void setup(tgWorld &world)
Create a box shape as an obstacle or add it to your tensegrity.
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.
virtual void setup(tgWorld &world)
virtual btVector3 centerOfMass() const
A template base class for a tensegrity spine.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
std::string tgString(std::string s, int i)
virtual double mass() const
Contains the definition of class tgRod.
virtual void step(double dt)
void notifyStep(double dt)