44 tgDataObserver::tgDataObserver(std::string filePrefix) :
47 m_filePrefix(filePrefix)
68 int fileTimeSize = 64;
69 char fileTime [fileTimeSize];
72 currentTime = localtime(&rawtime);
73 strftime(fileTime, fileTimeSize,
"%m%d%Y_%H%M%S.txt", currentTime);
74 m_fileName = m_filePrefix + fileTime;
75 std::cout << m_fileName << std::endl;
77 if (m_dataLogger != NULL)
88 tgOutput.open(m_fileName.c_str());
90 if (!tgOutput.is_open())
92 throw std::runtime_error(
"Logs does not exist. Please create a logs folder in your build directory or update your cmake file");
104 tgOutput <<
"Time" <<
",";
107 const std::vector<abstractMarker>& markers = model.getMarkers();
109 const std::size_t n = 0;
112 for (std::size_t i = 0; i < markers.size(); i++)
114 std::stringstream name;
116 name <<
"Marker " <<
" " << i;
117 tgOutput << name.str() <<
"_X" <<
","
118 << name.str() <<
"_Y" <<
","
119 << name.str() <<
"_Z" <<
",";
122 for (std::size_t i = 0; i < children.size(); i++)
127 std::stringstream name;
129 if(tgCast::cast<tgModel, tgSpringCableActuator>(children[i]) != 0)
131 name << children[i]->getTags() <<
" " << stringNum;
132 tgOutput << name.str() <<
"_RL" <<
","
133 << name.str() <<
"_AL" <<
","
134 << name.str() <<
"_Ten" <<
",";
137 else if(tgCast::cast<tgModel, tgRod>(children[i]) != 0)
139 name << children[i]->getTags() <<
" " << rodNum;
140 tgOutput << name.str() <<
"_X" <<
","
141 << name.str() <<
"_Y" <<
","
142 << name.str() <<
"_Z" <<
","
143 << name.str() <<
"_mass" <<
",";
149 tgOutput << std::endl;
162 tgOutput.open(m_fileName.c_str(), std::ios::app);
163 tgOutput << m_totalTime <<
",";
168 tgOutput.open(m_fileName.c_str(), std::ios::app);
169 tgOutput << std::endl;
Contains the definition of interface class tgDataLogger.
Convenience function for combining strings with ints, mostly for naming structures.
Utility class for class casting and filtering collections by type.
Markers for specific places on a tensegrity.
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...
Definition of tgObserver class.
virtual void onStep(tgModel &model, double dt)
virtual void onSetup(tgModel &model)
Contains the definition of class tgRod.
virtual ~tgDataObserver()
std::vector< tgModel * > getDescendants() const