45 tscDataObserver::tscDataObserver(std::string filePrefix) :
48 m_filePrefix(filePrefix)
69 int fileTimeSize = 64;
70 char fileTime [fileTimeSize];
73 currentTime = localtime(&rawtime);
74 strftime(fileTime, fileTimeSize,
"%m%d%Y_%H%M%S.txt", currentTime);
75 m_fileName = m_filePrefix + fileTime;
76 std::cout << m_fileName << std::endl;
78 if (m_dataLogger != NULL)
89 tgOutput.open(m_fileName.c_str());
91 if (!tgOutput.is_open())
93 throw std::runtime_error(
"Logs does not exist. Please create a logs folder in your build directory or update your cmake file");
105 tgOutput <<
"Time" <<
",";
107 for (std::size_t i = 0; i < children.size(); i++)
112 std::stringstream name;
114 if(tgCast::cast<tgModel, tgSpringCableActuator>(children[i]) != 0)
116 name << children[i]->getTags() <<
" " << stringNum;
117 tgOutput << name.str() <<
"_RL" <<
","
118 << name.str() <<
"_AL" <<
","
119 << name.str() <<
"_Ten" <<
",";
122 else if(tgCast::cast<tgModel, tgRod>(children[i]) != 0)
129 int numSeg = model.getSegments();
131 for (
int i = 0; i < numSeg; i++)
133 std::stringstream name;
135 name <<
"segment_" << i+1;
136 tgOutput << name.str() <<
"_X" <<
","
137 << name.str() <<
"_Y" <<
","
138 << name.str() <<
"_Z" <<
",";
141 tgOutput << std::endl;
154 tgOutput.open(m_fileName.c_str(), std::ios::app);
155 tgOutput << m_totalTime <<
",";
160 tgOutput.open(m_fileName.c_str(), std::ios::app);
162 int numSeg = model.getSegments();
164 for (
int i = 0; i < numSeg; i++)
167 std::vector<double> com = model.getSegmentCOM(i);
169 tgOutput << com[0] <<
","
174 tgOutput << std::endl;
virtual void onSetup(BaseSpineModelLearning &model)
virtual ~tscDataObserver()
Convenience function for combining strings with ints, mostly for naming structures.
Utility class for class casting and filtering collections by type.
A template base class for a tensegrity spine.
virtual void onVisit(const tgModelVisitor &r) const
Contains the definition of class tgModel.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
virtual void onStep(BaseSpineModelLearning &model, double dt)
Definition of tgObserver class.
Contains the definition of interface class tscDataLogger.
Contains the definition of class tgRod.
std::vector< tgModel * > getDescendants() const