47 #include <json/json.h>
60 std::string filePath = FileHelpers::getResourcePath(
"ICRA2015/static/controlVars.json");
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());
249 stringList = subject.getMuscles(
"outer top");
250 m_config.outsideTopLength.clear();
251 for(std::size_t i = 0; i < stringList.size(); i++)
253 m_config.outsideTopLength.push_back(stringList[i]->getStartLength());
256 stringList = subject.getMuscles(
"outer left");
257 m_config.outsideLeftLength.clear();
258 for(std::size_t i = 0; i < stringList.size(); i++)
260 m_config.outsideLeftLength.push_back(stringList[i]->getStartLength());
263 stringList = subject.getMuscles(
"outer right");
264 m_config.outsideRightLength.clear();
265 for(std::size_t i = 0; i < stringList.size(); i++)
267 m_config.outsideRightLength.push_back(stringList[i]->getStartLength());
280 simTime += updateTime;
283 #ifdef LOGGING // Conditional compile for data logging
284 m_dataObserver.
onStep(subject, updateTime);
289 segments = subject.getSegments();
291 applyImpedanceControlGeneric(m_config.top_controller,
292 subject.getMuscles(
"inner top"),
299 subject.getMuscles(
"inner left"),
300 m_config.insideLeftLength,
301 m_config.insideLeftTens,
306 subject.getMuscles(
"inner right"),
307 m_config.insideRightLength,
308 m_config.insideRightTens,
312 applyImpedanceControlGeneric(m_config.top_controller,
313 subject.getMuscles(
"outer top"),
314 m_config.outsideTopLength,
315 m_config.outsideTopTens,
319 applyImpedanceControlGeneric(m_config.out_controller,
320 subject.getMuscles(
"outer left"),
321 m_config.outsideLeftLength,
322 m_config.outsideLeftTens,
326 applyImpedanceControlGeneric(m_config.out_controller,
327 subject.getMuscles(
"outer right"),
328 m_config.outsideRightLength,
329 m_config.outsideRightTens,
334 std::vector<tgBaseRigid*> rigids = subject.getAllRigids();
335 btRigidBody* seg1Body = rigids[0]->getPRigidBody();
336 btRigidBody* seg2Body = rigids[15]->getPRigidBody();
337 btRigidBody* seg3Body = rigids[29]->getPRigidBody();
345 btVector3 force(0.0, 0.0, 0.0);
347 if (simTime > 30.0 && simTime < 35.0)
349 force = btVector3(0.0, 0.0, 2.3 * 981.0 * (simTime - 30) / 5.0);
351 else if (simTime >= 35.0 && simTime < 40.0)
353 force = btVector3(0.0, 0.0, 2.3 * 981.0);
355 else if (simTime >= 40.0 && simTime < 45.0)
357 force = btVector3(0.0, 0.0, 2.3 * 981.0 * (45 - simTime)/5.0);
361 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.
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()
Contains the definition of class tgUtil and overloaded operator<<() free functions.
virtual void onSetup(tgModel &model)
Tetraspine, configured for learning in the NTRT simulator.