5
5
import argparse
6
6
import os
7
7
8
+ from hal .files .models .files import Document
9
+ from hal .files .models .system import ls_recurse , is_file
8
10
from matplotlib import pyplot as plt
9
- import matplotlib .dates as mdates
10
11
12
+ from config .amk import AMK_VALUES_1 , Motors , AMK_VALUES_2
11
13
from parsers .can .amk import AMKParser
12
- from parsers .can .ti import TIParser
13
14
from parsers .logs .yolo import YOLOLogParser
14
15
from parsers .models .explorer import LogExplorer
15
16
17
+ DEFAULT_OUTPUT_FOLDER = os .path .join (os .getcwd (), 'out' )
18
+
16
19
17
20
def create_args ():
18
21
"""
@@ -24,6 +27,8 @@ def create_args():
24
27
'-h for full usage' )
25
28
parser .add_argument ('-i' , dest = 'file' ,
26
29
help = 'file to parse' , required = True )
30
+ parser .add_argument ('-o' , dest = 'out' ,
31
+ help = 'output folder' , default = DEFAULT_OUTPUT_FOLDER , required = False )
27
32
return parser
28
33
29
34
@@ -37,10 +42,11 @@ def parse_args(parser):
37
42
38
43
args = parser .parse_args ()
39
44
file = str (args .file )
45
+ out = str (args .out )
40
46
41
47
assert os .path .exists (file )
42
48
43
- return file
49
+ return file , out
44
50
45
51
46
52
def get_plot (messages , labels , time_index , y_indexes ):
@@ -62,58 +68,106 @@ def get_plot(messages, labels, time_index, y_indexes):
62
68
pass # todo print exc
63
69
64
70
65
- def parse_file (file_path ):
71
+ def get_explorer (file_path ):
66
72
message_classes = [
67
73
{
68
- "id" : "13" ,
69
- "labels" : ["throttle (%)" , "brake (%)" ],
70
- "bytes parser" : TIParser ,
71
- "func" : TIParser .get_as_potentiometers
72
- },
73
- {
74
- "id" : "14" ,
75
- "labels" : ["steering (°)" , "TI core temp (C)" ],
76
- "bytes parser" : TIParser ,
77
- "func" : TIParser .get_as_steering
78
- },
79
- {
80
- "id" : "16" ,
81
- "labels" : ["FR susp (mm)" , "FL susp (mm)" ],
82
- "bytes parser" : TIParser ,
83
- "func" : TIParser .get_as_suspensions_1
84
- },
85
- {
86
- "id" : "283" ,
74
+ "id" : AMK_VALUES_1 [Motors .FL ],
75
+ "filename" : "AMK1_FL" ,
87
76
"labels" : ["FL status" , "FL actual velocity (x100 rpm)" , "FL torque curr (A)" , "FL mag curr (A)" ,
88
77
"FL calc torque (Nm)" ],
89
78
"bytes parser" : AMKParser ,
90
79
"func" : AMKParser .get_as_actual_values_1
91
80
},
92
81
{
93
- "id" : "284" ,
82
+ "id" : AMK_VALUES_2 [Motors .FL ],
83
+ "filename" : "AMK2_FL" ,
84
+ "labels" : ["FL T motor (°C)" , "FL T inverter (°C)" , "FL error" , "FL T IGBT (°C)" ],
85
+ "bytes parser" : AMKParser ,
86
+ "func" : AMKParser .get_as_actual_values_2
87
+ },
88
+ {
89
+ "id" : AMK_VALUES_1 [Motors .FR ],
90
+ "filename" : "AMK1_FR" ,
94
91
"labels" : ["FR status" , "FR actual velocity (x100 rpm)" , "FR torque curr (A)" , "FR mag curr (A)" ,
95
92
"FR calc torque (Nm)" ],
96
93
"bytes parser" : AMKParser ,
97
94
"func" : AMKParser .get_as_actual_values_1
98
95
},
99
96
{
100
- "id" : "287" ,
97
+ "id" : AMK_VALUES_2 [Motors .FR ],
98
+ "filename" : "AMK2_FR" ,
99
+ "labels" : ["FR T motor (°C)" , "FR T inverter (°C)" , "FR error" , "FR T IGBT (°C)" ],
100
+ "bytes parser" : AMKParser ,
101
+ "func" : AMKParser .get_as_actual_values_2
102
+ },
103
+ {
104
+ "id" : AMK_VALUES_1 [Motors .RL ],
105
+ "filename" : "AMK1_RL" ,
101
106
"labels" : ["RL status" , "RL actual velocity (x100 rpm)" , "RL torque curr (A)" , "RL mag curr (A)" ,
102
107
"RL calc torque (Nm)" ],
103
108
"bytes parser" : AMKParser ,
104
109
"func" : AMKParser .get_as_actual_values_1
105
110
},
106
111
{
107
- "id" : "288" ,
112
+ "id" : AMK_VALUES_2 [Motors .RL ],
113
+ "filename" : "AMK2_RL" ,
114
+ "labels" : ["RL T motor (°C)" , "RL T inverter (°C)" , "RL error" , "RL T IGBT (°C)" ],
115
+ "bytes parser" : AMKParser ,
116
+ "func" : AMKParser .get_as_actual_values_2
117
+ },
118
+ {
119
+ "id" : AMK_VALUES_1 [Motors .RR ],
120
+ "filename" : "AMK1_RR" ,
108
121
"labels" : ["RR status" , "RR actual velocity (x100 rpm)" , "RR torque curr (A)" , "RR mag curr (A)" ,
109
122
"RR calc torque (Nm)" ],
110
123
"bytes parser" : AMKParser ,
111
124
"func" : AMKParser .get_as_actual_values_1
125
+ },
126
+ {
127
+ "id" : AMK_VALUES_2 [Motors .RR ],
128
+ "filename" : "AMK2_RR" ,
129
+ "labels" : ["RR T motor (°C)" , "RR T inverter (°C)" , "RR error" , "RR T IGBT (°C)" ],
130
+ "bytes parser" : AMKParser ,
131
+ "func" : AMKParser .get_as_actual_values_2
112
132
}
113
- ]
133
+ ] # todo read .json
114
134
115
135
explorer = LogExplorer (file_path , YOLOLogParser , message_classes )
136
+ return explorer , message_classes
137
+
138
+
139
+ def plot (explorer , messages_list , labels_list ):
140
+ for i in range (1 , 8 , 2 ):
141
+ plt .subplot (2 , 2 , int (i / 2 ) + 1 ) # select subplot
142
+
143
+ # labels = [labels_list[i][1]]
144
+ # y_indexes = [10, 11, 12, 13]
145
+
146
+ labels = [labels_list [i ][0 ], labels_list [i ][1 ], labels_list [i ][3 ]]
147
+ y_indexes = [9 , 10 , 12 ]
148
+
149
+ explorer .plot (messages_list [i ], labels , time_index = 8 , y_indexes = y_indexes )
150
+
151
+ # show plots
152
+ plt .show ()
153
+
116
154
155
+ def save (explorer , messages_list , labels_list , files_list , output_folder ):
156
+ if output_folder :
157
+ print ('Saving to {}' .format (output_folder ))
158
+ explorer .save_many_to_csv (
159
+ messages_list ,
160
+ labels_list ,
161
+ files_list ,
162
+ output_folder
163
+ )
164
+
165
+
166
+ def print_log (explorer , messages_list , labels_list ):
167
+ explorer .pretty_print (messages_list , labels_list )
168
+
169
+
170
+ def get_lists (explorer , message_classes ):
117
171
messages_list = [
118
172
explorer .get_messages (
119
173
message_class ['bytes parser' ],
@@ -127,46 +181,30 @@ def parse_file(file_path):
127
181
for message_class in message_classes
128
182
]
129
183
files_list = [
130
- message_class ['id ' ]
184
+ message_class ['filename ' ]
131
185
for message_class in message_classes
132
186
]
133
-
134
- # save to .csv
135
- # output_folder = os.path.join(os.getcwd(), 'out')
136
- # print('Saving to {}'.format(output_folder))
137
- # explorer.save_many_to_csv(
138
- # messages_list,
139
- # labels_list,
140
- # files_list,
141
- # output_folder
142
- # )
143
-
144
- # print all classes
145
- # explorer.pretty_print(messages_list, labels_list)
146
-
147
- # 2 x 2 plots
148
- # for i in range(3, 7, 1):
149
- # plt.subplot(2, 2, i - 2) # select subplot
150
- #
151
- # explorer.plot(messages_list[0], labels_list[0], time_index=8, y_indexes=[9, 10]) # throttle brake
152
- # explorer.plot(messages_list[1], labels_list[1], time_index=8, y_indexes=[9]) # steering
153
- # explorer.plot(messages_list[2], labels_list[2], time_index=8, y_indexes=[9, 10]) # potentiometers
154
- #
155
- # explorer.plot(messages_list[i], labels_list[i][1:], time_index=8, y_indexes=[10]) # motors
156
-
157
- explorer .plot (messages_list [0 ], labels_list [0 ], time_index = 8 , y_indexes = [9 , 10 ]) # throttle brake
158
- explorer .plot (messages_list [1 ], labels_list [1 ], time_index = 8 , y_indexes = [9 ]) # steering
159
- explorer .plot (messages_list [2 ], labels_list [2 ], time_index = 8 , y_indexes = [9 , 10 ]) # potentiometers
160
-
161
- explorer .plot (messages_list [6 ], labels_list [6 ][1 :], time_index = 8 , y_indexes = [10 ]) # motors
162
-
163
- # show plots
164
- plt .show ()
187
+ return messages_list , labels_list , files_list
165
188
166
189
167
190
def main ():
168
- file_path = parse_args (create_args ())
169
- parse_file (file_path )
191
+ folder_path , out_folder = parse_args (create_args ())
192
+ file_extension = ".csv"
193
+ files = sorted ([
194
+ file
195
+ for file in ls_recurse (folder_path )
196
+ if is_file (file ) and Document (file ).extension == file_extension
197
+ ])
198
+
199
+ for file_path in files :
200
+ output_folder_name = os .path .basename (file_path ).replace (file_extension , '' )
201
+ output_folder = os .path .join (out_folder , output_folder_name )
202
+
203
+ explorer , message_classes = get_explorer (file_path )
204
+ messages_list , labels_list , files_list = get_lists (explorer , message_classes )
205
+ plot (explorer , messages_list , labels_list )
206
+ save (explorer , messages_list , labels_list , files_list , output_folder )
207
+ # print_log(explorer, messages_list, labels_list)
170
208
171
209
172
210
if __name__ == '__main__' :
0 commit comments