32 #include "LinearMath/btVector3.h"
46 TetraSpineLearningModel::TetraSpineLearningModel(
size_t segments) :
51 TetraSpineLearningModel::~TetraSpineLearningModel()
56 void addNodes(
tgStructure& tetra,
double edge,
double height)
59 tetra.
addNode(-edge / 2.0, 0, 0);
61 tetra.
addNode( edge / 2.0, 0, 0);
65 tetra.
addNode(0, height / 2.0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
70 tetra.
addPair(0, 1,
"back bottom rod");
71 tetra.
addPair(0, 2,
"back right rod");
72 tetra.
addPair(0, 3,
"front right rod");
73 tetra.
addPair(1, 2,
"back left rod");
74 tetra.
addPair(1, 3,
"front left rod");
75 tetra.
addPair(2, 3,
"front top rod");
83 const btVector3 offset(0, 0, -edge * 0.75);
84 for (
size_t i = 0; i < segmentCount; ++i)
89 t->addTags(
tgString(
"segment num", i + 1));
90 t->move((i + 1) * offset);
99 const std::vector<tgStructure*> children = snake.
getChildren();
100 for (
size_t i = 1; i < children.size(); ++i)
102 tgNodes n0 = children[i-1]->getNodes();
103 tgNodes n1 = children[i ]->getNodes();
105 snake.
addPair(n0[0], n1[0],
"outer right muscle");
106 snake.
addPair(n0[1], n1[1],
"outer left muscle");
107 snake.
addPair(n0[2], n1[2],
"outer top muscle");
109 snake.
addPair(n0[0], n1[3],
"inner right muscle");
110 snake.
addPair(n0[1], n1[3],
"inner left muscle");
111 snake.
addPair(n0[2], n1[3],
"inner top muscle");
115 void mapMuscles(TetraSpineLearningModel::MuscleMap& muscleMap,
130 std::cout <<
"StructureInfo:" << std::endl
131 << structureInfo << std::endl
132 <<
"Model: " << std::endl
133 << model << std::endl;
135 const std::vector<tgSpringCableActuator*> outerMuscles =
137 for (
size_t i = 0; i < outerMuscles.size(); ++i)
140 assert(pMuscle != NULL);
141 std::cout <<
"Outer muscle: " << *pMuscle << std::endl;
151 const double edge = 38.1;
152 const double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
153 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
157 addNodes(tetra, edge, height);
162 tetra.move(btVector3(0.0, 2.0, 100.0));
166 addSegments(snake, tetra, edge, m_segments);
172 #if (0) // Original parameters
173 const double density = 4.2 / 300.0;
174 const double radius = 0.5;
175 const double friction = 0.5;
178 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
183 #else // Params for In Won
184 const double density = .00311;
185 const double radius = 0.635;
186 const double friction = 0.5;
189 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
199 structureInfo.buildInto(*
this, world);
203 m_allMuscles = this->find<tgSpringCableActuator> (
"muscle");
204 m_allSegments = this->find<tgModel> (
"segment");
205 mapMuscles(m_muscleMap, *
this);
208 trace(structureInfo, *
this);
226 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Convenience function for combining strings with ints, mostly for naming structures.
Utility class for class casting and filtering collections by type.
virtual void setup(tgWorld &world)
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...
virtual void step(const double dt)
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
virtual void setup(tgWorld &world)
Definition of class tgStructureInfo.
Tetraspine, configured for learning in the NTRT simulator.
Contains the definition of class tgUtil and overloaded operator<<() free functions.
Definition of class tgBuildSpec.
virtual void step(double dt)
void addNode(double x, double y, double z, std::string tags="")