Merge branch 'master' into tici-camerad

pull/2048/head
Tici Agent 5 years ago
commit 2a0bd5241a
  1. 16
      .dockerignore
  2. 15
      .github/workflows/test.yaml
  3. 43
      Dockerfile.openpilot_base
  4. 24
      Dockerfile.openpilotci
  5. 2
      Jenkinsfile
  6. 8
      SConstruct
  7. 2
      cereal
  8. 22
      common/gpio.py
  9. 4
      common/hardware.py
  10. 2
      release/files_common
  11. 17
      scripts/code_stats.py
  12. 4
      selfdrive/boardd/boardd.cc
  13. 8
      selfdrive/car/honda/values.py
  14. 2
      selfdrive/clocksd/SConscript
  15. 30
      selfdrive/clocksd/clocksd.cc
  16. 6
      selfdrive/common/swaglog.cc
  17. 4
      selfdrive/common/visionipc.c
  18. 3
      selfdrive/debug/get_fingerprint.py
  19. 3
      selfdrive/debug/internal/measure_modeld_packet_drop.py
  20. 2
      selfdrive/manager.py
  21. 27
      selfdrive/modeld/modeld.cc
  22. 10
      selfdrive/modeld/models/commonmodel.c
  23. 4
      selfdrive/modeld/models/commonmodel.h
  24. 23
      selfdrive/pandad.py
  25. 88
      selfdrive/thermald/thermald.py
  26. 2
      selfdrive/ui/paint.cc
  27. 6
      selfdrive/ui/qt/ui.cc
  28. 2
      selfdrive/ui/sidebar.cc
  29. 2
      tools/replay/sensorium.py

@ -1,5 +1,21 @@
.git .git
.DS_Store .DS_Store
*.dylib
*.DSYM
*.d
*.pyc
*.pyo
.*.swp
.*.swo
.*.un~
*.tmp
*.o
*.o-*
*.os
*.os-*
*.so
*.a
notebooks notebooks
phone phone
massivemap massivemap

@ -11,9 +11,14 @@ env:
CI_RUN: docker run -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID --rm tmppilotci /bin/bash -c CI_RUN: docker run -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID --rm tmppilotci /bin/bash -c
UNIT_TEST: coverage run --append -m unittest discover UNIT_TEST: coverage run --append -m unittest discover
BUILD: | BUILD: |
docker pull $(grep -ioP '(?<=^from)\s+\S+' Dockerfile.openpilot) || true # build the openpilot docker base image
docker pull $(grep -ioP '(?<=^from)\s+\S+' Dockerfile.openpilot_base) || true
docker pull docker.io/commaai/openpilot-base:latest || true
docker build --cache-from docker.io/commaai/openpilot-base:latest -t commaai/openpilot-base:latest -f Dockerfile.openpilot_base .
# build the final CI image
docker pull docker.io/commaai/openpilotci:latest || true docker pull docker.io/commaai/openpilotci:latest || true
docker build --cache-from docker.io/commaai/openpilotci:latest -t tmppilot -f Dockerfile.openpilot . docker build --cache-from docker.io/commaai/openpilotci:latest -t tmppilot -f Dockerfile.openpilotci .
jobs: jobs:
build_release: build_release:
@ -30,7 +35,7 @@ jobs:
run: | run: |
mkdir $TEST_DIR mkdir $TEST_DIR
cp -pR --parents $(cat release/files_common) $TEST_DIR cp -pR --parents $(cat release/files_common) $TEST_DIR
cp Dockerfile.openpilot $TEST_DIR cp Dockerfile.openpilot_base Dockerfile.openpilotci $TEST_DIR
# need this to build on x86 # need this to build on x86
cp -pR --parents phonelibs/libyuv phonelibs/snpe \ cp -pR --parents phonelibs/libyuv phonelibs/snpe \
@ -88,6 +93,8 @@ jobs:
- name: Push to dockerhub - name: Push to dockerhub
run: | run: |
docker login -u wmelching -p ${{ secrets.COMMA_DOCKERHUB_TOKEN}} docker login -u wmelching -p ${{ secrets.COMMA_DOCKERHUB_TOKEN}}
docker tag commaai/openpilot-base:latest docker.io/commaai/openpilot-base:latest
docker push docker.io/commaai/openpilot-base:latest
docker tag tmppilot docker.io/commaai/openpilotci:latest docker tag tmppilot docker.io/commaai/openpilotci:latest
docker push docker.io/commaai/openpilotci:latest docker push docker.io/commaai/openpilotci:latest
@ -102,7 +109,7 @@ jobs:
with: with:
submodules: true submodules: true
- name: Build Docker image - name: Build Docker image
run: echo "RUN cd /tmp/openpilot && scons -c && scons -j3" >> Dockerfile.openpilot && eval "$BUILD" run: echo "RUN cd /tmp/openpilot && scons -c && scons -j\$(nproc)" >> Dockerfile.openpilotci && eval "$BUILD"
- name: Push to dockerhub - name: Push to dockerhub
run: | run: |
docker login -u wmelching -p ${{ secrets.COMMA_DOCKERHUB_TOKEN}} docker login -u wmelching -p ${{ secrets.COMMA_DOCKERHUB_TOKEN}}

@ -1,6 +1,5 @@
FROM ubuntu:16.04 FROM ubuntu:16.04
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /tmp/openpilot:${PYTHONPATH}
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \ autoconf \
@ -22,7 +21,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libffi-dev \ libffi-dev \
libglew-dev \ libglew-dev \
libgles2-mesa-dev \ libgles2-mesa-dev \
libglfw3-dev \
libglib2.0-0 \ libglib2.0-0 \
liblzma-dev \ liblzma-dev \
libomp-dev \ libomp-dev \
@ -58,42 +56,5 @@ RUN pyenv install 3.8.2 && \
pip install --no-cache-dir --upgrade pip==20.1.1 && \ pip install --no-cache-dir --upgrade pip==20.1.1 && \
pip install --no-cache-dir pipenv==2018.11.26 && \ pip install --no-cache-dir pipenv==2018.11.26 && \
cd /tmp && \ cd /tmp && \
pipenv install --system --deploy --clear && \ pipenv install --system --deploy --dev --clear && \
pip uninstall -y pipenv && \ pip uninstall -y pipenv
pip install --no-cache-dir \
matplotlib==3.1.1 \
dictdiffer==0.8.0 \
fastcluster==1.1.25 \
aenum==2.2.1 \
lru-dict==1.1.6 \
scipy==1.4.1 \
tenacity==5.1.1 \
azure-common==1.1.23 \
azure-nspkg==3.0.2 \
azure-storage-blob==2.1.0 \
azure-storage-common==2.1.0 \
azure-storage-nspkg==3.1.0 \
pycurl==7.43.0.3 \
coverage==5.1 \
pre-commit==2.4.0 \
parameterized==0.7.4
RUN mkdir -p /tmp/openpilot
COPY SConstruct \
.pylintrc \
.pre-commit-config.yaml \
/tmp/openpilot/
COPY ./pyextra /tmp/openpilot/pyextra
COPY ./phonelibs /tmp/openpilot/phonelibs
COPY ./laika /tmp/openpilot/laika
COPY ./laika_repo /tmp/openpilot/laika_repo
COPY ./rednose /tmp/openpilot/rednose
COPY ./tools /tmp/openpilot/tools
COPY ./release /tmp/openpilot/release
COPY ./common /tmp/openpilot/common
COPY ./opendbc /tmp/openpilot/opendbc
COPY ./cereal /tmp/openpilot/cereal
COPY ./panda /tmp/openpilot/panda
COPY ./selfdrive /tmp/openpilot/selfdrive

@ -0,0 +1,24 @@
FROM commaai/openpilot-base:latest
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /tmp/openpilot:${PYTHONPATH}
RUN mkdir -p /tmp/openpilot
COPY SConstruct \
.pylintrc \
.pre-commit-config.yaml \
/tmp/openpilot/
COPY ./pyextra /tmp/openpilot/pyextra
COPY ./phonelibs /tmp/openpilot/phonelibs
COPY ./laika /tmp/openpilot/laika
COPY ./laika_repo /tmp/openpilot/laika_repo
COPY ./rednose /tmp/openpilot/rednose
COPY ./tools /tmp/openpilot/tools
COPY ./release /tmp/openpilot/release
COPY ./common /tmp/openpilot/common
COPY ./opendbc /tmp/openpilot/opendbc
COPY ./cereal /tmp/openpilot/cereal
COPY ./panda /tmp/openpilot/panda
COPY ./selfdrive /tmp/openpilot/selfdrive

2
Jenkinsfile vendored

@ -70,7 +70,7 @@ pipeline {
stage('PC tests') { stage('PC tests') {
agent { agent {
dockerfile { dockerfile {
filename 'Dockerfile.openpilot' filename 'Dockerfile.openpilotci'
args '--privileged --shm-size=1G --user=root' args '--privileged --shm-size=1G --user=root'
} }
} }

@ -302,19 +302,19 @@ SConscript(['selfdrive/controls/lib/longitudinal_mpc_model/SConscript'])
SConscript(['selfdrive/boardd/SConscript']) SConscript(['selfdrive/boardd/SConscript'])
SConscript(['selfdrive/proclogd/SConscript']) SConscript(['selfdrive/proclogd/SConscript'])
SConscript(['selfdrive/clocksd/SConscript'])
SConscript(['selfdrive/loggerd/SConscript']) SConscript(['selfdrive/loggerd/SConscript'])
SConscript(['selfdrive/locationd/SConscript']) SConscript(['selfdrive/locationd/SConscript'])
SConscript(['selfdrive/locationd/models/SConscript']) SConscript(['selfdrive/locationd/models/SConscript'])
if arch == "aarch64": if arch == "aarch64":
SConscript(['selfdrive/logcatd/SConscript']) SConscript(['selfdrive/logcatd/SConscript'])
SConscript(['selfdrive/sensord/SConscript']) SConscript(['selfdrive/sensord/SConscript'])
SConscript(['selfdrive/clocksd/SConscript'])
else:
SConscript(['tools/lib/index_log/SConscript'])
if arch != "larch64": if arch != "larch64":
SConscript(['selfdrive/ui/SConscript']) SConscript(['selfdrive/ui/SConscript'])
if arch == "x86_64":
SConscript(['tools/lib/index_log/SConscript'])

@ -1 +1 @@
Subproject commit 146f42944a81babba84ba810ae9e52d197df3eb7 Subproject commit b40925942610dd0e985224da21b20572a02a31bc

@ -0,0 +1,22 @@
GPIO_HUB_RST_N = 30
GPIO_UBLOX_RST_N = 32
GPIO_UBLOX_SAFEBOOT_N = 33
GPIO_UBLOX_PWR_EN = 34
GPIO_STM_RST_N = 124
GPIO_STM_BOOT0 = 134
def gpio_init(pin, output):
try:
with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f:
f.write(b"out" if output else b"in")
except Exception as e:
print(f"Failed to set gpio {pin} direction: {e}")
def gpio_set(pin, high):
try:
with open(f"/sys/class/gpio/gpio{pin}/value", 'wb') as f:
f.write(b"1" if high else b"0")
except Exception as e:
print(f"Failed to set gpio {pin} value: {e}")

@ -0,0 +1,4 @@
import os
EON = os.path.isfile('/EON')
TICI = os.path.isfile('/TICI')

@ -18,6 +18,8 @@ apk/ai.comma*.apk
common/.gitignore common/.gitignore
common/__init__.py common/__init__.py
common/android.py common/android.py
common/hardware.py
common/gpio.py
common/realtime.py common/realtime.py
common/clock.pyx common/clock.pyx
common/timeout.py common/timeout.py

@ -26,6 +26,9 @@ class Analyzer(ast.NodeVisitor):
self.generic_visit(node) self.generic_visit(node)
tlns = 0 tlns = 0
carlns = 0
scriptlns = 0
testlns = 0
for f in sorted(pyf): for f in sorted(pyf):
if f not in fouts: if f not in fouts:
continue continue
@ -35,7 +38,17 @@ for f in sorted(pyf):
tree = ast.parse(src) tree = ast.parse(src)
Analyzer().visit(tree) Analyzer().visit(tree)
print("%5d %s %s" % (lns, f, xbit)) print("%5d %s %s" % (lns, f, xbit))
tlns += lns if 'test' in f:
testlns += lns
elif f.startswith('tools/') or f.startswith('scripts/') or f.startswith('selfdrive/debug'):
scriptlns += lns
elif f.startswith('selfdrive/car'):
carlns += lns
else:
tlns += lns
print("%d lines of parsed openpilot python" % tlns) print("%d lines of openpilot python" % tlns)
print("%d lines of car ports" % carlns)
print("%d lines of tools/scripts/debug" % scriptlns)
print("%d lines of tests" % testlns)
#print(sorted(list(imps))) #print(sorted(list(imps)))

@ -392,8 +392,8 @@ void hardware_control_thread() {
LOGD("start hardware control thread"); LOGD("start hardware control thread");
SubMaster sm({"thermal", "frontFrame"}); SubMaster sm({"thermal", "frontFrame"});
// Only control fan speed on UNO // Other pandas don't have hardware to control
if (panda->hw_type != cereal::HealthData::HwType::UNO) return; if (panda->hw_type != cereal::HealthData::HwType::UNO && panda->hw_type != cereal::HealthData::HwType::DOS) return;
uint64_t last_front_frame_t = 0; uint64_t last_front_frame_t = 0;
uint16_t prev_fan_speed = 999; uint16_t prev_fan_speed = 999;

@ -645,10 +645,12 @@ FW_VERSIONS = {
(Ecu.vsa, 0x18da28f1, None): [ (Ecu.vsa, 0x18da28f1, None): [
b'57114-TPA-G020\x00\x00', b'57114-TPA-G020\x00\x00',
b'57114-TPG-A020\x00\x00', b'57114-TPG-A020\x00\x00',
b'57114-TMB-H030\x00\x00',
], ],
(Ecu.eps, 0x18da30f1, None): [ (Ecu.eps, 0x18da30f1, None): [
b'39990-TPA-G030\x00\x00', b'39990-TPA-G030\x00\x00',
b'39990-TPG-A020\x00\x00', b'39990-TPG-A020\x00\x00',
b'39990-TMA-H020\x00\x00',
], ],
(Ecu.gateway, 0x18daeff1, None): [ (Ecu.gateway, 0x18daeff1, None): [
b'38897-TMA-H110\x00\x00', b'38897-TMA-H110\x00\x00',
@ -661,10 +663,12 @@ FW_VERSIONS = {
(Ecu.fwdCamera, 0x18dab5f1, None): [ (Ecu.fwdCamera, 0x18dab5f1, None): [
b'36161-TPA-E050\x00\x00', b'36161-TPA-E050\x00\x00',
b'36161-TPG-A030\x00\x00', b'36161-TPG-A030\x00\x00',
b'36161-TMB-H040\x00\x00',
], ],
(Ecu.combinationMeter, 0x18da60f1, None): [ (Ecu.combinationMeter, 0x18da60f1, None): [
b'78109-TPA-G520\x00\x00', b'78109-TPA-G520\x00\x00',
b'78109-TPG-A110\x00\x00', b'78109-TPG-A110\x00\x00',
b'78109-TMB-H220\x00\x00',
], ],
(Ecu.hud, 0x18da61f1, None): [ (Ecu.hud, 0x18da61f1, None): [
b'78209-TLA-X010\x00\x00', b'78209-TLA-X010\x00\x00',
@ -672,10 +676,12 @@ FW_VERSIONS = {
(Ecu.fwdRadar, 0x18dab0f1, None): [ (Ecu.fwdRadar, 0x18dab0f1, None): [
b'36802-TPA-E040\x00\x00', b'36802-TPA-E040\x00\x00',
b'36802-TPG-A020\x00\x00', b'36802-TPG-A020\x00\x00',
b'36802-TMB-H040\x00\x00',
], ],
(Ecu.srs, 0x18da53f1, None): [ (Ecu.srs, 0x18da53f1, None): [
b'77959-TLA-G220\x00\x00', b'77959-TLA-G220\x00\x00',
b'77959-TLA-C320\x00\x00', b'77959-TLA-C320\x00\x00',
b'77959-TLA-H240\x00\x00',
], ],
}, },
CAR.FIT: { CAR.FIT: {
@ -891,6 +897,7 @@ FW_VERSIONS = {
b'77959-TXM-A230\x00\x00', b'77959-TXM-A230\x00\x00',
], ],
(Ecu.vsa, 0x18da28f1, None): [ (Ecu.vsa, 0x18da28f1, None): [
b'57114-TXM-A030\x00\x00',
b'57114-TXM-A040\x00\x00', b'57114-TXM-A040\x00\x00',
], ],
(Ecu.shiftByWire, 0x18da0bf1, None): [ (Ecu.shiftByWire, 0x18da0bf1, None): [
@ -900,6 +907,7 @@ FW_VERSIONS = {
b'38897-TXM-A020\x00\x00', b'38897-TXM-A020\x00\x00',
], ],
(Ecu.combinationMeter, 0x18da60f1, None): [ (Ecu.combinationMeter, 0x18da60f1, None): [
b'78109-TXM-A010\x00\x00',
b'78109-TXM-A020\x00\x00', b'78109-TXM-A020\x00\x00',
], ],
}, },

@ -1,2 +1,2 @@
Import('env', 'common', 'cereal', 'messaging') Import('env', 'common', 'cereal', 'messaging')
env.Program('clocksd.cc', LIBS=['diag', 'time_genoff', common, cereal, messaging, 'capnp', 'zmq', 'kj']) env.Program('clocksd.cc', LIBS=[common, cereal, messaging, 'capnp', 'zmq', 'kj'])

@ -1,12 +1,22 @@
#include <chrono>
#include <thread>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/timerfd.h>
#include <sys/time.h> #include <sys/time.h>
#include <utils/Timers.h>
#include <cassert>
#include "messaging.hpp" #include "messaging.hpp"
#include "common/timing.h" #include "common/timing.h"
// Apple doesn't have timerfd
#ifndef __APPLE__
#include <sys/timerfd.h>
#endif
#ifdef QCOM
namespace { namespace {
int64_t arm_cntpct() { int64_t arm_cntpct() {
int64_t v; int64_t v;
@ -14,13 +24,14 @@ namespace {
return v; return v;
} }
} }
#endif
int main() { int main() {
setpriority(PRIO_PROCESS, 0, -13); setpriority(PRIO_PROCESS, 0, -13);
int err = 0;
PubMaster pm({"clocks"}); PubMaster pm({"clocks"});
#ifndef __APPLE__
int timerfd = timerfd_create(CLOCK_BOOTTIME, 0); int timerfd = timerfd_create(CLOCK_BOOTTIME, 0);
assert(timerfd >= 0); assert(timerfd >= 0);
@ -30,19 +41,26 @@ int main() {
spec.it_value.tv_sec = 1; spec.it_value.tv_sec = 1;
spec.it_value.tv_nsec = 0; spec.it_value.tv_nsec = 0;
err = timerfd_settime(timerfd, 0, &spec, 0); int err = timerfd_settime(timerfd, 0, &spec, 0);
assert(err == 0); assert(err == 0);
uint64_t expirations = 0; uint64_t expirations = 0;
while ((err = read(timerfd, &expirations, sizeof(expirations)))) { while ((err = read(timerfd, &expirations, sizeof(expirations)))) {
if (err < 0) break; if (err < 0) break;
#else
// Just run at 1Hz on apple
while (true){
std::this_thread::sleep_for(std::chrono::seconds(1));
#endif
uint64_t boottime = nanos_since_boot(); uint64_t boottime = nanos_since_boot();
uint64_t monotonic = nanos_monotonic(); uint64_t monotonic = nanos_monotonic();
uint64_t monotonic_raw = nanos_monotonic_raw(); uint64_t monotonic_raw = nanos_monotonic_raw();
uint64_t wall_time = nanos_since_epoch(); uint64_t wall_time = nanos_since_epoch();
#ifdef QCOM
uint64_t modem_uptime_v = arm_cntpct() / 19200ULL; // 19.2 mhz clock uint64_t modem_uptime_v = arm_cntpct() / 19200ULL; // 19.2 mhz clock
#endif
capnp::MallocMessageBuilder msg; capnp::MallocMessageBuilder msg;
cereal::Event::Builder event = msg.initRoot<cereal::Event>(); cereal::Event::Builder event = msg.initRoot<cereal::Event>();
@ -53,11 +71,15 @@ int main() {
clocks.setMonotonicNanos(monotonic); clocks.setMonotonicNanos(monotonic);
clocks.setMonotonicRawNanos(monotonic_raw); clocks.setMonotonicRawNanos(monotonic_raw);
clocks.setWallTimeNanos(wall_time); clocks.setWallTimeNanos(wall_time);
#ifdef QCOM
clocks.setModemUptimeMillis(modem_uptime_v); clocks.setModemUptimeMillis(modem_uptime_v);
#endif
pm.send("clocks", msg); pm.send("clocks", msg);
} }
#ifndef __APPLE__
close(timerfd); close(timerfd);
#endif
return 0; return 0;
} }

@ -93,15 +93,13 @@ void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func
{"created", seconds_since_epoch()} {"created", seconds_since_epoch()}
}; };
char* log_s = strdup(log_j.dump().c_str()); std::string log_s = log_j.dump();
assert(log_s);
free(msg_buf); free(msg_buf);
char levelnum_c = levelnum; char levelnum_c = levelnum;
zmq_send(s.sock, &levelnum_c, 1, ZMQ_NOBLOCK | ZMQ_SNDMORE); zmq_send(s.sock, &levelnum_c, 1, ZMQ_NOBLOCK | ZMQ_SNDMORE);
zmq_send(s.sock, log_s, strlen(log_s), ZMQ_NOBLOCK); zmq_send(s.sock, log_s.c_str(), log_s.length(), ZMQ_NOBLOCK);
free(log_s);
pthread_mutex_unlock(&s.lock); pthread_mutex_unlock(&s.lock);
} }

@ -90,6 +90,7 @@ int visionstream_init(VisionStream *s, VisionStreamType type, bool tbuffer, Visi
err = vipc_send(s->ipc_fd, &p); err = vipc_send(s->ipc_fd, &p);
if (err < 0) { if (err < 0) {
close(s->ipc_fd); close(s->ipc_fd);
s->ipc_fd = -1;
return -1; return -1;
} }
@ -97,6 +98,7 @@ int visionstream_init(VisionStream *s, VisionStreamType type, bool tbuffer, Visi
err = vipc_recv(s->ipc_fd, &rp); err = vipc_recv(s->ipc_fd, &rp);
if (err <= 0) { if (err <= 0) {
close(s->ipc_fd); close(s->ipc_fd);
s->ipc_fd = -1;
return -1; return -1;
} }
assert(rp.type == VIPC_STREAM_BUFS); assert(rp.type == VIPC_STREAM_BUFS);
@ -190,5 +192,5 @@ void visionstream_destroy(VisionStream *s) {
} }
} }
if (s->bufs) free(s->bufs); if (s->bufs) free(s->bufs);
close(s->ipc_fd); if (s->ipc_fd >= 0) close(s->ipc_fd);
} }

@ -17,6 +17,9 @@ logcan = messaging.sub_sock('can')
msgs = {} msgs = {}
while True: while True:
lc = messaging.recv_sock(logcan, True) lc = messaging.recv_sock(logcan, True)
if lc is None:
continue
for c in lc.can: for c in lc.can:
# read also msgs sent by EON on CAN bus 0x80 and filter out the # read also msgs sent by EON on CAN bus 0x80 and filter out the
# addr with more than 11 bits # addr with more than 11 bits

@ -11,6 +11,9 @@ if __name__ == "__main__":
while True: while True:
m = messaging.recv_one(modeld_sock) m = messaging.recv_one(modeld_sock)
if m is None:
continue
frame_id = m.model.frameId frame_id = m.model.frameId
t = m.logMonoTime / 1e9 t = m.logMonoTime / 1e9
frame_cnt += 1 frame_cnt += 1

@ -239,6 +239,7 @@ car_started_processes = [
'proclogd', 'proclogd',
'ubloxd', 'ubloxd',
'locationd', 'locationd',
'clocksd',
] ]
driver_view_processes = [ driver_view_processes = [
@ -255,7 +256,6 @@ if WEBCAM:
if ANDROID: if ANDROID:
car_started_processes += [ car_started_processes += [
'sensord', 'sensord',
'clocksd',
'gpsd', 'gpsd',
'dmonitoringmodeld', 'dmonitoringmodeld',
] ]

@ -52,6 +52,13 @@ void* live_thread(void *arg) {
0.0, 0.0, 1.0; 0.0, 0.0, 1.0;
#endif #endif
// debayering does a 2x downscale
mat3 yuv_transform = transform_scale_buffer((mat3){{
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
}}, 0.5);
while (!do_exit) { while (!do_exit) {
if (sm.update(10) > 0){ if (sm.update(10) > 0){
@ -68,12 +75,13 @@ void* live_thread(void *arg) {
camera_frame_from_ground.col(2) = camera_frame_from_road_frame.col(3); camera_frame_from_ground.col(2) = camera_frame_from_road_frame.col(3);
auto warp_matrix = camera_frame_from_ground * ground_from_medmodel_frame; auto warp_matrix = camera_frame_from_ground * ground_from_medmodel_frame;
mat3 transform = {};
pthread_mutex_lock(&transform_lock);
for (int i=0; i<3*3; i++) { for (int i=0; i<3*3; i++) {
cur_transform.v[i] = warp_matrix(i / 3, i % 3); transform.v[i] = warp_matrix(i / 3, i % 3);
} }
mat3 model_transform = matmul3(yuv_transform, transform);
pthread_mutex_lock(&transform_lock);
cur_transform = model_transform;
run_model = true; run_model = true;
pthread_mutex_unlock(&transform_lock); pthread_mutex_unlock(&transform_lock);
} }
@ -118,13 +126,6 @@ int main(int argc, char **argv) {
model_init(&model, device_id, context, true); model_init(&model, device_id, context, true);
LOGW("models loaded, modeld starting"); LOGW("models loaded, modeld starting");
// debayering does a 2x downscale
mat3 yuv_transform = transform_scale_buffer((mat3){{
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
}}, 0.5);
// loop // loop
VisionStream stream; VisionStream stream;
while (!do_exit) { while (!do_exit) {
@ -160,7 +161,7 @@ int main(int argc, char **argv) {
} }
pthread_mutex_lock(&transform_lock); pthread_mutex_lock(&transform_lock);
mat3 transform = cur_transform; mat3 model_transform = cur_transform;
const bool run_model_this_iter = run_model; const bool run_model_this_iter = run_model;
pthread_mutex_unlock(&transform_lock); pthread_mutex_unlock(&transform_lock);
@ -177,8 +178,6 @@ int main(int argc, char **argv) {
vec_desire[desire] = 1.0; vec_desire[desire] = 1.0;
} }
mat3 model_transform = matmul3(yuv_transform, transform);
mt1 = millis_since_boot(); mt1 = millis_since_boot();
// TODO: don't make copies! // TODO: don't make copies!

@ -7,25 +7,23 @@
void frame_init(ModelFrame* frame, int width, int height, void frame_init(ModelFrame* frame, int width, int height,
cl_device_id device_id, cl_context context) { cl_device_id device_id, cl_context context) {
int err; int err;
frame->device_id = device_id;
frame->context = context;
transform_init(&frame->transform, context, device_id); transform_init(&frame->transform, context, device_id);
frame->transformed_width = width; frame->transformed_width = width;
frame->transformed_height = height; frame->transformed_height = height;
frame->transformed_y_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE, frame->transformed_y_cl = clCreateBuffer(context, CL_MEM_READ_WRITE,
(size_t)frame->transformed_width*frame->transformed_height, NULL, &err); (size_t)frame->transformed_width*frame->transformed_height, NULL, &err);
assert(err == 0); assert(err == 0);
frame->transformed_u_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE, frame->transformed_u_cl = clCreateBuffer(context, CL_MEM_READ_WRITE,
(size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err); (size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
assert(err == 0); assert(err == 0);
frame->transformed_v_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE, frame->transformed_v_cl = clCreateBuffer(context, CL_MEM_READ_WRITE,
(size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err); (size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
assert(err == 0); assert(err == 0);
frame->net_input_size = ((width*height*3)/2)*sizeof(float); frame->net_input_size = ((width*height*3)/2)*sizeof(float);
frame->net_input = clCreateBuffer(frame->context, CL_MEM_READ_WRITE, frame->net_input = clCreateBuffer(context, CL_MEM_READ_WRITE,
frame->net_input_size, (void*)NULL, &err); frame->net_input_size, (void*)NULL, &err);
assert(err == 0); assert(err == 0);

@ -20,10 +20,6 @@ float softplus(float input);
float sigmoid(float input); float sigmoid(float input);
typedef struct ModelFrame { typedef struct ModelFrame {
cl_device_id device_id;
cl_context context;
// input
Transform transform; Transform transform;
int transformed_width, transformed_height; int transformed_width, transformed_height;
cl_mem transformed_y_cl, transformed_u_cl, transformed_v_cl; cl_mem transformed_y_cl, transformed_u_cl, transformed_v_cl;

@ -3,8 +3,27 @@
import os import os
import time import time
from common.hardware import TICI
from common.gpio import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N, gpio_init, gpio_set
from panda import BASEDIR, Panda, PandaDFU, build_st
from selfdrive.swaglog import cloudlog from selfdrive.swaglog import cloudlog
from panda import Panda, PandaDFU, BASEDIR, build_st
def set_panda_power(power=True):
if not TICI:
return
gpio_init(GPIO_STM_RST_N, True)
gpio_init(GPIO_STM_BOOT0, True)
gpio_init(GPIO_HUB_RST_N, True)
gpio_set(GPIO_STM_RST_N, False)
gpio_set(GPIO_HUB_RST_N, True)
gpio_set(GPIO_STM_BOOT0, False)
time.sleep(0.1)
gpio_set(GPIO_STM_RST_N, power)
def get_firmware_fn(): def get_firmware_fn():
@ -88,10 +107,12 @@ def update_panda():
def main(): def main():
set_panda_power()
update_panda() update_panda()
os.chdir("boardd") os.chdir("boardd")
os.execvp("./boardd", ["./boardd"]) os.execvp("./boardd", ["./boardd"])
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -1,23 +1,33 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import datetime import datetime
import psutil import os
import time import time
from collections import namedtuple
import psutil
from smbus2 import SMBus from smbus2 import SMBus
import cereal.messaging as messaging
from cereal import log from cereal import log
from common.android import ANDROID, get_network_type, get_network_strength from common.android import get_network_strength, get_network_type
from common.params import Params, put_nonblocking
from common.realtime import sec_since_boot, DT_TRML
from common.numpy_fast import clip, interp
from common.filter_simple import FirstOrderFilter from common.filter_simple import FirstOrderFilter
from selfdrive.version import terms_version, training_version, get_git_branch from common.hardware import EON, TICI
from selfdrive.swaglog import cloudlog from common.numpy_fast import clip, interp
import cereal.messaging as messaging from common.params import Params, put_nonblocking
from common.realtime import DT_TRML, sec_since_boot
from selfdrive.controls.lib.alertmanager import set_offroad_alert from selfdrive.controls.lib.alertmanager import set_offroad_alert
from selfdrive.loggerd.config import get_available_percent from selfdrive.loggerd.config import get_available_percent
from selfdrive.pandad import get_expected_signature from selfdrive.pandad import get_expected_signature
from selfdrive.thermald.power_monitoring import PowerMonitoring, get_battery_capacity, get_battery_status, \ from selfdrive.swaglog import cloudlog
get_battery_current, get_battery_voltage, get_usb_present from selfdrive.thermald.power_monitoring import (PowerMonitoring,
get_battery_capacity,
get_battery_current,
get_battery_status,
get_battery_voltage,
get_usb_present)
from selfdrive.version import get_git_branch, terms_version, training_version
ThermalConfig = namedtuple('ThermalConfig', ['cpu', 'gpu', 'mem', 'bat', 'ambient'])
FW_SIGNATURE = get_expected_signature() FW_SIGNATURE = get_expected_signature()
@ -34,31 +44,34 @@ LEON = False
last_eon_fan_val = None last_eon_fan_val = None
def read_tz(x, clip=True): def get_thermal_config():
if not ANDROID: # (tz, scale)
# we don't monitor thermal on PC if EON:
return ThermalConfig(cpu=((5, 7, 10, 12), 10), gpu=((16,), 10), mem=(2, 10), bat=(29, 1000), ambient=(25, 1))
elif TICI:
return ThermalConfig(cpu=((1, 2, 3, 4, 5, 6, 7, 8), 1000), gpu=((48,49), 1000), mem=(15, 1000), bat=(None, 1), ambient=(70, 1000))
else:
return ThermalConfig(cpu=((None,), 1), gpu=((None,), 1), mem=(None, 1), bat=(None, 1), ambient=(None, 1))
def read_tz(x):
if x is None:
return 0 return 0
try: try:
with open("/sys/devices/virtual/thermal/thermal_zone%d/temp" % x) as f: with open("/sys/devices/virtual/thermal/thermal_zone%d/temp" % x) as f:
ret = int(f.read()) return int(f.read())
if clip:
ret = max(0, ret)
except FileNotFoundError: except FileNotFoundError:
return 0 return 0
return ret
def read_thermal(thermal_config):
def read_thermal():
dat = messaging.new_message('thermal') dat = messaging.new_message('thermal')
dat.thermal.cpu0 = read_tz(5) dat.thermal.cpu = [read_tz(z) / thermal_config.cpu[1] for z in thermal_config.cpu[0]]
dat.thermal.cpu1 = read_tz(7) dat.thermal.gpu = [read_tz(z) / thermal_config.gpu[1] for z in thermal_config.gpu[0]]
dat.thermal.cpu2 = read_tz(10) dat.thermal.mem = read_tz(thermal_config.mem[0]) / thermal_config.mem[1]
dat.thermal.cpu3 = read_tz(12) dat.thermal.ambient = read_tz(thermal_config.ambient[0]) / thermal_config.ambient[1]
dat.thermal.mem = read_tz(2) dat.thermal.bat = read_tz(thermal_config.bat[0]) / thermal_config.bat[1]
dat.thermal.gpu = read_tz(16)
dat.thermal.bat = read_tz(29)
dat.thermal.pa0 = read_tz(25)
return dat return dat
@ -183,11 +196,13 @@ def thermald_thread():
pm = PowerMonitoring() pm = PowerMonitoring()
no_panda_cnt = 0 no_panda_cnt = 0
thermal_config = get_thermal_config()
while 1: while 1:
health = messaging.recv_sock(health_sock, wait=True) health = messaging.recv_sock(health_sock, wait=True)
location = messaging.recv_sock(location_sock) location = messaging.recv_sock(location_sock)
location = location.gpsLocation if location else None location = location.gpsLocation if location else None
msg = read_thermal() msg = read_thermal(thermal_config)
if health is not None: if health is not None:
usb_power = health.health.usbPowerMode != log.HealthData.UsbPowerMode.client usb_power = health.health.usbPowerMode != log.HealthData.UsbPowerMode.client
@ -208,7 +223,7 @@ def thermald_thread():
is_uno = health.health.hwType == log.HealthData.HwType.uno is_uno = health.health.hwType == log.HealthData.HwType.uno
has_relay = health.health.hwType in [log.HealthData.HwType.blackPanda, log.HealthData.HwType.uno, log.HealthData.HwType.dos] has_relay = health.health.hwType in [log.HealthData.HwType.blackPanda, log.HealthData.HwType.uno, log.HealthData.HwType.dos]
if is_uno or not ANDROID: if (not EON) or is_uno:
cloudlog.info("Setting up UNO fan handler") cloudlog.info("Setting up UNO fan handler")
handle_fan = handle_fan_uno handle_fan = handle_fan_uno
else: else:
@ -243,7 +258,7 @@ def thermald_thread():
msg.thermal.usbOnline = get_usb_present() msg.thermal.usbOnline = get_usb_present()
# Fake battery levels on uno for frame # Fake battery levels on uno for frame
if is_uno: if (not EON) or is_uno:
msg.thermal.batteryPercent = 100 msg.thermal.batteryPercent = 100
msg.thermal.batteryStatus = "Charging" msg.thermal.batteryStatus = "Charging"
msg.thermal.bat = 0 msg.thermal.bat = 0
@ -251,14 +266,9 @@ def thermald_thread():
current_filter.update(msg.thermal.batteryCurrent / 1e6) current_filter.update(msg.thermal.batteryCurrent / 1e6)
# TODO: add car battery voltage check # TODO: add car battery voltage check
max_cpu_temp = cpu_temp_filter.update( max_cpu_temp = cpu_temp_filter.update(max(msg.thermal.cpu))
max(msg.thermal.cpu0, max_comp_temp = max(max_cpu_temp, msg.thermal.mem, max(msg.thermal.gpu))
msg.thermal.cpu1, bat_temp = msg.thermal.bat
msg.thermal.cpu2,
msg.thermal.cpu3) / 10.0)
max_comp_temp = max(max_cpu_temp, msg.thermal.mem / 10., msg.thermal.gpu / 10.)
bat_temp = msg.thermal.bat / 1000.
if handle_fan is not None: if handle_fan is not None:
fan_speed = handle_fan(max_cpu_temp, bat_temp, fan_speed, ignition) fan_speed = handle_fan(max_cpu_temp, bat_temp, fan_speed, ignition)

@ -637,8 +637,6 @@ static void ui_draw_vision_header(UIState *s) {
} }
static void ui_draw_vision_footer(UIState *s) { static void ui_draw_vision_footer(UIState *s) {
nvgBeginPath(s->vg);
nvgRect(s->vg, s->scene.ui_viz_rx, footer_y, s->scene.ui_viz_rw, footer_h);
ui_draw_vision_face(s); ui_draw_vision_face(s);

@ -5,7 +5,13 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QSurfaceFormat fmt; QSurfaceFormat fmt;
#ifdef __APPLE__
fmt.setVersion(3, 2);
fmt.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
fmt.setRenderableType(QSurfaceFormat::OpenGL);
#else
fmt.setRenderableType(QSurfaceFormat::OpenGLES); fmt.setRenderableType(QSurfaceFormat::OpenGLES);
#endif
QSurfaceFormat::setDefaultFormat(fmt); QSurfaceFormat::setDefaultFormat(fmt);
QApplication a(argc, argv); QApplication a(argc, argv);

@ -124,7 +124,7 @@ static void ui_draw_sidebar_temp_metric(UIState *s) {
char temp_value_str[32]; char temp_value_str[32];
char temp_value_unit[32]; char temp_value_unit[32];
const int temp_y_offset = 0; const int temp_y_offset = 0;
snprintf(temp_value_str, sizeof(temp_value_str), "%d", s->scene.thermal.getPa0()); snprintf(temp_value_str, sizeof(temp_value_str), "%.0f", s->scene.thermal.getAmbient());
snprintf(temp_value_unit, sizeof(temp_value_unit), "%s", "°C"); snprintf(temp_value_unit, sizeof(temp_value_unit), "%s", "°C");
snprintf(temp_label_str, sizeof(temp_label_str), "%s", "TEMP"); snprintf(temp_label_str, sizeof(temp_label_str), "%s", "TEMP");
strcat(temp_value_str, temp_value_unit); strcat(temp_value_str, temp_value_unit);

@ -26,7 +26,7 @@ if __name__ == "__main__":
while 1: while 1:
fpkt = messaging.recv_one(frame) fpkt = messaging.recv_one(frame)
if len(fpkt.frame.image) == 0: if fpkt is None or len(fpkt.frame.image) == 0:
continue continue
sm.update(timeout=1) sm.update(timeout=1)
rgb_img_raw = fpkt.frame.image rgb_img_raw = fpkt.frame.image

Loading…
Cancel
Save