Skip to content

Commit

Permalink
Resolve merge, code updates to match up 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rafcabezas committed Dec 22, 2020
1 parent ed95e62 commit 1fe04cc
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 27 deletions.
4 changes: 4 additions & 0 deletions common/basedir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))

from selfdrive.hardware import PC
is_tbp = os.path.isfile('/data/tinkla_buddy_pro')
if PC:
PERSIST = os.path.join(BASEDIR, "persist")
elif is_tbp:
PERSIST = "/data/params/persist"
PARAMS = "/data/params"
else:
PERSIST = "/persist"
19 changes: 17 additions & 2 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
from selfdrive.controls.lib.planner import LON_MPC_STEP
from selfdrive.locationd.calibrationd import Calibration
from selfdrive.hardware import HARDWARE
from selfdrive.tinklad.tinkla_interface import TinklaClient

LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
LANE_DEPARTURE_THRESHOLD = 0.1
STEER_ANGLE_SATURATION_TIMEOUT = 1.0 / DT_CTRL
STEER_ANGLE_SATURATION_THRESHOLD = 2.5 # Degrees
STEER_ANGLE_SATURATION_THRESHOLD = 250 # Degrees

SIMULATION = "SIMULATION" in os.environ
NOSENSOR = "NOSENSOR" in os.environ
Expand All @@ -41,9 +42,14 @@


class Controls:

tinklaClient = None

def __init__(self, sm=None, pm=None, can_sock=None):
config_realtime_process(3, Priority.CTRL_HIGH)

self.tinklaClient = TinklaClient()

# Setup sockets
self.pm = pm
if self.pm is None:
Expand Down Expand Up @@ -209,6 +215,7 @@ def update_events(self, CS):
self.events.add(EventName.radarCommIssue)
elif not self.sm.all_alive_and_valid():
self.events.add(EventName.commIssue)
logAllAliveAndValidInfoToTinklad(sm=self.sm, tinklaClient=self.tinklaClient)
if not self.sm['pathPlan'].mpcSolutionValid:
self.events.add(EventName.plannerError)
if not self.sm['liveLocationKalman'].sensorsOK and not NOSENSOR:
Expand Down Expand Up @@ -571,10 +578,18 @@ def controlsd_thread(self):
self.rk.monitor_time()
self.prof.display()

def logAllAliveAndValidInfoToTinklad(sm, tinklaClient):
# areAllAlive, aliveProcessName, aliveCount = sm.all_alive_with_info()
# areAllValid, validProcessName, validCount = sm.all_valid_with_info()
# if not areAllAlive:
# tinklaClient.logProcessCommErrorEvent(source="carcontroller", processName=aliveProcessName, count=aliveCount, eventType="Not Alive")
# else:
# tinklaClient.logProcessCommErrorEvent(source="carcontroller", processName=validProcessName, count=validCount, eventType="Not Valid")
pass

def main(sm=None, pm=None, logcan=None):
controls = Controls(sm, pm, logcan)
controls.controlsd_thread()


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions selfdrive/crash.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from selfdrive.hardware import PC
from selfdrive.swaglog import cloudlog

from selfdrive.tinklad.tinkla_interface import TinklaClient

if os.getenv("NOLOG") or os.getenv("NOCRASH") or PC:
def capture_exception(*args, **kwargs):
pass
Expand All @@ -32,8 +34,13 @@ def install():
client = Client('https://1994756b5e6f41cf939a4c65de45f4f2:cefebaf3a8aa40d182609785f7189bd7@app.getsentry.com/77924',
install_sys_hook=False, transport=HTTPTransport, release=version, tags=tags)

def sendCrashInfoToTinklad():
tinklaClient = TinklaClient()
tinklaClient.logCrashStackTraceEvent()

def capture_exception(*args, **kwargs):
exc_info = sys.exc_info()
sendCrashInfoToTinklad()
if not exc_info[0] is capnp.lib.capnp.KjException:
client.captureException(*args, **kwargs)
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
Expand Down
70 changes: 62 additions & 8 deletions selfdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import signal
import shutil
import subprocess
from cereal import tinkla
import datetime
import textwrap
import time
import traceback
Expand Down Expand Up @@ -114,9 +116,10 @@ def build():
for i in range(3, -1, -1):
print("....%d" % i)
time.sleep(1)
subprocess.check_call(["scons", "-c"], cwd=BASEDIR, env=env)
shutil.rmtree("/tmp/scons_cache", ignore_errors=True)
shutil.rmtree("/data/scons_cache", ignore_errors=True)
#Raf: Commented out while merging/compiling
#subprocess.check_call(["scons", "-c"], cwd=BASEDIR, env=env)
#shutil.rmtree("/tmp/scons_cache", ignore_errors=True)
#shutil.rmtree("/data/scons_cache", ignore_errors=True)
else:
print("scons build failed after retry")
sys.exit(1)
Expand Down Expand Up @@ -149,10 +152,13 @@ def build():
from selfdrive.loggerd.config import ROOT
from selfdrive.launcher import launcher
from selfdrive.hardware.eon.apk import update_apks, pm_apply_packages, start_offroad
from selfdrive.car.tesla.readconfig import CarSettings
from selfdrive.tinklad.tinkla_interface import TinklaClient


# comment out anything you don't want to run
managed_processes = {
"tinklad": "selfdrive.tinklad.tinklad",
"thermald": "selfdrive.thermald.thermald",
"uploader": "selfdrive.loggerd.uploader",
"deleter": "selfdrive.loggerd.deleter",
Expand Down Expand Up @@ -200,13 +206,18 @@ def get_running():
kill_processes = ['sensord']

persistent_processes = [
'tinklad',
'thermald',
'logmessaged',
'ui',
'uploader',
'deleter',
]

if not WEBCAM:
persistent_processes += [
'logmessaged',
'uploader',
]

if not PC:
persistent_processes += [
'updated',
Expand Down Expand Up @@ -403,6 +414,9 @@ def manager_init():
dongle_id = reg_res
else:
raise Exception("server registration failed")
#BB
if not dongle_id:
dongle_id = "nada"
os.environ['DONGLE_ID'] = dongle_id

if not dirty:
Expand All @@ -425,6 +439,22 @@ def manager_init():
os.chmod(os.path.join(BASEDIR, "cereal"), 0o755)
os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755)

def sendUserInfoToTinkla(params, tinklaClient):
carSettings = CarSettings()
gitRemote = params.get("GitRemote")
gitBranch = params.get("GitBranch")
gitHash = params.get("GitCommit")
dongleId = params.get("DongleId")
userHandle = carSettings.userHandle
info = tinkla.Interface.UserInfo.new_message(
openPilotId=dongleId,
userHandle=userHandle,
gitRemote=gitRemote,
gitBranch=gitBranch,
gitHash=gitHash
)
tinklaClient.setUserInfo(info)

def manager_thread():

cloudlog.info("manager start")
Expand Down Expand Up @@ -458,9 +488,23 @@ def manager_thread():
params = Params()
thermal_sock = messaging.sub_sock('thermal')

# Tinkla interface
last_tinklad_send_attempt_time = 0
tinklaClient = TinklaClient()
sendUserInfoToTinkla(params=params, tinklaClient=tinklaClient)
start_t = time.time()
first_proc = None

while 1:
msg = messaging.recv_sock(thermal_sock, wait=True)

# Attempt to send pending messages if there's any that queued while offline
# Seems this loop runs every second or so, throttle to once every 30s
now = time.time()
if now - last_tinklad_send_attempt_time >= 30:
tinklaClient.attemptToSendPendingMessages()
last_tinklad_send_attempt_time = now

if msg.thermal.freeSpace < 0.05:
logger_dead = True

Expand Down Expand Up @@ -493,23 +537,29 @@ def manager_thread():
started_prev = msg.thermal.started

# check the status of all processes, did any of them die?
running_list = ["%s%s\u001b[0m" % ("\u001b[32m" if running[p].is_alive() else "\u001b[31m", p) for p in running]
cloudlog.debug(' '.join(running_list))
# running_list = ["%s%s\u001b[0m" % ("\u001b[32m" if running[p].is_alive() else "\u001b[31m", p) for p in running]
#cloudlog.debug(' '.join(running_list))

# Exit main loop when uninstall is needed
if params.get("DoUninstall", encoding='utf8') == "1":
break

def manager_prepare():

carSettings = CarSettings()
# build all processes
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Spinner has to start from 70 here
total = 100.0 if PREBUILT else 30.0

spinText = ""
if spinner is not None:
spinText = carSettings.spinnerText

for i, p in enumerate(managed_processes):
perc = (100.0 - total) + total * (i + 1) / len(managed_processes)
spinner.update(str(int(perc)))
spinner.update(spinText + str(int(perc)))
prepare_managed_process(p)

def main():
Expand All @@ -530,6 +580,9 @@ def main():
("OpenpilotEnabledToggle", "1"),
("LaneChangeEnabled", "1"),
("IsDriverViewEnabled", "0"),
#Tesla
("SpeedLimitOffset", "0"),
("LimitSetSpeed", "0"),
]

# set unset params
Expand Down Expand Up @@ -561,6 +614,7 @@ def main():
except Exception:
traceback.print_exc()
crash.capture_exception()
print ("EXIT ON EXCEPTION")
finally:
cleanup_all_processes(None, None)

Expand Down
32 changes: 32 additions & 0 deletions selfdrive/modeld/dmonitoringmodeld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
#include <linux/limits.h>
#endif

bool get_bool_config_option(const char *key) {
char line[500];
FILE *stream;
stream = fopen("/data/bb_openpilot.cfg", "r");
while(fgets(line, 500, stream) != NULL)
{
char setting[256], value[256], oper[10];
if(line[0] == '#') continue;
if(sscanf(line, "%s %s %s", setting, oper, value) != 3) {
continue;
}
if ((strcmp(key, setting) == 0) && (strcmp("True", value) == 0)) {
fclose(stream);
return true;
}
}
fclose(stream);
return false;
}

volatile sig_atomic_t do_exit = 0;

Expand Down Expand Up @@ -47,6 +66,8 @@ int main(int argc, char **argv) {
}
LOGW("connected with buffer size: %d", buf_info.buf_len);

bool is_dm_throttled = get_bool_config_option("throttle_driver_monitor");
bool is_dm_disabled = !get_bool_config_option("enable_driver_monitor");
double last = 0;
while (!do_exit) {
VIPCBuf *buf;
Expand All @@ -67,6 +88,17 @@ int main(int argc, char **argv) {

LOGD("dmonitoring process: %.2fms, from last %.2fms", t2-t1, t1-last);
last = t1;
if (is_dm_disabled) {
usleep(1*1000*1000);
} else if (is_dm_throttled) {
usleep(250*1000);
} else {
#ifdef QCOM2
// this makes it run at about 2.7Hz on tici CPU to deal with modeld lags
// TODO: DSP needs to be freed (again)
usleep(250000);
#endif
}
}
visionstream_destroy(&stream);
}
Expand Down
Loading

0 comments on commit 1fe04cc

Please sign in to comment.