-
Notifications
You must be signed in to change notification settings - Fork 2
/
log_formatter.py
132 lines (109 loc) · 4.32 KB
/
log_formatter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import sys
import os
import mc_log_ui
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import img2pdf
from PIL import Image # img2pdfと一緒にインストールされたPillowを使います
import shutil
def main():
args = sys.argv
log_path = None
config_path = None
if len(args) == 2:
log_path = args[1]
print(args[1])
elif len(args) == 3:
config_path = args[1]
log_path = args[2]
print("log " + log_path) # log file
print("config " + config_path) # config file
log = mc_log_ui.read_log(log_path)
xyz = ["x", "y", "z"]
wrench = ["fx", "fy", "fz", "cx", "cy", "cz"]
joint = ["0" , "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
logged_list = []
centroidal_param = [
"CentroidalManager_IRSL_LOG_ControlRobot_position",
"CentroidalManager_IRSL_LOG_ControlRobot_orientation",
"CentroidalManager_IRSL_LOG_RealRobot_position",
"CentroidalManager_IRSL_LOG_RealRobot_orientation",
"CentroidalManager_IRSL_LOG_PlannedRobot_dcm",
"CentroidalManager_IRSL_LOG_RealRobot_dcm",
"CentroidalManager_CoM_planned",
"CentroidalManager_CoM_controlRobot",
"CentroidalManager_CoM_realRobot_com",
"CentroidalManager_CoM_realRobot_comVelocity",
"CentroidalManager_CoM_realRobot_comAcceleration",
"CentroidalManager_CoM_planned",
"CentroidalManager_ZMP_ref",
"CentroidalManager_ZMP_control",
"CentroidalManager_ZMP_planned",
"CentroidalManager_ZMP_measured",
]
foottask_param = [
"FootTask_Left_filteredMeasuredWrench",
"FootTask_Right_filteredMeasuredWrench",
"FootTask_Left_targetWrench",
"FootTask_Right_targetWrench",
]
footmanger_param = [
"FootManager_supportPhase",
]
qout_param = [
"CentroidalManager_IRSL_LOG_ControlRobot_q",
"CentroidalManager_IRSL_LOG_RealRobot_q",
]
# add "x", "y", "z" to the logged_list
for log_name in centroidal_param:
for axis in xyz:
logged_list.append(log_name + "_" + axis)
# add "fx", "fy", "fz", "cx", "cy", "cz" to the logged_list
for log_name in foottask_param:
for axis in wrench:
logged_list.append(log_name + "_" + axis)
# add "supportPhase" to the logged_list
for log_name in footmanger_param:
logged_list.append(log_name)
# add "qout" to the logged_list
for log_name in qout_param:
for joint_name in joint:
logged_list.append(log_name + "_" + joint_name)
#columns : logged_list
#index : log["t"]
df = pd.DataFrame(index=log["t"], columns=logged_list)
#pandas.DataFrameにデータを格納
for log_name in logged_list:
df[log_name] = log[log_name]
#データの保存先 / ファイル名
file_name = (log_path.split('/')[-1]).strip(".bin")
#データ用フォルダの作成
if not os.path.isdir(file_name):
os.mkdir(file_name)
#データをcsvファイルに書き出し
df.to_csv(file_name + "/" + file_name + ".csv")
#image用フォルダの作成
if not os.path.isdir(file_name + "/image"):
os.mkdir(file_name + "/image")
#データをimageに書き出し
for i in range(len(logged_list)):
fig, ax = plt.subplots()
ax.plot(df[logged_list[i]], "o-", markersize=0.1, color='Red')
ax.set_title(logged_list[i])
fig.tight_layout()
fig.savefig(file_name + "/image/" + logged_list[i] + ".png")
pdf_path = file_name + "/" + file_name + ".pdf"
image_path = file_name + "/image/"
extension = ".png"
with open(pdf_path,"wb") as f:
# 画像フォルダの中にあるPNGファイルを取得し配列に追加、バイナリ形式でファイルに書き込む
f.write(img2pdf.convert([Image.open(image_path+j).filename for j in os.listdir(image_path)if j.endswith(extension)]))
# binファイルのコピー
shutil.copyfile(log_path,file_name + "/" + log_path.split('/')[-1])
# configファイルをtextファイルにコピー
if(config_path != None):
shutil.copyfile(config_path,file_name + "/" + file_name + ".txt")
if __name__ == "__main__":
main()