修正 dashcamd 和 safetyguard 邏輯

This commit is contained in:
Rick Lan
2019-07-03 12:41:53 +10:00
parent 13ae651f46
commit 11a7b2d9bf
3 changed files with 16 additions and 21 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ class DriverStatus():
not (standstill and self.awareness - self.step_change <= self.threshold_prompt):
self.awareness = max(self.awareness - self.step_change, -0.1)
if params.get("DragonDisableDriverSafetyCheck") == "0":
if params.get("DragonDisableDriverSafetyCheck") == "1":
alert = None
if self.awareness <= 0.:
# terminal red alert: disengagement required
+8 -9
View File
@@ -27,14 +27,12 @@ def main(gctx=None):
if not os.path.exists(dashcam_videos):
os.makedirs(dashcam_videos)
context = zmq.Context()
thermal_sock = messaging.sub_sock(context, service_list['thermal'].port)
poller = zmq.Poller()
sock = messaging.sub_sock(service_list['thermal'].port, poller)
poller.poll(timeout=1000)
while 1:
if params.get("DragonEnableDashcam") == "1":
# get health of board, log this in "thermal"
msg = messaging.recv_sock(thermal_sock, wait=True)
now = datetime.datetime.now()
file_name = now.strftime("%Y-%m-%d_%H-%M-%S")
os.system("screenrecord --bit-rate %s --time-limit %s %s%s.mp4 &" % (bit_rates, duration, dashcam_videos, file_name))
@@ -45,13 +43,14 @@ def main(gctx=None):
# we should clean up files here if use too much spaces
# when used spaces greater than max available storage
# or when free space is less than 10%
print(used_spaces)
print(max_storage)
if used_spaces >= max_storage or msg.thermal.freeSpace < freespace_limit:
# get health of board, log this in "thermal"
msg = messaging.recv_sock(sock, wait=True)
if used_spaces >= max_storage or (msg is not None and msg.thermal.freeSpace < freespace_limit):
# get all the files in the dashcam_videos path
files = [f for f in sorted(os.listdir(dashcam_videos)) if os.path.isfile(dashcam_videos + f)]
for file in files:
msg = messaging.recv_sock(thermal_sock, wait=True)
msg = messaging.recv_sock(sock, wait=True)
# delete file one by one and once it has enough space for 1 video, we stop deleting
if used_spaces - last_used_spaces < max_size_per_file or msg.thermal.freeSpace < freespace_limit:
os.system("rm -fr %s" % (dashcam_videos + file))
+7 -11
View File
@@ -15,9 +15,9 @@ mediaplayer = '/data/openpilot/selfdrive/dragonpilot/mediaplayer/'
def main(gctx=None):
context = zmq.Context()
poller = zmq.Poller()
controls_state_sock = messaging.sub_sock(context, service_list['controlsState'].port, conflate=True, poller=poller)
sock = messaging.sub_sock(service_list['controlsState'].port, poller)
poller.poll(timeout=1000)
last_v_ego = 0.
last_active = False
@@ -27,22 +27,18 @@ def main(gctx=None):
while 1:
controls_state = None
v_ego = 0
active = False
for socket, event in poller.poll(100):
if socket is controls_state_sock:
controls_state = messaging.recv_one(socket)
controls_state = messaging.recv_sock(sock, wait=True)
if controls_state is not None:
v_ego = controls_state.controlsState.vEgo
active = controls_state.controlsState.active
# we are driving and all of sudden we dont have any speed at all
# we better warn the driver before it's too late
if last_active and last_v_ego >= 5 and v_ego == 0:
subprocess.Popen([mediaplayer + 'mediaplayer', '/data/openpilot/selfdrive/dragonpilot/safeguardd/error.wav'], shell = False, stdin=None, stdout=None, stderr=None, env = env, close_fds=True)
# we are driving and all of sudden we dont have any speed at all
# we better warn the driver before it's too late
if last_active and last_v_ego >= 5 and v_ego == 0:
subprocess.Popen([mediaplayer + 'mediaplayer', '/data/openpilot/selfdrive/dragonpilot/safeguardd/error.wav'], shell = False, stdin=None, stdout=None, stderr=None, env = env, close_fds=True)
last_active = active
last_v_ego = v_ego