42 #include "dev/btietz/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"))
136 controlLength = allMuscles[i]->getStartLength();
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();
144 else if(allMuscles[i]->hasTag(
"seg2"))
146 amplitude = root.get(
"in_top_amp_b",
"UTF-8").asDouble();
147 phase = root.get(
"back_offset",
"UTF-8").asDouble();
152 throw std::runtime_error(
"Missing tags!");
155 else if (allMuscles[i]->hasTag(
"outer top"))
161 if (allMuscles[i]->hasTag(
"seg1"))
163 amplitude = root.get(
"out_top_amp_a",
"UTF-8").asDouble();
164 phase = root.get(
"front_offset",
"UTF-8").asDouble();
166 controlLength = 18.5;
168 else if(allMuscles[i]->hasTag(
"seg2"))
170 amplitude = root.get(
"out_top_amp_b",
"UTF-8").asDouble();
171 phase = root.get(
"back_offset",
"UTF-8").asDouble();
172 controlLength = 19.8;
176 throw std::runtime_error(
"Missing tags!");
179 else if (allMuscles[i]->hasTag(
"inner"))
184 controlLength = allMuscles[i]->getStartLength();
186 if (allMuscles[i]->hasTag(
"seg1"))
188 amplitude = root.get(
"in_bottom_amp_a",
"UTF-8").asDouble();
189 phase = root.get(
"front_offset",
"UTF-8").asDouble();
191 else if(allMuscles[i]->hasTag(
"seg2"))
193 amplitude = root.get(
"in_bottom_amp_b",
"UTF-8").asDouble();
194 phase = root.get(
"back_offset",
"UTF-8").asDouble();
198 throw std::runtime_error(
"Missing tags!");
201 else if (allMuscles[i]->hasTag(
"outer"))
206 controlLength = 19.0 ;
207 if (allMuscles[i]->hasTag(
"seg1"))
209 amplitude = root.get(
"out_bottom_amp_a",
"UTF-8").asDouble();
210 phase = root.get(
"front_offset",
"UTF-8").asDouble();
212 else if(allMuscles[i]->hasTag(
"seg2"))
214 amplitude = root.get(
"out_bottom_amp_b",
"UTF-8").asDouble();
215 phase = root.get(
"back_offset",
"UTF-8").asDouble();
219 throw std::runtime_error(
"Missing tags!");
224 throw std::runtime_error(
"Missing tags!");
243 allMuscles[i]->attach(pStringControl);
244 m_sineControllers.push_back(pStringControl);
247 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)