46 #include <json/json.h>
56 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(
"controlVars.json"), root );
57 if ( !parsingSuccessful )
60 std::cout <<
"Failed to parse configuration\n"
61 << reader.getFormattedErrorMessages();
67 double kTen = root.get(
"inside_imp_ten",
"UTF-8").asDouble();
68 double kPos = root.get(
"inside_imp_pos",
"UTF-8").asDouble();
69 double kVel = root.get(
"inside_imp_vel",
"UTF-8").asDouble();
72 kTen = root.get(
"outside_imp_ten",
"UTF-8").asDouble();
73 kPos = root.get(
"outside_imp_pos",
"UTF-8").asDouble();
74 kVel = root.get(
"outside_imp_vel",
"UTF-8").asDouble();
77 insideLength = root.get(
"inside_length",
"UTF-8").asDouble();
78 outsideLength = root.get(
"outside_length",
"UTF-8").asDouble();
79 offsetSpeed = root.get(
"offset_speed",
"UTF-8").asDouble();
80 cpgAmplitude = root.get(
"cpg_amplitude",
"UTF-8").asDouble();
81 cpgFrequency = root.get(
"cpg_frequency",
"UTF-8").asDouble();
82 bodyWaves = root.get(
"bodyWaves",
"UTF-8").asDouble();
83 insideMod = root.get(
"insideMod",
"UTF-8").asDouble();
88 phaseOffsets.push_back(root.get(
"top_offset",
"UTF-8").asDouble());
89 phaseOffsets.push_back(root.get(
"left_offset",
"UTF-8").asDouble());
90 phaseOffsets.push_back(root.get(
"right_offset",
"UTF-8").asDouble());
97 SerializedSineWaves::Config::~Config()
100 delete out_controller;
123 std::vector<tgBasicActuator* > stringList_ba = tgCast::filter<tgSpringCableActuator, tgBasicActuator>(stringList);
125 for(std::size_t i = 0; i < stringList_ba.size(); i++)
128 cycle = sin(simTime * m_config.cpgFrequency + 2 * m_config.bodyWaves * M_PI * i / (segments) + m_config.
phaseOffsets[phase]);
129 target = m_config.
offsetSpeed + cycle*m_config.cpgAmplitude;
137 #if (0) // Conditional compile for verbose control
138 std::cout <<
"Inside String " << i <<
" tension " << setTension
139 <<
" act tension " << stringList[i]->getMuscle()->getTension()
140 <<
" length " << stringList[i]->getMuscle()->getActualLength() << std::endl;
149 std::vector<tgBasicActuator* > stringList_ba = tgCast::filter<tgSpringCableActuator, tgBasicActuator>(stringList);
151 for(std::size_t i = 0; i < stringList_ba.size(); i++)
154 cycle = sin(simTime * m_config.cpgFrequency + 2 * m_config.bodyWaves * M_PI * i / (segments) + m_config.
phaseOffsets[phase]);
155 target = m_config.
offsetSpeed + cycle*m_config.cpgAmplitude;
157 double setTension = m_config.out_controller->
control(*( stringList_ba[i]),
159 m_config.outsideLength,
162 #if(0) // Conditional compile for verbose control
163 std::cout <<
"Outside String " << i <<
" com tension " << setTension
164 <<
" act tension " << stringList[i]->getMuscle()->getTension()
165 <<
" length " << stringList[i]->getMuscle()->getActualLength() << std::endl;
177 simTime += updateTime;
181 segments = subject.getSegments();
Contains the definition of class ImpedanceControl. $Id$.
Config(std::string fileName)
SerializedSineWaves(std::string fileName)
virtual void onStep(BaseSpineModelLearning &subject, double dt)
Utility class for class casting and filtering collections by type.
void applyImpedanceControlOutside(const std::vector< tgSpringCableActuator * > stringList, double dt, std::size_t phase)
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
A series of functions to assist with file input/output.
std::vector< double > phaseOffsets
Contains the definition of class tgBasicActuator.
void applyImpedanceControlInside(const std::vector< tgSpringCableActuator * > stringList, double dt, std::size_t phase)
A Sine Wave controller for TetraSpine using JSON serialization.
tgImpedanceController * in_controller
Tetraspine, configured for learning in the NTRT simulator.
Contains the definition of class tgUtil and overloaded operator<<() free functions.
double control(tgBasicController &mLocalController, double deltaTimeSeconds, double newPosition, double offsetVel=0)
Control Functions.