catch type/value error and give default values

This commit is contained in:
Rick Lan
2020-03-18 10:57:09 +10:00
parent 92dc4a0849
commit 071babe348
5 changed files with 28 additions and 8 deletions

View File

@@ -61,8 +61,8 @@ def dmonitoringd_thread(sm=None, pm=None):
dp_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True
try:
dp_awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8'))
except TypeError:
dp_awareness_time = 0.
except (TypeError, ValueError):
dp_awareness_time = 70.
driver_status.awareness_time = 86400 if dp_awareness_time <= 0. else dp_awareness_time * 60.
else:
dp_enable_driver_monitoring = False

View File

@@ -78,7 +78,10 @@ class LanePlanner():
def update_d_poly(self, v_ego):
ts = sec_since_boot()
if ts - self.ts_last_check >= 5.:
self.camera_offset = int(params.get("DragonCameraOffset", encoding='utf8')) * 0.01
try:
self.camera_offset = int(params.get("DragonCameraOffset", encoding='utf8')) * 0.01
except (TypeError, ValueError):
self.camera_offset = CAMERA_OFFSET
self.ts_last_check = ts
# only offset left and right lane lines; offsetting p_poly does not make sense
self.l_poly[3] += self.camera_offset

View File

@@ -97,19 +97,30 @@ class PathPlanner():
if self.lane_change_enabled:
self.dragon_auto_lc_enabled = True if self.params.get("DragonEnableAutoLC", encoding='utf8') == "1" else False
# adjustable assisted lc min speed
self.dragon_assisted_lc_min_mph = int(self.params.get("DragonAssistedLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS
try:
self.dragon_assisted_lc_min_mph = float(self.params.get("DragonAssistedLCMinMPH", encoding='utf8'))
except (TypeError, ValueError):
self.dragon_assisted_lc_min_mph = 37
self.dragon_assisted_lc_min_mph *= CV.MPH_TO_MS
if self.dragon_assisted_lc_min_mph < 0:
self.dragon_assisted_lc_min_mph = 0
if self.dragon_auto_lc_enabled:
# adjustable auto lc min speed
self.dragon_auto_lc_min_mph = int(self.params.get("DragonAutoLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS
try:
self.dragon_auto_lc_min_mph = float(self.params.get("DragonAutoLCMinMPH", encoding='utf8'))
except (TypeError, ValueError):
self.dragon_auto_lc_min_mph = 60
self.dragon_auto_lc_min_mph *= CV.MPH_TO_MS
if self.dragon_auto_lc_min_mph < 0:
self.dragon_auto_lc_min_mph = 0
# when auto lc is smaller than assisted lc, we set assisted lc to the same speed as auto lc
if self.dragon_auto_lc_min_mph < self.dragon_assisted_lc_min_mph:
self.dragon_assisted_lc_min_mph = self.dragon_auto_lc_min_mph
# adjustable auto lc delay
self.dragon_auto_lc_delay = int(self.params.get("DragonAutoLCDelay", encoding='utf8'))
try:
self.dragon_auto_lc_delay = float(self.params.get("DragonAutoLCDelay", encoding='utf8'))
except (TypeError, ValueError):
self.dragon_auto_lc_delay = 2.
if self.dragon_auto_lc_delay < 0:
self.dragon_auto_lc_delay = 0
else:

View File

@@ -152,7 +152,10 @@ class Planner():
modified = dp_get_last_modified()
if self.dp_last_modified != modified:
self.dragon_slow_on_curve = False if self.params.get("DragonEnableSlowOnCurve", encoding='utf8') == "0" else True
self.dragon_accel_profile = int(self.params.get("DragonAccelProfile", encoding='utf8'))
try:
self.dragon_accel_profile = int(self.params.get("DragonAccelProfile", encoding='utf8'))
except (TypeError, ValueError):
self.dragon_accel_profile = ACCEL_NORMAL_MODE
if self.dragon_accel_profile >= 2 or self.dragon_accel_profile <= -2:
self.dragon_accel_profile = 0
self.dp_last_modified = modified

View File

@@ -24,7 +24,10 @@ def main():
if dp_last_modified != modified:
enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False
if enabled:
secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60
try:
secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60
except (TypeError, ValueError):
secs = 0
dp_last_modified = modified
if last_enabled != enabled or last_secs != secs or started or usb_online: