42 #include "examples/IROS_2015/hardwareSineWaves/tgSineStringControl.h"
46 #include <json/json.h>
59 m_dataObserver(
"logs/TCData")
68 #ifdef LOGGING // Conditional compile for data logging
69 m_dataObserver.
onSetup(subject);
80 if (m_updateTime >= m_controlTime)
83 #ifdef LOGGING // Conditional compile for data logging
84 m_dataObserver.
onStep(subject, m_updateTime);
93 for(
size_t i = 0; i < m_sineControllers.size(); i++)
95 delete m_sineControllers[i];
97 m_sineControllers.clear();
102 std::vector <tgSpringCableActuator*> allMuscles = subject.getAllMuscles();
107 double controlLength;
116 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(
"controlVars.json"), root );
117 if ( !parsingSuccessful )
120 std::cout <<
"Failed to parse configuration\n"
121 << reader.getFormattedErrorMessages();
123 throw std::invalid_argument(
"Bad JSON filename");
126 m_controlTime = root.get(
"updateFrequency",
"UTF-8").asDouble();
127 double frequency = root.get(
"cpg_frequency",
"UTF-8").asDouble();
129 for (std::size_t i = 0; i < allMuscles.size(); i++)
131 if (allMuscles[i]->hasTag(
"inner top"))
138 if (allMuscles[i]->hasTag(
"seg1"))
140 amplitude = root.get(
"in_top_amp_a",
"UTF-8").asDouble();
141 phase = root.get(
"front_offset",
"UTF-8").asDouble();
142 controlLength = 19.0;
145 else if(allMuscles[i]->hasTag(
"seg2"))
147 amplitude = root.get(
"in_top_amp_b",
"UTF-8").asDouble();
148 phase = root.get(
"back_offset",
"UTF-8").asDouble();
149 controlLength = 18.0;
154 throw std::runtime_error(
"Missing tags!");
157 else if (allMuscles[i]->hasTag(
"outer top"))
163 if (allMuscles[i]->hasTag(
"seg1"))
165 amplitude = root.get(
"out_top_amp_a",
"UTF-8").asDouble();
166 phase = root.get(
"front_offset",
"UTF-8").asDouble();
168 controlLength = 18.5;
170 else if(allMuscles[i]->hasTag(
"seg2"))
172 amplitude = root.get(
"out_top_amp_b",
"UTF-8").asDouble();
173 phase = root.get(
"back_offset",
"UTF-8").asDouble();
174 controlLength = 19.8;
178 throw std::runtime_error(
"Missing tags!");
181 else if (allMuscles[i]->hasTag(
"inner"))
188 if (allMuscles[i]->hasTag(
"seg1"))
190 amplitude = root.get(
"in_bottom_amp_a",
"UTF-8").asDouble();
191 phase = root.get(
"front_offset",
"UTF-8").asDouble();
192 controlLength = 21.5;
194 else if(allMuscles[i]->hasTag(
"seg2"))
196 amplitude = root.get(
"in_bottom_amp_b",
"UTF-8").asDouble();
197 phase = root.get(
"back_offset",
"UTF-8").asDouble();
198 controlLength = 22.5;
202 throw std::runtime_error(
"Missing tags!");
205 else if (allMuscles[i]->hasTag(
"outer"))
210 controlLength = 19.0;
211 if (allMuscles[i]->hasTag(
"seg1"))
213 amplitude = root.get(
"out_bottom_amp_a",
"UTF-8").asDouble();
214 phase = root.get(
"front_offset",
"UTF-8").asDouble();
216 else if(allMuscles[i]->hasTag(
"seg2"))
218 amplitude = root.get(
"out_bottom_amp_b",
"UTF-8").asDouble();
219 phase = root.get(
"back_offset",
"UTF-8").asDouble();
223 throw std::runtime_error(
"Missing tags!");
228 throw std::runtime_error(
"Missing tags!");
248 allMuscles[i]->attach(pStringControl);
249 m_sineControllers.push_back(pStringControl);
252 assert(m_sineControllers.size() == allMuscles.size());
Contains the definition of class ImpedanceControl. $Id$.
virtual void setupWaves(BaseSpineModelLearning &subject)
virtual void onTeardown(BaseSpineModelLearning &subject)
Controller for TetraSpineLearningModel.
A class to read a learning configuration from a .ini file.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
A series of functions to assist with file input/output.
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
virtual void onStep(tgModel &model, double dt)
virtual void onSetup(BaseSpineModelLearning &subject)
virtual void onSetup(tgModel &model)
virtual void onStep(BaseSpineModelLearning &subject, double dt)