NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgDataLogger.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
26 #include "tgDataLogger.h"
27 
28 #include "util/tgBaseCPGNode.h"
30 #include "core/tgRod.h"
31 #include "core/abstractMarker.h"
32 
33 #include "LinearMath/btVector3.h"
34 
35 #include <iostream>
36 #include <fstream>
37 
38 tgDataLogger::tgDataLogger(std::string fileName) :
39 m_fileName(fileName)
40 {}
41 
44 
45 { }
46 
47 void tgDataLogger::render(const tgRod& rod) const
48 {
49  std::ofstream tgOutput;
50  tgOutput.open(m_fileName.c_str(), std::ios::app);
51 
52  btVector3 com = rod.centerOfMass();
53 
54  tgOutput << com[0] << ","
55  << com[1] << ","
56  << com[2] << ","
57  << rod.mass() << ",";
58 
59  tgOutput.close();
60 }
61 
63 {
64  std::ofstream tgOutput;
65  tgOutput.open(m_fileName.c_str(), std::ios::app);
66 
67  tgOutput << mSCA.getRestLength() << ","
68  << mSCA.getCurrentLength() << ","
69  << mSCA.getTension() << ",";
70 
71  tgOutput.close();
72 }
73 
74 void tgDataLogger::render(const tgModel& model) const
75 {
76  const std::vector<abstractMarker>& markers = model.getMarkers();
77 
78  const std::size_t n = 0;
79  for (std::size_t i = 0; i < n; i++)
80  {
81  std::ofstream tgOutput;
82  tgOutput.open(m_fileName.c_str(), std::ios::app);
83 
84  btVector3 worldPos = markers[i].getWorldPosition();
85 
86  tgOutput << worldPos[0] << ","
87  << worldPos[1] << ","
88  << worldPos[2] << ",";
89 
90  tgOutput.close();
91 
92  }
93 }
virtual void render(const tgRod &rod) const
virtual const double getTension() const
Contains the definition of interface class tgDataLogger.
Markers for specific places on a tensegrity.
virtual btVector3 centerOfMass() const
Definition: tgBaseRigid.cpp:74
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
virtual ~tgDataLogger()
virtual const double getRestLength() const
virtual double mass() const
Definition: tgBaseRigid.h:65
Contains the definition of class tgRod.
virtual const double getCurrentLength() const
Definition of class tgBaseCPGNode.
Definition: tgRod.h:43