@@ -24,14 +24,28 @@ void DataToLog::init(ProfileLog &aProfileLog) {
24
24
orientation.resize (4 * aProfileLog.length );
25
25
accelerometer.resize (3 * aProfileLog.length );
26
26
gyrometer.resize (3 * aProfileLog.length );
27
- force_sensors.resize (aProfileLog.nbForceSensors * 6 * aProfileLog.length );
27
+ force_sensors.resize (aProfileLog.nbForceSensors * 6 * aProfileLog.length );
28
28
temperatures.resize (aProfileLog.nbDofs * aProfileLog.length );
29
29
controls.resize (aProfileLog.nbDofs * aProfileLog.length );
30
30
timestamp.resize (aProfileLog.length );
31
31
duration.resize (aProfileLog.length );
32
32
33
33
for (unsigned int i = 0 ; i < aProfileLog.nbDofs * aProfileLog.length ; i++) {
34
- motor_angle[i] = joint_angle[i] = velocities[i] = 0.0 ;
34
+ motor_angle[i] = joint_angle[i] = velocities[i] = torques[i] =
35
+ motor_currents[i] = temperatures[i] = controls[i] = 0.0 ;
36
+ }
37
+ for (unsigned int i = 0 ; i < 4 * aProfileLog.length ; i++) {
38
+ orientation[i] = 0 ;
39
+ }
40
+ for (unsigned int i = 0 ; i < 3 * aProfileLog.length ; i++) {
41
+ accelerometer[i] = gyrometer[i] = 0 ;
42
+ }
43
+ for (unsigned int i = 0 ; i < aProfileLog.nbForceSensors *6 *aProfileLog.length ;
44
+ i++) {
45
+ force_sensors[i] = 0 ;
46
+ }
47
+ for (unsigned int i = 0 ; i < aProfileLog.length ; i++) {
48
+ timestamp[i] = duration[i] = 0 ;
35
49
}
36
50
}
37
51
@@ -129,36 +143,36 @@ void Log::save(std::string &fileName) {
129
143
assert (lref_ == lrefts_*profileLog_.nbDofs );
130
144
131
145
std::string suffix (" -mastate.log" );
132
- saveVector (fileName, suffix, StoredData_.motor_angle , profileLog_.nbDofs , lref_ );
146
+ saveVector (fileName, suffix, StoredData_.motor_angle , profileLog_.nbDofs );
133
147
suffix = " -jastate.log" ;
134
- saveVector (fileName, suffix, StoredData_.joint_angle , profileLog_.nbDofs , lref_ );
148
+ saveVector (fileName, suffix, StoredData_.joint_angle , profileLog_.nbDofs );
135
149
suffix = " -vstate.log" ;
136
- saveVector (fileName, suffix, StoredData_.velocities , profileLog_.nbDofs , lref_ );
150
+ saveVector (fileName, suffix, StoredData_.velocities , profileLog_.nbDofs );
137
151
suffix = " -torques.log" ;
138
- saveVector (fileName, suffix, StoredData_.torques , profileLog_.nbDofs , lref_ );
152
+ saveVector (fileName, suffix, StoredData_.torques , profileLog_.nbDofs );
139
153
suffix = " -motor-currents.log" ;
140
- saveVector (fileName, suffix, StoredData_.motor_currents , profileLog_.nbDofs , lref_ );
154
+ saveVector (fileName, suffix, StoredData_.motor_currents , profileLog_.nbDofs );
141
155
suffix = " -accelero.log" ;
142
- saveVector (fileName, suffix, StoredData_.accelerometer , 3 , 3 *lrefts_ );
156
+ saveVector (fileName, suffix, StoredData_.accelerometer , 3 );
143
157
suffix = " -gyro.log" ;
144
- saveVector (fileName, suffix, StoredData_.gyrometer , 3 , 3 *lrefts_ );
158
+ saveVector (fileName, suffix, StoredData_.gyrometer , 3 );
145
159
146
160
ostringstream oss;
147
161
oss << " -forceSensors.log" ;
148
162
suffix = oss.str ();
149
- saveVector (fileName, suffix, StoredData_.force_sensors ,
150
- 6 * profileLog_.nbForceSensors ,
151
- 6 * profileLog_.nbForceSensors * lrefts_);
163
+ if (profileLog_.nbForceSensors > 0 ) {
164
+ saveVector (fileName, suffix, StoredData_.force_sensors ,
165
+ 6 * profileLog_.nbForceSensors );
166
+ }
152
167
153
168
suffix = " -temperatures.log" ;
154
- saveVector (fileName, suffix, StoredData_.temperatures , profileLog_.nbDofs ,
155
- lref_);
169
+ saveVector (fileName, suffix, StoredData_.temperatures , profileLog_.nbDofs );
156
170
157
171
suffix = " -controls.log" ;
158
- saveVector (fileName, suffix, StoredData_.controls , profileLog_.nbDofs , lref_ );
172
+ saveVector (fileName, suffix, StoredData_.controls , profileLog_.nbDofs );
159
173
160
174
suffix = " -duration.log" ;
161
- saveVector (fileName, suffix, StoredData_.duration , 1 , lrefts_ );
175
+ saveVector (fileName, suffix, StoredData_.duration , 1 );
162
176
}
163
177
164
178
inline void writeHeaderToBinaryBuffer (ofstream &of, const std::size_t &nVector,
@@ -176,8 +190,7 @@ inline void writeToBinaryFile(ofstream &of, const double &t, const double &dt,
176
190
}
177
191
178
192
void Log::saveVector (std::string &fileName, std::string &suffix,
179
- const std::vector<double > &avector, std::size_t size,
180
- std::size_t start) {
193
+ const std::vector<double > &avector, std::size_t size) {
181
194
ostringstream oss;
182
195
oss << fileName;
183
196
oss << suffix.c_str ();
@@ -192,7 +205,7 @@ void Log::saveVector(std::string &fileName, std::string &suffix,
192
205
193
206
writeHeaderToBinaryBuffer (aof, profileLog_.length , size + 2 );
194
207
for (unsigned long int i = 0 ; i < profileLog_.length ; i++) {
195
- std::size_t k = (start + i) % profileLog_.length ;
208
+ std::size_t k = i % profileLog_.length ;
196
209
197
210
// Compute and save dt
198
211
if (i == 0 ) {
0 commit comments