47 #include <json/json.h>
62 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(filePath), root );
63 if ( !parsingSuccessful )
66 std::cout <<
"Failed to parse configuration\n"
67 << reader.getFormattedErrorMessages();
68 throw std::invalid_argument(
"Bad config filename");
73 double kTens = root.get(
"inside_imp_ten",
"UTF-8").asDouble();
74 double kPos = root.get(
"inside_imp_pos",
"UTF-8").asDouble();
75 double kVel = root.get(
"inside_imp_vel",
"UTF-8").asDouble();
78 kTens = root.get(
"outside_imp_ten",
"UTF-8").asDouble();
79 kPos = root.get(
"outside_imp_pos",
"UTF-8").asDouble();
80 kVel = root.get(
"outside_imp_vel",
"UTF-8").asDouble();
83 kTens = root.get(
"top_imp_ten",
"UTF-8").asDouble();
84 kPos = root.get(
"top_imp_pos",
"UTF-8").asDouble();
85 kVel = root.get(
"top_imp_vel",
"UTF-8").asDouble();
88 rod_edge = root.get(
"rod_edge",
"UTF-8").asDouble();
89 rod_front = root.get(
"rod_front",
"UTF-8").asDouble();
90 rod_offset = root.get(
"rod_offset",
"UTF-8").asDouble();
93 insideLength = sqrt(pow( (
rod_edge * sin(M_PI/6)), 2) + pow( (rod_front - rod_offset), 2));
94 std::cout <<
"Computed inside length: " << insideLength << std::endl;
96 outsideLength = rod_offset;
97 outsideTopLength = rod_offset;
101 insideTopTens.push_back(root.get(
"in_top_tens_a",
"UTF-8").asDouble());
102 insideTopTens.push_back(root.get(
"in_top_tens_b",
"UTF-8").asDouble());
103 insideLeftTens.clear();
104 insideLeftTens.push_back(root.get(
"in_left_tens_a",
"UTF-8").asDouble());
105 insideLeftTens.push_back(root.get(
"in_left_tens_b",
"UTF-8").asDouble());
106 insideRightTens.clear();
107 insideRightTens.push_back(root.get(
"in_right_tens_a",
"UTF-8").asDouble());
108 insideRightTens.push_back(root.get(
"in_right_tens_b",
"UTF-8").asDouble());
110 outsideTopTens.clear();
111 outsideTopTens.push_back(root.get(
"out_top_tens_a",
"UTF-8").asDouble());
112 outsideTopTens.push_back(root.get(
"out_top_tens_b",
"UTF-8").asDouble());
113 outsideLeftTens.clear();
114 outsideLeftTens.push_back(root.get(
"out_left_tens_a",
"UTF-8").asDouble());
115 outsideLeftTens.push_back(root.get(
"out_left_tens_b",
"UTF-8").asDouble());
116 outsideRightTens.clear();
117 outsideRightTens.push_back(root.get(
"out_right_tens_a",
"UTF-8").asDouble());
118 outsideRightTens.push_back(root.get(
"out_right_tens_b",
"UTF-8").asDouble());
121 insideTopLength.push_back(root.get(
"in_top_length_a",
"UTF-8").asDouble());
122 insideTopLength.push_back(root.get(
"in_top_length_b",
"UTF-8").asDouble());
123 insideLeftLength.clear();
124 insideLeftLength.push_back(root.get(
"in_left_length_a",
"UTF-8").asDouble());
125 insideLeftLength.push_back(root.get(
"in_left_length_b",
"UTF-8").asDouble());
126 insideRightLength.clear();
127 insideRightLength.push_back(root.get(
"in_right_length_a",
"UTF-8").asDouble());
128 insideRightLength.push_back(root.get(
"in_right_length_b",
"UTF-8").asDouble());
130 outsideTopLength.clear();
131 outsideTopLength.push_back(root.get(
"out_top_length_a",
"UTF-8").asDouble());
132 outsideTopLength.push_back(root.get(
"out_top_length_b",
"UTF-8").asDouble());
133 outsideLeftLength.clear();
134 outsideLeftLength.push_back(root.get(
"out_left_length_a",
"UTF-8").asDouble());
135 outsideLeftLength.push_back(root.get(
"out_left_length_b",
"UTF-8").asDouble());
136 outsideRightLength.clear();
137 outsideRightLength.push_back(root.get(
"out_right_length_a",
"UTF-8").asDouble());
138 outsideRightLength.push_back(root.get(
"out_right_length_b",
"UTF-8").asDouble());
142 offsetSpeed = root.get(
"offset_speed",
"UTF-8").asDouble();
143 cpgAmplitude = root.get(
"cpg_amplitude",
"UTF-8").asDouble();
144 cpgFrequency = root.get(
"cpg_frequency",
"UTF-8").asDouble();
145 bodyWaves = root.get(
"bodyWaves",
"UTF-8").asDouble();
146 insideMod = root.get(
"insideMod",
"UTF-8").asDouble();
151 phaseOffsets.push_back(root.get(
"top_offset",
"UTF-8").asDouble());
152 phaseOffsets.push_back(root.get(
"left_offset",
"UTF-8").asDouble());
153 phaseOffsets.push_back(root.get(
"right_offset",
"UTF-8").asDouble());
160 SerializedSpineControl::Config::~Config()
162 delete in_controller;
163 delete out_controller;
170 m_dataObserver(
"logs/TCData"),
186 const std::vector<tgSpringCableActuator*> stringList,
187 const std::vector<double> stringLengths,
188 const std::vector<double> tensions,
192 assert(stringList.size() == stringLengths.size() && stringList.size() == tensions.size());
195 for(std::size_t i = 0; i < stringList.size(); i++)
197 tgBasicActuator& m_sca = *(tgCast::cast<tgSpringCableActuator, tgBasicActuator>(stringList[i]));
201 cycle = sin(simTime * m_config.cpgFrequency + 2 * m_config.bodyWaves * M_PI * i / (segments) + m_config.
phaseOffsets[phase]);
202 target = m_config.
offsetSpeed + cycle*m_config.cpgAmplitude;
204 double setTension = controller->controlTension(m_sca,
210 #ifdef VERBOSE // Conditional compile for verbose control
211 std::cout <<
"Top Outside String " << i <<
" com tension " << setTension
212 <<
" act tension " << stringList[i]->getMuscle()->getTension()
213 <<
" length " << stringList[i]->getMuscle()->getActualLength() << std::endl;
220 #ifdef LOGGING // Conditional compile for data logging
221 m_dataObserver.
onSetup(subject);
226 std::vector<tgSpringCableActuator*> stringList;
228 stringList = subject.getMuscles(
"inner top");
230 for(std::size_t i = 0; i < stringList.size(); i++)
235 stringList = subject.getMuscles(
"inner left");
236 m_config.insideLeftLength.clear();
237 for(std::size_t i = 0; i < stringList.size(); i++)
239 m_config.insideLeftLength.push_back(stringList[i]->getStartLength());
242 stringList = subject.getMuscles(
"inner right");
243 m_config.insideRightLength.clear();
244 for(std::size_t i = 0; i < stringList.size(); i++)
246 m_config.insideRightLength.push_back(stringList[i]->getStartLength());
251 stringList = subject.getMuscles(
"outer top");
252 m_config.outsideTopLength.clear();
253 for(std::size_t i = 0; i < stringList.size(); i++)
255 m_config.outsideTopLength.push_back(stringList[i]->getStartLength());
258 stringList = subject.getMuscles(
"outer left");
259 m_config.outsideLeftLength.clear();
260 for(std::size_t i = 0; i < stringList.size(); i++)
262 m_config.outsideLeftLength.push_back(stringList[i]->getStartLength());
265 stringList = subject.getMuscles(
"outer right");
266 m_config.outsideRightLength.clear();
267 for(std::size_t i = 0; i < stringList.size(); i++)
269 m_config.outsideRightLength.push_back(stringList[i]->getStartLength());
282 simTime += updateTime;
285 #ifdef LOGGING // Conditional compile for data logging
286 m_dataObserver.
onStep(subject, updateTime);
291 segments = subject.getSegments();
293 applyImpedanceControlGeneric(m_config.top_controller,
294 subject.getMuscles(
"inner top"),
301 subject.getMuscles(
"inner left"),
302 m_config.insideLeftLength,
303 m_config.insideLeftTens,
308 subject.getMuscles(
"inner right"),
309 m_config.insideRightLength,
310 m_config.insideRightTens,
314 applyImpedanceControlGeneric(m_config.top_controller,
315 subject.getMuscles(
"outer top"),
316 m_config.outsideTopLength,
317 m_config.outsideTopTens,
321 applyImpedanceControlGeneric(m_config.out_controller,
322 subject.getMuscles(
"outer left"),
323 m_config.outsideLeftLength,
324 m_config.outsideLeftTens,
328 applyImpedanceControlGeneric(m_config.out_controller,
329 subject.getMuscles(
"outer right"),
330 m_config.outsideRightLength,
331 m_config.outsideRightTens,
336 std::vector<tgBaseRigid*> rigids = subject.getAllRigids();
337 btRigidBody* seg1Body = rigids[0]->getPRigidBody();
338 btRigidBody* seg2Body = rigids[15]->getPRigidBody();
339 btRigidBody* seg3Body = rigids[29]->getPRigidBody();
347 btVector3 force(0.0, 0.0, 0.0);
349 if (simTime > 30.0 && simTime < 35.0)
351 force = btVector3(0.0, 0.0, 2.3 * 981.0 * (simTime - 30) / 5.0);
353 else if (simTime >= 35.0 && simTime < 40.0)
355 force = btVector3(0.0, 0.0, 2.3 * 981.0);
357 else if (simTime >= 40.0 && simTime < 45.0)
359 force = btVector3(0.0, 0.0, 2.3 * 981.0 * (45 - simTime)/5.0);
363 force = btVector3(0.0, 0.0, 0.0);
Contains the definition of class ImpedanceControl. $Id$.
std::vector< double > insideTopLength
Create a box shape as an obstacle or add it to your tensegrity.
btVector3 getRelativePosition() const
A Sine Wave controller for TetraSpine using JSON serialization.
Markers for specific places on a tensegrity.
Config(std::string fileName)
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
std::vector< double > phaseOffsets
tgImpedanceController * in_controller
A series of functions to assist with file input/output.
static std::string getResourcePath(std::string relPath)
virtual void onStep(BaseSpineModelLearning &subject, double dt)
Contains the definition of class tgBasicActuator.
SerializedSpineControl(std::string fileName)
virtual void onSetup(BaseSpineModelLearning &subject)
std::vector< double > insideTopTens
virtual void onStep(tgModel &model, double dt)
~SerializedSpineControl()
Rand seeding simular to the evolution and terrain classes.
virtual void onSetup(tgModel &model)
Tetraspine, configured for learning in the NTRT simulator.