Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving P,I,F parameters from pid controller #116

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion selfdrive/car/tesla/PCC_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ def __init__(self,carcontroller):
self.params = Params()
self.average_speed_over_x_suggestions = 3 #10x a second
self.maxsuggestedspeed_avg = MovingAverage(self.average_speed_over_x_suggestions)

def load_pid(self):
try:
v_pid_json = open(V_PID_FILE)
data = json.load(v_pid_json)
if (self.LoC):
self.LoC.pid.p = data['p']
self.LoC.pid.i = data['i']
self.LoC.pid.f = data['f']
else:
print("self.LoC not initialized!")
except IOError:
print("file not present, creating at next reset")

#Helper function for saving the PCC pid constants across drives
def save_pid(self, pid):
data = {}
data['p'] = pid.p
data['i'] = pid.i
data['f'] = pid.f
try:
with open(V_PID_FILE , 'w') as outfile :
json.dump(data, outfile)
except IOError:
print("PDD pid parameters could not be saved to file")

def max_v_by_speed_limit(self,pedal_set_speed_ms ,speed_limit_ms, CS):
# if more than 10 kph / 2.78 ms, consider we have speed limit
Expand All @@ -195,6 +220,9 @@ def max_v_by_speed_limit(self,pedal_set_speed_ms ,speed_limit_ms, CS):
return pedal_set_speed_ms

def reset(self, v_pid):
#save the pid parameters to params file
self.save_pid(self.LoC.pid)

if self.LoC and RESET_PID_ON_DISENGAGE:
self.LoC.reset(v_pid)

Expand Down Expand Up @@ -378,7 +406,12 @@ def update_pdl(self, enabled, CS, frame, actuators, pcm_speed, speed_limit_ms, s
# how much accel and break we have to do
####################################################################
if PCCModes.is_selected(FollowMode(), CS.cstm_btns):
self.v_pid = self.calc_follow_speed_ms(CS,alca_enabled)
# Get v_id from the stored file, only the first activation where v_pid eq 0
if (not RESET_PID_ON_DISENGAGE and self.v_pid == 0.):
self.load_pid()
else:
self.v_pid = self.calc_follow_speed_ms(CS,alca_enabled)

if mapd is not None:
v_curve = max_v_in_mapped_curve_ms(mapd.liveMapData, self.pedal_speed_kph)
if v_curve:
Expand Down