manager runs on Mac, and other openpilot for PC fixes (#1037)

* use the openpilot/persist directory on PC

* manager runs on mac

* sim runs w/o carla

* fix params location in test

* that rmtree can fail and it's okay

* refactor params clear functionality

* set PARAMS_PATH

old-commit-hash: c42e2ecc50
commatwo_master
George Hotz 5 years ago committed by GitHub
parent 8969fa7e09
commit c20b197bce
  1. 2
      common/android.py
  2. 4
      common/api/__init__.py
  3. 7
      common/basedir.py
  4. 6
      common/ffi_wrapper.py
  5. 9
      common/params.py
  6. 5
      selfdrive/athena/athenad.py
  7. 3
      selfdrive/controls/lib/cluster/fastcluster_py.py
  8. 3
      selfdrive/controls/lib/lateral_mpc/libmpc_py.py
  9. 3
      selfdrive/controls/lib/longitudinal_mpc/libmpc_py.py
  10. 13
      selfdrive/manager.py
  11. 21
      selfdrive/registration.py
  12. 3
      selfdrive/test/longitudinal_maneuvers/test_longitudinal.py
  13. 3
      selfdrive/test/process_replay/process_replay.py
  14. 3
      selfdrive/test/test_car_models.py
  15. 23
      tools/sim/controller.py

@ -92,6 +92,8 @@ def parse_service_call_bytes(ret):
def get_network_type(NetworkType): def get_network_type(NetworkType):
wifi_check = parse_service_call_string(service_call(["connectivity", "2"])) wifi_check = parse_service_call_string(service_call(["connectivity", "2"]))
if wifi_check is None:
return NetworkType.none
if 'WIFI' in wifi_check: if 'WIFI' in wifi_check:
return NetworkType.wifi return NetworkType.wifi
else: else:

@ -1,13 +1,13 @@
import jwt import jwt
import requests import requests
from datetime import datetime, timedelta from datetime import datetime, timedelta
from common.basedir import PERSIST
from selfdrive.version import version from selfdrive.version import version
class Api(): class Api():
def __init__(self, dongle_id): def __init__(self, dongle_id):
self.dongle_id = dongle_id self.dongle_id = dongle_id
with open('/persist/comma/id_rsa') as f: with open(PERSIST+'/comma/id_rsa') as f:
self.private_key = f.read() self.private_key = f.read()
def get(self, *args, **kwargs): def get(self, *args, **kwargs):

@ -1,4 +1,11 @@
import os import os
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))
from common.android import ANDROID
if ANDROID:
PERSIST = "/persist"
PARAMS = "/data/params"
else:
PERSIST = os.path.join(BASEDIR, "persist")
PARAMS = os.path.join(BASEDIR, "persist", "params")

@ -2,8 +2,14 @@ import os
import sys import sys
import fcntl import fcntl
import hashlib import hashlib
import platform
from cffi import FFI from cffi import FFI
def suffix():
if platform.system() == "Darwin":
return ".dylib"
else:
return ".so"
def ffi_wrap(name, c_code, c_header, tmpdir="/tmp/ccache", cflags="", libraries=None): def ffi_wrap(name, c_code, c_header, tmpdir="/tmp/ccache", cflags="", libraries=None):
if libraries is None: if libraries is None:

@ -29,7 +29,7 @@ import fcntl
import tempfile import tempfile
import threading import threading
from enum import Enum from enum import Enum
from common.basedir import PARAMS
def mkdirs_exists_ok(path): def mkdirs_exists_ok(path):
try: try:
@ -320,7 +320,7 @@ def write_db(params_path, key, value):
lock.release() lock.release()
class Params(): class Params():
def __init__(self, db='/data/params'): def __init__(self, db=PARAMS):
self.db = db self.db = db
# create the database if it doesn't exist... # create the database if it doesn't exist...
@ -328,6 +328,11 @@ class Params():
with self.transaction(write=True): with self.transaction(write=True):
pass pass
def clear_all(self):
shutil.rmtree(self.db, ignore_errors=True)
with self.transaction(write=True):
pass
def transaction(self, write=False): def transaction(self, write=False):
if write: if write:
return DBWriter(self.db) return DBWriter(self.db)

@ -19,6 +19,7 @@ from selfdrive.loggerd.config import ROOT
import cereal.messaging as messaging import cereal.messaging as messaging
from common import android from common import android
from common.basedir import PERSIST
from common.api import Api from common.api import Api
from common.params import Params from common.params import Params
from cereal.services import service_list from cereal.services import service_list
@ -188,10 +189,10 @@ def startLocalProxy(global_end_event, remote_ws_uri, local_port):
@dispatcher.add_method @dispatcher.add_method
def getPublicKey(): def getPublicKey():
if not os.path.isfile('/persist/comma/id_rsa.pub'): if not os.path.isfile(PERSIST+'/comma/id_rsa.pub'):
return None return None
with open('/persist/comma/id_rsa.pub', 'r') as f: with open(PERSIST+'/comma/id_rsa.pub', 'r') as f:
return f.read() return f.read()
@dispatcher.add_method @dispatcher.add_method

@ -2,9 +2,10 @@ import os
import numpy as np import numpy as np
from cffi import FFI from cffi import FFI
from common.ffi_wrapper import suffix
cluster_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) cluster_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
cluster_fn = os.path.join(cluster_dir, "libfastcluster.so") cluster_fn = os.path.join(cluster_dir, "libfastcluster"+suffix())
ffi = FFI() ffi = FFI()
ffi.cdef(""" ffi.cdef("""

@ -1,9 +1,10 @@
import os import os
from cffi import FFI from cffi import FFI
from common.ffi_wrapper import suffix
mpc_dir = os.path.dirname(os.path.abspath(__file__)) mpc_dir = os.path.dirname(os.path.abspath(__file__))
libmpc_fn = os.path.join(mpc_dir, "libmpc.so") libmpc_fn = os.path.join(mpc_dir, "libmpc"+suffix())
ffi = FFI() ffi = FFI()
ffi.cdef(""" ffi.cdef("""

@ -1,11 +1,12 @@
import os import os
from cffi import FFI from cffi import FFI
from common.ffi_wrapper import suffix
mpc_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) mpc_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
def _get_libmpc(mpc_id): def _get_libmpc(mpc_id):
libmpc_fn = os.path.join(mpc_dir, "libmpc%d.so" % mpc_id) libmpc_fn = os.path.join(mpc_dir, "libmpc%d%s" % (mpc_id, suffix()))
ffi = FFI() ffi = FFI()
ffi.cdef(""" ffi.cdef("""

@ -9,7 +9,7 @@ import shutil
import subprocess import subprocess
import datetime import datetime
from common.basedir import BASEDIR from common.basedir import BASEDIR, PARAMS
from common.android import ANDROID from common.android import ANDROID
sys.path.append(os.path.join(BASEDIR, "pyextra")) sys.path.append(os.path.join(BASEDIR, "pyextra"))
os.environ['BASEDIR'] = BASEDIR os.environ['BASEDIR'] = BASEDIR
@ -22,6 +22,8 @@ try:
os.mkdir("/dev/shm") os.mkdir("/dev/shm")
except FileExistsError: except FileExistsError:
pass pass
except PermissionError:
print("WARNING: failed to make /dev/shm")
if ANDROID: if ANDROID:
os.chmod("/dev/shm", 0o777) os.chmod("/dev/shm", 0o777)
@ -365,9 +367,10 @@ def manager_init(should_register=True):
pass pass
# ensure shared libraries are readable by apks # ensure shared libraries are readable by apks
os.chmod(BASEDIR, 0o755) if ANDROID:
os.chmod(os.path.join(BASEDIR, "cereal"), 0o755) os.chmod(BASEDIR, 0o755)
os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755) os.chmod(os.path.join(BASEDIR, "cereal"), 0o755)
os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755)
def manager_thread(): def manager_thread():
# now loop # now loop
@ -454,6 +457,8 @@ def uninstall():
android.reboot(reason="recovery") android.reboot(reason="recovery")
def main(): def main():
os.environ['PARAMS_PATH'] = PARAMS
# the flippening! # the flippening!
os.system('LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1') os.system('LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1')

@ -8,6 +8,7 @@ from common.android import get_imei, get_serial, get_subscriber_info
from common.api import api_get from common.api import api_get
from common.params import Params from common.params import Params
from common.file_helpers import mkdirs_exists_ok from common.file_helpers import mkdirs_exists_ok
from common.basedir import PERSIST
def register(): def register():
params = Params() params = Params()
@ -22,24 +23,24 @@ def register():
# create a key for auth # create a key for auth
# your private key is kept on your device persist partition and never sent to our servers # your private key is kept on your device persist partition and never sent to our servers
# do not erase your persist partition # do not erase your persist partition
if not os.path.isfile("/persist/comma/id_rsa.pub"): if not os.path.isfile(PERSIST+"/comma/id_rsa.pub"):
cloudlog.warning("generating your personal RSA key") cloudlog.warning("generating your personal RSA key")
mkdirs_exists_ok("/persist/comma") mkdirs_exists_ok(PERSIST+"/comma")
assert os.system("openssl genrsa -out /persist/comma/id_rsa.tmp 2048") == 0 assert os.system("openssl genrsa -out "+PERSIST+"/comma/id_rsa.tmp 2048") == 0
assert os.system("openssl rsa -in /persist/comma/id_rsa.tmp -pubout -out /persist/comma/id_rsa.tmp.pub") == 0 assert os.system("openssl rsa -in "+PERSIST+"/comma/id_rsa.tmp -pubout -out "+PERSIST+"/comma/id_rsa.tmp.pub") == 0
os.rename("/persist/comma/id_rsa.tmp", "/persist/comma/id_rsa") os.rename(PERSIST+"/comma/id_rsa.tmp", PERSIST+"/comma/id_rsa")
os.rename("/persist/comma/id_rsa.tmp.pub", "/persist/comma/id_rsa.pub") os.rename(PERSIST+"/comma/id_rsa.tmp.pub", PERSIST+"/comma/id_rsa.pub")
# make key readable by app users (ai.comma.plus.offroad) # make key readable by app users (ai.comma.plus.offroad)
os.chmod('/persist/comma/', 0o755) os.chmod(PERSIST+'/comma/', 0o755)
os.chmod('/persist/comma/id_rsa', 0o744) os.chmod(PERSIST+'/comma/id_rsa', 0o744)
dongle_id, access_token = params.get("DongleId", encoding='utf8'), params.get("AccessToken", encoding='utf8') dongle_id, access_token = params.get("DongleId", encoding='utf8'), params.get("AccessToken", encoding='utf8')
public_key = open("/persist/comma/id_rsa.pub").read() public_key = open(PERSIST+"/comma/id_rsa.pub").read()
# create registration token # create registration token
# in the future, this key will make JWTs directly # in the future, this key will make JWTs directly
private_key = open("/persist/comma/id_rsa").read() private_key = open(PERSIST+"/comma/id_rsa").read()
# late import # late import
import jwt import jwt

@ -4,7 +4,6 @@ os.environ['OLD_CAN'] = '1'
os.environ['NOCRASH'] = '1' os.environ['NOCRASH'] = '1'
import unittest import unittest
import shutil
import matplotlib import matplotlib
matplotlib.use('svg') matplotlib.use('svg')
@ -328,8 +327,8 @@ class LongitudinalControl(unittest.TestCase):
setup_output() setup_output()
shutil.rmtree('/data/params', ignore_errors=True)
params = Params() params = Params()
params.clear_all()
params.put("Passive", "1" if os.getenv("PASSIVE") else "0") params.put("Passive", "1" if os.getenv("PASSIVE") else "0")
params.put("OpenpilotEnabledToggle", "1") params.put("OpenpilotEnabledToggle", "1")
params.put("CommunityFeaturesToggle", "1") params.put("CommunityFeaturesToggle", "1")

@ -3,7 +3,6 @@ import os
import sys import sys
import threading import threading
import importlib import importlib
import shutil
if "CI" in os.environ: if "CI" in os.environ:
tqdm = lambda x: x tqdm = lambda x: x
@ -260,8 +259,8 @@ def replay_process(cfg, lr):
all_msgs = sorted(lr, key=lambda msg: msg.logMonoTime) all_msgs = sorted(lr, key=lambda msg: msg.logMonoTime)
pub_msgs = [msg for msg in all_msgs if msg.which() in list(cfg.pub_sub.keys())] pub_msgs = [msg for msg in all_msgs if msg.which() in list(cfg.pub_sub.keys())]
shutil.rmtree('/data/params', ignore_errors=True)
params = Params() params = Params()
params.clear_all()
params.manager_start() params.manager_start()
params.put("OpenpilotEnabledToggle", "1") params.put("OpenpilotEnabledToggle", "1")
params.put("Passive", "0") params.put("Passive", "0")

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import shutil
import time import time
import os import os
import sys import sys
@ -487,8 +486,8 @@ if __name__ == "__main__":
elif "UNLOGGER_PATH" not in os.environ: elif "UNLOGGER_PATH" not in os.environ:
continue continue
shutil.rmtree('/data/params')
params = Params() params = Params()
params.clear_all()
params.manager_start() params.manager_start()
params.put("OpenpilotEnabledToggle", "1") params.put("OpenpilotEnabledToggle", "1")
params.put("CommunityFeaturesToggle", "1") params.put("CommunityFeaturesToggle", "1")

@ -5,7 +5,6 @@ import math
import atexit import atexit
import numpy as np import numpy as np
import threading import threading
import carla
import random import random
import cereal.messaging as messaging import cereal.messaging as messaging
from common.params import Params from common.params import Params
@ -62,15 +61,16 @@ def health_function():
rk.keep_time() rk.keep_time()
def fake_driver_monitoring(): def fake_driver_monitoring():
pm = messaging.PubMaster(['driverMonitoring']) pm = messaging.PubMaster(['driverState'])
while 1: while 1:
dat = messaging.new_message() dat = messaging.new_message()
dat.init('driverMonitoring') dat.init('driverState')
dat.driverMonitoring.faceProb = 1.0 dat.driverState.faceProb = 1.0
pm.send('driverMonitoring', dat) pm.send('driverState', dat)
time.sleep(0.1) time.sleep(0.1)
def go(): def go():
import carla
client = carla.Client("127.0.0.1", 2000) client = carla.Client("127.0.0.1", 2000)
client.set_timeout(5.0) client.set_timeout(5.0)
world = client.load_world('Town03') world = client.load_world('Town03')
@ -123,8 +123,6 @@ def go():
print("done") print("done")
atexit.register(destroy) atexit.register(destroy)
threading.Thread(target=health_function).start()
threading.Thread(target=fake_driver_monitoring).start()
# can loop # can loop
sendcan = messaging.sub_sock('sendcan') sendcan = messaging.sub_sock('sendcan')
@ -151,5 +149,16 @@ if __name__ == "__main__":
params.put("HasAcceptedTerms", terms_version) params.put("HasAcceptedTerms", terms_version)
params.put("CompletedTrainingVersion", training_version) params.put("CompletedTrainingVersion", training_version)
threading.Thread(target=health_function).start()
threading.Thread(target=fake_driver_monitoring).start()
# no carla, still run
try:
import carla
except ImportError:
print("WARNING: NO CARLA")
while 1:
time.sleep(1)
go() go()

Loading…
Cancel
Save