43 tgDataObserver::tgDataObserver(std::string filePrefix) :
46 m_filePrefix(filePrefix)
67 int fileTimeSize = 64;
68 char fileTime [fileTimeSize];
71 currentTime = localtime(&rawtime);
72 strftime(fileTime, fileTimeSize,
"%m%d%Y_%H%M%S.txt", currentTime);
73 m_fileName = m_filePrefix + fileTime;
74 std::cout << m_fileName << std::endl;
76 if (m_dataLogger != NULL)
87 tgOutput.open(m_fileName.c_str());
89 if (!tgOutput.is_open())
91 throw std::runtime_error(
"Logs does not exist. Please create a logs folder in your build directory or update your cmake file");
103 tgOutput <<
"Time" <<
",";
105 for (std::size_t i = 0; i < children.size(); i++)
110 std::stringstream name;
112 if(tgCast::cast<tgModel, tgSpringCableActuator>(children[i]) != 0)
114 name << children[i]->getTags() <<
" " << stringNum;
115 tgOutput << name.str() <<
"_RL" <<
","
116 << name.str() <<
"_AL" <<
","
117 << name.str() <<
"_Ten" <<
",";
120 else if(tgCast::cast<tgModel, tgRod>(children[i]) != 0)
122 name << children[i]->getTags() <<
" " << rodNum;
123 tgOutput << name.str() <<
"_X" <<
","
124 << name.str() <<
"_Y" <<
","
125 << name.str() <<
"_Z" <<
","
126 << name.str() <<
"_mass" <<
",";
132 tgOutput << std::endl;
145 tgOutput.open(m_fileName.c_str(), std::ios::app);
146 tgOutput << m_totalTime <<
",";
151 tgOutput.open(m_fileName.c_str(), std::ios::app);
152 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.
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