Skip to content

Commit b1beaab

Browse files
committed
add amk config
1 parent 430e2b9 commit b1beaab

File tree

4 files changed

+133
-62
lines changed

4 files changed

+133
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tmp/
33
data/
44
output/
55
venv/
6+
out/
67

78
### PyCharm ###
89
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm

peeper/config/__init__.py

Whitespace-only changes.

peeper/config/amk.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from enum import Enum
2+
3+
4+
class Motors(Enum):
5+
FL = 3
6+
FR = 2
7+
RL = 1
8+
RR = 0
9+
10+
11+
AMK_VALUES_1_CAN_IDS = ['283', '284', '287', '288']
12+
AMK_VALUES_2_CAN_IDS = ['285', '286', '289', '28a']
13+
AMK_SETPOINTS_CAN_IDS = ['184', '185', '188', '189']
14+
15+
AMK_VALUES_1 = {
16+
Motors.FL: AMK_VALUES_1_CAN_IDS[Motors.FL.value],
17+
Motors.FR: AMK_VALUES_1_CAN_IDS[Motors.FR.value],
18+
Motors.RL: AMK_VALUES_1_CAN_IDS[Motors.RL.value],
19+
Motors.RR: AMK_VALUES_1_CAN_IDS[Motors.RR.value]
20+
}
21+
AMK_VALUES_2 = {
22+
Motors.FL: AMK_VALUES_2_CAN_IDS[Motors.FL.value],
23+
Motors.FR: AMK_VALUES_2_CAN_IDS[Motors.FR.value],
24+
Motors.RL: AMK_VALUES_2_CAN_IDS[Motors.RL.value],
25+
Motors.RR: AMK_VALUES_2_CAN_IDS[Motors.RR.value]
26+
}
27+
AMK_SETPOINTS = {
28+
Motors.FL: AMK_SETPOINTS_CAN_IDS[Motors.FL.value],
29+
Motors.FR: AMK_SETPOINTS_CAN_IDS[Motors.FR.value],
30+
Motors.RL: AMK_SETPOINTS_CAN_IDS[Motors.RL.value],
31+
Motors.RR: AMK_SETPOINTS_CAN_IDS[Motors.RR.value]
32+
}

peeper/parsers/cli.py

Lines changed: 100 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
import argparse
66
import os
77

8+
from hal.files.models.files import Document
9+
from hal.files.models.system import ls_recurse, is_file
810
from matplotlib import pyplot as plt
9-
import matplotlib.dates as mdates
1011

12+
from config.amk import AMK_VALUES_1, Motors, AMK_VALUES_2
1113
from parsers.can.amk import AMKParser
12-
from parsers.can.ti import TIParser
1314
from parsers.logs.yolo import YOLOLogParser
1415
from parsers.models.explorer import LogExplorer
1516

17+
DEFAULT_OUTPUT_FOLDER = os.path.join(os.getcwd(), 'out')
18+
1619

1720
def create_args():
1821
"""
@@ -24,6 +27,8 @@ def create_args():
2427
'-h for full usage')
2528
parser.add_argument('-i', dest='file',
2629
help='file to parse', required=True)
30+
parser.add_argument('-o', dest='out',
31+
help='output folder', default=DEFAULT_OUTPUT_FOLDER, required=False)
2732
return parser
2833

2934

@@ -37,10 +42,11 @@ def parse_args(parser):
3742

3843
args = parser.parse_args()
3944
file = str(args.file)
45+
out = str(args.out)
4046

4147
assert os.path.exists(file)
4248

43-
return file
49+
return file, out
4450

4551

4652
def get_plot(messages, labels, time_index, y_indexes):
@@ -62,58 +68,106 @@ def get_plot(messages, labels, time_index, y_indexes):
6268
pass # todo print exc
6369

6470

65-
def parse_file(file_path):
71+
def get_explorer(file_path):
6672
message_classes = [
6773
{
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",
8776
"labels": ["FL status", "FL actual velocity (x100 rpm)", "FL torque curr (A)", "FL mag curr (A)",
8877
"FL calc torque (Nm)"],
8978
"bytes parser": AMKParser,
9079
"func": AMKParser.get_as_actual_values_1
9180
},
9281
{
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",
9491
"labels": ["FR status", "FR actual velocity (x100 rpm)", "FR torque curr (A)", "FR mag curr (A)",
9592
"FR calc torque (Nm)"],
9693
"bytes parser": AMKParser,
9794
"func": AMKParser.get_as_actual_values_1
9895
},
9996
{
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",
101106
"labels": ["RL status", "RL actual velocity (x100 rpm)", "RL torque curr (A)", "RL mag curr (A)",
102107
"RL calc torque (Nm)"],
103108
"bytes parser": AMKParser,
104109
"func": AMKParser.get_as_actual_values_1
105110
},
106111
{
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",
108121
"labels": ["RR status", "RR actual velocity (x100 rpm)", "RR torque curr (A)", "RR mag curr (A)",
109122
"RR calc torque (Nm)"],
110123
"bytes parser": AMKParser,
111124
"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
112132
}
113-
]
133+
] # todo read .json
114134

115135
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+
116154

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):
117171
messages_list = [
118172
explorer.get_messages(
119173
message_class['bytes parser'],
@@ -127,46 +181,30 @@ def parse_file(file_path):
127181
for message_class in message_classes
128182
]
129183
files_list = [
130-
message_class['id']
184+
message_class['filename']
131185
for message_class in message_classes
132186
]
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
165188

166189

167190
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)
170208

171209

172210
if __name__ == '__main__':

0 commit comments

Comments
 (0)