Skip to content

Commit 803f448

Browse files
author
Ross Fisher
authored
Merge pull request commaai#19 from ShaneSmiskol/patch-2
use json instead of pickle to improve readability of raw file. also use with open(...) as it automatically closes the file afterwards
2 parents f556c0b + e1af898 commit 803f448

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

selfdrive/controls/lib/curvature_learner.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from numpy import clip
2-
import pickle
2+
import json
33
import csv
44
import os
55

@@ -19,15 +19,17 @@ def __init__(self, debug=False):
1919
self.frame = 0
2020
self.debug = debug
2121
try:
22-
self.learned_offsets = pickle.load(open("/data/curvaturev4.p", "rb"))
22+
with open("/data/curvaturev4.json", "r") as f:
23+
self.learned_offsets = json.load(f)
2324
except (OSError, IOError):
2425
self.learned_offsets = {
2526
"center": 0.,
2627
"inner": 0.,
2728
"outer": 0.
2829
}
29-
pickle.dump(self.learned_offsets, open("/data/curvaturev4.p", "wb"))
30-
os.chmod("/data/curvaturev4.p", 0o777)
30+
with open("/data/curvaturev4.json", "w") as f:
31+
json.dump(self.learned_offsets, f)
32+
os.chmod("/data/curvaturev4.json", 0o777)
3133

3234
def update(self, angle_steers=0., d_poly=None, v_ego=0.):
3335
if angle_steers > 0.1:
@@ -55,7 +57,8 @@ def update(self, angle_steers=0., d_poly=None, v_ego=0.):
5557
self.frame += 1
5658

5759
if self.frame == 12000: # every 2 mins
58-
pickle.dump(self.learned_offsets, open("/data/curvaturev4.p", "wb"))
60+
with open("/data/curvaturev4.json", "w") as f:
61+
json.dump(self.learned_offsets, f)
5962
self.frame = 0
6063
if self.debug:
6164
with open('/data/curvdebug.csv', 'a') as csv_file:

0 commit comments

Comments
 (0)