logSplitter.cpp
Go to the documentation of this file.
1 #include <limits>
2 #include <iomanip>
3 #include <fstream>
4 #include <iostream>
5 #include <stdlib.h>
6 #include "hrpsys/idl/RobotHardwareService.hh"
7 
8 int main(int argc, char *argv[])
9 {
10  if (argc < 9){
11  std::cerr << "Usage: " << argv[0] << " [basename of rstate2 log] [dof] [no. of extra servo states] [no. of force sensors] [no. of 3 axes gyro] [no. of 3 axes accelerometers] [no. of batteries] [no. of thermometers]" << std::endl;
12  return 1;
13  }
14 
15  std::string basename(argv[1]);
16  std::ifstream ifs((basename+".rstate2").c_str());
17  if (!ifs.is_open()){
18  std::cerr << "failed to open " << argv[1] << ".rstate2" << std::endl;
19  return 2;
20  }
21  int dof = atoi(argv[2]);
22  int nextrass = atoi(argv[3]);
23  int nfsensor = atoi(argv[4]);
24  int ngyro = atoi(argv[5]);
25  int naccel = atoi(argv[6]);
26  int nbattery = atoi(argv[7]);
27  int ntemp = atoi(argv[8]);
28 
29  std::ofstream ofsq((basename+".q").c_str());
30  std::ofstream ofsqref((basename+".qRef").c_str());
31  std::ofstream ofstau((basename+".tau").c_str());
32  std::ofstream ofsss((basename+".sstate").c_str());
33  std::ofstream ofsfsensor((basename+".fsensor").c_str());
34  std::ofstream ofsgyro((basename+".gyro").c_str());
35  std::ofstream ofsaccel((basename+".accel").c_str());
36  std::ofstream ofsbat((basename+".bat").c_str());
37  std::ofstream ofstemp((basename+".temp").c_str());
38 
39  ofsq.setf(std::ios::fixed, std::ios::floatfield);
40  ofsqref.setf(std::ios::fixed, std::ios::floatfield);
41  ofstau.setf(std::ios::fixed, std::ios::floatfield);
42  ofsss.setf(std::ios::fixed, std::ios::floatfield);
43  ofsfsensor.setf(std::ios::fixed, std::ios::floatfield);
44  ofsgyro.setf(std::ios::fixed, std::ios::floatfield);
45  ofsaccel.setf(std::ios::fixed, std::ios::floatfield);
46  ofsbat.setf(std::ios::fixed, std::ios::floatfield);
47  ofstemp.setf(std::ios::fixed, std::ios::floatfield);
48 
49  double time, v;
50  int ss;
51  std::string str;
52 
53  ifs >> time;
54  while(!ifs.eof()){
55  // q
56  ofsq << time << " ";
57  for (int i=0; i<dof; i++){
58  ifs >> v; ofsq << v << " ";
59  }
60  ofsq << std::endl;
61  // qRef
62  ofsqref << time << " ";
63  for (int i=0; i<dof; i++){
64  ifs >> v; ofsqref << v << " ";
65  }
66  ofsqref << std::endl;
67  // tau
68  ofstau << time << " ";
69  for (int i=0; i<dof; i++){
70  ifs >> v; ofstau << v << " ";
71  }
72  ofstau << std::endl;
73  // servo state
74  ofsss << time << " ";
75  for (int i=0; i<dof; i++){
76  ifs >> ss;
77  ofsss << ((ss&OpenHRP::RobotHardwareService::CALIB_STATE_MASK) >> OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT) << " ";
78  ofsss << ((ss&OpenHRP::RobotHardwareService::SERVO_STATE_MASK) >> OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT) << " ";
79  ofsss << ((ss&OpenHRP::RobotHardwareService::POWER_STATE_MASK) >> OpenHRP::RobotHardwareService::POWER_STATE_SHIFT) << " ";
80  ofsss << ((ss&OpenHRP::RobotHardwareService::SERVO_ALARM_MASK) >> OpenHRP::RobotHardwareService::SERVO_ALARM_SHIFT) << " ";
81  ofsss << ((ss&OpenHRP::RobotHardwareService::DRIVER_TEMP_MASK) >> OpenHRP::RobotHardwareService::DRIVER_TEMP_SHIFT) << " ";
82  for (int j=0; j<nextrass; j++){
83  ifs >> ss;
84  ofsss << ss << " ";
85  }
86  }
87  ofsss << std::endl;
88  // force sensor
89  ofsfsensor << time << " ";
90  for (int i=0; i<6*nfsensor; i++){
91  ifs >> v; ofsfsensor << v << " ";
92  }
93  ofsfsensor << std::endl;
94  // gyro
95  ofsgyro << time << " ";
96  for (int i=0; i<3*ngyro; i++){
97  ifs >> v; ofsgyro << v << " ";
98  }
99  ofsgyro << std::endl;
100  // accelerometer
101  ofsaccel << time << " ";
102  for (int i=0; i<3*naccel; i++){
103  ifs >> v; ofsaccel << v << " ";
104  }
105  ofsaccel << std::endl;
106  // battery
107  ofsbat << time << " ";
108  for (int i=0; i<3*nbattery+2; i++){
109  ifs >> str;
110  if (str == "nan"){
111  v = std::numeric_limits<double>::quiet_NaN();
112  }else{
113  v = atof(str.c_str());
114  }
115  ofsbat << v << " ";
116  }
117  ofsbat << std::endl;
118  // thermometer
119  ofstemp << time << " ";
120  for (int i=0; i<ntemp; i++){
121  ifs >> v; ofstemp << v << " ";
122  }
123  ofstemp << std::endl;
124 
125  ifs >> time;
126  }
127 
128  return 0;
129 }
ifs
std::string basename(const std::string name)
png_uint_32 i
def j(str, encoding="cp932")
int main(int argc, char *argv[])
Definition: logSplitter.cpp:8


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50