From 7ad44b7d53cb6d4f0ebdd1102ba7dcce2d3ae80f Mon Sep 17 00:00:00 2001 From: YassineYousfi Date: Thu, 12 May 2022 13:28:04 -0700 Subject: [PATCH 01/91] hatanaka 2.4 (#24508) * hatanaka 2.4 * wrong hashes --- Pipfile | 2 +- Pipfile.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Pipfile b/Pipfile index 1f0f91dbeb..8a57558f10 100644 --- a/Pipfile +++ b/Pipfile @@ -82,7 +82,7 @@ tqdm = "*" urllib3 = "*" utm = "*" websocket_client = "*" -hatanaka = "*" +hatanaka = "==2.4" [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index 3f4bd1f4fd..118a2c3cd5 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "72117588efb763049752818a64ea7b13448e2ec7e396e8dd4bd7f066622c5314" + "sha256": "56ab0eb7dd800742b25b7b68e335870b6a52ee27030cb044398e0a1b0ccdc9e6" }, "pipfile-spec": 6, "requires": { @@ -322,13 +322,13 @@ }, "hatanaka": { "hashes": [ - "sha256:0e095d35ed4f607eb77ae47ecb310e4c25f5a6267037b703ea258ed03e5c47da", - "sha256:84faa953b4f641a6d3cf8187f1775ba7e7f8d815f7bcd48cfb18553b766cbc41", - "sha256:ccf8be554deee2fc70be52bd2f1d3d4dd370001caa74333bf041933d69a19023", - "sha256:ce1628029c6b50c142a8fc5f15453c4cf2a3fd88a7128075415aeb5c9a2727d0" + "sha256:5a0624f6812b13abb4c996398a60338566885c1786841c4c04de9b1b91da28d2", + "sha256:8fda4aa56f27313de75a806a2f5aa83ed5bb2dc7561bebab856a774d06cf1ee7", + "sha256:c22970b99169bddaf22e5239672e856a6bc9602c435f8793d26ad49619a70a99", + "sha256:ef594d63473782fac46df5b0c92a59211a3efea1d47c1a964244a0abffc9f3f6" ], "index": "pypi", - "version": "==2.8.0" + "version": "==2.4" }, "hexdump": { "hashes": [ @@ -366,7 +366,7 @@ "sha256:6f62d78e2f89b4500b080fe3a81690850cd254227f27f75c3a0c491a1f351ba7", "sha256:e8443a5e7a020e9d7f97f1d7d9cd17c88bcb3bc7e218bf9cf5095fe550be2951" ], - "markers": "python_version < '4' and python_full_version >= '3.6.1'", + "markers": "python_version < '4.0' and python_full_version >= '3.6.1'", "version": "==5.10.1" }, "itsdangerous": { @@ -1132,7 +1132,7 @@ "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708", "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376" ], - "markers": "python_version < '3.10'", + "markers": "python_version >= '3.7'", "version": "==4.2.0" }, "urllib3": { @@ -2410,7 +2410,7 @@ "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708", "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376" ], - "markers": "python_version < '3.10'", + "markers": "python_version >= '3.7'", "version": "==4.2.0" }, "urllib3": { From 41b3f253d1d644b90e8bb7258ee43597468766c6 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 14:50:45 -0700 Subject: [PATCH 02/91] boardd: set extra pandas to silent safety mode (#24511) --- selfdrive/boardd/boardd.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index fdce7bab5f..1154318428 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -115,11 +115,15 @@ bool safety_setter_thread(std::vector pandas) { return false; } + // set to ELM327 for fingerprinting pandas[0]->set_safety_model(cereal::CarParams::SafetyModel::ELM327); + for (int i = 1; i < pandas.size(); i++) { + pandas[i]->set_safety_model(cereal::CarParams::SafetyModel::SILENT); + } Params p = Params(); - // switch to SILENT when CarVin param is read + // wait for VIN to be read while (true) { if (do_exit || !check_all_connected(pandas) || !ignition) { return false; @@ -135,6 +139,7 @@ bool safety_setter_thread(std::vector pandas) { util::sleep_for(20); } + // set to ELM327 for ECU knockouts pandas[0]->set_safety_model(cereal::CarParams::SafetyModel::ELM327, 1U); std::string params; From f918ab7967ba25d8fe21275fd03330046cfe94de Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 May 2022 14:55:43 -0700 Subject: [PATCH 03/91] process replay CI: print diff after test (#24513) * make sure we print the diff before updating refs * cause fail * when only uploading no need to print success status or update diff don't print succeed/fail when only uploading * Revert "cause fail" This reverts commit 6e5db1a0ac6ccd0e6a0885d72d79d75c610bdc1f. * Revert "when only uploading no need to print success status or update diff" This reverts commit d6727f30a109fd7330746005aa7b228c9eca3e79. --- .github/workflows/selfdrive_tests.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/selfdrive_tests.yaml b/.github/workflows/selfdrive_tests.yaml index feb7cfa1d5..98cdeab306 100644 --- a/.github/workflows/selfdrive_tests.yaml +++ b/.github/workflows/selfdrive_tests.yaml @@ -317,13 +317,6 @@ jobs: ${{ env.RUN }} "scons -j$(nproc) && \ FILEREADER_CACHE=1 CI=1 coverage run selfdrive/test/process_replay/test_processes.py && \ coverage xml" - - name: Upload reference logs - if: ${{ failure() && github.event_name == 'pull_request' && github.repository == 'commaai/openpilot' && env.AZURE_TOKEN != '' }} - run: | - ${{ env.RUN }} "scons -j$(nproc) && \ - CI=1 AZURE_TOKEN='$AZURE_TOKEN' python selfdrive/test/process_replay/test_processes.py --upload-only" - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v2 - name: Print diff if: always() run: cat selfdrive/test/process_replay/diff.txt @@ -333,6 +326,13 @@ jobs: with: name: process_replay_diff.txt path: selfdrive/test/process_replay/diff.txt + - name: Upload reference logs + if: ${{ failure() && github.event_name == 'pull_request' && github.repository == 'commaai/openpilot' && env.AZURE_TOKEN != '' }} + run: | + ${{ env.RUN }} "scons -j$(nproc) && \ + CI=1 AZURE_TOKEN='$AZURE_TOKEN' python selfdrive/test/process_replay/test_processes.py --upload-only" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v2 #model_replay: # name: model replay From 912973e76a65b9de59bf4526099ba1e66160119f Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 14:59:11 -0700 Subject: [PATCH 04/91] bump cereal --- cereal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cereal b/cereal index 8e8831f8e0..b1b0a407b2 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 8e8831f8e03deb62dd5fcfc638e134cdc8e9adbf +Subproject commit b1b0a407b23d9c085fa0661d381d494e74ca719a From 6518ecca8ff75475c6f79aac1af660c1ccc74da9 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 May 2022 16:59:52 -0700 Subject: [PATCH 05/91] Add desired curvature to controlsState (#24510) * Add desired_curvature to controlsState * clean up * bump * bump * update refs from GitHub! Co-authored-by: Jason Shuler --- selfdrive/controls/controlsd.py | 16 ++++++++++------ selfdrive/test/process_replay/ref_commit | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index cdf9f38e15..cf23ec6d80 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -167,6 +167,8 @@ class Controls: self.logged_comm_issue = None self.button_timers = {ButtonEvent.Type.decelCruise: 0, ButtonEvent.Type.accelCruise: 0} self.last_actuators = car.CarControl.Actuators.new_message() + self.desired_curvature = 0.0 + self.desired_curvature_rate = 0.0 # TODO: no longer necessary, aside from process replay self.sm['liveParameters'].valid = True @@ -571,13 +573,13 @@ class Controls: actuators.accel = self.LoC.update(CC.longActive, CS, long_plan, pid_accel_limits, t_since_plan) # Steering PID loop and lateral MPC - desired_curvature, desired_curvature_rate = get_lag_adjusted_curvature(self.CP, CS.vEgo, - lat_plan.psis, - lat_plan.curvatures, - lat_plan.curvatureRates) + self.desired_curvature, self.desired_curvature_rate = get_lag_adjusted_curvature(self.CP, CS.vEgo, + lat_plan.psis, + lat_plan.curvatures, + lat_plan.curvatureRates) actuators.steer, actuators.steeringAngleDeg, lac_log = self.LaC.update(CC.latActive, CS, self.VM, params, - self.last_actuators, desired_curvature, - desired_curvature_rate, self.sm['liveLocationKalman']) + self.last_actuators, self.desired_curvature, + self.desired_curvature_rate, self.sm['liveLocationKalman']) else: lac_log = log.ControlsState.LateralDebugState.new_message() if self.sm.rcv_frame['testJoystick'] > 0: @@ -721,6 +723,8 @@ class Controls: controlsState.enabled = self.enabled controlsState.active = self.active controlsState.curvature = curvature + controlsState.desiredCurvature = self.desired_curvature + controlsState.desiredCurvatureRate = self.desired_curvature_rate controlsState.state = self.state controlsState.engageable = not self.events.any(ET.NO_ENTRY) controlsState.longControlState = self.LoC.long_control_state diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index ac8f59b26b..5c039f66b8 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -10b766fa845934f0258c52cdf2103d0e1a9496c9 \ No newline at end of file +16a3e2f9ef2bf013bc71bed6085a5296eb276f85 From 934bc1e6fb2ab9b9476438b2f9aea45a4dcb5298 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 May 2022 17:05:22 -0700 Subject: [PATCH 06/91] process replay: don't print diff when only uploading (#24514) when only uploading no need to print success status or update diff don't print succeed/fail when only uploading --- .../test/process_replay/test_processes.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/selfdrive/test/process_replay/test_processes.py b/selfdrive/test/process_replay/test_processes.py index 9d7feac477..fdf10cbfdc 100755 --- a/selfdrive/test/process_replay/test_processes.py +++ b/selfdrive/test/process_replay/test_processes.py @@ -185,18 +185,19 @@ if __name__ == "__main__": upload_file(cur_log_fn, os.path.basename(cur_log_fn)) os.remove(cur_log_fn) - diff1, diff2, failed = format_diff(results, ref_commit) - with open(os.path.join(PROC_REPLAY_DIR, "diff.txt"), "w") as f: - f.write(diff2) - print(diff1) - - if failed: - print("TEST FAILED") - if not upload: - print("\n\nTo push the new reference logs for this commit run:") - print("./test_processes.py --upload-only") - else: - print("TEST SUCCEEDED") + if not args.upload_only: + diff1, diff2, failed = format_diff(results, ref_commit) + with open(os.path.join(PROC_REPLAY_DIR, "diff.txt"), "w") as f: + f.write(diff2) + print(diff1) + + if failed: + print("TEST FAILED") + if not args.update_refs: + print("\n\nTo push the new reference logs for this commit run:") + print("./test_processes.py --upload-only") + else: + print("TEST SUCCEEDED") if upload: with open(REF_COMMIT_FN, "w") as f: From 28a08ff12ec661770e31a7460e9880fe66ef5e69 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 17:07:32 -0700 Subject: [PATCH 07/91] can_printer: add frequency --- selfdrive/debug/can_printer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/debug/can_printer.py b/selfdrive/debug/can_printer.py index 0aaaf1350b..3f991d4e6c 100755 --- a/selfdrive/debug/can_printer.py +++ b/selfdrive/debug/can_printer.py @@ -26,8 +26,9 @@ def can_printer(bus, max_msg, addr, ascii_decode): for addr in sorted(msgs.keys()): a = f"\"{msgs[addr][-1].decode('ascii', 'backslashreplace')}\"" if ascii_decode else "" x = binascii.hexlify(msgs[addr][-1]).decode('ascii') + freq = len(msgs[addr]) / (sec_since_boot() - start) if max_msg is None or addr < max_msg: - dd += "%04X(%4d)(%6d) %s %s\n" % (addr, addr, len(msgs[addr]), x.ljust(20), a) + dd += "%04X(%4d)(%6d)(%3dHz) %s %s\n" % (addr, addr, len(msgs[addr]), freq, x.ljust(20), a) print(dd) lp = sec_since_boot() From d686f9e527f235d513f856e70b60cc0f37cb5559 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 May 2022 19:19:47 -0700 Subject: [PATCH 08/91] process replay: save logs to folder (#24509) * save logs to folder for proc replay * use fakedata dir * fix * only once and where needed --- selfdrive/test/process_replay/process_replay.py | 1 + selfdrive/test/process_replay/regen.py | 6 +----- selfdrive/test/process_replay/test_processes.py | 9 +++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index c1b89713f3..4978525f4f 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -25,6 +25,7 @@ NUMPY_TOLERANCE = 1e-7 CI = "CI" in os.environ TIMEOUT = 15 PROC_REPLAY_DIR = os.path.dirname(os.path.abspath(__file__)) +FAKEDATA = os.path.join(PROC_REPLAY_DIR, "fakedata/") ProcessConfig = namedtuple('ProcessConfig', ['proc_name', 'pub_sub', 'ignore', 'init_callback', 'should_recv_callback', 'tolerance', 'fake_pubsubmaster', 'submaster_config'], defaults=({},)) diff --git a/selfdrive/test/process_replay/regen.py b/selfdrive/test/process_replay/regen.py index d8ca67dc33..d9e80ca335 100755 --- a/selfdrive/test/process_replay/regen.py +++ b/selfdrive/test/process_replay/regen.py @@ -16,17 +16,13 @@ from common.transformations.camera import eon_f_frame_size, eon_d_frame_size, ti from selfdrive.car.fingerprints import FW_VERSIONS from selfdrive.manager.process import ensure_running from selfdrive.manager.process_config import managed_processes -from selfdrive.test.process_replay.process_replay import setup_env, check_enabled +from selfdrive.test.process_replay.process_replay import FAKEDATA, setup_env, check_enabled from selfdrive.test.update_ci_routes import upload_route from tools.lib.route import Route from tools.lib.framereader import FrameReader from tools.lib.logreader import LogReader -process_replay_dir = os.path.dirname(os.path.abspath(__file__)) -FAKEDATA = os.path.join(process_replay_dir, "fakedata/") - - def replay_panda_states(s, msgs): pm = messaging.PubMaster([s, 'peripheralState']) rk = Ratekeeper(service_list[s].frequency, print_delay_threshold=None) diff --git a/selfdrive/test/process_replay/test_processes.py b/selfdrive/test/process_replay/test_processes.py index fdf10cbfdc..ec94cc333b 100755 --- a/selfdrive/test/process_replay/test_processes.py +++ b/selfdrive/test/process_replay/test_processes.py @@ -7,7 +7,7 @@ from typing import Any, Dict from selfdrive.car.car_helpers import interface_names from selfdrive.test.openpilotci import get_url, upload_file from selfdrive.test.process_replay.compare_logs import compare_logs, save_log -from selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, check_enabled, replay_process +from selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, FAKEDATA, check_enabled, replay_process from selfdrive.version import get_commit from tools.lib.logreader import LogReader @@ -131,6 +131,7 @@ if __name__ == "__main__": full_test = all(len(x) == 0 for x in (args.whitelist_procs, args.whitelist_cars, args.blacklist_procs, args.blacklist_cars, args.ignore_fields, args.ignore_msgs)) upload = args.update_refs or args.upload_only + os.makedirs(os.path.dirname(FAKEDATA), exist_ok=True) if upload: assert full_test, "Need to run full test when updating refs" @@ -171,9 +172,9 @@ if __name__ == "__main__": (not len(args.whitelist_procs) and cfg.proc_name in args.blacklist_procs): continue - cur_log_fn = os.path.join(PROC_REPLAY_DIR, f"{segment}_{cfg.proc_name}_{cur_commit}.bz2") + cur_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{cur_commit}.bz2") if not args.upload_only: - ref_log_fn = os.path.join(PROC_REPLAY_DIR, f"{segment}_{cfg.proc_name}_{ref_commit}.bz2") + ref_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{ref_commit}.bz2") results[segment][cfg.proc_name], log_msgs = test_process(cfg, lr, ref_log_fn, args.ignore_fields, args.ignore_msgs) # save logs so we can upload when updating refs @@ -185,8 +186,8 @@ if __name__ == "__main__": upload_file(cur_log_fn, os.path.basename(cur_log_fn)) os.remove(cur_log_fn) + diff1, diff2, failed = format_diff(results, ref_commit) if not args.upload_only: - diff1, diff2, failed = format_diff(results, ref_commit) with open(os.path.join(PROC_REPLAY_DIR, "diff.txt"), "w") as f: f.write(diff2) print(diff1) From affeb2ef73169282a8c450bdd89101c9860e535d Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 19:38:58 -0700 Subject: [PATCH 09/91] jenkins: prune lfs objects --- selfdrive/test/setup_device_ci.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfdrive/test/setup_device_ci.sh b/selfdrive/test/setup_device_ci.sh index 1b518ddb21..72f5fff28b 100755 --- a/selfdrive/test/setup_device_ci.sh +++ b/selfdrive/test/setup_device_ci.sh @@ -19,6 +19,7 @@ fi umount /data/safe_staging/merged/ || true sudo umount /data/safe_staging/merged/ || true +rm -rf /data/safe_staging/* || true export KEYS_PARAM_PATH="/data/params/d/GithubSshKeys" export KEYS_PATH="/usr/comma/setup_keys" @@ -54,7 +55,6 @@ cd $SOURCE_DIR rm -f .git/index.lock git reset --hard -git fetch find . -maxdepth 1 -not -path './.git' -not -name '.' -not -name '..' -exec rm -rf '{}' \; git fetch --verbose origin $GIT_COMMIT git reset --hard $GIT_COMMIT @@ -63,6 +63,8 @@ git clean -xdf git submodule update --init --recursive git submodule foreach --recursive "git reset --hard && git clean -xdf" +git lfs prune + echo "git checkout done, t=$SECONDS" rsync -a --delete $SOURCE_DIR $TEST_DIR From eff08cb17f2b0d00d24cd13729b8d16ec394c82c Mon Sep 17 00:00:00 2001 From: YassineYousfi Date: Thu, 12 May 2022 19:47:33 -0700 Subject: [PATCH 10/91] Joint Model (#24213) * update models * wip lanelines mhp parsing * typos * newer models * 95995a49-db0c-4261-8776-b90780dc2a8c/600 * Use laneful policy to prevent planner aggression * c8c3ab69-bd2c-4d1c-a7f8-9e8457e4827b/950 * ede8f75a-df3e-41fb-bc56-63e2f33858e5/950 * 7205c5af-7532-4215-ad9b-678789054db7/995 * bfb34fa3-1d72-4987-854f-43d42ee01015/950 * change cost * 8ae2477a-b452-4601-b04c-d3af66ea5e98/950 * Update heading cost * 9b991314-94f5-4f0b-872e-58d95266e4d0/333 * 9b991314-94f5-4f0b-872e-58d95266e4d0/950 * ede8f75a-df3e-41fb-bc56-63e2f33858e5/950 * undo lateral planner changes * rm whitespace * update ref Co-authored-by: Harald Schafer --- models/supercombo.dlc | 4 +-- models/supercombo.onnx | 4 +-- selfdrive/modeld/models/driving.cc | 29 ++++++++++------- selfdrive/modeld/models/driving.h | 32 ++++++++++++------- .../process_replay/model_replay_ref_commit | 2 +- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/models/supercombo.dlc b/models/supercombo.dlc index a27e3d1180..e46a5ef679 100644 --- a/models/supercombo.dlc +++ b/models/supercombo.dlc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba3fe3e61853cc1434e3e220f40c8e9d1f1b9bab8458196ba3bea6a10b82c6ed -size 72718099 +oid sha256:d7e58be246bb9fb27e1f7a60ab2ed1ec4ee7bdc99cf82d92af694f77c83e43aa +size 108294663 diff --git a/models/supercombo.onnx b/models/supercombo.onnx index 3039035fbc..9efe640760 100644 --- a/models/supercombo.onnx +++ b/models/supercombo.onnx @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bda57c1a66944f5a633ecd739a24d62702c717a234f2fdcc499dfa1d61c3c19e -size 73147489 +oid sha256:9b0c23ca7198d945303f407cf374c9e5cffc13e0ca2fde3420748e7fbb3eddf8 +size 108687135 diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index e14411df78..696e36078f 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -228,19 +228,24 @@ void fill_plan(cereal::ModelDataV2::Builder &framed, const ModelOutputPlanPredic void fill_lane_lines(cereal::ModelDataV2::Builder &framed, const std::array &plan_t, const ModelOutputLaneLines &lanes) { + + const auto &left_far = lanes.get_lane_idx(0); + const auto &left_near = lanes.get_lane_idx(1); + const auto &right_near = lanes.get_lane_idx(2); + const auto &right_far = lanes.get_lane_idx(3); std::array left_far_y, left_far_z; std::array left_near_y, left_near_z; std::array right_near_y, right_near_z; std::array right_far_y, right_far_z; for (int j=0; j left_far; - std::array left_near; - std::array right_near; - std::array right_far; -}; -static_assert(sizeof(ModelOutputLinesXY) == sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*4); - struct ModelOutputLineProbVal { float val_deprecated; float val; @@ -99,12 +93,28 @@ struct ModelOutputLinesProb { }; static_assert(sizeof(ModelOutputLinesProb) == sizeof(ModelOutputLineProbVal)*4); +struct ModelOutputLaneLinesElement { + std::array mean; + std::array std; + std::array prob; +}; +static_assert(sizeof(ModelOutputLaneLinesElement) == (sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*2) + sizeof(float)*LANELINES_MHP_N); + struct ModelOutputLaneLines { - ModelOutputLinesXY mean; - ModelOutputLinesXY std; + std::array prediction; ModelOutputLinesProb prob; + + constexpr const ModelOutputLaneLinesElement &get_lane_idx(int lane_idx) const { + int max_idx = 0; + for (int i = 1; i < prediction.size(); i++) { + if (prediction[i].prob[lane_idx] > prediction[max_idx].prob[lane_idx]) { + max_idx = i; + } + } + return prediction[max_idx]; + } }; -static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLinesXY)*2) + sizeof(ModelOutputLinesProb)); +static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLaneLinesElement)*LANELINES_MHP_N) + (sizeof(ModelOutputLinesProb))); struct ModelOutputEdgessXY { std::array left; diff --git a/selfdrive/test/process_replay/model_replay_ref_commit b/selfdrive/test/process_replay/model_replay_ref_commit index bf4e1eadb8..1f652422f7 100644 --- a/selfdrive/test/process_replay/model_replay_ref_commit +++ b/selfdrive/test/process_replay/model_replay_ref_commit @@ -1 +1 @@ -5fb5cd71a6e878cf45593ecea22c93e932f70c31 \ No newline at end of file +885bbd4bc01d474795ae81da734be78b75fa4658 From f9e2e82400d2d84edb1f97121216a62de6716be5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 May 2022 21:19:33 -0700 Subject: [PATCH 11/91] Dynamically parse DBCs (#24455) * test commit * bump * bump * doesn't work * bump * bump * bump * no more of these files * bump * bump opendbc * bump * bump opendbc * bump opendbc * bump opendbc * bump opendbc * remove dbc_out * bump opendbc to master * bump opendbc --- opendbc | 2 +- release/files_common | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/opendbc b/opendbc index 9564b74d80..bd7589b628 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit 9564b74d80525c9f289b730febbb2348c529c9cc +Subproject commit bd7589b62802f3df3b1e2b8f99ea721a7c33ab95 diff --git a/release/files_common b/release/files_common index 46f555fe0b..696f827fba 100644 --- a/release/files_common +++ b/release/files_common @@ -524,7 +524,6 @@ opendbc/can/common.h opendbc/can/common.pxd opendbc/can/common_dbc.h opendbc/can/dbc.cc -opendbc/can/dbc.py opendbc/can/dbc_template.cc opendbc/can/packer.cc opendbc/can/packer.py @@ -532,9 +531,6 @@ opendbc/can/packer_pyx.pyx opendbc/can/parser.cc opendbc/can/parser.py opendbc/can/parser_pyx.pyx -opendbc/can/process_dbc.py -opendbc/can/dbc_out/.gitkeep -opendbc/can/dbc_out/.gitignore opendbc/chrysler_pacifica_2017_hybrid.dbc opendbc/chrysler_pacifica_2017_hybrid_private_fusion.dbc From c643d7460938e0dee04e3578670f0d523cb2f4ba Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 22:08:04 -0700 Subject: [PATCH 12/91] jenkins: workaround lfs bug --- selfdrive/test/setup_device_ci.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selfdrive/test/setup_device_ci.sh b/selfdrive/test/setup_device_ci.sh index 72f5fff28b..99acc050ea 100755 --- a/selfdrive/test/setup_device_ci.sh +++ b/selfdrive/test/setup_device_ci.sh @@ -55,15 +55,16 @@ cd $SOURCE_DIR rm -f .git/index.lock git reset --hard -find . -maxdepth 1 -not -path './.git' -not -name '.' -not -name '..' -exec rm -rf '{}' \; git fetch --verbose origin $GIT_COMMIT +find . -maxdepth 1 -not -path './.git' -not -name '.' -not -name '..' -exec rm -rf '{}' \; git reset --hard $GIT_COMMIT git checkout $GIT_COMMIT git clean -xdf git submodule update --init --recursive git submodule foreach --recursive "git reset --hard && git clean -xdf" -git lfs prune +git lfs pull +(ulimit -n 65535 && git lfs prune) echo "git checkout done, t=$SECONDS" From ef81afc35488905b00f1a0a5d0c0fc36b2bc856f Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 12 May 2022 22:52:45 -0700 Subject: [PATCH 13/91] Revert "Joint Model (#24213)" This reverts commit eff08cb17f2b0d00d24cd13729b8d16ec394c82c. --- models/supercombo.dlc | 4 +-- models/supercombo.onnx | 4 +-- selfdrive/modeld/models/driving.cc | 29 +++++++---------- selfdrive/modeld/models/driving.h | 32 +++++++------------ .../process_replay/model_replay_ref_commit | 2 +- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/models/supercombo.dlc b/models/supercombo.dlc index e46a5ef679..a27e3d1180 100644 --- a/models/supercombo.dlc +++ b/models/supercombo.dlc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d7e58be246bb9fb27e1f7a60ab2ed1ec4ee7bdc99cf82d92af694f77c83e43aa -size 108294663 +oid sha256:ba3fe3e61853cc1434e3e220f40c8e9d1f1b9bab8458196ba3bea6a10b82c6ed +size 72718099 diff --git a/models/supercombo.onnx b/models/supercombo.onnx index 9efe640760..3039035fbc 100644 --- a/models/supercombo.onnx +++ b/models/supercombo.onnx @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9b0c23ca7198d945303f407cf374c9e5cffc13e0ca2fde3420748e7fbb3eddf8 -size 108687135 +oid sha256:bda57c1a66944f5a633ecd739a24d62702c717a234f2fdcc499dfa1d61c3c19e +size 73147489 diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index 696e36078f..e14411df78 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -228,24 +228,19 @@ void fill_plan(cereal::ModelDataV2::Builder &framed, const ModelOutputPlanPredic void fill_lane_lines(cereal::ModelDataV2::Builder &framed, const std::array &plan_t, const ModelOutputLaneLines &lanes) { - - const auto &left_far = lanes.get_lane_idx(0); - const auto &left_near = lanes.get_lane_idx(1); - const auto &right_near = lanes.get_lane_idx(2); - const auto &right_far = lanes.get_lane_idx(3); std::array left_far_y, left_far_z; std::array left_near_y, left_near_z; std::array right_near_y, right_near_z; std::array right_far_y, right_far_z; for (int j=0; j left_far; + std::array left_near; + std::array right_near; + std::array right_far; +}; +static_assert(sizeof(ModelOutputLinesXY) == sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*4); + struct ModelOutputLineProbVal { float val_deprecated; float val; @@ -93,28 +99,12 @@ struct ModelOutputLinesProb { }; static_assert(sizeof(ModelOutputLinesProb) == sizeof(ModelOutputLineProbVal)*4); -struct ModelOutputLaneLinesElement { - std::array mean; - std::array std; - std::array prob; -}; -static_assert(sizeof(ModelOutputLaneLinesElement) == (sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*2) + sizeof(float)*LANELINES_MHP_N); - struct ModelOutputLaneLines { - std::array prediction; + ModelOutputLinesXY mean; + ModelOutputLinesXY std; ModelOutputLinesProb prob; - - constexpr const ModelOutputLaneLinesElement &get_lane_idx(int lane_idx) const { - int max_idx = 0; - for (int i = 1; i < prediction.size(); i++) { - if (prediction[i].prob[lane_idx] > prediction[max_idx].prob[lane_idx]) { - max_idx = i; - } - } - return prediction[max_idx]; - } }; -static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLaneLinesElement)*LANELINES_MHP_N) + (sizeof(ModelOutputLinesProb))); +static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLinesXY)*2) + sizeof(ModelOutputLinesProb)); struct ModelOutputEdgessXY { std::array left; diff --git a/selfdrive/test/process_replay/model_replay_ref_commit b/selfdrive/test/process_replay/model_replay_ref_commit index 1f652422f7..bf4e1eadb8 100644 --- a/selfdrive/test/process_replay/model_replay_ref_commit +++ b/selfdrive/test/process_replay/model_replay_ref_commit @@ -1 +1 @@ -885bbd4bc01d474795ae81da734be78b75fa4658 +5fb5cd71a6e878cf45593ecea22c93e932f70c31 \ No newline at end of file From 01a237ef02cf989a3e2dc8a529d5a0338a09e123 Mon Sep 17 00:00:00 2001 From: Ross Fisher Date: Fri, 13 May 2022 05:12:59 -0400 Subject: [PATCH 14/91] Fix gcc-arm-embedded for m1 mac (#24515) * Fix gcc-arm-embedded for m1 mac * put in /tmp * update comment Co-authored-by: Willem Melching --- tools/mac_setup.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/mac_setup.sh b/tools/mac_setup.sh index b85981dc04..214a917f8b 100755 --- a/tools/mac_setup.sh +++ b/tools/mac_setup.sh @@ -52,9 +52,14 @@ brew "zeromq" brew "protobuf" brew "protobuf-c" brew "swig" -cask "gcc-arm-embedded" EOS +# Install gcc-arm-embedded 10.3-2021.10. 11.x is broken on M1 Macs with Xcode 13.3~ +brew uninstall gcc-arm-embedded || true +curl -L https://github.com/Homebrew/homebrew-cask/raw/d407663b8017a0a062c7fc0b929faf2e16abd1ff/Casks/gcc-arm-embedded.rb > /tmp/gcc-arm-embedded.rb +brew install --cask /tmp/gcc-arm-embedded.rb +rm /tmp/gcc-arm-embedded.rb + echo "[ ] finished brew install t=$SECONDS" BREW_PREFIX=$(brew --prefix) From 6b0440f9c959118ccf7ea1c59dfbc76a3faf15e2 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 13 May 2022 13:53:38 +0200 Subject: [PATCH 15/91] dbc regex, do not escape underscore (#24522) * dbc regex, do not escape underscore * bump opendbc --- opendbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc b/opendbc index bd7589b628..c699a06af5 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit bd7589b62802f3df3b1e2b8f99ea721a7c33ab95 +Subproject commit c699a06af5091795177503a192edfb1c440b59e5 From 822ea1fbd9ee761c8dce59d727eebe943e640502 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 13 May 2022 15:48:38 +0200 Subject: [PATCH 16/91] Add sensord test to Jenkins (#24524) * Add sensord test to Jenkins * add second configuration * add other configs too * rename * move into existing HW tests --- Jenkinsfile | 1 + selfdrive/sensord/test/__init__.py | 0 selfdrive/sensord/test/test_sensord.py | 78 ++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 selfdrive/sensord/test/__init__.py create mode 100755 selfdrive/sensord/test/test_sensord.py diff --git a/Jenkinsfile b/Jenkinsfile index c5edda56fd..0c816cbb82 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -124,6 +124,7 @@ pipeline { ["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"], ["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"], ["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"], + ["test sensord", "python selfdrive/sensord/test/test_sensord.py"], ]) } } diff --git a/selfdrive/sensord/test/__init__.py b/selfdrive/sensord/test/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/selfdrive/sensord/test/test_sensord.py b/selfdrive/sensord/test/test_sensord.py new file mode 100755 index 0000000000..96d8891265 --- /dev/null +++ b/selfdrive/sensord/test/test_sensord.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +import time +import unittest + +import cereal.messaging as messaging +from selfdrive.hardware import TICI +from selfdrive.test.helpers import with_processes + +TEST_TIMESPAN = 10 + +SENSOR_CONFIGURATIONS = ( + { + ('bmx055', 'acceleration'), + ('bmx055', 'gyroUncalibrated'), + ('bmx055', 'magneticUncalibrated'), + ('bmx055', 'temperature'), + ('lsm6ds3', 'acceleration'), + ('lsm6ds3', 'gyroUncalibrated'), + ('lsm6ds3', 'temperature'), + ('rpr0521', 'light'), + }, + { + ('lsm6ds3', 'acceleration'), + ('lsm6ds3', 'gyroUncalibrated'), + ('lsm6ds3', 'temperature'), + ('mmc5603nj', 'magneticUncalibrated'), + ('rpr0521', 'light'), + }, + { + ('bmx055', 'acceleration'), + ('bmx055', 'gyroUncalibrated'), + ('bmx055', 'magneticUncalibrated'), + ('bmx055', 'temperature'), + ('lsm6ds3trc', 'acceleration'), + ('lsm6ds3trc', 'gyroUncalibrated'), + ('lsm6ds3trc', 'temperature'), + ('rpr0521', 'light'), + }, + { + ('lsm6ds3trc', 'acceleration'), + ('lsm6ds3trc', 'gyroUncalibrated'), + ('lsm6ds3trc', 'temperature'), + ('mmc5603nj', 'magneticUncalibrated'), + ('rpr0521', 'light'), + }, +) + + +class TestSensord(unittest.TestCase): + @classmethod + def setUpClass(cls): + if not TICI: + raise unittest.SkipTest + + @with_processes(['sensord']) + def test_sensors_present(self): + sensor_events = messaging.sub_sock("sensorEvents", timeout=0.1) + + start_time_sec = time.time() + events = [] + while time.time() - start_time_sec < TEST_TIMESPAN: + events += messaging.drain_sock(sensor_events) + time.sleep(0.01) + + seen = set() + for event in events: + for measurement in event.sensorEvents: + # Filter out unset events + if measurement.version == 0: + continue + seen.add((str(measurement.source), measurement.which())) + + self.assertIn(seen, SENSOR_CONFIGURATIONS) + + +if __name__ == "__main__": + unittest.main() From 489fbb74b0f532c738cf8c06afe1a5f9ce1e1651 Mon Sep 17 00:00:00 2001 From: Joost Wooning Date: Fri, 13 May 2022 16:49:31 +0200 Subject: [PATCH 17/91] camerad: combine debayering and rgb_to_yuv opencl kernels (#24452) * camerad: combine debayering and rgb_to_yuv opencl kernels * fix border * fix snapshot * rename function * update camerad cpu usage * update camerad power draw * vignetting equal to previously * test other local worksize * use less floats * reduce amount of code * move barrier back * make faster * fix corners * cleanup * cleanup * allow more jitter on driverState timing Co-authored-by: Comma Device --- selfdrive/camerad/cameras/camera_common.cc | 14 +- selfdrive/camerad/cameras/real_debayer.cl | 203 ++++++++++-------- selfdrive/camerad/snapshot/snapshot.py | 38 +++- selfdrive/hardware/tici/test_power_draw.py | 2 +- selfdrive/test/process_replay/test_debayer.py | 39 +--- selfdrive/test/test_onroad.py | 4 +- 6 files changed, 157 insertions(+), 143 deletions(-) diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 676e740811..3e4814e65c 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -52,9 +52,9 @@ public: CL_CHECK(clSetKernelArg(krnl_, 0, sizeof(cl_mem), &cam_buf_cl)); CL_CHECK(clSetKernelArg(krnl_, 1, sizeof(cl_mem), &buf_cl)); + const size_t globalWorkSize[] = {size_t(width / 2), size_t(height / 2)}; const int debayer_local_worksize = 16; - constexpr int localMemSize = (debayer_local_worksize + 2 * (3 / 2)) * (debayer_local_worksize + 2 * (3 / 2)) * sizeof(short int); - const size_t globalWorkSize[] = {size_t(width), size_t(height)}; + constexpr int localMemSize = (debayer_local_worksize * 2 + 2) * (debayer_local_worksize * 2 + 2) * 2; const size_t localWorkSize[] = {debayer_local_worksize, debayer_local_worksize}; CL_CHECK(clSetKernelArg(krnl_, 2, localMemSize, 0)); CL_CHECK(clSetKernelArg(krnl_, 3, sizeof(float), &black_level)); @@ -141,6 +141,7 @@ bool CameraBuf::acquire() { cur_frame_data = camera_bufs_metadata[cur_buf_idx]; cur_rgb_buf = vipc_server->get_buffer(rgb_type); + cur_yuv_buf = vipc_server->get_buffer(yuv_type); cl_mem camrabuf_cl = camera_bufs[cur_buf_idx].buf_cl; cl_event event; @@ -157,18 +158,15 @@ bool CameraBuf::acquire() { #else if (camera_state->camera_id == CAMERA_ID_IMX390) black_level = 64.0; #endif - debayer->queue(q, camrabuf_cl, cur_rgb_buf->buf_cl, rgb_width, rgb_height, gain, black_level, &event); + debayer->queue(q, camrabuf_cl, cur_yuv_buf->buf_cl, rgb_width, rgb_height, gain, black_level, &event); } else { assert(rgb_stride == camera_state->ci.frame_stride); - CL_CHECK(clEnqueueCopyBuffer(q, camrabuf_cl, cur_rgb_buf->buf_cl, 0, 0, cur_rgb_buf->len, 0, 0, &event)); + rgb2yuv->queue(q, camrabuf_cl, cur_rgb_buf->buf_cl); } clWaitForEvents(1, &event); CL_CHECK(clReleaseEvent(event)); - cur_yuv_buf = vipc_server->get_buffer(yuv_type); - rgb2yuv->queue(q, cur_rgb_buf->buf_cl, cur_yuv_buf->buf_cl); - cur_frame_data.processing_time = (millis_since_boot() - start_time) / 1000.0; VisionIpcBufExtra extra = { @@ -176,9 +174,7 @@ bool CameraBuf::acquire() { cur_frame_data.timestamp_sof, cur_frame_data.timestamp_eof, }; - cur_rgb_buf->set_frame_id(cur_frame_data.frame_id); cur_yuv_buf->set_frame_id(cur_frame_data.frame_id); - vipc_server->send(cur_rgb_buf, &extra); vipc_server->send(cur_yuv_buf, &extra); return true; diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index 461b41dce3..b1b41f2bf1 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -1,10 +1,22 @@ #ifdef HALF_AS_FLOAT #define half float +#define half2 float2 #define half3 float3 +#define half4 float4 #else #pragma OPENCL EXTENSION cl_khr_fp16 : enable #endif +#define UV_WIDTH RGB_WIDTH / 2 +#define UV_HEIGHT RGB_HEIGHT / 2 +#define U_OFFSET RGB_WIDTH * RGB_HEIGHT +#define V_OFFSET RGB_WIDTH * RGB_HEIGHT + UV_WIDTH * UV_HEIGHT + +#define RGB_TO_Y(r, g, b) ((((mul24(b, 13) + mul24(g, 65) + mul24(r, 33)) + 64) >> 7) + 16) +#define RGB_TO_U(r, g, b) ((mul24(b, 56) - mul24(g, 37) - mul24(r, 19) + 0x8080) >> 8) +#define RGB_TO_V(r, g, b) ((mul24(r, 56) - mul24(g, 47) - mul24(b, 9) + 0x8080) >> 8) +#define AVERAGE(x, y, z, w) ((convert_ushort(x) + convert_ushort(y) + convert_ushort(z) + convert_ushort(w) + 1) >> 1) + // post wb CCM const __constant half3 color_correction_0 = (half3)(1.82717181, -0.31231438, 0.07307673); const __constant half3 color_correction_1 = (half3)(-0.5743977, 1.36858544, -0.53183455); @@ -75,115 +87,122 @@ __kernel void debayer10(const __global uchar * in, float black_level ) { - const int x_global = get_global_id(0); - const int y_global = get_global_id(1); + const int gid_x = get_global_id(0); + const int gid_y = get_global_id(1); + + const int lid_x = get_local_id(0); + const int lid_y = get_local_id(1); - const int x_local = get_local_id(0); - const int y_local = get_local_id(1); + const int localRowLen = mad24(get_local_size(0), 2, 2); // 2 padding + const int localColLen = mad24(get_local_size(1), 2, 2); - const int localRowLen = 2 + get_local_size(0); // 2 padding - const int localColLen = 2 + get_local_size(1); + const int x_global = mul24(gid_x, 2); + const int y_global = mul24(gid_y, 2); - const int localOffset = (y_local + 1) * localRowLen + x_local + 1; + const int x_local = mad24(lid_x, 2, 1); + const int y_local = mad24(lid_y, 2, 1); - int out_idx = 3 * x_global + 3 * y_global * RGB_WIDTH; + const int x_global_mod = (gid_x == 0 || gid_x == get_global_size(0) - 1) ? -1: 1; + const int y_global_mod = (gid_y == 0 || gid_y == get_global_size(1) - 1) ? -1: 1; - // cache padding - int localColOffset = -1; + int localColOffset = 0; int globalColOffset; - const int x_global_mod = (x_global == 0 || x_global == RGB_WIDTH - 1) ? -1: 1; - const int y_global_mod = (y_global == 0 || y_global == RGB_HEIGHT - 1) ? -1: 1; - - half pv = val_from_10(in, x_global, y_global, black_level); - cached[localOffset] = pv; - - // cache padding - if (x_local < 1) { - localColOffset = x_local; - globalColOffset = -1; - cached[(y_local + 1) * localRowLen + x_local] = val_from_10(in, x_global-x_global_mod, y_global, black_level); - } else if (x_local >= get_local_size(0) - 1) { - localColOffset = x_local + 2; - globalColOffset = 1; - cached[localOffset + 1] = val_from_10(in, x_global+x_global_mod, y_global, black_level); + cached[mad24(y_local + 0, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 0, black_level); + cached[mad24(y_local + 0, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 1, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 1, black_level); + + if (lid_x == 0) { // left edge + localColOffset = -1; + globalColOffset = -x_global_mod; + cached[mad24(y_local + 0, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 1, black_level); + } else if (lid_x == get_local_size(0) - 1) { // right edge + localColOffset = 2; + globalColOffset = x_global_mod + 1; + cached[mad24(y_local + 0, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 1, black_level); } - if (y_local < 1) { - cached[y_local * localRowLen + x_local + 1] = val_from_10(in, x_global, y_global-y_global_mod, black_level); - if (localColOffset != -1) { - cached[y_local * localRowLen + localColOffset] = val_from_10(in, x_global+(x_global_mod*globalColOffset), y_global-y_global_mod, black_level); + if (lid_y == 0) { // top row + cached[mad24(y_local - 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global - y_global_mod, black_level); + cached[mad24(y_local - 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global - y_global_mod, black_level); + if (localColOffset != 0) { // cache corners + cached[mad24(y_local - 1, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global - y_global_mod, black_level); } - } else if (y_local >= get_local_size(1) - 1) { - cached[(y_local + 2) * localRowLen + x_local + 1] = val_from_10(in, x_global, y_global+y_global_mod, black_level); - if (localColOffset != -1) { - cached[(y_local + 2) * localRowLen + localColOffset] = val_from_10(in, x_global+(x_global_mod*globalColOffset), y_global+y_global_mod, black_level); + } else if (lid_y == get_local_size(1) - 1) { // bottom row + cached[mad24(y_local + 2, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + y_global_mod + 1, black_level); + cached[mad24(y_local + 2, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + y_global_mod + 1, black_level); + if (localColOffset != 0) { // cache corners + cached[mad24(y_local + 2, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global + y_global_mod + 1, black_level); } } // sync barrier(CLK_LOCAL_MEM_FENCE); - half d1 = cached[localOffset - localRowLen - 1]; - half d2 = cached[localOffset - localRowLen + 1]; - half d3 = cached[localOffset + localRowLen - 1]; - half d4 = cached[localOffset + localRowLen + 1]; - half n1 = cached[localOffset - localRowLen]; - half n2 = cached[localOffset + 1]; - half n3 = cached[localOffset + localRowLen]; - half n4 = cached[localOffset - 1]; - half3 rgb; + uchar3 rgb_out[4]; - // a simplified version of https://opensignalprocessingjournal.com/contents/volumes/V6/TOSIGPJ-6-1/TOSIGPJ-6-1.pdf - if (x_global % 2 == 0) { - if (y_global % 2 == 0) { - rgb.y = pv; // G1(R) - half k1 = get_k(d1, pv, d2, pv); - half k2 = get_k(d2, pv, d4, pv); - half k3 = get_k(d3, pv, d4, pv); - half k4 = get_k(d1, pv, d3, pv); - // R_G1 - rgb.x = (k2*n2+k4*n4)/(k2+k4); - // B_G1 - rgb.z = (k1*n1+k3*n3)/(k1+k3); - } else { - rgb.z = pv; // B - half k1 = get_k(d1, d3, d2, d4); - half k2 = get_k(n1, n4, n2, n3); - half k3 = get_k(d1, d2, d3, d4); - half k4 = get_k(n1, n2, n3, n4); - // G_B - rgb.y = (k1*(n1+n3)*0.5+k3*(n2+n4)*0.5)/(k1+k3); - // R_B - rgb.x = (k2*(d2+d3)*0.5+k4*(d1+d4)*0.5)/(k2+k4); - } - } else { - if (y_global % 2 == 0) { - rgb.x = pv; // R - half k1 = get_k(d1, d3, d2, d4); - half k2 = get_k(n1, n4, n2, n3); - half k3 = get_k(d1, d2, d3, d4); - half k4 = get_k(n1, n2, n3, n4); - // G_R - rgb.y = (k1*(n1+n3)*0.5+k3*(n2+n4)*0.5)/(k1+k3); - // B_R - rgb.z = (k2*(d2+d3)*0.5+k4*(d1+d4)*0.5)/(k2+k4); - } else { - rgb.y = pv; // G2(B) - half k1 = get_k(d1, pv, d2, pv); - half k2 = get_k(d2, pv, d4, pv); - half k3 = get_k(d3, pv, d4, pv); - half k4 = get_k(d1, pv, d3, pv); - // R_G2 - rgb.x = (k1*n1+k3*n3)/(k1+k3); - // B_G2 - rgb.z = (k2*n2+k4*n4)/(k2+k4); - } - } + const half4 va = vload4(0, cached + mad24(lid_y * 2 + 0, localRowLen, lid_x * 2)); + const half4 vb = vload4(0, cached + mad24(lid_y * 2 + 1, localRowLen, lid_x * 2)); + const half4 vc = vload4(0, cached + mad24(lid_y * 2 + 2, localRowLen, lid_x * 2)); + const half4 vd = vload4(0, cached + mad24(lid_y * 2 + 3, localRowLen, lid_x * 2)); - uchar3 rgbc = convert_uchar3_sat(color_correct(clamp(rgb, (half)0.0, (half)1.0)) * 255.0); - out[out_idx + 0] = rgbc.z; - out[out_idx + 1] = rgbc.y; - out[out_idx + 2] = rgbc.x; + // a simplified version of https://opensignalprocessingjournal.com/contents/volumes/V6/TOSIGPJ-6-1/TOSIGPJ-6-1.pdf + const half k01 = get_k(va.s0, vb.s1, va.s2, vb.s1); + const half k02 = get_k(va.s2, vb.s1, vc.s2, vb.s1); + const half k03 = get_k(vc.s0, vb.s1, vc.s2, vb.s1); + const half k04 = get_k(va.s0, vb.s1, vc.s0, vb.s1); + rgb.x = (k02*vb.s2+k04*vb.s0)/(k02+k04); // R_G1 + rgb.y = vb.s1; // G1(R) + rgb.z = (k01*va.s1+k03*vc.s1)/(k01+k03); // B_G1 + rgb_out[0] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); + + const half k11 = get_k(va.s1, vc.s1, va.s3, vc.s3); + const half k12 = get_k(va.s2, vb.s1, vb.s3, vc.s2); + const half k13 = get_k(va.s1, va.s3, vc.s1, vc.s3); + const half k14 = get_k(va.s2, vb.s3, vc.s2, vb.s1); + rgb.x = vb.s2; // R + rgb.y = (k11*(va.s2+vc.s2)*0.5+k13*(vb.s3+vb.s1)*0.5)/(k11+k13); // G_R + rgb.z = (k12*(va.s3+vc.s1)*0.5+k14*(va.s1+vc.s3)*0.5)/(k12+k14); // B_R + rgb_out[1] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); + + const half k21 = get_k(vb.s0, vd.s0, vb.s2, vd.s2); + const half k22 = get_k(vb.s1, vc.s0, vc.s2, vd.s1); + const half k23 = get_k(vb.s0, vb.s2, vd.s0, vd.s2); + const half k24 = get_k(vb.s1, vc.s2, vd.s1, vc.s0); + rgb.x = (k22*(vb.s2+vd.s0)*0.5+k24*(vb.s0+vd.s2)*0.5)/(k22+k24); // R_B + rgb.y = (k21*(vb.s1+vd.s1)*0.5+k23*(vc.s2+vc.s0)*0.5)/(k21+k23); // G_B + rgb.z = vc.s1; // B + rgb_out[2] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); + + const half k31 = get_k(vb.s1, vc.s2, vb.s3, vc.s2); + const half k32 = get_k(vb.s3, vc.s2, vd.s3, vc.s2); + const half k33 = get_k(vd.s1, vc.s2, vd.s3, vc.s2); + const half k34 = get_k(vb.s1, vc.s2, vd.s1, vc.s2); + rgb.x = (k31*vb.s2+k33*vd.s2)/(k31+k33); // R_G2 + rgb.y = vc.s2; // G2(B) + rgb.z = (k32*vc.s3+k34*vc.s1)/(k32+k34); // B_G2 + rgb_out[3] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); + + // write ys + uchar2 yy = (uchar2)( + RGB_TO_Y(rgb_out[0].s0, rgb_out[0].s1, rgb_out[0].s2), + RGB_TO_Y(rgb_out[1].s0, rgb_out[1].s1, rgb_out[1].s2) + ); + vstore2(yy, 0, out + mad24(gid_y * 2, RGB_WIDTH, gid_x * 2)); + yy = (uchar2)( + RGB_TO_Y(rgb_out[2].s0, rgb_out[2].s1, rgb_out[2].s2), + RGB_TO_Y(rgb_out[3].s0, rgb_out[3].s1, rgb_out[3].s2) + ); + vstore2(yy, 0, out + mad24(gid_y * 2 + 1, RGB_WIDTH, gid_x * 2)); + + // write uvs + const short ar = AVERAGE(rgb_out[0].s0, rgb_out[1].s0, rgb_out[2].s0, rgb_out[3].s0); + const short ag = AVERAGE(rgb_out[0].s1, rgb_out[1].s1, rgb_out[2].s1, rgb_out[3].s1); + const short ab = AVERAGE(rgb_out[0].s2, rgb_out[1].s2, rgb_out[2].s2, rgb_out[3].s2); + out[U_OFFSET + mad24(gid_y, UV_WIDTH, gid_x)] = RGB_TO_U(ar, ag, ab); + out[V_OFFSET + mad24(gid_y, UV_WIDTH, gid_x)] = RGB_TO_V(ar, ag, ab); } diff --git a/selfdrive/camerad/snapshot/snapshot.py b/selfdrive/camerad/snapshot/snapshot.py index 1ec7677d31..2e8f7093da 100755 --- a/selfdrive/camerad/snapshot/snapshot.py +++ b/selfdrive/camerad/snapshot/snapshot.py @@ -17,9 +17,9 @@ from selfdrive.manager.process_config import managed_processes LM_THRESH = 120 # defined in selfdrive/camerad/imgproc/utils.h VISION_STREAMS = { - "roadCameraState": VisionStreamType.VISION_STREAM_RGB_ROAD, - "driverCameraState": VisionStreamType.VISION_STREAM_RGB_DRIVER, - "wideRoadCameraState": VisionStreamType.VISION_STREAM_RGB_WIDE_ROAD, + "roadCameraState": VisionStreamType.VISION_STREAM_ROAD, + "driverCameraState": VisionStreamType.VISION_STREAM_DRIVER, + "wideRoadCameraState": VisionStreamType.VISION_STREAM_WIDE_ROAD, } @@ -28,12 +28,28 @@ def jpeg_write(fn, dat): img.save(fn, "JPEG") -def extract_image(buf, w, h, stride): - img = np.hstack([buf[i * stride:i * stride + 3 * w] for i in range(h)]) - b = img[::3].reshape(h, w) - g = img[1::3].reshape(h, w) - r = img[2::3].reshape(h, w) - return np.dstack([r, g, b]) +def yuv_to_rgb(y, u, v): + ul = np.repeat(np.repeat(u, 2).reshape(u.shape[0], y.shape[1]), 2, axis=0).reshape(y.shape) + vl = np.repeat(np.repeat(v, 2).reshape(v.shape[0], y.shape[1]), 2, axis=0).reshape(y.shape) + + yuv = np.dstack((y, ul, vl)).astype(np.int16) + yuv[:, :, 1:] -= 128 + + m = np.array([ + [1.00000, 1.00000, 1.00000], + [0.00000, -0.39465, 2.03211], + [1.13983, -0.58060, 0.00000], + ]) + rgb = np.dot(yuv, m) + return rgb.astype(np.uint8) + + +def extract_image(buf, w, h): + y = np.array(buf[:w*h], dtype=np.uint8).reshape((h, w)) + u = np.array(buf[w*h: w*h+(w//2)*(h//2)], dtype=np.uint8).reshape((h//2, w//2)) + v = np.array(buf[w*h+(w//2)*(h//2):], dtype=np.uint8).reshape((h//2, w//2)) + + return yuv_to_rgb(y, u, v) def rois_in_focus(lapres: List[float]) -> float: @@ -63,10 +79,10 @@ def get_snapshots(frame="roadCameraState", front_frame="driverCameraState", focu rear, front = None, None if frame is not None: c = vipc_clients[frame] - rear = extract_image(c.recv(), c.width, c.height, c.stride) + rear = extract_image(c.recv(), c.width, c.height) if front_frame is not None: c = vipc_clients[front_frame] - front = extract_image(c.recv(), c.width, c.height, c.stride) + front = extract_image(c.recv(), c.width, c.height) return rear, front diff --git a/selfdrive/hardware/tici/test_power_draw.py b/selfdrive/hardware/tici/test_power_draw.py index 4261e10442..95c7505421 100755 --- a/selfdrive/hardware/tici/test_power_draw.py +++ b/selfdrive/hardware/tici/test_power_draw.py @@ -19,7 +19,7 @@ class Proc: warmup: float = 3. PROCS = [ - Proc('camerad', 2.5), + Proc('camerad', 2.17), Proc('modeld', 0.95), Proc('dmonitoringmodeld', 0.25), Proc('loggerd', 0.45, warmup=10.), diff --git a/selfdrive/test/process_replay/test_debayer.py b/selfdrive/test/process_replay/test_debayer.py index 6488184263..a70d478ff9 100755 --- a/selfdrive/test/process_replay/test_debayer.py +++ b/selfdrive/test/process_replay/test_debayer.py @@ -10,6 +10,7 @@ from selfdrive.hardware import PC, TICI from common.basedir import BASEDIR from selfdrive.test.openpilotci import BASE_URL, get_url from selfdrive.version import get_commit +from selfdrive.camerad.snapshot.snapshot import yuv_to_rgb from tools.lib.logreader import LogReader from tools.lib.filereader import FileReader @@ -68,38 +69,20 @@ def init_kernels(frame_offset=0): build_args += ' -DHALF_AS_FLOAT=1 -cl-std=CL2.0' debayer_prg = cl.Program(ctx, f.read()).build(options=build_args) - with open(os.path.join(BASEDIR, 'selfdrive/camerad/transforms/rgb_to_yuv.cl')) as f: - build_args = f' -cl-fast-relaxed-math -cl-denorms-are-zero -DWIDTH={FRAME_WIDTH} -DHEIGHT={FRAME_HEIGHT}' + \ - f' -DUV_WIDTH={UV_WIDTH} -DUV_HEIGHT={UV_HEIGHT} -DRGB_STRIDE={FRAME_WIDTH*3}' + \ - f' -DRGB_SIZE={FRAME_WIDTH*FRAME_HEIGHT}' - rgb_to_yuv_prg = cl.Program(ctx, f.read()).build(options=build_args) + return ctx, debayer_prg - return ctx, debayer_prg, rgb_to_yuv_prg - - -def debayer_frame(ctx, debayer_prg, rgb_to_yuv_prg, data, rgb=False): +def debayer_frame(ctx, debayer_prg, data, rgb=False): q = cl.CommandQueue(ctx) - rgb_buff = np.empty(FRAME_WIDTH * FRAME_HEIGHT * 3, dtype=np.uint8) yuv_buff = np.empty(FRAME_WIDTH * FRAME_HEIGHT + UV_SIZE * 2, dtype=np.uint8) cam_g = cl.Buffer(ctx, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=data) - rgb_wg = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, FRAME_WIDTH * FRAME_HEIGHT * 3) yuv_g = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, FRAME_WIDTH * FRAME_HEIGHT + UV_SIZE * 2) - local_worksize = (16, 16) if TICI else (8, 8) - local_mem = cl.LocalMemory(648 if TICI else 400) - ev1 = debayer_prg.debayer10(q, (FRAME_WIDTH, FRAME_HEIGHT), local_worksize, cam_g, rgb_wg, local_mem, np.float32(42)) - cl.enqueue_copy(q, rgb_buff, rgb_wg, wait_for=[ev1]).wait() - cl.enqueue_barrier(q) - - rgb_rg = cl.Buffer(ctx, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=rgb_buff) - cl.enqueue_barrier(q) - - ev3 = rgb_to_yuv_prg.rgb_to_yuv(q, (FRAME_WIDTH // 4, FRAME_HEIGHT // 4), None, rgb_rg, yuv_g) - cl.enqueue_barrier(q) - - cl.enqueue_copy(q, yuv_buff, yuv_g, wait_for=[ev3]).wait() + local_worksize = (20, 20) if TICI else (4, 4) + local_mem = cl.LocalMemory(3528 if TICI else 400) + ev1 = debayer_prg.debayer10(q, (UV_WIDTH, UV_HEIGHT), local_worksize, cam_g, yuv_g, local_mem, np.float32(42)) + cl.enqueue_copy(q, yuv_buff, yuv_g, wait_for=[ev1]).wait() cl.enqueue_barrier(q) y = yuv_buff[:FRAME_WIDTH*FRAME_HEIGHT].reshape((FRAME_HEIGHT, FRAME_WIDTH)) @@ -107,13 +90,13 @@ def debayer_frame(ctx, debayer_prg, rgb_to_yuv_prg, data, rgb=False): v = yuv_buff[FRAME_WIDTH*FRAME_HEIGHT+UV_SIZE:].reshape((UV_HEIGHT, UV_WIDTH)) if rgb: - return rgb_buff.reshape((FRAME_HEIGHT, FRAME_WIDTH, 3))[:, :, (2, 1, 0)] + return yuv_to_rgb(y, u, v) else: return y, u, v def debayer_replay(lr): - ctx, debayer_prg, rgb_to_yuv_prg = init_kernels() + ctx, debayer_prg = init_kernels() frames = [] for m in lr: @@ -121,7 +104,7 @@ def debayer_replay(lr): cs = m.roadCameraState if cs.image: data = np.frombuffer(cs.image, dtype=np.uint8) - img = debayer_frame(ctx, debayer_prg, rgb_to_yuv_prg, data) + img = debayer_frame(ctx, debayer_prg, data) frames.append(img) @@ -173,7 +156,7 @@ if __name__ == "__main__": frame_diff = np.abs(np.subtract(fr, cmp_f)) diff_len = len(np.nonzero(frame_diff)[0]) - if diff_len > 1000: + if diff_len > 10000: diff += f'different at a large amount of pixels ({diff_len})\n' else: diff += 'different at (frame, yuv, pixel, ref, HEAD):\n' diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 21696645cd..8644baac8d 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -23,7 +23,7 @@ from tools.lib.logreader import LogReader PROCS = { "selfdrive.controls.controlsd": 31.0, "./loggerd": 50.0, - "./camerad": 26.0, + "./camerad": 16.5, "./locationd": 9.1, "selfdrive.controls.plannerd": 11.7, "./_ui": 21.0, @@ -59,7 +59,7 @@ TIMINGS = { "roadCameraState": [2.5, 0.35], "driverCameraState": [2.5, 0.35], "modelV2": [2.5, 0.35], - "driverState": [2.5, 0.35], + "driverState": [2.5, 0.40], "liveLocationKalman": [2.5, 0.35], "wideRoadCameraState": [1.5, 0.35], } From ed5c14e86cf918e62da236ecce8a82f2a9733ad8 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 13 May 2022 13:18:09 -0700 Subject: [PATCH 18/91] add body to release (#24528) * add body to release * sort * add dbc --- release/files_common | 93 +++++++------------------------------------- 1 file changed, 15 insertions(+), 78 deletions(-) diff --git a/release/files_common b/release/files_common index 696f827fba..4013310559 100644 --- a/release/files_common +++ b/release/files_common @@ -109,85 +109,20 @@ selfdrive/car/fw_versions.py selfdrive/car/isotp_parallel_query.py selfdrive/car/tests/__init__.py selfdrive/car/tests/test_car_interfaces.py -selfdrive/car/chrysler/__init__.py -selfdrive/car/chrysler/carstate.py -selfdrive/car/chrysler/interface.py -selfdrive/car/chrysler/radar_interface.py -selfdrive/car/chrysler/values.py -selfdrive/car/chrysler/carcontroller.py -selfdrive/car/chrysler/chryslercan.py -selfdrive/car/honda/__init__.py -selfdrive/car/honda/carstate.py -selfdrive/car/honda/interface.py -selfdrive/car/honda/radar_interface.py -selfdrive/car/honda/values.py -selfdrive/car/honda/carcontroller.py -selfdrive/car/honda/hondacan.py -selfdrive/car/hyundai/__init__.py -selfdrive/car/hyundai/carstate.py -selfdrive/car/hyundai/interface.py -selfdrive/car/hyundai/radar_interface.py -selfdrive/car/hyundai/values.py -selfdrive/car/hyundai/carcontroller.py -selfdrive/car/hyundai/hyundaican.py -selfdrive/car/toyota/__init__.py -selfdrive/car/toyota/carstate.py -selfdrive/car/toyota/tunes.py -selfdrive/car/toyota/interface.py -selfdrive/car/toyota/radar_interface.py -selfdrive/car/toyota/values.py -selfdrive/car/toyota/carcontroller.py -selfdrive/car/toyota/toyotacan.py -selfdrive/car/nissan/__init__.py -selfdrive/car/nissan/carcontroller.py -selfdrive/car/nissan/carstate.py -selfdrive/car/nissan/interface.py -selfdrive/car/nissan/nissancan.py -selfdrive/car/nissan/radar_interface.py -selfdrive/car/nissan/values.py -selfdrive/car/volkswagen/__init__.py -selfdrive/car/volkswagen/carstate.py -selfdrive/car/volkswagen/interface.py -selfdrive/car/volkswagen/radar_interface.py -selfdrive/car/volkswagen/values.py -selfdrive/car/volkswagen/carcontroller.py -selfdrive/car/volkswagen/volkswagencan.py -selfdrive/car/gm/__init__.py -selfdrive/car/gm/carstate.py -selfdrive/car/gm/interface.py -selfdrive/car/gm/radar_interface.py -selfdrive/car/gm/values.py -selfdrive/car/gm/carcontroller.py -selfdrive/car/gm/gmcan.py -selfdrive/car/ford/__init__.py -selfdrive/car/ford/carstate.py -selfdrive/car/ford/interface.py -selfdrive/car/ford/radar_interface.py -selfdrive/car/ford/values.py -selfdrive/car/ford/carcontroller.py -selfdrive/car/ford/fordcan.py -selfdrive/car/subaru/__init__.py -selfdrive/car/subaru/carstate.py -selfdrive/car/subaru/interface.py -selfdrive/car/subaru/radar_interface.py -selfdrive/car/subaru/values.py -selfdrive/car/subaru/carcontroller.py -selfdrive/car/subaru/subarucan.py -selfdrive/car/mazda/__init__.py -selfdrive/car/mazda/carstate.py -selfdrive/car/mazda/interface.py -selfdrive/car/mazda/radar_interface.py -selfdrive/car/mazda/values.py -selfdrive/car/mazda/carcontroller.py -selfdrive/car/mazda/mazdacan.py -selfdrive/car/tesla/__init__.py -selfdrive/car/tesla/teslacan.py -selfdrive/car/tesla/carcontroller.py -selfdrive/car/tesla/radar_interface.py -selfdrive/car/tesla/values.py -selfdrive/car/tesla/carstate.py -selfdrive/car/tesla/interface.py + +selfdrive/car/body/*.py +selfdrive/car/chrysler/*.py +selfdrive/car/ford/*.py +selfdrive/car/gm/*.py +selfdrive/car/honda/*.py +selfdrive/car/hyundai/*.py +selfdrive/car/mazda/*.py selfdrive/car/mock/*.py +selfdrive/car/nissan/*.py +selfdrive/car/subaru/*.py +selfdrive/car/tesla/*.py +selfdrive/car/toyota/*.py +selfdrive/car/volkswagen/*.py selfdrive/clocksd/.gitignore selfdrive/clocksd/SConscript @@ -532,6 +467,8 @@ opendbc/can/parser.cc opendbc/can/parser.py opendbc/can/parser_pyx.pyx +opendbc/comma_body.dbc + opendbc/chrysler_pacifica_2017_hybrid.dbc opendbc/chrysler_pacifica_2017_hybrid_private_fusion.dbc From 11e1ad3e3fd37b08498a3d600a6b75d00ed29b4b Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 13 May 2022 15:32:09 -0700 Subject: [PATCH 19/91] bump opendbc and remove common file (#24529) * bump and remove file * bump opendbc to master --- opendbc | 2 +- release/files_common | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/opendbc b/opendbc index c699a06af5..c53965dfbd 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit c699a06af5091795177503a192edfb1c440b59e5 +Subproject commit c53965dfbd9ac980e550b5e549896c03f9a56d9c diff --git a/release/files_common b/release/files_common index 4013310559..12bb8b2ed9 100644 --- a/release/files_common +++ b/release/files_common @@ -459,7 +459,6 @@ opendbc/can/common.h opendbc/can/common.pxd opendbc/can/common_dbc.h opendbc/can/dbc.cc -opendbc/can/dbc_template.cc opendbc/can/packer.cc opendbc/can/packer.py opendbc/can/packer_pyx.pyx From 12b22cf867c3cae19f3ec097675247482be71b4b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 13 May 2022 16:47:55 -0700 Subject: [PATCH 20/91] CI: add SSH for pushing branches --- Dockerfile.openpilot_base | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.openpilot_base b/Dockerfile.openpilot_base index c5a024db82..0de3008baf 100644 --- a/Dockerfile.openpilot_base +++ b/Dockerfile.openpilot_base @@ -4,7 +4,7 @@ ENV PYTHONUNBUFFERED 1 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install -y --no-install-recommends sudo tzdata locales && \ + apt-get install -y --no-install-recommends sudo tzdata locales ssh && \ rm -rf /var/lib/apt/lists/* RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen @@ -29,5 +29,5 @@ RUN cd /tmp && \ cd /usr/lib/gcc/arm-none-eabi/9.2.1 && \ rm -rf arm/ && \ rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp -RUN sudo git config --global --add safe.directory /tmp/openpilot +RUN sudo git config --global --add safe.directory /tmp/openpilot From a693b3a26b2dcbd7910e4fa98318f23c13c3d815 Mon Sep 17 00:00:00 2001 From: ClockeNessMnstr Date: Fri, 13 May 2022 19:52:20 -0400 Subject: [PATCH 21/91] LatControlTorque: clean up class variable (#24526) * move to super * no class variable * there's CP * whitespace * drop CI from latcontrol super * Revert "drop CI from latcontrol super" This reverts commit 9218273060ade6431c4fc4c310b27e7e210158b9. Co-authored-by: Shane Smiskol --- selfdrive/controls/lib/latcontrol_torque.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selfdrive/controls/lib/latcontrol_torque.py b/selfdrive/controls/lib/latcontrol_torque.py index a373384254..9a1ac2f9ea 100644 --- a/selfdrive/controls/lib/latcontrol_torque.py +++ b/selfdrive/controls/lib/latcontrol_torque.py @@ -25,12 +25,12 @@ JERK_THRESHOLD = 0.2 class LatControlTorque(LatControl): def __init__(self, CP, CI): super().__init__(CP, CI) - self.CP = CP self.pid = PIDController(CP.lateralTuning.torque.kp, CP.lateralTuning.torque.ki, k_f=CP.lateralTuning.torque.kf, pos_limit=self.steer_max, neg_limit=-self.steer_max) self.get_steer_feedforward = CI.get_steer_feedforward_function() self.use_steering_angle = CP.lateralTuning.torque.useSteeringAngle self.friction = CP.lateralTuning.torque.friction + self.kf = CP.lateralTuning.torque.kf def reset(self): super().reset() @@ -61,7 +61,7 @@ class LatControlTorque(LatControl): ff = desired_lateral_accel - params.roll * ACCELERATION_DUE_TO_GRAVITY # convert friction into lateral accel units for feedforward friction_compensation = interp(desired_lateral_jerk, [-JERK_THRESHOLD, JERK_THRESHOLD], [-self.friction, self.friction]) - ff += friction_compensation / self.CP.lateralTuning.torque.kf + ff += friction_compensation / self.kf output_torque = self.pid.update(error, override=CS.steeringPressed, feedforward=ff, speed=CS.vEgo, From 94b9972eb798408a3c412716b8d9eb8ddb9354bc Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Fri, 13 May 2022 17:56:02 -0700 Subject: [PATCH 22/91] encoderd: enable (#24492) * enable encoderd * correct enable line * fix loggerd tests * fix power draw and cpu tests * correct cpu for encoderd * fix a bug, video_writer is shared * fix issue with not recording dcam * add recording state * wooo tests pass. encode id keeps counting * core 3 * loggerd then encoderd * stop loggerd first * core 3 always online * see the camera when we see encoder packet * encoderd on small core uses 37% * remove encoder logic from loggerd * delete unit test that doesn't really make sense anymore Co-authored-by: Comma Device --- release/files_common | 7 +- selfdrive/hardware/tici/test_power_draw.py | 2 +- selfdrive/loggerd/SConscript | 6 +- selfdrive/loggerd/encoder/encoder.cc | 2 +- selfdrive/loggerd/encoder/encoder.h | 5 +- selfdrive/loggerd/encoder/ffmpeg_encoder.h | 1 - selfdrive/loggerd/encoder/v4l_encoder.cc | 4 +- selfdrive/loggerd/encoder/v4l_encoder.h | 1 - selfdrive/loggerd/encoderd.cc | 31 +- selfdrive/loggerd/loggerd.cc | 292 ++++++++---------- selfdrive/loggerd/loggerd.h | 27 -- selfdrive/loggerd/main.cc | 18 -- selfdrive/loggerd/remote_encoder.cc | 82 ----- selfdrive/loggerd/remote_encoder.h | 11 - selfdrive/loggerd/tests/test_encoder.py | 2 + selfdrive/loggerd/tests/test_loggerd.cc | 93 ------ selfdrive/loggerd/tests/test_loggerd.py | 2 + .../loggerd/{encoder => }/video_writer.cc | 4 +- .../loggerd/{encoder => }/video_writer.h | 0 selfdrive/manager/process_config.py | 1 + selfdrive/test/test_onroad.py | 3 +- 21 files changed, 160 insertions(+), 434 deletions(-) delete mode 100644 selfdrive/loggerd/main.cc delete mode 100644 selfdrive/loggerd/remote_encoder.cc delete mode 100644 selfdrive/loggerd/remote_encoder.h delete mode 100644 selfdrive/loggerd/tests/test_loggerd.cc rename selfdrive/loggerd/{encoder => }/video_writer.cc (96%) rename selfdrive/loggerd/{encoder => }/video_writer.h (100%) diff --git a/release/files_common b/release/files_common index 12bb8b2ed9..3f8c88547e 100644 --- a/release/files_common +++ b/release/files_common @@ -237,16 +237,13 @@ selfdrive/loggerd/encoder/encoder.cc selfdrive/loggerd/encoder/encoder.h selfdrive/loggerd/encoder/v4l_encoder.cc selfdrive/loggerd/encoder/v4l_encoder.h -selfdrive/loggerd/encoder/video_writer.cc -selfdrive/loggerd/encoder/video_writer.h -selfdrive/loggerd/remote_encoder.cc -selfdrive/loggerd/remote_encoder.h +selfdrive/loggerd/video_writer.cc +selfdrive/loggerd/video_writer.h selfdrive/loggerd/logger.cc selfdrive/loggerd/logger.h selfdrive/loggerd/loggerd.cc selfdrive/loggerd/loggerd.h selfdrive/loggerd/encoderd.cc -selfdrive/loggerd/main.cc selfdrive/loggerd/bootlog.cc selfdrive/loggerd/encoder/ffmpeg_encoder.cc selfdrive/loggerd/encoder/ffmpeg_encoder.h diff --git a/selfdrive/hardware/tici/test_power_draw.py b/selfdrive/hardware/tici/test_power_draw.py index 95c7505421..0435193bc8 100755 --- a/selfdrive/hardware/tici/test_power_draw.py +++ b/selfdrive/hardware/tici/test_power_draw.py @@ -22,7 +22,7 @@ PROCS = [ Proc('camerad', 2.17), Proc('modeld', 0.95), Proc('dmonitoringmodeld', 0.25), - Proc('loggerd', 0.45, warmup=10.), + Proc('encoderd', 0.42), ] diff --git a/selfdrive/loggerd/SConscript b/selfdrive/loggerd/SConscript index 81eca19a47..a15aac380d 100644 --- a/selfdrive/loggerd/SConscript +++ b/selfdrive/loggerd/SConscript @@ -5,7 +5,7 @@ libs = [common, cereal, messaging, visionipc, 'avformat', 'avcodec', 'swscale', 'avutil', 'yuv', 'OpenCL', 'pthread'] -src = ['logger.cc', 'loggerd.cc', 'encoder/video_writer.cc', 'remote_encoder.cc', 'encoder/encoder.cc'] +src = ['logger.cc', 'video_writer.cc', 'encoder/encoder.cc'] if arch == "larch64": src += ['encoder/v4l_encoder.cc'] else: @@ -19,9 +19,9 @@ if arch == "Darwin": logger_lib = env.Library('logger', src) libs.insert(0, logger_lib) -env.Program('loggerd', ['main.cc'], LIBS=libs) +env.Program('loggerd', ['loggerd.cc'], LIBS=libs) env.Program('encoderd', ['encoderd.cc'], LIBS=libs) env.Program('bootlog.cc', LIBS=libs) if GetOption('test'): - env.Program('tests/test_logger', ['tests/test_runner.cc', 'tests/test_loggerd.cc', 'tests/test_logger.cc'], LIBS=libs + ['curl', 'crypto']) + env.Program('tests/test_logger', ['tests/test_runner.cc', 'tests/test_logger.cc'], LIBS=libs + ['curl', 'crypto']) diff --git a/selfdrive/loggerd/encoder/encoder.cc b/selfdrive/loggerd/encoder/encoder.cc index 84f26d9787..86fd441979 100644 --- a/selfdrive/loggerd/encoder/encoder.cc +++ b/selfdrive/loggerd/encoder/encoder.cc @@ -24,7 +24,7 @@ void VideoEncoder::publisher_publish(VideoEncoder *e, int segment_num, uint32_t edata.setTimestampSof(extra.timestamp_sof); edata.setTimestampEof(extra.timestamp_eof); edata.setType(e->codec); - edata.setEncodeId(idx); + edata.setEncodeId(e->cnt++); edata.setSegmentNum(segment_num); edata.setSegmentId(idx); edata.setFlags(flags); diff --git a/selfdrive/loggerd/encoder/encoder.h b/selfdrive/loggerd/encoder/encoder.h index abdcc9c4bf..94c9c551d9 100644 --- a/selfdrive/loggerd/encoder/encoder.h +++ b/selfdrive/loggerd/encoder/encoder.h @@ -7,7 +7,7 @@ #include "cereal/messaging/messaging.h" #include "cereal/visionipc/visionipc.h" #include "selfdrive/common/queue.h" -#include "selfdrive/loggerd/encoder/video_writer.h" +#include "selfdrive/loggerd/video_writer.h" #include "selfdrive/camerad/cameras/camera_common.h" #define V4L2_BUF_FLAG_KEYFRAME 8 @@ -49,6 +49,9 @@ protected: CameraType type; private: + // total frames encoded + int cnt = 0; + // publishing std::unique_ptr pm; const char *service_name; diff --git a/selfdrive/loggerd/encoder/ffmpeg_encoder.h b/selfdrive/loggerd/encoder/ffmpeg_encoder.h index 5f90e198fc..ae41abc69f 100644 --- a/selfdrive/loggerd/encoder/ffmpeg_encoder.h +++ b/selfdrive/loggerd/encoder/ffmpeg_encoder.h @@ -13,7 +13,6 @@ extern "C" { #include "selfdrive/loggerd/encoder/encoder.h" #include "selfdrive/loggerd/loggerd.h" -#include "selfdrive/loggerd/encoder/video_writer.h" class FfmpegEncoder : public VideoEncoder { public: diff --git a/selfdrive/loggerd/encoder/v4l_encoder.cc b/selfdrive/loggerd/encoder/v4l_encoder.cc index f5608a067e..26d79cc2a9 100644 --- a/selfdrive/loggerd/encoder/v4l_encoder.cc +++ b/selfdrive/loggerd/encoder/v4l_encoder.cc @@ -115,8 +115,8 @@ void V4LEncoder::dequeue_handler(V4LEncoder *e) { } if (env_debug_encoder) { - printf("%20s got(%d) %6d bytes flags %8x idx %4d id %8d ts %ld lat %.2f ms (%lu frames free)\n", - e->filename, index, bytesused, flags, idx, frame_id, ts, millis_since_boot()-(ts/1000.), e->free_buf_in.size()); + printf("%20s got(%d) %6d bytes flags %8x idx %3d/%4d id %8d ts %ld lat %.2f ms (%lu frames free)\n", + e->filename, index, bytesused, flags, e->segment_num, idx, frame_id, ts, millis_since_boot()-(ts/1000.), e->free_buf_in.size()); } // requeue the buffer diff --git a/selfdrive/loggerd/encoder/v4l_encoder.h b/selfdrive/loggerd/encoder/v4l_encoder.h index 13ebab20da..2f62e334fc 100644 --- a/selfdrive/loggerd/encoder/v4l_encoder.h +++ b/selfdrive/loggerd/encoder/v4l_encoder.h @@ -2,7 +2,6 @@ #include "selfdrive/common/queue.h" #include "selfdrive/loggerd/encoder/encoder.h" -#include "selfdrive/loggerd/encoder/video_writer.h" #define BUF_IN_COUNT 7 #define BUF_OUT_COUNT 6 diff --git a/selfdrive/loggerd/encoderd.cc b/selfdrive/loggerd/encoderd.cc index 18e88ca8bb..297eaf88d0 100644 --- a/selfdrive/loggerd/encoderd.cc +++ b/selfdrive/loggerd/encoderd.cc @@ -50,7 +50,7 @@ void encoder_thread(EncoderdState *s, const LogCameraInfo &cam_info) { // init encoders if (encoders.empty()) { VisionBuf buf_info = vipc_client.buffers[0]; - LOGD("encoder init %dx%d", buf_info.width, buf_info.height); + LOGW("encoder %s init %dx%d", cam_info.filename, buf_info.width, buf_info.height); // main encoder encoders.push_back(new Encoder(cam_info.filename, cam_info.type, buf_info.width, buf_info.height, @@ -86,11 +86,19 @@ void encoder_thread(EncoderdState *s, const LogCameraInfo &cam_info) { } lagging = false; - if (cam_info.trigger_rotate) { - if (!sync_encoders(s, cam_info.type, extra.frame_id)) { - continue; + if (!sync_encoders(s, cam_info.type, extra.frame_id)) { + continue; + } + if (do_exit) break; + + // do rotation if required + const int frames_per_seg = SEGMENT_LENGTH * MAIN_FPS; + if (cur_seg >= 0 && extra.frame_id >= ((cur_seg + 1) * frames_per_seg) + s->start_frame_id) { + for (auto &e : encoders) { + e->encoder_close(); + e->encoder_open(NULL); } - if (do_exit) break; + ++cur_seg; } // encode a frame @@ -102,15 +110,6 @@ void encoder_thread(EncoderdState *s, const LogCameraInfo &cam_info) { LOGE("Failed to encode frame. frame_id: %d", extra.frame_id); } } - - const int frames_per_seg = SEGMENT_LENGTH * MAIN_FPS; - if (cur_seg >= 0 && extra.frame_id >= ((cur_seg + 1) * frames_per_seg) + s->start_frame_id) { - for (auto &e : encoders) { - e->encoder_close(); - e->encoder_open(NULL); - } - ++cur_seg; - } } } @@ -128,7 +127,7 @@ void encoderd_thread() { for (const auto &cam : cameras_logged) { if (cam.enable) { encoder_threads.push_back(std::thread(encoder_thread, &s, cam)); - if (cam.trigger_rotate) s.max_waiting++; + s.max_waiting++; } } for (auto &t : encoder_threads) t.join(); @@ -139,7 +138,7 @@ int main() { int ret; ret = util::set_realtime_priority(52); assert(ret == 0); - ret = util::set_core_affinity({7}); + ret = util::set_core_affinity({3}); assert(ret == 0); } encoderd_thread(); diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 9462abba8f..06fd9c74e5 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -1,163 +1,18 @@ #include "selfdrive/loggerd/loggerd.h" -#include "selfdrive/loggerd/remote_encoder.h" -bool env_remote_encoder = getenv("REMOTE_ENCODER") != NULL; +#include "selfdrive/loggerd/video_writer.h" ExitHandler do_exit; -// Handle initial encoder syncing by waiting for all encoders to reach the same frame id -bool sync_encoders(LoggerdState *s, CameraType cam_type, uint32_t frame_id) { - if (s->camera_synced[cam_type]) return true; - - if (s->max_waiting > 1 && s->encoders_ready != s->max_waiting) { - // add a small margin to the start frame id in case one of the encoders already dropped the next frame - update_max_atomic(s->start_frame_id, frame_id + 2); - if (std::exchange(s->camera_ready[cam_type], true) == false) { - ++s->encoders_ready; - LOGD("camera %d encoder ready", cam_type); - } - return false; - } else { - if (s->max_waiting == 1) update_max_atomic(s->start_frame_id, frame_id); - bool synced = frame_id >= s->start_frame_id; - s->camera_synced[cam_type] = synced; - if (!synced) LOGD("camera %d waiting for frame %d, cur %d", cam_type, (int)s->start_frame_id, frame_id); - return synced; - } -} - -bool trigger_rotate_if_needed(LoggerdState *s, int cur_seg, uint32_t frame_id) { - const int frames_per_seg = SEGMENT_LENGTH * MAIN_FPS; - if (cur_seg >= 0 && frame_id >= ((cur_seg + 1) * frames_per_seg) + s->start_frame_id) { - // trigger rotate and wait until the main logger has rotated to the new segment - ++s->ready_to_rotate; - std::unique_lock lk(s->rotate_lock); - s->rotate_cv.wait(lk, [&] { - return s->rotate_segment > cur_seg || do_exit; - }); - return !do_exit; - } - return false; -} - -void encoder_thread(LoggerdState *s, const LogCameraInfo &cam_info) { - util::set_thread_name(cam_info.filename); - - int cur_seg = -1; - int encode_idx = 0; - LoggerHandle *lh = NULL; - std::vector encoders; - VisionIpcClient vipc_client = VisionIpcClient("camerad", cam_info.stream_type, false); - - // While we write them right to the log for sync, we also publish the encode idx to the socket - const char *service_name = cam_info.type == DriverCam ? "driverEncodeIdx" : (cam_info.type == WideRoadCam ? "wideRoadEncodeIdx" : "roadEncodeIdx"); - PubMaster pm({service_name}); - - while (!do_exit) { - if (!vipc_client.connect(false)) { - util::sleep_for(5); - continue; - } - - // init encoders - if (encoders.empty()) { - VisionBuf buf_info = vipc_client.buffers[0]; - LOGD("encoder init %dx%d", buf_info.width, buf_info.height); - - // main encoder - encoders.push_back(new Encoder(cam_info.filename, cam_info.type, buf_info.width, buf_info.height, - cam_info.fps, cam_info.bitrate, - cam_info.is_h265 ? cereal::EncodeIndex::Type::FULL_H_E_V_C : cereal::EncodeIndex::Type::QCAMERA_H264, - buf_info.width, buf_info.height, cam_info.record)); - // qcamera encoder - if (cam_info.has_qcamera) { - encoders.push_back(new Encoder(qcam_info.filename, cam_info.type, buf_info.width, buf_info.height, - qcam_info.fps, qcam_info.bitrate, - qcam_info.is_h265 ? cereal::EncodeIndex::Type::FULL_H_E_V_C : cereal::EncodeIndex::Type::QCAMERA_H264, - qcam_info.frame_width, qcam_info.frame_height, true)); - } - } - - while (!do_exit) { - VisionIpcBufExtra extra; - VisionBuf* buf = vipc_client.recv(&extra); - if (buf == nullptr) continue; - - if (cam_info.trigger_rotate) { - s->last_camera_seen_tms = millis_since_boot(); - if (!sync_encoders(s, cam_info.type, extra.frame_id)) { - continue; - } - - // check if we're ready to rotate - trigger_rotate_if_needed(s, cur_seg, extra.frame_id); - if (do_exit) break; - } - - // rotate the encoder if the logger is on a newer segment - if (s->rotate_segment > cur_seg) { - cur_seg = s->rotate_segment; - - LOGW("camera %d rotate encoder to %s", cam_info.type, s->segment_path); - for (auto &e : encoders) { - e->encoder_close(); - e->encoder_open(s->segment_path); - } - if (lh) { - lh_close(lh); - } - lh = logger_get_handle(&s->logger); - } - - // encode a frame - for (int i = 0; i < encoders.size(); ++i) { - int out_id = encoders[i]->encode_frame(buf->y, buf->u, buf->v, - buf->width, buf->height, &extra); - - if (out_id == -1) { - LOGE("Failed to encode frame. frame_id: %d encode_id: %d", extra.frame_id, encode_idx); - } - - // publish encode index - if (i == 0 && out_id != -1) { - MessageBuilder msg; - // this is really ugly - bool valid = (buf->get_frame_id() == extra.frame_id); - auto eidx = cam_info.type == DriverCam ? msg.initEvent(valid).initDriverEncodeIdx() : - (cam_info.type == WideRoadCam ? msg.initEvent(valid).initWideRoadEncodeIdx() : msg.initEvent(valid).initRoadEncodeIdx()); - eidx.setFrameId(extra.frame_id); - eidx.setTimestampSof(extra.timestamp_sof); - eidx.setTimestampEof(extra.timestamp_eof); - if (Hardware::TICI()) { - eidx.setType(cereal::EncodeIndex::Type::FULL_H_E_V_C); - } else { - eidx.setType(cam_info.type == DriverCam ? cereal::EncodeIndex::Type::FRONT : cereal::EncodeIndex::Type::FULL_H_E_V_C); - } - eidx.setEncodeId(encode_idx); - eidx.setSegmentNum(cur_seg); - eidx.setSegmentId(out_id); - if (lh) { - auto bytes = msg.toBytes(); - lh_log(lh, bytes.begin(), bytes.size(), true); - } - pm.send(service_name, msg); - } - } - - encode_idx++; - } - - if (lh) { - lh_close(lh); - lh = NULL; - } - } - - LOG("encoder destroy"); - for(auto &e : encoders) { - e->encoder_close(); - delete e; - } -} +struct LoggerdState { + LoggerState logger = {}; + char segment_path[4096]; + std::mutex rotate_lock; + std::atomic rotate_segment; + std::atomic last_camera_seen_tms; + std::atomic ready_to_rotate; // count of encoders ready to rotate + int max_waiting = 0; + double last_rotate_tms = 0.; // last rotate time in ms +}; void logger_rotate(LoggerdState *s) { { @@ -169,7 +24,6 @@ void logger_rotate(LoggerdState *s) { s->ready_to_rotate = 0; s->last_rotate_tms = millis_since_boot(); } - s->rotate_cv.notify_all(); LOGW((s->logger.part == 0) ? "logging to %s" : "rotated to %s", s->segment_path); } @@ -187,6 +41,99 @@ void rotate_if_needed(LoggerdState *s) { } } +struct RemoteEncoder { + std::unique_ptr writer; + int segment = -1; + std::vector q; + int logger_segment = -1; + int dropped_frames = 0; + bool recording = false; +}; + +int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct RemoteEncoder &re) { + const LogCameraInfo &cam_info = (name == "driverEncodeData") ? cameras_logged[1] : + ((name == "wideRoadEncodeData") ? cameras_logged[2] : + ((name == "qRoadEncodeData") ? qcam_info : cameras_logged[0])); + + // rotation happened, process the queue (happens before the current message) + int bytes_count = 0; + if (re.logger_segment != s->rotate_segment) { + re.logger_segment = s->rotate_segment; + for (auto &qmsg: re.q) { + bytes_count += handle_encoder_msg(s, qmsg, name, re); + } + re.q.clear(); + } + + // extract the message + capnp::FlatArrayMessageReader cmsg(kj::ArrayPtr((capnp::word *)msg->getData(), msg->getSize())); + auto event = cmsg.getRoot(); + auto edata = (name == "driverEncodeData") ? event.getDriverEncodeData() : + ((name == "wideRoadEncodeData") ? event.getWideRoadEncodeData() : + ((name == "qRoadEncodeData") ? event.getQRoadEncodeData() : event.getRoadEncodeData())); + auto idx = edata.getIdx(); + auto flags = idx.getFlags(); + + if (!re.recording) { + // only create on iframe + if (flags & V4L2_BUF_FLAG_KEYFRAME) { + if (re.dropped_frames) { + // this should only happen for the first segment, maybe + LOGD("%s: dropped %d non iframe packets before init", name.c_str(), re.dropped_frames); + re.dropped_frames = 0; + } + // if we aren't recording, don't create the writer + if (cam_info.record) { + re.writer.reset(new VideoWriter(s->segment_path, + cam_info.filename, idx.getType() != cereal::EncodeIndex::Type::FULL_H_E_V_C, + cam_info.frame_width, cam_info.frame_height, cam_info.fps, idx.getType())); + // write the header + auto header = edata.getHeader(); + re.writer->write((uint8_t *)header.begin(), header.size(), idx.getTimestampEof()/1000, true, false); + } + re.segment = idx.getSegmentNum(); + re.recording = true; + } else { + ++re.dropped_frames; + return bytes_count; + } + } + + if (re.segment != idx.getSegmentNum()) { + if (re.recording) { + // encoder is on the next segment, this segment is over so we close the videowriter + re.writer.reset(); + re.recording = false; + ++s->ready_to_rotate; + LOGD("rotate %d -> %d ready %d/%d for %s", re.segment, idx.getSegmentNum(), s->ready_to_rotate.load(), s->max_waiting, name.c_str()); + } + // queue up all the new segment messages, they go in after the rotate + re.q.push_back(msg); + } else { + if (re.writer) { + auto data = edata.getData(); + re.writer->write((uint8_t *)data.begin(), data.size(), idx.getTimestampEof()/1000, false, flags & V4L2_BUF_FLAG_KEYFRAME); + } + + // put it in log stream as the idx packet + MessageBuilder bmsg; + auto evt = bmsg.initEvent(event.getValid()); + evt.setLogMonoTime(event.getLogMonoTime()); + if (name == "driverEncodeData") { evt.setDriverEncodeIdx(idx); } + if (name == "wideRoadEncodeData") { evt.setWideRoadEncodeIdx(idx); } + if (name == "qRoadEncodeData") { evt.setQRoadEncodeIdx(idx); } + if (name == "roadEncodeData") { evt.setRoadEncodeIdx(idx); } + auto new_msg = bmsg.toBytes(); + logger_log(&s->logger, (uint8_t *)new_msg.begin(), new_msg.size(), true); // always in qlog? + bytes_count += new_msg.size(); + + // this frees the message + delete msg; + } + + return bytes_count; +} + void loggerd_thread() { // setup messaging typedef struct QlogState { @@ -202,7 +149,7 @@ void loggerd_thread() { // subscribe to all socks for (const auto& it : services) { - const bool encoder = env_remote_encoder && (strcmp(it.name+strlen(it.name)-strlen("EncodeData"), "EncodeData") == 0); + const bool encoder = strcmp(it.name+strlen(it.name)-strlen("EncodeData"), "EncodeData") == 0; if (!it.should_log && !encoder) continue; LOGD("logging %s (on port %d)", it.name, it.port); @@ -225,15 +172,10 @@ void loggerd_thread() { // init encoders s.last_camera_seen_tms = millis_since_boot(); - std::vector encoder_threads; for (const auto &cam : cameras_logged) { if (cam.enable) { - if (env_remote_encoder) { - if (cam.has_qcamera) { s.max_waiting++; } - } else { - encoder_threads.push_back(std::thread(encoder_thread, &s, cam)); - } - if (cam.trigger_rotate) s.max_waiting++; + s.max_waiting++; + if (cam.has_qcamera) { s.max_waiting++; } } } @@ -252,6 +194,7 @@ void loggerd_thread() { const bool in_qlog = qs.freq != -1 && (qs.counter++ % qs.freq == 0); if (qs.encoder) { + s.last_camera_seen_tms = millis_since_boot(); bytes_count += handle_encoder_msg(&s, msg, qs.name, remote_encoders[sock]); } else { logger_log(&s.logger, (uint8_t *)msg->getData(), msg->getSize(), in_qlog); @@ -275,10 +218,6 @@ void loggerd_thread() { } } - LOGW("closing encoders"); - s.rotate_cv.notify_all(); - for (auto &t : encoder_threads) t.join(); - LOGW("closing logger"); logger_close(&s.logger, &do_exit); @@ -291,3 +230,18 @@ void loggerd_thread() { // messaging cleanup for (auto &[sock, qs] : qlog_states) delete sock; } + +int main(int argc, char** argv) { + if (Hardware::TICI()) { + int ret; + ret = util::set_core_affinity({0, 1, 2, 3}); + assert(ret == 0); + // TODO: why does this impact camerad timings? + //ret = util::set_realtime_priority(1); + //assert(ret == 0); + } + + loggerd_thread(); + + return 0; +} \ No newline at end of file diff --git a/selfdrive/loggerd/loggerd.h b/selfdrive/loggerd/loggerd.h index 447c4fb4c9..98e3deee00 100644 --- a/selfdrive/loggerd/loggerd.h +++ b/selfdrive/loggerd/loggerd.h @@ -50,7 +50,6 @@ struct LogCameraInfo { int bitrate; bool is_h265; bool has_qcamera; - bool trigger_rotate; bool enable; bool record; }; @@ -64,7 +63,6 @@ const LogCameraInfo cameras_logged[] = { .bitrate = MAIN_BITRATE, .is_h265 = true, .has_qcamera = true, - .trigger_rotate = true, .enable = true, .record = true, .frame_width = 1928, @@ -78,7 +76,6 @@ const LogCameraInfo cameras_logged[] = { .bitrate = DCAM_BITRATE, .is_h265 = true, .has_qcamera = false, - .trigger_rotate = true, .enable = true, .record = Params().getBool("RecordFront"), .frame_width = 1928, @@ -92,7 +89,6 @@ const LogCameraInfo cameras_logged[] = { .bitrate = MAIN_BITRATE, .is_h265 = true, .has_qcamera = false, - .trigger_rotate = true, .enable = Hardware::TICI(), .record = Hardware::TICI(), .frame_width = 1928, @@ -109,26 +105,3 @@ const LogCameraInfo qcam_info = { .frame_width = Hardware::TICI() ? 526 : 480, .frame_height = Hardware::TICI() ? 330 : 360 // keep pixel count the same? }; - -struct LoggerdState { - LoggerState logger = {}; - char segment_path[4096]; - std::mutex rotate_lock; - std::condition_variable rotate_cv; - std::atomic rotate_segment; - std::atomic last_camera_seen_tms; - std::atomic ready_to_rotate; // count of encoders ready to rotate - int max_waiting = 0; - double last_rotate_tms = 0.; // last rotate time in ms - - // Sync logic for startup - std::atomic encoders_ready = 0; - std::atomic start_frame_id = 0; - bool camera_ready[WideRoadCam + 1] = {}; - bool camera_synced[WideRoadCam + 1] = {}; -}; - -bool sync_encoders(LoggerdState *s, CameraType cam_type, uint32_t frame_id); -bool trigger_rotate_if_needed(LoggerdState *s, int cur_seg, uint32_t frame_id); -void rotate_if_needed(LoggerdState *s); -void loggerd_thread(); diff --git a/selfdrive/loggerd/main.cc b/selfdrive/loggerd/main.cc deleted file mode 100644 index c9bb35bfdb..0000000000 --- a/selfdrive/loggerd/main.cc +++ /dev/null @@ -1,18 +0,0 @@ -#include "selfdrive/loggerd/loggerd.h" - -#include - -int main(int argc, char** argv) { - if (Hardware::TICI()) { - int ret; - ret = util::set_core_affinity({0, 1, 2, 3}); - assert(ret == 0); - // TODO: why does this impact camerad timings? - //ret = util::set_realtime_priority(1); - //assert(ret == 0); - } - - loggerd_thread(); - - return 0; -} diff --git a/selfdrive/loggerd/remote_encoder.cc b/selfdrive/loggerd/remote_encoder.cc deleted file mode 100644 index c640ab5d6c..0000000000 --- a/selfdrive/loggerd/remote_encoder.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include "selfdrive/loggerd/loggerd.h" -#include "selfdrive/loggerd/remote_encoder.h" - -int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct RemoteEncoder &re) { - const LogCameraInfo &cam_info = (name == "driverEncodeData") ? cameras_logged[1] : - ((name == "wideRoadEncodeData") ? cameras_logged[2] : - ((name == "qRoadEncodeData") ? qcam_info : cameras_logged[0])); - if (!cam_info.record) return 0; // TODO: handle this by not subscribing - - // rotation happened, process the queue (happens before the current message) - int bytes_count = 0; - if (re.logger_segment != s->rotate_segment) { - re.logger_segment = s->rotate_segment; - for (auto &qmsg: re.q) { - bytes_count += handle_encoder_msg(s, qmsg, name, re); - } - re.q.clear(); - } - - // extract the message - capnp::FlatArrayMessageReader cmsg(kj::ArrayPtr((capnp::word *)msg->getData(), msg->getSize())); - auto event = cmsg.getRoot(); - auto edata = (name == "driverEncodeData") ? event.getDriverEncodeData() : - ((name == "wideRoadEncodeData") ? event.getWideRoadEncodeData() : - ((name == "qRoadEncodeData") ? event.getQRoadEncodeData() : event.getRoadEncodeData())); - auto idx = edata.getIdx(); - auto flags = idx.getFlags(); - - if (!re.writer) { - // only create on iframe - if (flags & V4L2_BUF_FLAG_KEYFRAME) { - if (re.dropped_frames) { - // this should only happen for the first segment, maybe - LOGD("%s: dropped %d non iframe packets before init", name.c_str(), re.dropped_frames); - re.dropped_frames = 0; - } - re.writer.reset(new VideoWriter(s->segment_path, - cam_info.filename, idx.getType() != cereal::EncodeIndex::Type::FULL_H_E_V_C, - cam_info.frame_width, cam_info.frame_height, cam_info.fps, idx.getType())); - // write the header - auto header = edata.getHeader(); - re.writer->write((uint8_t *)header.begin(), header.size(), idx.getTimestampEof()/1000, true, false); - re.segment = idx.getSegmentNum(); - } else { - ++re.dropped_frames; - return bytes_count; - } - } - - if (re.segment != idx.getSegmentNum()) { - if (re.writer) { - // encoder is on the next segment, this segment is over so we close the videowriter - re.writer.reset(); - ++s->ready_to_rotate; - LOGD("rotate %d -> %d ready %d/%d", re.segment, idx.getSegmentNum(), s->ready_to_rotate.load(), s->max_waiting); - } - // queue up all the new segment messages, they go in after the rotate - re.q.push_back(msg); - } else { - auto data = edata.getData(); - re.writer->write((uint8_t *)data.begin(), data.size(), idx.getTimestampEof()/1000, false, flags & V4L2_BUF_FLAG_KEYFRAME); - - // put it in log stream as the idx packet - MessageBuilder bmsg; - auto evt = bmsg.initEvent(event.getValid()); - evt.setLogMonoTime(event.getLogMonoTime()); - if (name == "driverEncodeData") { evt.setDriverEncodeIdx(idx); } - if (name == "wideRoadEncodeData") { evt.setWideRoadEncodeIdx(idx); } - if (name == "qRoadEncodeData") { evt.setQRoadEncodeIdx(idx); } - if (name == "roadEncodeData") { evt.setRoadEncodeIdx(idx); } - auto new_msg = bmsg.toBytes(); - logger_log(&s->logger, (uint8_t *)new_msg.begin(), new_msg.size(), true); // always in qlog? - bytes_count += new_msg.size(); - - // this frees the message - delete msg; - } - - return bytes_count; -} - - diff --git a/selfdrive/loggerd/remote_encoder.h b/selfdrive/loggerd/remote_encoder.h deleted file mode 100644 index 79e628f514..0000000000 --- a/selfdrive/loggerd/remote_encoder.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "selfdrive/loggerd/encoder/video_writer.h" - -struct RemoteEncoder { - std::unique_ptr writer; - int segment = -1; - std::vector q; - int logger_segment = -1; - int dropped_frames = 0; -}; - -int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct RemoteEncoder &re); \ No newline at end of file diff --git a/selfdrive/loggerd/tests/test_encoder.py b/selfdrive/loggerd/tests/test_encoder.py index 88b06b4b4c..2e69f3b29a 100755 --- a/selfdrive/loggerd/tests/test_encoder.py +++ b/selfdrive/loggerd/tests/test_encoder.py @@ -62,6 +62,7 @@ class TestEncoder(unittest.TestCase): managed_processes['sensord'].start() managed_processes['loggerd'].start() + managed_processes['encoderd'].start() time.sleep(1.0) managed_processes['camerad'].start() @@ -150,6 +151,7 @@ class TestEncoder(unittest.TestCase): time.sleep(0.1) finally: managed_processes['loggerd'].stop() + managed_processes['encoderd'].stop() managed_processes['camerad'].stop() managed_processes['sensord'].stop() diff --git a/selfdrive/loggerd/tests/test_loggerd.cc b/selfdrive/loggerd/tests/test_loggerd.cc deleted file mode 100644 index d84185cbba..0000000000 --- a/selfdrive/loggerd/tests/test_loggerd.cc +++ /dev/null @@ -1,93 +0,0 @@ -#include - -#include "catch2/catch.hpp" -#include "selfdrive/loggerd/loggerd.h" - -int random_int(int min, int max) { - std::random_device dev; - std::mt19937 rng(dev()); - std::uniform_int_distribution dist(min, max); - return dist(rng); -} - -int get_synced_frame_id(LoggerdState *s, CameraType cam_type, int start_frame_id) { - int frame_id = start_frame_id; - while (!sync_encoders(s, cam_type, frame_id)) { - ++frame_id; - usleep(0); - } - return frame_id; -}; - -TEST_CASE("sync_encoders") { - const int max_waiting = GENERATE(1, 2, 3); - - for (int test_cnt = 0; test_cnt < 10; ++test_cnt) { - LoggerdState s{.max_waiting = max_waiting}; - std::vector start_frames; - std::vector> futures; - - for (int i = 0; i < max_waiting; ++i) { - int start_frame_id = random_int(0, 20); - start_frames.push_back(start_frame_id); - futures.emplace_back(std::async(std::launch::async, get_synced_frame_id, &s, (CameraType)i, start_frame_id)); - } - - // get results - int synced_frame_id = 0; - for (int i = 0; i < max_waiting; ++i) { - if (i == 0) { - synced_frame_id = futures[i].get(); - // require synced_frame_id equal start_frame_id if max_waiting == 1 - if (max_waiting == 1) { - REQUIRE(synced_frame_id == start_frames[0]); - } - } else { - REQUIRE(futures[i].get() == synced_frame_id); - } - } - } -} - -const int MAX_SEGMENT_CNT = 100; - -std::pair encoder_thread(LoggerdState *s) { - int cur_seg = 0; - uint32_t frame_id = s->start_frame_id; - - while (cur_seg < MAX_SEGMENT_CNT) { - ++frame_id; - if (trigger_rotate_if_needed(s, cur_seg, frame_id)) { - cur_seg = s->rotate_segment; - } - util::sleep_for(0); - } - - return {cur_seg, frame_id}; -} - -TEST_CASE("trigger_rotate") { - const int encoders = GENERATE(1, 2, 3); - const int start_frame_id = random_int(0, 20); - - LoggerdState s{ - .max_waiting = encoders, - .start_frame_id = start_frame_id, - }; - - std::vector>> futures; - for (int i = 0; i < encoders; ++i) { - futures.emplace_back(std::async(std::launch::async, encoder_thread, &s)); - } - - while (s.rotate_segment < MAX_SEGMENT_CNT) { - rotate_if_needed(&s); - util::sleep_for(10); - } - - for (auto &f : futures) { - auto [encoder_seg, frame_id] = f.get(); - REQUIRE(encoder_seg == MAX_SEGMENT_CNT); - REQUIRE(frame_id == start_frame_id + encoder_seg * (SEGMENT_LENGTH * MAIN_FPS)); - } -} diff --git a/selfdrive/loggerd/tests/test_loggerd.py b/selfdrive/loggerd/tests/test_loggerd.py index f9f938ae7a..1d3fcfce09 100755 --- a/selfdrive/loggerd/tests/test_loggerd.py +++ b/selfdrive/loggerd/tests/test_loggerd.py @@ -126,6 +126,7 @@ class TestLoggerd(unittest.TestCase): length = random.randint(1, 3) os.environ["LOGGERD_SEGMENT_LENGTH"] = str(length) managed_processes["loggerd"].start() + managed_processes["encoderd"].start() fps = 20.0 for n in range(1, int(num_segs*length*fps)+1): @@ -140,6 +141,7 @@ class TestLoggerd(unittest.TestCase): time.sleep(1.0/fps) managed_processes["loggerd"].stop() + managed_processes["encoderd"].stop() route_path = str(self._get_latest_log_dir()).rsplit("--", 1)[0] for n in range(num_segs): diff --git a/selfdrive/loggerd/encoder/video_writer.cc b/selfdrive/loggerd/video_writer.cc similarity index 96% rename from selfdrive/loggerd/encoder/video_writer.cc rename to selfdrive/loggerd/video_writer.cc index 4eb66606c6..24ea98eb30 100644 --- a/selfdrive/loggerd/encoder/video_writer.cc +++ b/selfdrive/loggerd/video_writer.cc @@ -1,7 +1,7 @@ #include #include -#include "selfdrive/loggerd/encoder/video_writer.h" +#include "selfdrive/loggerd/video_writer.h" #include "selfdrive/common/swaglog.h" #include "selfdrive/common/util.h" @@ -88,7 +88,7 @@ void VideoWriter::write(uint8_t *data, int len, long long timestamp, bool codecc // TODO: can use av_write_frame for non raw? int err = av_interleaved_write_frame(ofmt_ctx, &pkt); - if (err < 0) { LOGW("ts encoder write issue"); } + if (err < 0) { LOGW("ts encoder write issue len: %d ts: %lu", len, timestamp); } av_packet_unref(&pkt); } diff --git a/selfdrive/loggerd/encoder/video_writer.h b/selfdrive/loggerd/video_writer.h similarity index 100% rename from selfdrive/loggerd/encoder/video_writer.h rename to selfdrive/loggerd/video_writer.h diff --git a/selfdrive/manager/process_config.py b/selfdrive/manager/process_config.py index 901a928796..ad3cabbbd9 100644 --- a/selfdrive/manager/process_config.py +++ b/selfdrive/manager/process_config.py @@ -24,6 +24,7 @@ procs = [ NativeProcess("clocksd", "selfdrive/clocksd", ["./clocksd"]), NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], enabled=(not PC or WEBCAM), callback=driverview), NativeProcess("logcatd", "selfdrive/logcatd", ["./logcatd"]), + NativeProcess("encoderd", "selfdrive/loggerd", ["./encoderd"]), NativeProcess("loggerd", "selfdrive/loggerd", ["./loggerd"], onroad=False, callback=logging), NativeProcess("modeld", "selfdrive/modeld", ["./modeld"]), NativeProcess("navd", "selfdrive/ui/navd", ["./navd"], offroad=True), diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 8644baac8d..f098d353d2 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -22,7 +22,8 @@ from tools.lib.logreader import LogReader # Baseline CPU usage by process PROCS = { "selfdrive.controls.controlsd": 31.0, - "./loggerd": 50.0, + "./loggerd": 10.0, + "./encoderd": 37.3, "./camerad": 16.5, "./locationd": 9.1, "selfdrive.controls.plannerd": 11.7, From 8572c6aee61f87521f971948d832420085e118e6 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 13 May 2022 19:33:46 -0700 Subject: [PATCH 23/91] Update body test route (#24532) * update body test route * Revert "update body test route" This reverts commit 7b918cb48bdb1b7596d8ba49f5915b69695e4a45. * bump opendbc * Revert "Revert "update body test route"" This reverts commit d27276b8341d8e4a92633a1a8ef88b7737532177. --- opendbc | 2 +- selfdrive/car/tests/routes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opendbc b/opendbc index c53965dfbd..490ddedc59 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit c53965dfbd9ac980e550b5e549896c03f9a56d9c +Subproject commit 490ddedc593ea003dc42c08718d7ea8d5a5778f0 diff --git a/selfdrive/car/tests/routes.py b/selfdrive/car/tests/routes.py index 88309e571d..6f8816a008 100644 --- a/selfdrive/car/tests/routes.py +++ b/selfdrive/car/tests/routes.py @@ -29,7 +29,7 @@ non_tested_cars = [ TestRoute = namedtuple('TestRoute', ['route', 'car_fingerprint', 'segment'], defaults=(None,)) routes = [ - TestRoute("d6ac8ebdb47bc549|2022-03-31--13-10-06", COMMA.BODY), + TestRoute("efdf9af95e71cd84|2022-05-13--19-03-31", COMMA.BODY), TestRoute("0c94aa1e1296d7c6|2021-05-05--19-48-37", CHRYSLER.JEEP_CHEROKEE), TestRoute("91dfedae61d7bd75|2021-05-22--20-07-52", CHRYSLER.JEEP_CHEROKEE_2019), From 531f4483b2c24c054b0d0fa264438a8a864e09fa Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 00:18:30 -0700 Subject: [PATCH 24/91] CI: build master-ci in Actions (#24533) * jenkins: build master-ci on pc * make target configurable * build on actions * no wait * more fetch * v3 has push? * example * remove that * wait * v1.1.1 * this one works * schedule * clear out target first * no lfs --- .github/workflows/release.yaml | 27 +++++++++++++++++++++ Jenkinsfile | 15 +----------- release/build_devel.sh | 44 ++++++++++++++++++---------------- release/build_release.sh | 1 + release/files_common | 5 ++++ release/files_pc | 6 ++--- release/files_tici | 9 ------- release/identity.sh | 1 - 8 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..7101a768c4 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,27 @@ +name: release +on: + schedule: + - cron: '0 * * * *' + workflow_dispatch: + +jobs: + build_masterci: + name: build master-ci + runs-on: ubuntu-20.04 + timeout-minutes: 60 + if: github.repository == 'commaai/openpilot' + steps: + - name: Wait for green check mark + uses: lewagon/wait-on-check-action@v0.2 + with: + ref: master + wait-interval: 30 + running-workflow-name: 'build master-ci' + - uses: actions/checkout@v3 + with: + lfs: true + submodules: true + fetch-depth: 0 + - name: Build master-ci + run: | + BRANCH=test-master-ci release/build_devel.sh diff --git a/Jenkinsfile b/Jenkinsfile index 0c816cbb82..cc7347b12a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -107,7 +107,7 @@ pipeline { } steps { phone_steps("tici", [ - ["build master-ci", "cd $SOURCE_DIR/release && EXTRA_FILES='tools/' ./build_devel.sh"], + ["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR EXTRA_FILES='tools/' ./build_devel.sh"], ["build openpilot", "cd selfdrive/manager && ./build.py"], ["test manager", "python selfdrive/manager/test/test_manager.py"], ["onroad tests", "cd selfdrive/test/ && ./test_onroad.py"], @@ -150,18 +150,6 @@ pipeline { } } - - stage('Push master-ci') { - when { - branch 'master' - } - steps { - phone_steps("tici-build", [ - ["push devel", "cd $SOURCE_DIR/release && PUSH='master-ci' ./build_devel.sh"], - ]) - } - } - } post { @@ -176,4 +164,3 @@ pipeline { } } } - diff --git a/release/build_devel.sh b/release/build_devel.sh index db8c69bd7a..8028b74639 100755 --- a/release/build_devel.sh +++ b/release/build_devel.sh @@ -1,25 +1,30 @@ -#!/usr/bin/bash -e +#!/usr/bin/bash + +set -ex DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" -TARGET_DIR=/data/openpilot -SOURCE_DIR="$(git rev-parse --show-toplevel)" +SOURCE_DIR="$(git -C $DIR rev-parse --show-toplevel)" +if [ -z "$TARGET_DIR" ]; then + TARGET_DIR="$(mktemp -d)" +fi # set git identity source $DIR/identity.sh echo "[-] Setting up repo T=$SECONDS" -if [ ! -d "$TARGET_DIR" ]; then - mkdir -p $TARGET_DIR - cd $TARGET_DIR - git init - git remote add origin git@github.com:commaai/openpilot.git -fi + +cd $SOURCE_DIR +git fetch origin + +rm -rf $TARGET_DIR +mkdir -p $TARGET_DIR +cd $TARGET_DIR +cp -r $SOURCE_DIR/.git $TARGET_DIR +pre-commit uninstall || true echo "[-] bringing master-ci and devel in sync T=$SECONDS" cd $TARGET_DIR -git prune || true -git remote prune origin || true git fetch origin master-ci git fetch origin devel @@ -28,6 +33,7 @@ git reset --hard master-ci git checkout master-ci git reset --hard origin/devel git clean -xdf +git lfs uninstall # remove everything except .git echo "[-] erasing old openpilot T=$SECONDS" @@ -40,8 +46,7 @@ git clean -xdf # do the files copy echo "[-] copying files T=$SECONDS" cd $SOURCE_DIR -cp -pR --parents $(cat release/files_common) $TARGET_DIR/ -cp -pR --parents $(cat release/files_tici) $TARGET_DIR/ +cp -pR --parents $(cat release/files_*) $TARGET_DIR/ if [ ! -z "$EXTRA_FILES" ]; then cp -pR --parents $EXTRA_FILES $TARGET_DIR/ fi @@ -49,8 +54,8 @@ fi # append source commit hash and build date to version GIT_HASH=$(git --git-dir=$SOURCE_DIR/.git rev-parse --short HEAD) DATETIME=$(date '+%Y-%m-%dT%H:%M:%S') -VERSION=$(cat selfdrive/common/version.h | awk -F\" '{print $2}') -echo "#define COMMA_VERSION \"$VERSION-$GIT_HASH-$DATETIME\"" > selfdrive/common/version.h +VERSION=$(cat $SOURCE_DIR/selfdrive/common/version.h | awk -F\" '{print $2}') +#echo "#define COMMA_VERSION \"$VERSION-$GIT_HASH-$DATETIME\"" > $TARGET_DIR/selfdrive/common/version.h # in the directory cd $TARGET_DIR @@ -61,10 +66,9 @@ git add -f . git status git commit -a -m "openpilot v$VERSION release" -if [ ! -z "$PUSH" ]; then - echo "[-] Pushing to $PUSH T=$SECONDS" - git remote set-url origin git@github.com:commaai/openpilot.git - git push -f origin master-ci:$PUSH +if [ ! -z "$BRANCH" ]; then + echo "[-] Pushing to $BRANCH T=$SECONDS" + git push -f origin master-ci:$BRANCH fi -echo "[-] done T=$SECONDS" +echo "[-] done T=$SECONDS, ready at $TARGET_DIR" diff --git a/release/build_release.sh b/release/build_release.sh index 79ab4fb087..48a19037ff 100755 --- a/release/build_release.sh +++ b/release/build_release.sh @@ -19,6 +19,7 @@ fi # set git identity source $DIR/identity.sh +export GIT_SSH_COMMAND="ssh -i /data/gitkey" echo "[-] Setting up repo T=$SECONDS" rm -rf $BUILD_DIR diff --git a/release/files_common b/release/files_common index 3f8c88547e..d3ab5db65d 100644 --- a/release/files_common +++ b/release/files_common @@ -195,8 +195,13 @@ selfdrive/hardware/base.h selfdrive/hardware/base.py selfdrive/hardware/hw.h selfdrive/hardware/tici/__init__.py +selfdrive/hardware/tici/hardware.h selfdrive/hardware/tici/hardware.py +selfdrive/hardware/tici/pins.py +selfdrive/hardware/tici/agnos.py +selfdrive/hardware/tici/agnos.json selfdrive/hardware/tici/amplifier.py +selfdrive/hardware/tici/updater selfdrive/hardware/tici/iwlist.py selfdrive/hardware/pc/__init__.py selfdrive/hardware/pc/hardware.py diff --git a/release/files_pc b/release/files_pc index d00de7e475..610516bff6 100644 --- a/release/files_pc +++ b/release/files_pc @@ -1,5 +1,3 @@ -selfdrive/ui/replay/* +third_party/mapbox-gl-native-qt/x86_64/*.so -third_party/mapbox-gl-native-qt/x86_64/** - -third_party/qt-plugins/x86_64/** +third_party/qt-plugins/x86_64/geoservices/*.so diff --git a/release/files_tici b/release/files_tici index 68e075c971..75abc13abc 100644 --- a/release/files_tici +++ b/release/files_tici @@ -11,15 +11,6 @@ selfdrive/camerad/cameras/camera_qcom2.cc selfdrive/camerad/cameras/camera_qcom2.h selfdrive/camerad/cameras/real_debayer.cl -selfdrive/hardware/tici/__init__.py -selfdrive/hardware/tici/hardware.h -selfdrive/hardware/tici/hardware.py -selfdrive/hardware/tici/pins.py -selfdrive/hardware/tici/agnos.py -selfdrive/hardware/tici/agnos.json -selfdrive/hardware/tici/amplifier.py -selfdrive/hardware/tici/updater - selfdrive/ui/qt/spinner_larch64 selfdrive/ui/qt/text_larch64 selfdrive/ui/qt/maps/*.cc diff --git a/release/identity.sh b/release/identity.sh index b90372d825..c699c94650 100644 --- a/release/identity.sh +++ b/release/identity.sh @@ -2,4 +2,3 @@ export GIT_COMMITTER_NAME="Vehicle Researcher" export GIT_COMMITTER_EMAIL="user@comma.ai" export GIT_AUTHOR_NAME="Vehicle Researcher" export GIT_AUTHOR_EMAIL="user@comma.ai" -export GIT_SSH_COMMAND="ssh -i /data/gitkey" From 08cb0edb533646861b036e83a7d87c03bf677c8e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 00:43:40 -0700 Subject: [PATCH 25/91] push to real master-ci --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7101a768c4..ac9a31e312 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -24,4 +24,4 @@ jobs: fetch-depth: 0 - name: Build master-ci run: | - BRANCH=test-master-ci release/build_devel.sh + BRANCH=master-ci release/build_devel.sh From 5a58ebf183e1066f5d94163a05d9180a66447409 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 01:04:46 -0700 Subject: [PATCH 26/91] loggerd: adjust qcamera threshold, seemed to be tuned for comma two --- selfdrive/loggerd/tests/test_encoder.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/selfdrive/loggerd/tests/test_encoder.py b/selfdrive/loggerd/tests/test_encoder.py index 2e69f3b29a..969ac1c6a2 100755 --- a/selfdrive/loggerd/tests/test_encoder.py +++ b/selfdrive/loggerd/tests/test_encoder.py @@ -24,7 +24,7 @@ CAMERAS = [ ("fcamera.hevc", 20, FULL_SIZE, "roadEncodeIdx"), ("dcamera.hevc", 20, FULL_SIZE, "driverEncodeIdx"), ("ecamera.hevc", 20, FULL_SIZE, "wideRoadEncodeIdx"), - ("qcamera.ts", 20, 77066, None), + ("qcamera.ts", 20, 130000, None), ] # we check frame count, so we don't have to be too strict on size @@ -98,13 +98,12 @@ class TestEncoder(unittest.TestCase): cmd = "LD_LIBRARY_PATH=/usr/local/lib " + cmd expected_frames = fps * SEGMENT_LENGTH - frame_tolerance = 0 probe = subprocess.check_output(cmd, shell=True, encoding='utf8') frame_count = int(probe.split('\n')[0].strip()) counts.append(frame_count) - self.assertTrue(abs(expected_frames - frame_count) <= frame_tolerance, - f"segment #{i}: {camera} failed frame count check: expected {expected_frames}, got {frame_count}") + self.assertEqual(frame_count, expected_frames, + f"segment #{i}: {camera} failed frame count check: expected {expected_frames}, got {frame_count}") # sanity check file size file_size = os.path.getsize(file_path) From d6c6275163fde581b9c32059561d2f720063e808 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 14 May 2022 19:53:08 -0700 Subject: [PATCH 27/91] Fix process replay regen (#24517) * fix regen issues * compress like uploader --- selfdrive/test/process_replay/process_replay.py | 1 + selfdrive/test/process_replay/regen.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 4978525f4f..d7b922863a 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -350,6 +350,7 @@ def setup_env(simulation=False): params.put_bool("Passive", False) params.put_bool("DisengageOnAccelerator", True) params.put_bool("EnableWideCamera", False) + params.put_bool("DisableLogging", False) os.environ["NO_RADAR_SLEEP"] = "1" os.environ["REPLAY"] = "1" diff --git a/selfdrive/test/process_replay/regen.py b/selfdrive/test/process_replay/regen.py index d9e80ca335..9ec03f46bd 100755 --- a/selfdrive/test/process_replay/regen.py +++ b/selfdrive/test/process_replay/regen.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import bz2 import os import time import multiprocessing @@ -8,6 +9,7 @@ import argparse os.environ["USE_WEBCAM"] = "1" import cereal.messaging as messaging +from cereal import car from cereal.services import service_list from cereal.visionipc.visionipc_pyx import VisionIpcServer, VisionStreamType # pylint: disable=no-name-in-module, import-error from common.params import Params @@ -227,7 +229,7 @@ def regen_segment(lr, frs=None, outdir=FAKEDATA): # start procs up ignore = list(fake_daemons.keys()) + ['ui', 'manage_athenad', 'uploader'] - ensure_running(managed_processes.values(), started=True, not_run=ignore) + ensure_running(managed_processes.values(), started=True, params=Params(), CP=car.CarParams(), not_run=ignore) for procs in fake_daemons.values(): for p in procs: p.start() @@ -264,11 +266,18 @@ def regen_and_save(route, sidx, upload=False, use_route_meta=False): lr = LogReader(r.log_paths()[args.seg]) fr = FrameReader(r.camera_paths()[args.seg]) else: - lr = LogReader(f"cd:/{route.replace('|', '/')}/{sidx}/rlog") + lr = LogReader(f"cd:/{route.replace('|', '/')}/{sidx}/rlog.bz2") fr = FrameReader(f"cd:/{route.replace('|', '/')}/{sidx}/fcamera.hevc") rpath = regen_segment(lr, {'roadCameraState': fr}) - lr = LogReader(os.path.join(rpath, 'rlog2')) + # compress raw rlog before uploading + with open(os.path.join(rpath, "rlog"), "rb") as f: + data = bz2.compress(f.read()) + with open(os.path.join(rpath, "rlog.bz2"), "wb") as f: + f.write(data) + os.remove(os.path.join(rpath, "rlog")) + + lr = LogReader(os.path.join(rpath, 'rlog.bz2')) controls_state_active = [m.controlsState.active for m in lr if m.which() == 'controlsState'] assert any(controls_state_active), "Segment did not engage" From ab75c53792718d32e51d34336be3fae568051d2b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 19:55:12 -0700 Subject: [PATCH 28/91] replay: cleanup unused RGB buffers (#24537) * replay: cleanup unused RGB buffers * update replay cam * little more --- selfdrive/camerad/cameras/camera_replay.cc | 5 ++-- selfdrive/test/process_replay/regen.py | 2 -- selfdrive/ui/replay/camera.cc | 21 +++++-------- selfdrive/ui/replay/camera.h | 14 ++++----- selfdrive/ui/replay/framereader.cc | 34 +++++++++------------- selfdrive/ui/replay/framereader.h | 10 +++---- selfdrive/ui/replay/replay.cc | 2 +- selfdrive/ui/replay/tests/test_replay.cc | 3 +- tools/sim/bridge.py | 14 ++------- 9 files changed, 39 insertions(+), 66 deletions(-) diff --git a/selfdrive/camerad/cameras/camera_replay.cc b/selfdrive/camerad/cameras/camera_replay.cc index 05bdfb9236..56bda697c9 100644 --- a/selfdrive/camerad/cameras/camera_replay.cc +++ b/selfdrive/camerad/cameras/camera_replay.cc @@ -47,17 +47,16 @@ void camera_close(CameraState *s) { void run_camera(CameraState *s) { uint32_t stream_frame_id = 0, frame_id = 0; size_t buf_idx = 0; - std::unique_ptr rgb_buf = std::make_unique(s->frame->getRGBSize()); std::unique_ptr yuv_buf = std::make_unique(s->frame->getYUVSize()); while (!do_exit) { if (stream_frame_id == s->frame->getFrameCount()) { // loop stream stream_frame_id = 0; } - if (s->frame->get(stream_frame_id++, rgb_buf.get(), yuv_buf.get())) { + if (s->frame->get(stream_frame_id++, yuv_buf.get())) { s->buf.camera_bufs_metadata[buf_idx] = {.frame_id = frame_id}; auto &buf = s->buf.camera_bufs[buf_idx]; - CL_CHECK(clEnqueueWriteBuffer(buf.copy_q, buf.buf_cl, CL_TRUE, 0, s->frame->getRGBSize(), rgb_buf.get(), 0, NULL, NULL)); + CL_CHECK(clEnqueueWriteBuffer(buf.copy_q, buf.buf_cl, CL_TRUE, 0, s->frame->getYUVSize(), yuv_buf.get(), 0, NULL, NULL)); s->buf.queue(buf_idx); ++frame_id; buf_idx = (buf_idx + 1) % FRAME_BUF_COUNT; diff --git a/selfdrive/test/process_replay/regen.py b/selfdrive/test/process_replay/regen.py index 9ec03f46bd..3ceb989223 100755 --- a/selfdrive/test/process_replay/regen.py +++ b/selfdrive/test/process_replay/regen.py @@ -165,8 +165,6 @@ def replay_cameras(lr, frs): p.append(multiprocessing.Process(target=replay_camera, args=(s, stream, dt, vs, frames, size, use_extra_client))) - # hack to make UI work - vs.create_buffers(VisionStreamType.VISION_STREAM_RGB_ROAD, 4, True, eon_f_frame_size[0], eon_f_frame_size[1]) vs.start_listener() return vs, p diff --git a/selfdrive/ui/replay/camera.cc b/selfdrive/ui/replay/camera.cc index ab4f02e890..2e8b68a415 100644 --- a/selfdrive/ui/replay/camera.cc +++ b/selfdrive/ui/replay/camera.cc @@ -3,7 +3,7 @@ #include -CameraServer::CameraServer(std::pair camera_size[MAX_CAMERAS], bool send_yuv) : send_yuv(send_yuv) { +CameraServer::CameraServer(std::pair camera_size[MAX_CAMERAS]) { for (int i = 0; i < MAX_CAMERAS; ++i) { std::tie(cameras_[i].width, cameras_[i].height) = camera_size[i]; } @@ -25,10 +25,7 @@ void CameraServer::startVipcServer() { for (auto &cam : cameras_) { if (cam.width > 0 && cam.height > 0) { rInfo("camera[%d] frame size %dx%d", cam.type, cam.width, cam.height); - vipc_server_->create_buffers(cam.rgb_type, UI_BUF_COUNT, true, cam.width, cam.height); - if (send_yuv) { - vipc_server_->create_buffers(cam.yuv_type, YUV_BUFFER_COUNT, false, cam.width, cam.height); - } + vipc_server_->create_buffers(cam.stream_type, YUV_BUFFER_COUNT, false, cam.width, cam.height); if (!cam.thread.joinable()) { cam.thread = std::thread(&CameraServer::cameraThread, this, std::ref(cam)); } @@ -39,10 +36,9 @@ void CameraServer::startVipcServer() { void CameraServer::cameraThread(Camera &cam) { auto read_frame = [&](FrameReader *fr, int frame_id) { - VisionBuf *rgb_buf = vipc_server_->get_buffer(cam.rgb_type); - VisionBuf *yuv_buf = send_yuv ? vipc_server_->get_buffer(cam.yuv_type) : nullptr; - bool ret = fr->get(frame_id, (uint8_t *)rgb_buf->addr, yuv_buf ? (uint8_t *)yuv_buf->addr : nullptr); - return ret ? std::pair{rgb_buf, yuv_buf} : std::pair{nullptr, nullptr}; + VisionBuf *yuv_buf = vipc_server_->get_buffer(cam.stream_type); + bool ret = fr->get(frame_id, yuv_buf ? (uint8_t *)yuv_buf->addr : nullptr); + return ret ? yuv_buf : nullptr; }; while (true) { @@ -51,15 +47,14 @@ void CameraServer::cameraThread(Camera &cam) { const int id = eidx.getSegmentId(); bool prefetched = (id == cam.cached_id && eidx.getSegmentNum() == cam.cached_seg); - auto [rgb, yuv] = prefetched ? cam.cached_buf : read_frame(fr, id); - if (rgb || yuv) { + auto yuv = prefetched ? cam.cached_buf : read_frame(fr, id); + if (yuv) { VisionIpcBufExtra extra = { .frame_id = eidx.getFrameId(), .timestamp_sof = eidx.getTimestampSof(), .timestamp_eof = eidx.getTimestampEof(), }; - if (rgb) vipc_server_->send(rgb, &extra, false); - if (yuv) vipc_server_->send(yuv, &extra, false); + vipc_server_->send(yuv, &extra, false); } else { rError("camera[%d] failed to get frame:", cam.type, eidx.getSegmentId()); } diff --git a/selfdrive/ui/replay/camera.h b/selfdrive/ui/replay/camera.h index 753a059ce4..84f0172d5b 100644 --- a/selfdrive/ui/replay/camera.h +++ b/selfdrive/ui/replay/camera.h @@ -8,7 +8,7 @@ class CameraServer { public: - CameraServer(std::pair camera_size[MAX_CAMERAS] = nullptr, bool send_yuv = false); + CameraServer(std::pair camera_size[MAX_CAMERAS] = nullptr); ~CameraServer(); void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx); void waitForSent(); @@ -16,25 +16,23 @@ public: protected: struct Camera { CameraType type; - VisionStreamType rgb_type; - VisionStreamType yuv_type; + VisionStreamType stream_type; int width; int height; std::thread thread; SafeQueue> queue; int cached_id = -1; int cached_seg = -1; - std::pair cached_buf; + VisionBuf * cached_buf; }; void startVipcServer(); void cameraThread(Camera &cam); Camera cameras_[MAX_CAMERAS] = { - {.type = RoadCam, .rgb_type = VISION_STREAM_RGB_ROAD, .yuv_type = VISION_STREAM_ROAD}, - {.type = DriverCam, .rgb_type = VISION_STREAM_RGB_DRIVER, .yuv_type = VISION_STREAM_DRIVER}, - {.type = WideRoadCam, .rgb_type = VISION_STREAM_RGB_WIDE_ROAD, .yuv_type = VISION_STREAM_WIDE_ROAD}, + {.type = RoadCam, .stream_type = VISION_STREAM_ROAD}, + {.type = DriverCam, .stream_type = VISION_STREAM_DRIVER}, + {.type = WideRoadCam, .stream_type = VISION_STREAM_WIDE_ROAD}, }; std::atomic publishing_ = 0; std::unique_ptr vipc_server_; - bool send_yuv; }; diff --git a/selfdrive/ui/replay/framereader.cc b/selfdrive/ui/replay/framereader.cc index 3186b4ff3a..ca839e6819 100644 --- a/selfdrive/ui/replay/framereader.cc +++ b/selfdrive/ui/replay/framereader.cc @@ -170,15 +170,15 @@ bool FrameReader::initHardwareDecoder(AVHWDeviceType hw_device_type) { return true; } -bool FrameReader::get(int idx, uint8_t *rgb, uint8_t *yuv) { - assert(rgb || yuv); +bool FrameReader::get(int idx, uint8_t *yuv) { + assert(yuv != nullptr); if (!valid_ || idx < 0 || idx >= packets.size()) { return false; } - return decode(idx, rgb, yuv); + return decode(idx, yuv); } -bool FrameReader::decode(int idx, uint8_t *rgb, uint8_t *yuv) { +bool FrameReader::decode(int idx, uint8_t *yuv) { int from_idx = idx; if (idx != prev_idx + 1 && key_frames_count_ > 1) { // seeking to the nearest key frame @@ -194,7 +194,7 @@ bool FrameReader::decode(int idx, uint8_t *rgb, uint8_t *yuv) { for (int i = from_idx; i <= idx; ++i) { AVFrame *f = decodeFrame(packets[i]); if (f && i == idx) { - return copyBuffers(f, rgb, yuv); + return copyBuffers(f, yuv); } } return false; @@ -226,29 +226,21 @@ AVFrame *FrameReader::decodeFrame(AVPacket *pkt) { } } -bool FrameReader::copyBuffers(AVFrame *f, uint8_t *rgb, uint8_t *yuv) { +bool FrameReader::copyBuffers(AVFrame *f, uint8_t *yuv) { if (hw_pix_fmt == HW_PIX_FMT) { uint8_t *y = yuv ? yuv : nv12toyuv_buffer.data(); uint8_t *u = y + width * height; uint8_t *v = u + (width / 2) * (height / 2); libyuv::NV12ToI420(f->data[0], f->linesize[0], f->data[1], f->linesize[1], y, width, u, width / 2, v, width / 2, width, height); - libyuv::I420ToRGB24(y, width, u, width / 2, v, width / 2, - rgb, aligned_width * 3, width, height); } else { - if (yuv) { - uint8_t *u = yuv + width * height; - uint8_t *v = u + (width / 2) * (height / 2); - libyuv::I420Copy(f->data[0], f->linesize[0], - f->data[1], f->linesize[1], - f->data[2], f->linesize[2], - yuv, width, u, width / 2, v, width / 2, - width, height); - } - libyuv::I420ToRGB24(f->data[0], f->linesize[0], - f->data[1], f->linesize[1], - f->data[2], f->linesize[2], - rgb, aligned_width * 3, width, height); + uint8_t *u = yuv + width * height; + uint8_t *v = u + (width / 2) * (height / 2); + libyuv::I420Copy(f->data[0], f->linesize[0], + f->data[1], f->linesize[1], + f->data[2], f->linesize[2], + yuv, width, u, width / 2, v, width / 2, + width, height); } return true; } diff --git a/selfdrive/ui/replay/framereader.h b/selfdrive/ui/replay/framereader.h index b58aca5f74..443636e27d 100644 --- a/selfdrive/ui/replay/framereader.h +++ b/selfdrive/ui/replay/framereader.h @@ -19,10 +19,10 @@ class FrameReader { public: FrameReader(); ~FrameReader(); - bool load(const std::string &url, bool no_hw_decoder = false, std::atomic *abort = nullptr, bool local_cache = false, int chunk_size = -1, int retries = 0); + bool load(const std::string &url, bool no_hw_decoder = false, std::atomic *abort = nullptr, bool local_cache = false, + int chunk_size = -1, int retries = 0); bool load(const std::byte *data, size_t size, bool no_hw_decoder = false, std::atomic *abort = nullptr); - bool get(int idx, uint8_t *rgb, uint8_t *yuv); - int getRGBSize() const { return aligned_width * aligned_height * 3; } + bool get(int idx, uint8_t *yuv); int getYUVSize() const { return width * height * 3 / 2; } size_t getFrameCount() const { return packets.size(); } bool valid() const { return valid_; } @@ -32,9 +32,9 @@ public: private: bool initHardwareDecoder(AVHWDeviceType hw_device_type); - bool decode(int idx, uint8_t *rgb, uint8_t *yuv); + bool decode(int idx, uint8_t *yuv); AVFrame * decodeFrame(AVPacket *pkt); - bool copyBuffers(AVFrame *f, uint8_t *rgb, uint8_t *yuv); + bool copyBuffers(AVFrame *f, uint8_t *yuv); std::vector packets; std::unique_ptrav_frame_, hw_frame; diff --git a/selfdrive/ui/replay/replay.cc b/selfdrive/ui/replay/replay.cc index 1b1e91a4a7..1c8de6bf94 100644 --- a/selfdrive/ui/replay/replay.cc +++ b/selfdrive/ui/replay/replay.cc @@ -289,7 +289,7 @@ void Replay::startStream(const Segment *cur_segment) { camera_size[type] = {fr->width, fr->height}; } } - camera_server_ = std::make_unique(camera_size, true); + camera_server_ = std::make_unique(camera_size); } // start stream thread diff --git a/selfdrive/ui/replay/tests/test_replay.cc b/selfdrive/ui/replay/tests/test_replay.cc index 3cafa9b534..e80c526079 100644 --- a/selfdrive/ui/replay/tests/test_replay.cc +++ b/selfdrive/ui/replay/tests/test_replay.cc @@ -102,11 +102,10 @@ void read_segment(int n, const SegmentFile &segment_file, uint32_t flags) { if (cam == RoadCam || cam == WideRoadCam) { REQUIRE(fr->getFrameCount() == 1200); } - std::unique_ptr rgb_buf = std::make_unique(fr->getRGBSize()); std::unique_ptr yuv_buf = std::make_unique(fr->getYUVSize()); // sequence get 100 frames for (int i = 0; i < 100; ++i) { - REQUIRE(fr->get(i, rgb_buf.get(), yuv_buf.get())); + REQUIRE(fr->get(i, yuv_buf.get())); } } diff --git a/tools/sim/bridge.py b/tools/sim/bridge.py index 8729bd04d8..5d40c8ce94 100755 --- a/tools/sim/bridge.py +++ b/tools/sim/bridge.py @@ -70,11 +70,7 @@ class Camerad: self.frame_wide_id = 0 self.vipc_server = VisionIpcServer("camerad") - # TODO: remove RGB buffers once the last RGB vipc subscriber is removed - self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_RGB_ROAD, 4, True, W, H) self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_ROAD, 5, False, W, H) - - self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_RGB_WIDE_ROAD, 4, True, W, H) self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_WIDE_ROAD, 5, False, W, H) self.vipc_server.start_listener() @@ -92,16 +88,14 @@ class Camerad: self.Hdiv4 = H // 4 if (H % 4 == 0) else (H + (4 - H % 4)) // 4 def cam_callback_road(self, image): - self._cam_callback(image, self.frame_road_id, 'roadCameraState', - VisionStreamType.VISION_STREAM_RGB_ROAD, VisionStreamType.VISION_STREAM_ROAD) + self._cam_callback(image, self.frame_road_id, 'roadCameraState', VisionStreamType.VISION_STREAM_ROAD) self.frame_road_id += 1 def cam_callback_wide_road(self, image): - self._cam_callback(image, self.frame_wide_id, 'wideRoadCameraState', - VisionStreamType.VISION_STREAM_RGB_WIDE_ROAD, VisionStreamType.VISION_STREAM_WIDE_ROAD) + self._cam_callback(image, self.frame_wide_id, 'wideRoadCameraState', VisionStreamType.VISION_STREAM_WIDE_ROAD) self.frame_wide_id += 1 - def _cam_callback(self, image, frame_id, pub_type, rgb_type, yuv_type): + def _cam_callback(self, image, frame_id, pub_type, yuv_type): img = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) img = np.reshape(img, (H, W, 4)) img = img[:, :, [0, 1, 2]].copy() @@ -114,8 +108,6 @@ class Camerad: yuv = np.resize(yuv_cl.get(), rgb.size // 2) eof = int(frame_id * 0.05 * 1e9) - # TODO: remove RGB send once the last RGB vipc subscriber is removed - self.vipc_server.send(rgb_type, img.tobytes(), frame_id, eof, eof) self.vipc_server.send(yuv_type, yuv.data.tobytes(), frame_id, eof, eof) dat = messaging.new_message(pub_type) From 222c7cd60d96c5972fa9fd163d54c93116ffdd2c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 22:18:13 -0700 Subject: [PATCH 29/91] remove custom markdown rendering (#24538) * remove custom markdown rendering * remove from release --- common/markdown.py | 48 ----------------------------------- common/tests/test_markdown.py | 26 ------------------- release/files_common | 1 - selfdrive/updated.py | 4 +-- 4 files changed, 2 insertions(+), 77 deletions(-) delete mode 100755 common/markdown.py delete mode 100755 common/tests/test_markdown.py diff --git a/common/markdown.py b/common/markdown.py deleted file mode 100755 index 30c5bc2c09..0000000000 --- a/common/markdown.py +++ /dev/null @@ -1,48 +0,0 @@ -from typing import List - -HTML_REPLACEMENTS = [ - (r'&', r'&'), - (r'"', r'"'), -] - - -def parse_markdown(text: str, tab_length: int = 2) -> str: - lines = text.split("\n") - output: List[str] = [] - list_level = 0 - - def end_outstanding_lists(level: int, end_level: int) -> int: - while level > end_level: - level -= 1 - output.append("") - if level > 0: - output.append("") - return end_level - - for i, line in enumerate(lines): - if i + 1 < len(lines) and lines[i + 1].startswith("==="): # heading - output.append(f"

{line}

") - elif line.startswith("==="): - pass - elif line.lstrip().startswith("* "): # list - line_level = 1 + line.count(" " * tab_length, 0, line.index("*")) - if list_level >= line_level: - list_level = end_outstanding_lists(list_level, line_level) - else: - list_level += 1 - if list_level > 1: - output[-1] = output[-1].replace("", "") - output.append("
    ") - output.append(f"
  • {line.replace('*', '', 1).lstrip()}
  • ") - else: - list_level = end_outstanding_lists(list_level, 0) - if len(line) > 0: - output.append(line) - - end_outstanding_lists(list_level, 0) - output_str = "\n".join(output) + "\n" - - for (fr, to) in HTML_REPLACEMENTS: - output_str = output_str.replace(fr, to) - - return output_str diff --git a/common/tests/test_markdown.py b/common/tests/test_markdown.py deleted file mode 100755 index 9ac67f7e50..0000000000 --- a/common/tests/test_markdown.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -from markdown_it import MarkdownIt -import os -import unittest - -from common.basedir import BASEDIR -from common.markdown import parse_markdown - - -class TestMarkdown(unittest.TestCase): - # validate that our simple markdown parser produces the same output as `markdown_it` from pip - def test_current_release_notes(self): - self.maxDiff = None - - with open(os.path.join(BASEDIR, "RELEASES.md")) as f: - for r in f.read().split("\n\n"): - - # No hyperlink support is ok - if '[' in r: - continue - - self.assertEqual(MarkdownIt().render(r), parse_markdown(r)) - - -if __name__ == "__main__": - unittest.main() diff --git a/release/files_common b/release/files_common index d3ab5db65d..7dfafcb26c 100644 --- a/release/files_common +++ b/release/files_common @@ -26,7 +26,6 @@ common/ffi_wrapper.py common/file_helpers.py common/logging_extra.py common/numpy_fast.py -common/markdown.py common/params.py common/params_pyx.pyx common/xattr.py diff --git a/selfdrive/updated.py b/selfdrive/updated.py index 8c2dfbd1fb..19dba9825e 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -33,9 +33,9 @@ import time import threading from pathlib import Path from typing import List, Tuple, Optional +from markdown_it import MarkdownIt from common.basedir import BASEDIR -from common.markdown import parse_markdown from common.params import Params from selfdrive.hardware import TICI, HARDWARE from selfdrive.swaglog import cloudlog @@ -126,7 +126,7 @@ def set_params(new_version: bool, failed_count: int, exception: Optional[str]) - with open(os.path.join(FINALIZED, "RELEASES.md"), "rb") as f: r = f.read().split(b'\n\n', 1)[0] # Slice latest release notes try: - params.put("ReleaseNotes", parse_markdown(r.decode("utf-8"))) + params.put("ReleaseNotes", MarkdownIt().render(r.decode("utf-8"))) except Exception: params.put("ReleaseNotes", r + b"\n") except Exception: From 38e294f3932e1020832c4369f69a6844dbb3f8b2 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 14 May 2022 22:27:45 -0700 Subject: [PATCH 30/91] remove common/string_helpers.py --- common/string_helpers.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 common/string_helpers.py diff --git a/common/string_helpers.py b/common/string_helpers.py deleted file mode 100644 index 3038605fbb..0000000000 --- a/common/string_helpers.py +++ /dev/null @@ -1,6 +0,0 @@ -def replace_right(s, old, new, occurrence): - # replace_right('1232425', '2', ' ', 1) -> '12324 5' - # replace_right('1232425', '2', ' ', 2) -> '123 4 5' - - split = s.rsplit(old, occurrence) - return new.join(split) From 81dacbedcacaf9db43d19700e04e7361c0fbbbcc Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 15 May 2022 17:13:50 -0700 Subject: [PATCH 31/91] common: replace custom xattr implementation with os module's (#24448) * use os module's xattr function * fix that * handle in helper --- common/tests/test_xattr.py | 47 -------------------- release/files_common | 1 - selfdrive/loggerd/tests/test_deleter.py | 4 +- selfdrive/loggerd/tests/test_uploader.py | 13 +++--- selfdrive/loggerd/tools/mark_all_uploaded.py | 3 +- selfdrive/loggerd/tools/mark_unuploaded.py | 4 +- selfdrive/loggerd/xattr_cache.py | 30 ++++++++----- 7 files changed, 30 insertions(+), 72 deletions(-) delete mode 100644 common/tests/test_xattr.py mode change 100644 => 100755 selfdrive/loggerd/tests/test_deleter.py diff --git a/common/tests/test_xattr.py b/common/tests/test_xattr.py deleted file mode 100644 index 16f6d52977..0000000000 --- a/common/tests/test_xattr.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import tempfile -import shutil -import unittest - -from common.xattr import getxattr, setxattr, listxattr, removexattr - -class TestParams(unittest.TestCase): - USER_TEST='user.test' - def setUp(self): - self.tmpdir = tempfile.mkdtemp() - self.tmpfn = os.path.join(self.tmpdir, 'test.txt') - open(self.tmpfn, 'w').close() - #print("using", self.tmpfn) - - def tearDown(self): - shutil.rmtree(self.tmpdir) - - def test_getxattr_none(self): - a = getxattr(self.tmpfn, TestParams.USER_TEST) - assert a is None - - def test_listxattr_none(self): - l = listxattr(self.tmpfn) - assert l == [] - - def test_setxattr(self): - setxattr(self.tmpfn, TestParams.USER_TEST, b'123') - a = getxattr(self.tmpfn, TestParams.USER_TEST) - assert a == b'123' - - def test_listxattr(self): - setxattr(self.tmpfn, 'user.test1', b'123') - setxattr(self.tmpfn, 'user.test2', b'123') - l = listxattr(self.tmpfn) - assert l == ['user.test1', 'user.test2'] - - def test_removexattr(self): - setxattr(self.tmpfn, TestParams.USER_TEST, b'123') - a = getxattr(self.tmpfn, TestParams.USER_TEST) - assert a == b'123' - removexattr(self.tmpfn, TestParams.USER_TEST) - a = getxattr(self.tmpfn, TestParams.USER_TEST) - assert a is None - -if __name__ == "__main__": - unittest.main() diff --git a/release/files_common b/release/files_common index 7dfafcb26c..6c058e83b5 100644 --- a/release/files_common +++ b/release/files_common @@ -28,7 +28,6 @@ common/logging_extra.py common/numpy_fast.py common/params.py common/params_pyx.pyx -common/xattr.py common/profiler.py common/basedir.py common/dict_helpers.py diff --git a/selfdrive/loggerd/tests/test_deleter.py b/selfdrive/loggerd/tests/test_deleter.py old mode 100644 new mode 100755 index e0a063bd43..80fb5c997f --- a/selfdrive/loggerd/tests/test_deleter.py +++ b/selfdrive/loggerd/tests/test_deleter.py @@ -1,12 +1,12 @@ +#!/usr/bin/env python3 import os import time import threading import unittest from collections import namedtuple -import selfdrive.loggerd.deleter as deleter from common.timeout import Timeout, TimeoutException - +import selfdrive.loggerd.deleter as deleter from selfdrive.loggerd.tests.loggerd_tests_common import UploaderTestCase Stats = namedtuple("Stats", ['f_bavail', 'f_blocks', 'f_frsize']) diff --git a/selfdrive/loggerd/tests/test_uploader.py b/selfdrive/loggerd/tests/test_uploader.py index dd81108700..b8c01776ae 100755 --- a/selfdrive/loggerd/tests/test_uploader.py +++ b/selfdrive/loggerd/tests/test_uploader.py @@ -9,8 +9,6 @@ import json from selfdrive.swaglog import cloudlog import selfdrive.loggerd.uploader as uploader -from common.xattr import getxattr - from selfdrive.loggerd.tests.loggerd_tests_common import UploaderTestCase @@ -84,7 +82,7 @@ class TestUploader(UploaderTestCase): self.assertFalse(len(log_handler.upload_order) < len(exp_order), "Some files failed to upload") self.assertFalse(len(log_handler.upload_order) > len(exp_order), "Some files were uploaded twice") for f_path in exp_order: - self.assertTrue(getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not uploaded") + self.assertTrue(os.getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not uploaded") self.assertTrue(log_handler.upload_order == exp_order, "Files uploaded in wrong order") @@ -103,7 +101,7 @@ class TestUploader(UploaderTestCase): self.assertFalse(len(log_handler.upload_ignored) < len(exp_order), "Some files failed to ignore") self.assertFalse(len(log_handler.upload_ignored) > len(exp_order), "Some files were ignored twice") for f_path in exp_order: - self.assertTrue(getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not ignored") + self.assertTrue(os.getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not ignored") self.assertTrue(log_handler.upload_ignored == exp_order, "Files ignored in wrong order") @@ -128,7 +126,7 @@ class TestUploader(UploaderTestCase): self.assertFalse(len(log_handler.upload_order) < len(exp_order), "Some files failed to upload") self.assertFalse(len(log_handler.upload_order) > len(exp_order), "Some files were uploaded twice") for f_path in exp_order: - self.assertTrue(getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not uploaded") + self.assertTrue(os.getxattr(os.path.join(self.root, f_path.replace('.bz2', '')), uploader.UPLOAD_ATTR_NAME), "All files not uploaded") self.assertTrue(log_handler.upload_order == exp_order, "Files uploaded in wrong order") @@ -143,7 +141,8 @@ class TestUploader(UploaderTestCase): self.join_thread() for f_path in f_paths: - self.assertFalse(getxattr(f_path.replace('.bz2', ''), uploader.UPLOAD_ATTR_NAME), "File upload when locked") + uploaded = uploader.UPLOAD_ATTR_NAME in os.listxattr(f_path.replace('.bz2', '')) + self.assertFalse(uploaded, "File upload when locked") def test_clear_locks_on_startup(self): f_paths = self.gen_files(lock=True, boot=False) @@ -156,4 +155,4 @@ class TestUploader(UploaderTestCase): if __name__ == "__main__": - unittest.main(failfast=True) + unittest.main() diff --git a/selfdrive/loggerd/tools/mark_all_uploaded.py b/selfdrive/loggerd/tools/mark_all_uploaded.py index ff6e3c1f17..e60e6cfa2c 100644 --- a/selfdrive/loggerd/tools/mark_all_uploaded.py +++ b/selfdrive/loggerd/tools/mark_all_uploaded.py @@ -1,9 +1,8 @@ import os -from common.xattr import setxattr from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME, UPLOAD_ATTR_VALUE from selfdrive.loggerd.config import ROOT for folder in os.walk(ROOT): for file1 in folder[2]: full_path = os.path.join(folder[0], file1) - setxattr(full_path, UPLOAD_ATTR_NAME, UPLOAD_ATTR_VALUE) + os.setxattr(full_path, UPLOAD_ATTR_NAME, UPLOAD_ATTR_VALUE) diff --git a/selfdrive/loggerd/tools/mark_unuploaded.py b/selfdrive/loggerd/tools/mark_unuploaded.py index 0d3f765af4..343805d5fc 100755 --- a/selfdrive/loggerd/tools/mark_unuploaded.py +++ b/selfdrive/loggerd/tools/mark_unuploaded.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 +import os import sys -from common.xattr import removexattr from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME for fn in sys.argv[1:]: print(f"unmarking {fn}") - removexattr(fn, UPLOAD_ATTR_NAME) + os.removexattr(fn, UPLOAD_ATTR_NAME) diff --git a/selfdrive/loggerd/xattr_cache.py b/selfdrive/loggerd/xattr_cache.py index d01bf1aa8a..95e39f2032 100644 --- a/selfdrive/loggerd/xattr_cache.py +++ b/selfdrive/loggerd/xattr_cache.py @@ -1,15 +1,23 @@ -from typing import Dict, Tuple +import os +import errno +from typing import Dict, Tuple, Optional -from common.xattr import getxattr as getattr1 -from common.xattr import setxattr as setattr1 +_cached_attributes: Dict[Tuple, Optional[bytes]] = {} -cached_attributes: Dict[Tuple, bytes] = {} -def getxattr(path: str, attr_name: str) -> bytes: - if (path, attr_name) not in cached_attributes: - response = getattr1(path, attr_name) - cached_attributes[(path, attr_name)] = response - return cached_attributes[(path, attr_name)] +def getxattr(path: str, attr_name: str) -> Optional[bytes]: + key = (path, attr_name) + if key not in _cached_attributes: + try: + response = os.getxattr(path, attr_name) + except OSError as e: + # ENODATA means attribute hasn't been set + if e.errno == errno.ENODATA: + response = None + else: + raise + _cached_attributes[key] = response + return _cached_attributes[key] def setxattr(path: str, attr_name: str, attr_value: bytes) -> None: - cached_attributes.pop((path, attr_name), None) - return setattr1(path, attr_name, attr_value) + _cached_attributes.pop((path, attr_name), None) + return os.setxattr(path, attr_name, attr_value) From 319f3d1475f2f212b63f32dbace476f63b3caf14 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 15 May 2022 17:29:09 -0700 Subject: [PATCH 32/91] move models to selfdrive/modeld/ (#24539) * move models to selfdrive/modeld/ * two more refs --- release/build_release.sh | 2 +- release/files_common | 5 ++--- selfdrive/modeld/SConscript | 2 +- {models => selfdrive/modeld/models}/README.md | 0 selfdrive/modeld/models/dmonitoring.cc | 4 ++-- .../modeld/models}/dmonitoring_model.current | 0 {models => selfdrive/modeld/models}/dmonitoring_model.onnx | 0 .../modeld/models}/dmonitoring_model_q.dlc | 0 selfdrive/modeld/models/driving.cc | 6 +++--- {models => selfdrive/modeld/models}/supercombo.dlc | 0 {models => selfdrive/modeld/models}/supercombo.onnx | 0 selfdrive/modeld/thneed/weights_fixup.py | 7 ++++--- tools/sim/Dockerfile.sim | 1 - 13 files changed, 13 insertions(+), 14 deletions(-) rename {models => selfdrive/modeld/models}/README.md (100%) rename {models => selfdrive/modeld/models}/dmonitoring_model.current (100%) rename {models => selfdrive/modeld/models}/dmonitoring_model.onnx (100%) rename {models => selfdrive/modeld/models}/dmonitoring_model_q.dlc (100%) rename {models => selfdrive/modeld/models}/supercombo.dlc (100%) rename {models => selfdrive/modeld/models}/supercombo.onnx (100%) diff --git a/release/build_release.sh b/release/build_release.sh index 48a19037ff..f16bc14170 100755 --- a/release/build_release.sh +++ b/release/build_release.sh @@ -76,7 +76,7 @@ find . -name 'moc_*' -delete find . -name '__pycache__' -delete rm -rf panda/board panda/certs panda/crypto rm -rf .sconsign.dblite Jenkinsfile release/ -rm models/supercombo.dlc +rm selfdrive/modeld/models/supercombo.dlc # Move back signed panda fw mkdir -p panda/board/obj diff --git a/release/files_common b/release/files_common index 6c058e83b5..398ce8f941 100644 --- a/release/files_common +++ b/release/files_common @@ -56,9 +56,6 @@ common/transformations/transformations.pyx common/api/__init__.py -models/supercombo.dlc -models/dmonitoring_model_q.dlc - release/* tools/lib/* @@ -340,6 +337,8 @@ selfdrive/modeld/models/driving.cc selfdrive/modeld/models/driving.h selfdrive/modeld/models/dmonitoring.cc selfdrive/modeld/models/dmonitoring.h +selfdrive/modeld/models/supercombo.dlc +selfdrive/modeld/models/dmonitoring_model_q.dlc selfdrive/modeld/transforms/loadyuv.cc selfdrive/modeld/transforms/loadyuv.h diff --git a/selfdrive/modeld/SConscript b/selfdrive/modeld/SConscript index c6855e8c38..859488356e 100644 --- a/selfdrive/modeld/SConscript +++ b/selfdrive/modeld/SConscript @@ -63,7 +63,7 @@ common_model = lenv.Object(common_src) # build thneed model if use_thneed and arch == "larch64": - fn = File("#models/supercombo").abspath + fn = File("models/supercombo").abspath compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs) cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} {fn}.dlc {fn}_badweights.thneed --binary" diff --git a/models/README.md b/selfdrive/modeld/models/README.md similarity index 100% rename from models/README.md rename to selfdrive/modeld/models/README.md diff --git a/selfdrive/modeld/models/dmonitoring.cc b/selfdrive/modeld/models/dmonitoring.cc index 40f4220c0f..63c06b1550 100644 --- a/selfdrive/modeld/models/dmonitoring.cc +++ b/selfdrive/modeld/models/dmonitoring.cc @@ -39,9 +39,9 @@ void dmonitoring_init(DMonitoringModelState* s) { init_yuv_buf(s->resized_buf, MODEL_WIDTH, MODEL_HEIGHT); #ifdef USE_ONNX_MODEL - s->m = new ONNXModel("../../models/dmonitoring_model.onnx", &s->output[0], OUTPUT_SIZE, USE_DSP_RUNTIME); + s->m = new ONNXModel("models/dmonitoring_model.onnx", &s->output[0], OUTPUT_SIZE, USE_DSP_RUNTIME); #else - s->m = new SNPEModel("../../models/dmonitoring_model_q.dlc", &s->output[0], OUTPUT_SIZE, USE_DSP_RUNTIME); + s->m = new SNPEModel("models/dmonitoring_model_q.dlc", &s->output[0], OUTPUT_SIZE, USE_DSP_RUNTIME); #endif s->m->addCalib(s->calib, CALIB_LEN); diff --git a/models/dmonitoring_model.current b/selfdrive/modeld/models/dmonitoring_model.current similarity index 100% rename from models/dmonitoring_model.current rename to selfdrive/modeld/models/dmonitoring_model.current diff --git a/models/dmonitoring_model.onnx b/selfdrive/modeld/models/dmonitoring_model.onnx similarity index 100% rename from models/dmonitoring_model.onnx rename to selfdrive/modeld/models/dmonitoring_model.onnx diff --git a/models/dmonitoring_model_q.dlc b/selfdrive/modeld/models/dmonitoring_model_q.dlc similarity index 100% rename from models/dmonitoring_model_q.dlc rename to selfdrive/modeld/models/dmonitoring_model_q.dlc diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index e14411df78..e0421e8cca 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -32,11 +32,11 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context) { s->wide_frame = new ModelFrame(device_id, context); #ifdef USE_THNEED - s->m = std::make_unique("../../models/supercombo.thneed", + s->m = std::make_unique("models/supercombo.thneed", #elif USE_ONNX_MODEL - s->m = std::make_unique("../../models/supercombo.onnx", + s->m = std::make_unique("models/supercombo.onnx", #else - s->m = std::make_unique("../../models/supercombo.dlc", + s->m = std::make_unique("models/supercombo.dlc", #endif &s->output[0], NET_OUTPUT_SIZE, USE_GPU_RUNTIME, true); diff --git a/models/supercombo.dlc b/selfdrive/modeld/models/supercombo.dlc similarity index 100% rename from models/supercombo.dlc rename to selfdrive/modeld/models/supercombo.dlc diff --git a/models/supercombo.onnx b/selfdrive/modeld/models/supercombo.onnx similarity index 100% rename from models/supercombo.onnx rename to selfdrive/modeld/models/supercombo.onnx diff --git a/selfdrive/modeld/thneed/weights_fixup.py b/selfdrive/modeld/thneed/weights_fixup.py index 47875a9ee0..539b1b5d32 100755 --- a/selfdrive/modeld/thneed/weights_fixup.py +++ b/selfdrive/modeld/thneed/weights_fixup.py @@ -140,6 +140,7 @@ def weights_fixup(target, source_thneed, dlc): save_thneed(jdat, target) if __name__ == "__main__": - weights_fixup(os.path.join(BASEDIR, "models/supercombo_fixed.thneed"), - os.path.join(BASEDIR, "models/supercombo.thneed"), - os.path.join(BASEDIR, "models/supercombo.dlc")) + model_dir = os.path.join(BASEDIR, "selfdrive/modeld/models/") + weights_fixup(os.path.join(model_dir, "supercombo_fixed.thneed"), + os.path.join(model_dir, "supercombo.thneed"), + os.path.join(model_dir, "supercombo.dlc")) diff --git a/tools/sim/Dockerfile.sim b/tools/sim/Dockerfile.sim index 921e546d0c..27cf25550f 100644 --- a/tools/sim/Dockerfile.sim +++ b/tools/sim/Dockerfile.sim @@ -50,7 +50,6 @@ COPY ./pyextra $HOME/openpilot/pyextra COPY ./site_scons $HOME/openpilot/site_scons COPY ./rednose $HOME/openpilot/rednose COPY ./common $HOME/openpilot/common -COPY ./models $HOME/openpilot/models COPY ./opendbc $HOME/openpilot/opendbc COPY ./cereal $HOME/openpilot/cereal COPY ./panda $HOME/openpilot/panda From 6a48a7acef483907990e34e040deee70c689e700 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 15 May 2022 17:55:22 -0700 Subject: [PATCH 33/91] more comma two cleanup (#24300) * more comma two cleanup * fix up power monitoring --- release/files_common | 1 - selfdrive/camerad/cameras/sensor_i2c.h | 651 ------------------ selfdrive/hardware/base.py | 24 - selfdrive/hardware/pc/hardware.py | 18 - selfdrive/hardware/tici/hardware.py | 19 - selfdrive/thermald/power_monitoring.py | 51 +- .../thermald/tests/test_power_monitoring.py | 11 +- selfdrive/thermald/thermald.py | 2 - 8 files changed, 3 insertions(+), 774 deletions(-) delete mode 100644 selfdrive/camerad/cameras/sensor_i2c.h diff --git a/release/files_common b/release/files_common index 398ce8f941..828479f0ef 100644 --- a/release/files_common +++ b/release/files_common @@ -302,7 +302,6 @@ selfdrive/camerad/cameras/camera_common.h selfdrive/camerad/cameras/camera_common.cc selfdrive/camerad/cameras/camera_replay.cc selfdrive/camerad/cameras/camera_replay.h -selfdrive/camerad/cameras/sensor_i2c.h selfdrive/camerad/cameras/sensor2_i2c.h selfdrive/camerad/transforms/rgb_to_yuv.cc diff --git a/selfdrive/camerad/cameras/sensor_i2c.h b/selfdrive/camerad/cameras/sensor_i2c.h deleted file mode 100644 index b46ebb370a..0000000000 --- a/selfdrive/camerad/cameras/sensor_i2c.h +++ /dev/null @@ -1,651 +0,0 @@ -static struct msm_camera_i2c_reg_array init_array_imx298[] = { - {0x101,0x0,0}, // IMAGE_ORIENT - {0x601,0x0,0}, // test pattern - //{0xb02,0,0}, // green correction? - // external clock setting - {0x136,0x18,0}, {0x137,0x0,0}, // EXCK_FREQ = Extclk_frequency_mhz - // global setting? - {0x30f4,0x1,0}, - {0x30f5,0x7a,0}, - {0x30f6,0x0,0}, - {0x30f7,0xec,0}, - {0x30fc,0x1,0}, - {0x3101,0x1,0}, - {0x5b2f,0x8,0}, - {0x5d32,0x5,0}, - {0x5d7c,0x0,0}, - {0x5d7d,0x0,0}, - {0x5db9,0x1,0}, - {0x5e43,0x0,0}, - {0x6300,0x0,0}, - {0x6301,0xea,0}, - {0x6302,0x0,0}, - {0x6303,0xb4,0}, - {0x6564,0x0,0}, - {0x6565,0xb6,0}, - {0x6566,0x0,0}, - {0x6567,0xe6,0}, - {0x6714,0x1,0}, - {0x6758,0xb,0}, - {0x6910,0x4,0}, - {0x6916,0x1,0}, - {0x6918,0x4,0}, - {0x691e,0x1,0}, - {0x6931,0x1,0}, - {0x6937,0x2,0}, - {0x693b,0x2,0}, - {0x6d00,0x4a,0}, - {0x6d01,0x41,0}, - {0x6d02,0x23,0}, - {0x6d05,0x4c,0}, - {0x6d06,0x10,0}, - {0x6d08,0x30,0}, - {0x6d09,0x38,0}, - {0x6d0a,0x2c,0}, - {0x6d0b,0x2d,0}, - {0x6d0c,0x34,0}, - {0x6d0d,0x42,0}, - {0x6d19,0x1c,0}, - {0x6d1a,0x71,0}, - {0x6d1b,0xc6,0}, - {0x6d1c,0x94,0}, - {0x6d24,0xe4,0}, - {0x6d30,0xa,0}, - {0x6d31,0x1,0}, - {0x6d33,0xb,0}, - {0x6d34,0x5,0}, - {0x6d35,0x0,0}, - {0x83c2,0x3,0}, - {0x83c3,0x8,0}, - {0x83c4,0x48,0}, - {0x83c7,0x8,0}, - {0x83cb,0x0,0}, - {0xb101,0xff,0}, - {0xb103,0xff,0}, - {0xb105,0xff,0}, - {0xb107,0xff,0}, - {0xb109,0xff,0}, - {0xb10b,0xff,0}, - {0xb10d,0xff,0}, - {0xb10f,0xff,0}, - {0xb111,0xff,0}, - {0xb163,0x3c,0}, - {0xc2a0,0x8,0}, - {0xc2a3,0x3,0}, - {0xc2a5,0x8,0}, - {0xc2a6,0x48,0}, - {0xc2a9,0x0,0}, - {0xf800,0x5e,0}, - {0xf801,0x5e,0}, - {0xf802,0xcd,0}, - {0xf803,0x20,0}, - {0xf804,0x55,0}, - {0xf805,0xd4,0}, - {0xf806,0x1f,0}, - {0xf808,0xf8,0}, - {0xf809,0x3a,0}, - {0xf80a,0xf1,0}, - {0xf80b,0x7e,0}, - {0xf80c,0x55,0}, - {0xf80d,0x38,0}, - {0xf80e,0xe3,0}, - {0xf810,0x74,0}, - {0xf811,0x41,0}, - {0xf812,0xbf,0}, - {0xf844,0x40,0}, - {0xf845,0xba,0}, - {0xf846,0x70,0}, - {0xf847,0x47,0}, - {0xf848,0xc0,0}, - {0xf849,0xba,0}, - {0xf84a,0x70,0}, - {0xf84b,0x47,0}, - {0xf84c,0x82,0}, - {0xf84d,0xf6,0}, - {0xf84e,0x32,0}, - {0xf84f,0xfd,0}, - {0xf851,0xf0,0}, - {0xf852,0x2,0}, - {0xf853,0xf8,0}, - {0xf854,0x81,0}, - {0xf855,0xf6,0}, - {0xf856,0xc0,0}, - {0xf857,0xff,0}, - {0xf858,0x10,0}, - {0xf859,0xb5,0}, - {0xf85a,0xd,0}, - {0xf85b,0x48,0}, - {0xf85c,0x40,0}, - {0xf85d,0x7a,0}, - {0xf85e,0x1,0}, - {0xf85f,0x28,0}, - {0xf860,0x15,0}, - {0xf861,0xd1,0}, - {0xf862,0xc,0}, - {0xf863,0x49,0}, - {0xf864,0xc,0}, - {0xf865,0x46,0}, - {0xf866,0x40,0}, - {0xf867,0x3c,0}, - {0xf868,0x48,0}, - {0xf869,0x8a,0}, - {0xf86a,0x62,0}, - {0xf86b,0x8a,0}, - {0xf86c,0x80,0}, - {0xf86d,0x1a,0}, - {0xf86e,0x8a,0}, - {0xf86f,0x89,0}, - {0xf871,0xb2,0}, - {0xf872,0x10,0}, - {0xf873,0x18,0}, - {0xf874,0xa,0}, - {0xf875,0x46,0}, - {0xf876,0x20,0}, - {0xf877,0x32,0}, - {0xf878,0x12,0}, - {0xf879,0x88,0}, - {0xf87a,0x90,0}, - {0xf87b,0x42,0}, - {0xf87d,0xda,0}, - {0xf87e,0x10,0}, - {0xf87f,0x46,0}, - {0xf880,0x80,0}, - {0xf881,0xb2,0}, - {0xf882,0x88,0}, - {0xf883,0x81,0}, - {0xf884,0x84,0}, - {0xf885,0xf6,0}, - {0xf886,0xd2,0}, - {0xf887,0xf9,0}, - {0xf888,0xe0,0}, - {0xf889,0x67,0}, - {0xf88a,0x85,0}, - {0xf88b,0xf6,0}, - {0xf88c,0xa1,0}, - {0xf88d,0xfc,0}, - {0xf88e,0x10,0}, - {0xf88f,0xbd,0}, - {0xf891,0x18,0}, - {0xf892,0x21,0}, - {0xf893,0x24,0}, - {0xf895,0x18,0}, - {0xf896,0x19,0}, - {0xf897,0xb4,0}, - {0x4e29,0x1,0}, - // PDAF stuff - {0x3166,0x1,0}, //AREA_EN_0 - {0x3167,0x1,0}, - {0x3168,0x1,0}, - {0x3169,0x1,0}, - {0x316a,0x1,0}, - {0x316b,0x1,0}, - {0x316c,0x1,0}, - {0x316d,0x1,0}, - {0x3158,0x2,0}, - {0x3159,0x2,0}, - {0x315a,0x2,0}, - {0x315b,0x3,0}, - {0x3013,0x7,0}, //RMSC_NR_MODE - {0x3035,0x1,0}, - {0x3051,0x0,0}, - {0x3056,0x2,0}, - {0x3057,0x1,0}, - {0x3060,0x0,0}, - {0x8435,0x0,0}, - {0x8455,0x0,0}, - {0x847c,0x0,0}, - {0x84fb,0x1,0}, - {0x9619,0xa0,0}, - {0x961b,0xa0,0}, - {0x961d,0xa0,0}, - {0x961f,0x20,0}, - {0x9621,0x20,0}, - {0x9623,0x20,0}, - {0x9625,0xa0,0}, - {0x9627,0xa0,0}, - {0x9629,0xa0,0}, - {0x962b,0x20,0}, - {0x962d,0x20,0}, - {0x962f,0x20,0}, - {0x9901,0x35,0}, - {0x9903,0x23,0}, - {0x9905,0x23,0}, - {0x9906,0x0,0}, - {0x9907,0x31,0}, - {0x9908,0x0,0}, - {0x9909,0x1b,0}, - {0x990a,0x0,0}, - {0x990b,0x15,0}, - {0x990d,0x3f,0}, - {0x990f,0x3f,0}, - {0x9911,0x3f,0}, - {0x9913,0x64,0}, - {0x9915,0x64,0}, - {0x9917,0x64,0}, - {0x9919,0x50,0}, - {0x991b,0x60,0}, - {0x991d,0x65,0}, - {0x991f,0x1,0}, - {0x9921,0x1,0}, - {0x9923,0x1,0}, - {0x9925,0x23,0}, - {0x9927,0x23,0}, - {0x9929,0x23,0}, - {0x992b,0x2f,0}, - {0x992d,0x1a,0}, - {0x992f,0x14,0}, - {0x9931,0x3f,0}, - {0x9933,0x3f,0}, - {0x9935,0x3f,0}, - {0x9937,0x6b,0}, - {0x9939,0x7c,0}, - {0x993b,0x81,0}, - {0x9943,0xf,0}, - {0x9945,0xf,0}, - {0x9947,0xf,0}, - {0x9949,0xf,0}, - {0x994b,0xf,0}, - {0x994d,0xf,0}, - {0x994f,0x42,0}, - {0x9951,0xf,0}, - {0x9953,0xb,0}, - {0x9955,0x5a,0}, - {0x9957,0x13,0}, - {0x9959,0xc,0}, - {0x995a,0x0,0}, - {0x995b,0x0,0}, - {0x995c,0x0,0}, - {0x996b,0x0,0}, - {0x996d,0x10,0}, - {0x996f,0x10,0}, - {0x9971,0xc8,0}, - {0x9973,0x32,0}, - {0x9975,0x4,0}, - {0x9976,0xa,0}, - {0x9977,0xa,0}, - {0x9978,0xa,0}, - {0x99a4,0x2f,0}, - {0x99a5,0x2f,0}, - {0x99a6,0x2f,0}, - {0x99a7,0xa,0}, - {0x99a8,0xa,0}, - {0x99a9,0xa,0}, - {0x99aa,0x2f,0}, - {0x99ab,0x2f,0}, - {0x99ac,0x2f,0}, - {0x99ad,0x0,0}, - {0x99ae,0x0,0}, - {0x99af,0x0,0}, - {0x99b0,0x40,0}, - {0x99b1,0x40,0}, - {0x99b2,0x40,0}, - {0x99b3,0x30,0}, - {0x99b4,0x30,0}, - {0x99b5,0x30,0}, - {0x99bb,0xa,0}, - {0x99bd,0xa,0}, - {0x99bf,0xa,0}, - {0x99c0,0x9,0}, - {0x99c1,0x9,0}, - {0x99c2,0x9,0}, - {0x99c6,0x3c,0}, - {0x99c7,0x3c,0}, - {0x99c8,0x3c,0}, - {0x99c9,0xff,0}, - {0x99ca,0xff,0}, - {0x99cb,0xff,0}, - {0x9b01,0x35,0}, - {0x9b03,0x14,0}, - {0x9b05,0x14,0}, - {0x9b07,0x31,0}, - {0x9b09,0x1b,0}, - {0x9b0b,0x15,0}, - {0x9b0d,0x1e,0}, - {0x9b0f,0x1e,0}, - {0x9b11,0x1e,0}, - {0x9b13,0x64,0}, - {0x9b15,0x64,0}, - {0x9b17,0x64,0}, - {0x9b19,0x50,0}, - {0x9b1b,0x60,0}, - {0x9b1d,0x65,0}, - {0x9b1f,0x1,0}, - {0x9b21,0x1,0}, - {0x9b23,0x1,0}, - {0x9b25,0x14,0}, - {0x9b27,0x14,0}, - {0x9b29,0x14,0}, - {0x9b2b,0x2f,0}, - {0x9b2d,0x1a,0}, - {0x9b2f,0x14,0}, - {0x9b31,0x1e,0}, - {0x9b33,0x1e,0}, - {0x9b35,0x1e,0}, - {0x9b37,0x6b,0}, - {0x9b39,0x7c,0}, - {0x9b3b,0x81,0}, - {0x9b43,0xf,0}, - {0x9b45,0xf,0}, - {0x9b47,0xf,0}, - {0x9b49,0xf,0}, - {0x9b4b,0xf,0}, - {0x9b4d,0xf,0}, - {0x9b4f,0x2d,0}, - {0x9b51,0xb,0}, - {0x9b53,0x8,0}, - {0x9b55,0x40,0}, - {0x9b57,0xd,0}, - {0x9b59,0x8,0}, - {0x9b5a,0x0,0}, - {0x9b5b,0x0,0}, - {0x9b5c,0x0,0}, - {0x9b6b,0x0,0}, - {0x9b6d,0x10,0}, - {0x9b6f,0x10,0}, - {0x9b71,0xc8,0}, - {0x9b73,0x32,0}, - {0x9b75,0x4,0}, - {0x9bb0,0x40,0}, - {0x9bb1,0x40,0}, - {0x9bb2,0x40,0}, - {0x9bb3,0x30,0}, - {0x9bb4,0x30,0}, - {0x9bb5,0x30,0}, - {0x9bbb,0xa,0}, - {0x9bbd,0xa,0}, - {0x9bbf,0xa,0}, - {0x9bc0,0x9,0}, - {0x9bc1,0x9,0}, - {0x9bc2,0x9,0}, - {0x9bc6,0x18,0}, - {0x9bc7,0x18,0}, - {0x9bc8,0x18,0}, - {0x9bc9,0xff,0}, - {0x9bca,0xff,0}, - {0x9bcb,0xff,0}, - {0xb2b2,0x1,0}, -}; - -static struct msm_camera_i2c_reg_array mode_setting_array_imx298[] = { -// i2c settings for mode 3 -// { -// .x_output = 2328, -// .y_output = 1748, -// .line_length_pclk = 5536, -// .frame_length_lines = 1802, -// .vt_pixel_clk = 299300000, -// .op_pixel_clk = 299300000, -// .binning_factor = 2, -// .min_fps = 15.000000, -// .max_fps = 30.020000, -// .mode = 1, -// .offset_x = 0, -// .offset_y = 0, -// .scale_factor = 1.000000, -// .is_pdaf_supported = 1, -// } - -// mode settings - -// hdr settings -{0x0114, 0x03, 0}, // CSI_LANE_MODE = 4-lane -/*{0x0220, 0x00, 0}, // HDR_MODE = disable -{0x0221, 0x11, 0}, // HDR_RESO_REDU_H/V = Full Pixel -{0x0222, 0x10, 0}, // EXPO_RATIO = 16*/ -{0x0220, 0x01, 0}, // HDR_MODE = enable with combined gain and 16x ratio -{0x0221, 0x22, 0}, // HDR_RESO_REDU_H/V = 2 binning -{0x0222, 0x10, 0}, // EXPO_RATIO = 16 - -{0x0340, 0x07, 0}, {0x0341, 0x0a, 0}, // FRM_LENGTH = frame_length_lines = 1802 -{0x0342, 0x15, 0}, {0x0343, 0xa0, 0}, // LINE_LENGTH = line_length_pclk = 5536 -{0x0344, 0x00, 0}, {0x0345, 0x00, 0}, // x_addr_start -{0x0346, 0x00, 0}, {0x0347, 0x00, 0}, // y_addr_start -{0x0348, 0x12, 0}, {0x0349, 0x2f, 0}, // x_addr_end -{0x034a, 0x0d, 0}, {0x034b, 0xa7, 0}, // y_addr_end -{0x0381, 0x01, 0}, // x_even_inc -{0x0383, 0x01, 0}, // x_odd_inc -{0x0385, 0x01, 0}, // y_even_inc -{0x0387, 0x01, 0}, // y_odd_inc -{0x0900, 0x01, 0}, // BINNING_MODE = enable -{0x0901, 0x22, 0}, // BINING_TYPE_H/V = 2binning -{0x0902, 0x00, 0}, // binning_weighting = average - -{0x0b06, 1, 0}, // SING_DEF_CORR_EN -{0x0b0a, 1, 0}, // combined defect correct - -{0x3010, 0x66, 0}, // HDR_OUTPUT_CTRL = ATR + HDR compose + DPC1D + DCP2D -{0x3011, 0x01, 0}, // HDR_OUTPUT_CTRL2 = PD enable -{0x30c0, 0x11, 0}, // RED_GAIN_CB? -{0x300d, 0x00, 0}, // FORCE_FDSUM = disable -{0x30fd, 0x00, 0}, -{0x8493, 0x00, 0}, -{0x8863, 0x00, 0}, -{0x90d7, 0x19, 0}, - -// set black level -{0x3090, 1, 0}, -{0x3092, 0, 0}, -{0x3093, 0x38, 0}, - -// output size settings -{0x0112, 0x0a, 0}, {0x0113, 0x0a, 0}, // CS_DT_FMT_H = 0x0a0a (RAW10 output) -{0x034c, 0x09, 0}, {0x034d, 0x18, 0}, // X_OUT_SIZE = 2328 (1164*2) -{0x034e, 0x06, 0}, {0x034f, 0xd4, 0}, // Y_OUT_SIZE = 1748 (874*2) -{0x0401, 0x00, 0}, // SCALING_MODE -{0x0404, 0x00, 0}, {0x0405, 0x10, 0}, // SCALE_M -{0x0408, 0x00, 0}, {0x0409, 0x00, 0}, // DCROP_XOFS -{0x040a, 0x00, 0}, {0x040b, 0x00, 0}, // DCROP_YOFS -{0x040c, 0x09, 0}, {0x040d, 0x18, 0}, // DCROP_WIDTH -{0x040e, 0x06, 0}, {0x040f, 0xd4, 0}, // DCROP_HIGT - -// clock settings -// 299300000 -/* -{0x0301, 0x05, 0}, // VT_PIX_CLK_DIV -{0x0303, 0x02, 0}, // VT_SYS_CLK_DIV -{0x0305, 0x04, 0}, // PRE_PLL_CLK_DIV -{0x0306, 0x00, 0}, {0x0307, 0x7d, 0}, // PLL_MULTIPLIER . mode 1: 0xf6 -{0x0309, 0x0a, 0}, // OP_PIX_CLK_DIV -{0x030b, 0x01, 0}, // OP_SYS_CLK_DIV -{0x030d, 0x0f, 0}, // PREPLLCK_OP_DIV -{0x030e, 0x03, 0}, {0x030f, 0x41, 0}, // PLL_OP_MPY -{0x0310, 0x00, 0}, // PLL_MULT_DRIV -*/ -// 600000000 -{0x0301, 0x05, 0}, -{0x0303, 0x02, 0}, -{0x0305, 0x04, 0}, -{0x0306, 0x00, 0}, -{0x0307, 0xfa, 0}, -{0x0309, 0x0a, 0}, -{0x030b, 0x01, 0}, -{0x030d, 0x0f, 0}, -{0x030e, 0x03, 0}, {0x030f, 0x41, 0}, -{0x0310, 0x00, 0}, - -// data rate settings -/*{0x0820, 0x0b, 0}, // requested_link_bit_rate_mbps = 3000 -{0x0821, 0xb8, 0}, -{0x0822, 0x00, 0}, -{0x0823, 0x00, 0},*/ -{0x0820, 0x17, 0}, // requested_link_bit_rate_mbps = 6000 -{0x0821, 0x70, 0}, -{0x0822, 0x00, 0}, -{0x0823, 0x00, 0}, - -//integration time settings -{0x0202, 0x07, 0}, {0x0203, 0x00, 0}, // INTEG_TIME = 1792 -{0x0224, 0x01, 0}, {0x0225, 0xf4, 0}, // ST_COARSE_INTEG_TIME = 506 - -// gain settings -{0x0204, 0x00, 0}, {0x0205, 0x00, 0}, // ANA_GAIN_GLOBAL = 512 / (512 - X) -{0x0216, 0x00, 0}, {0x0217, 0x00, 0}, // ST_ANA_GAIN_GLOBAL[8] -{0x020e, 0x01, 0}, {0x020f, 0x00, 0}, // DIG_GAIN_GR -{0x0210, 0x01, 0}, {0x0211, 0x00, 0}, // DIG_GAIN_R -{0x0212, 0x01, 0}, {0x0213, 0x00, 0}, // DIG_GAIN_B -{0x0214, 0x01, 0}, {0x0215, 0x00, 0}, // DIG_GAIN_GB - -// HDR white balance settings (ABS_GAIN) -{0xb8e, 0x01, 0}, {0xb8f, 0x00, 0}, // GR -{0xb90, 0x02, 0}, {0xb91, 0x2b, 0}, // R -{0xb92, 0x01, 0}, {0xb93, 0xd4, 0}, // B -{0xb94, 0x01, 0}, {0xb95, 0x00, 0}, // GB - -// phase detection settings -{0x3058, 0x00, 0}, // NML_NR_EN -{0x3103, 0x01, 0}, // NML_PD_CAL_ENABLE = enable -{0x3108, 0x00, 0}, {0x3109, 0x2c, 0}, //PD_AREA_X_OFFSET -{0x310a, 0x00, 0}, {0x310b, 0x24, 0}, //PD_AREA_Y_OFFSET -{0x310c, 0x01, 0}, {0x310d, 0xa4, 0}, //PD_AREA_WIDTH -{0x310e, 0x01, 0}, {0x310f, 0xa4, 0}, //PD_AREA_HEIGHT -// whole size is 0x918 x 0x6d4 -{0x3110, 0x03, 0}, // PD_AREA_0 = 0x375-0x4d1, 0x258-0x3b6 -{0x3111, 0x75, 0}, -{0x3112, 0x02, 0}, -{0x3113, 0x58, 0}, -{0x3114, 0x04, 0}, -{0x3115, 0xd1, 0}, -{0x3116, 0x03, 0}, -{0x3117, 0xb6, 0}, -{0x3118, 0x04, 0}, // PD_AREA_1 = 0x446-0x5a2, 0x258-0x3b6 -{0x3119, 0x46, 0}, -{0x311a, 0x02, 0}, -{0x311b, 0x58, 0}, -{0x311c, 0x05, 0}, -{0x311d, 0xa2, 0}, -{0x311e, 0x03, 0}, -{0x311f, 0xb6, 0}, -{0x3120, 0x03, 0}, // PD_AREA_2 = 0x375-0x4d1, 0x32a-0x488 -{0x3121, 0x75, 0}, -{0x3122, 0x03, 0}, -{0x3123, 0x2a, 0}, -{0x3124, 0x04, 0}, -{0x3125, 0xd1, 0}, -{0x3126, 0x04, 0}, -{0x3127, 0x88, 0}, -{0x3128, 0x04, 0}, // PD_AREA_3 = 0x446-0x5a2, 0x32a-0x488 -{0x3129, 0x46, 0}, -{0x312a, 0x03, 0}, -{0x312b, 0x2a, 0}, -{0x312c, 0x05, 0}, -{0x312d, 0xa2, 0}, -{0x312e, 0x04, 0}, -{0x312f, 0x88, 0}, -{0x3130, 0x03, 0}, // PD_AREA_4 = 0x375-0x5a2, 0x258-0x488 -{0x3131, 0x75, 0}, -{0x3132, 0x02, 0}, -{0x3133, 0x58, 0}, -{0x3134, 0x05, 0}, -{0x3135, 0xa2, 0}, -{0x3136, 0x04, 0}, -{0x3137, 0x88, 0}, -{0x3138, 0x02, 0}, // PD_AREA_5 = 0x2ba-0x65d, 0x210-0x4d0 -{0x3139, 0xba, 0}, -{0x313a, 0x02, 0}, -{0x313b, 0x10, 0}, -{0x313c, 0x06, 0}, -{0x313d, 0x5d, 0}, -{0x313e, 0x04, 0}, -{0x313f, 0xd0, 0}, -{0x3140, 0x00, 0}, // PD_AREA_6 = 0xa1-0x876, 0x6b-0x676 -{0x3141, 0xa1, 0}, -{0x3142, 0x00, 0}, -{0x3143, 0x6b, 0}, -{0x3144, 0x08, 0}, -{0x3145, 0x76, 0}, -{0x3146, 0x06, 0}, -{0x3147, 0x76, 0}, -{0x3148, 0x00, 0}, // PD_AREA_7 = 0xa1-0x876, 0x5e-0x34c -{0x3149, 0xa1, 0}, -{0x314a, 0x00, 0}, -{0x314b, 0x5e, 0}, -{0x314c, 0x08, 0}, -{0x314d, 0x76, 0}, -{0x314e, 0x03, 0}, -{0x314f, 0x4c, 0}, -{0x3165, 0x02, 0}, // AREA_EN_0 = free area -}; - -// static struct msm_camera_i2c_reg_array reg_array3[] = { -// // REG_HOLD ON -// {0x104,0x1,0}, -// // from regression -// {0x3002,0x0,0}, -// // FRM_LENGTH, 1802 vs 3554 -// // {0x340,0x7,0}, {0x341,0xa,0}, // camera start {0x340,0xd,0}, {0x341,0xe2,0}, -// // INTEG_TIME aka coarse_int_time_addr aka shutter speed -// {0x202,0x03,0}, {0x203,0xda,0}, -// // global_gain_addr -// {0x204,0x0,0}, {0x205,0x0,0}, - -// //?? -// {0x20e,0x1,0}, {0x20f,0x0,0}, -// {0x210,0x1,0}, {0x211,0x0,0}, -// {0x212,0x1,0}, {0x213,0x0,0}, -// {0x214,0x1,0}, {0x215,0x0,0}, - -// // REG_HOLD: mode setting -// {0x104,0x0,0}, -// }; - -// start, remove standby mode -static struct msm_camera_i2c_reg_array start_reg_array[] = {{0x100,0x1,0}}; - -// stop, enable standby mode -static struct msm_camera_i2c_reg_array stop_reg_array[] = {{0x100,0x0,0}}; - -/* -// still mode settings: - {0x847f, 0x0c0c,}, //_M_EQCTL - - {0x8436, 0xfd7f,}, //_M_Kgxdr - {0x8440, 0xf07f,}, //_M_X_LMT - {0x8443, 0xb41e,}, //_M_X_TGT - {0x841b, 0x4001,}, //_M_Kgx10 - - {0x84b6, 0xfd7f,}, //_M_Kgydr - {0x84c0, 0xf07f,}, //_M_Y_LMT - {0x84c3, 0xb41e,}, //_M_Y_TGT - {0x849b, 0x4001,}, //_M_Kgy10 - - {0x8438, 0x2d0f,}, //_M_Kgx11 - {0x84b8, 0x2d0f,}, //_M_Kgy11 - {0x8447, 0x002b,}, //_M_KgxTG - {0x84c7, 0x002b,}, //_M_KgyTG - - {0x847f, 0x0d0d,}, //_M_EQCTL -*/ - -static struct msm_camera_i2c_reg_array init_array_ov8865[] = { -// round 1 -//{0x103,0x1,0}, // software reset -{0x100,0x0,0}, // standby on -{0x3638,0xff,0}, -{0x302,0x1e,0}, {0x303,0x0,0}, {0x304,0x3,0}, {0x30d,0x1e,0}, {0x30e,0x0,0}, {0x30f,0x9,0}, {0x312,0x1,0}, {0x31e,0xc,0}, // PLL control -{0x3015,0x1,0}, {0x3018,0x72,0}, {0x3020,0x93,0}, {0x3022,0x1,0}, -{0x3031,0xa,0}, // 10-bit mode -{0x3106,0x1,0}, {0x3305,0xf1,0}, {0x3308,0x0,0}, {0x3309,0x28,0}, {0x330a,0x0,0}, {0x330b,0x20,0}, {0x330c,0x0,0}, {0x330d,0x0,0}, {0x330e,0x0,0}, {0x330f,0x40,0}, {0x3307,0x4,0}, {0x3604,0x4,0}, {0x3602,0x30,0}, {0x3605,0x0,0}, {0x3607,0x20,0}, {0x3608,0x11,0}, {0x3609,0x68,0}, {0x360a,0x40,0}, {0x360c,0xdd,0}, {0x360e,0xc,0}, {0x3610,0x7,0}, {0x3612,0x86,0}, {0x3613,0x58,0}, {0x3614,0x28,0}, {0x3617,0x40,0}, {0x3618,0x5a,0}, {0x3619,0x9b,0}, {0x361c,0x0,0}, {0x361d,0x60,0}, {0x3631,0x60,0}, {0x3633,0x10,0}, {0x3634,0x10,0}, {0x3635,0x10,0}, {0x3636,0x10,0}, {0x3641,0x55,0}, {0x3646,0x86,0}, {0x3647,0x27,0}, {0x364a,0x1b,0}, {0x3500,0x0,0}, {0x3501,0x4c,0}, {0x3502,0x0,0}, {0x3503,0x0,0}, {0x3508,0x2,0}, -{0x3509,0x0,0}, // AEC GAIN -{0x3700,0x24,0}, {0x3701,0xc,0}, {0x3702,0x28,0}, {0x3703,0x19,0}, {0x3704,0x14,0}, {0x3705,0x0,0}, {0x3706,0x38,0}, {0x3707,0x4,0}, {0x3708,0x24,0}, {0x3709,0x40,0}, {0x370a,0x0,0}, {0x370b,0xb8,0}, {0x370c,0x4,0}, {0x3718,0x12,0}, {0x3719,0x31,0}, {0x3712,0x42,0}, {0x3714,0x12,0}, {0x371e,0x19,0}, {0x371f,0x40,0}, {0x3720,0x5,0}, {0x3721,0x5,0}, {0x3724,0x2,0}, {0x3725,0x2,0}, {0x3726,0x6,0}, {0x3728,0x5,0}, {0x3729,0x2,0}, {0x372a,0x3,0}, {0x372b,0x53,0}, {0x372c,0xa3,0}, {0x372d,0x53,0}, {0x372e,0x6,0}, {0x372f,0x10,0}, {0x3730,0x1,0}, {0x3731,0x6,0}, {0x3732,0x14,0}, {0x3733,0x10,0}, {0x3734,0x40,0}, {0x3736,0x20,0}, {0x373a,0x2,0}, {0x373b,0xc,0}, {0x373c,0xa,0}, {0x373e,0x3,0}, {0x3755,0x40,0}, {0x3758,0x0,0}, {0x3759,0x4c,0}, {0x375a,0x6,0}, {0x375b,0x13,0}, {0x375c,0x40,0}, {0x375d,0x2,0}, {0x375e,0x0,0}, {0x375f,0x14,0}, {0x3767,0x1c,0}, {0x3768,0x4,0}, {0x3769,0x20,0}, {0x376c,0xc0,0}, {0x376d,0xc0,0}, {0x376a,0x8,0}, {0x3761,0x0,0}, {0x3762,0x0,0}, {0x3763,0x0,0}, {0x3766,0xff,0}, {0x376b,0x42,0}, {0x3772,0x23,0}, {0x3773,0x2,0}, {0x3774,0x16,0}, {0x3775,0x12,0}, {0x3776,0x8,0}, {0x37a0,0x44,0}, {0x37a1,0x3d,0}, {0x37a2,0x3d,0}, {0x37a3,0x1,0}, {0x37a4,0x0,0}, {0x37a5,0x8,0}, {0x37a6,0x0,0}, {0x37a7,0x44,0}, {0x37a8,0x58,0}, {0x37a9,0x58,0}, {0x3760,0x0,0}, {0x376f,0x1,0}, {0x37aa,0x44,0}, {0x37ab,0x2e,0}, {0x37ac,0x2e,0}, {0x37ad,0x33,0}, {0x37ae,0xd,0}, {0x37af,0xd,0}, {0x37b0,0x0,0}, {0x37b1,0x0,0}, {0x37b2,0x0,0}, {0x37b3,0x42,0}, {0x37b4,0x42,0}, {0x37b5,0x33,0}, {0x37b6,0x0,0}, {0x37b7,0x0,0}, {0x37b8,0x0,0}, {0x37b9,0xff,0}, {0x3800,0x0,0}, {0x3801,0xc,0}, {0x3802,0x0,0}, {0x3803,0xc,0}, -{0x3804,0xc,0}, {0x3805,0xd3,0}, // 3283 -{0x3806,0x9,0}, {0x3807,0xa3,0}, // 2467 -{0x3808,0x6,0}, {0x3809,0x60,0}, // 0x660 = 1632 (width) -{0x380a,0x4,0}, {0x380b,0xc8,0}, // 0x4c8 = 1224 (height) -{0x380c,0x6,0}, {0x380d,0x42,0}, // line_length_pck -{0x380e,0x5,0}, {0x380f,0xda,0}, // frame_length_lines -{0x3810,0x0,0}, {0x3811,0x4,0}, {0x3813,0x4,0}, -{0x3814,0x3,0}, {0x3815,0x1,0}, // H-binning -{0x3820,0x6,0}, // format1 -{0x3821,0x40,0}, // format2 -{0x382a,0x3,0}, {0x382b,0x1,0}, // V-binning -{0x382d,0x7f,0}, {0x3830,0x8,0}, {0x3836,0x2,0}, {0x3837,0x18,0}, -{0x3841,0xff,0}, -{0x3846,0x88,0}, {0x3d85,0x6,0}, {0x3d8c,0x75,0}, {0x3d8d,0xef,0}, {0x3f08,0xb,0}, {0x4000,0xf1,0}, {0x4001,0x14,0}, {0x4005,0x10,0}, {0x4006,0x1,0}, {0x4007,0x1,0}, {0x400b,0xc,0}, {0x400d,0x10,0}, {0x401b,0x0,0}, {0x401d,0x0,0}, {0x4020,0x0,0}, {0x4021,0x0,0}, {0x4022,0x4,0}, {0x4023,0x1f,0}, {0x4024,0x6,0}, {0x4025,0x20,0}, {0x4026,0x6,0}, {0x4027,0x4f,0}, {0x4028,0x0,0}, {0x4029,0x2,0}, {0x402a,0x4,0}, {0x402b,0x4,0}, {0x402c,0x2,0}, {0x402d,0x2,0}, {0x402e,0x8,0}, {0x402f,0x2,0}, {0x401f,0x0,0}, {0x4034,0x3f,0}, {0x4300,0xff,0}, {0x4301,0x0,0}, {0x4302,0xf,0}, {0x4500,0x40,0}, {0x4503,0x10,0}, {0x4601,0x74,0}, {0x481f,0x32,0}, {0x4837,0x15,0}, {0x4850,0x10,0}, {0x4851,0x32,0}, {0x4b00,0x2a,0}, {0x4b0d,0x0,0}, {0x4d00,0x4,0}, {0x4d01,0x18,0}, {0x4d02,0xc3,0}, {0x4d03,0xff,0}, {0x4d04,0xff,0}, {0x4d05,0xff,0}, {0x5000,0x96,0}, {0x5001,0x1,0}, {0x5002,0x8,0}, {0x5901,0x0,0}, -{0x5e00,0x0,0}, -//{0x5e00,0x80,0}, -{0x5e01,0x41,0}, {0x5b00,0x2,0}, {0x5b01,0xd0,0}, {0x5b02,0x3,0}, {0x5b03,0xff,0}, {0x5b05,0x6c,0}, {0x5780,0xfc,0}, {0x5781,0xdf,0}, {0x5782,0x3f,0}, {0x5783,0x8,0}, {0x5784,0xc,0}, {0x5786,0x20,0}, {0x5787,0x40,0}, {0x5788,0x8,0}, {0x5789,0x8,0}, {0x578a,0x2,0}, {0x578b,0x1,0}, {0x578c,0x1,0}, {0x578d,0xc,0}, {0x578e,0x2,0}, {0x578f,0x1,0}, {0x5790,0x1,0}, {0x5800,0x1d,0}, {0x5801,0xe,0}, {0x5802,0xc,0}, {0x5803,0xc,0}, {0x5804,0xf,0}, {0x5805,0x22,0}, {0x5806,0xa,0}, {0x5807,0x6,0}, {0x5808,0x5,0}, {0x5809,0x5,0}, {0x580a,0x7,0}, {0x580b,0xa,0}, {0x580c,0x6,0}, {0x580d,0x2,0}, {0x580e,0x0,0}, {0x580f,0x0,0}, {0x5810,0x3,0}, {0x5811,0x7,0}, {0x5812,0x6,0}, {0x5813,0x2,0}, {0x5814,0x0,0}, {0x5815,0x0,0}, {0x5816,0x3,0}, {0x5817,0x7,0}, {0x5818,0x9,0}, {0x5819,0x6,0}, {0x581a,0x4,0}, {0x581b,0x4,0}, {0x581c,0x6,0}, {0x581d,0xa,0}, {0x581e,0x19,0}, {0x581f,0xd,0}, {0x5820,0xb,0}, {0x5821,0xb,0}, {0x5822,0xe,0}, {0x5823,0x22,0}, {0x5824,0x23,0}, {0x5825,0x28,0}, {0x5826,0x29,0}, {0x5827,0x27,0}, {0x5828,0x13,0}, {0x5829,0x26,0}, {0x582a,0x33,0}, {0x582b,0x32,0}, {0x582c,0x33,0}, {0x582d,0x16,0}, {0x582e,0x14,0}, {0x582f,0x30,0}, {0x5830,0x31,0}, {0x5831,0x30,0}, {0x5832,0x15,0}, {0x5833,0x26,0}, {0x5834,0x23,0}, {0x5835,0x21,0}, {0x5836,0x23,0}, {0x5837,0x5,0}, {0x5838,0x36,0}, {0x5839,0x27,0}, {0x583a,0x28,0}, {0x583b,0x26,0}, {0x583c,0x24,0}, {0x583d,0xdf,0}, -//{0x100,0x1,0}, -// round 2 (color calibration) -{0x7010,0x0,0}, {0x7011,0x0,0}, {0x7012,0x0,0}, {0x7013,0x0,0}, {0x7014,0x0,0}, {0x7015,0x0,0}, {0x7016,0x0,0}, {0x7017,0x0,0}, {0x7018,0x0,0}, {0x7019,0x0,0}, {0x701a,0x0,0}, {0x701b,0x0,0}, {0x701c,0x0,0}, {0x701d,0x0,0}, {0x701e,0x0,0}, {0x701f,0x0,0}, {0x7020,0x0,0}, {0x7021,0x0,0}, {0x7022,0x0,0}, {0x7023,0x0,0}, {0x7024,0x0,0}, {0x7025,0x0,0}, {0x7026,0x0,0}, {0x7027,0x0,0}, {0x7028,0x0,0}, {0x7029,0x0,0}, {0x702a,0x0,0}, {0x702b,0x0,0}, {0x702c,0x0,0}, {0x702d,0x0,0}, {0x702e,0x0,0}, {0x702f,0x0,0}, {0x7030,0x0,0}, {0x7031,0x0,0}, {0x7032,0x0,0}, {0x7033,0x0,0}, {0x7034,0x0,0}, {0x7035,0x0,0}, {0x7036,0x0,0}, {0x7037,0x0,0}, {0x7038,0x0,0}, {0x7039,0x0,0}, {0x703a,0x0,0}, {0x703b,0x0,0}, {0x703c,0x0,0}, {0x703d,0x0,0}, {0x703e,0x0,0}, {0x703f,0x0,0}, {0x7040,0x0,0}, {0x7041,0x0,0}, {0x7042,0x0,0}, {0x7043,0x0,0}, {0x7044,0x0,0}, {0x7045,0x0,0}, {0x7046,0x0,0}, {0x7047,0x0,0}, {0x7048,0x0,0}, {0x7049,0x0,0}, {0x704a,0x0,0}, {0x704b,0x0,0}, {0x704c,0x0,0}, {0x704d,0x0,0}, {0x704e,0x0,0}, {0x704f,0x0,0}, {0x7050,0x0,0}, {0x7051,0x0,0}, {0x7052,0x0,0}, {0x7053,0x0,0}, {0x7054,0x0,0}, {0x7055,0x0,0}, {0x7056,0x0,0}, {0x7057,0x0,0}, {0x7058,0x0,0}, {0x7059,0x0,0}, {0x705a,0x0,0}, {0x705b,0x0,0}, {0x705c,0x0,0}, {0x705d,0x0,0}, {0x705e,0x0,0}, {0x705f,0x0,0}, {0x7060,0x0,0}, {0x7061,0x0,0}, {0x7062,0x0,0}, {0x7063,0x0,0}, {0x7064,0x0,0}, {0x7065,0x0,0}, {0x7066,0x0,0}, {0x7067,0x0,0}, {0x7068,0x0,0}, {0x7069,0x0,0}, {0x706a,0x0,0}, {0x706b,0x0,0}, {0x706c,0x0,0}, {0x706d,0x0,0}, {0x706e,0x0,0}, {0x706f,0x0,0}, {0x7070,0x0,0}, {0x7071,0x0,0}, {0x7072,0x0,0}, {0x7073,0x0,0}, {0x7074,0x0,0}, {0x7075,0x0,0}, {0x7076,0x0,0}, {0x7077,0x0,0}, {0x7078,0x0,0}, {0x7079,0x0,0}, {0x707a,0x0,0}, {0x707b,0x0,0}, {0x707c,0x0,0}, {0x707d,0x0,0}, {0x707e,0x0,0}, {0x707f,0x0,0}, {0x7080,0x0,0}, {0x7081,0x0,0}, {0x7082,0x0,0}, {0x7083,0x0,0}, {0x7084,0x0,0}, {0x7085,0x0,0}, {0x7086,0x0,0}, {0x7087,0x0,0}, {0x7088,0x0,0}, {0x7089,0x0,0}, {0x708a,0x0,0}, {0x708b,0x0,0}, {0x708c,0x0,0}, {0x708d,0x0,0}, {0x708e,0x0,0}, {0x708f,0x0,0}, {0x7090,0x0,0}, {0x7091,0x0,0}, {0x7092,0x0,0}, {0x7093,0x0,0}, {0x7094,0x0,0}, {0x7095,0x0,0}, {0x7096,0x0,0}, {0x7097,0x0,0}, {0x7098,0x0,0}, {0x7099,0x0,0}, {0x709a,0x0,0}, {0x709b,0x0,0}, {0x709c,0x0,0}, {0x709d,0x0,0}, {0x709e,0x0,0}, {0x709f,0x0,0}, {0x70a0,0x0,0}, {0x70a1,0x0,0}, {0x70a2,0x0,0}, {0x70a3,0x0,0}, {0x70a4,0x0,0}, {0x70a5,0x0,0}, {0x70a6,0x0,0}, {0x70a7,0x0,0}, {0x70a8,0x0,0}, {0x70a9,0x0,0}, {0x70aa,0x0,0}, {0x70ab,0x0,0}, {0x70ac,0x0,0}, {0x70ad,0x0,0}, {0x70ae,0x0,0}, {0x70af,0x0,0}, {0x70b0,0x0,0}, {0x70b1,0x0,0}, {0x70b2,0x0,0}, {0x70b3,0x0,0}, {0x70b4,0x0,0}, {0x70b5,0x0,0}, {0x70b6,0x0,0}, {0x70b7,0x0,0}, {0x70b8,0x0,0}, {0x70b9,0x0,0}, {0x70ba,0x0,0}, {0x70bb,0x0,0}, {0x70bc,0x0,0}, {0x70bd,0x0,0}, {0x70be,0x0,0}, {0x70bf,0x0,0}, {0x70c0,0x0,0}, {0x70c1,0x0,0}, {0x70c2,0x0,0}, {0x70c3,0x0,0}, {0x70c4,0x0,0}, {0x70c5,0x0,0}, {0x70c6,0x0,0}, {0x70c7,0x0,0}, {0x70c8,0x0,0}, {0x70c9,0x0,0}, {0x70ca,0x0,0}, {0x70cb,0x0,0}, {0x70cc,0x0,0}, {0x70cd,0x0,0}, {0x70ce,0x0,0}, {0x70cf,0x0,0}, {0x70d0,0x0,0}, {0x70d1,0x0,0}, {0x70d2,0x0,0}, {0x70d3,0x0,0}, {0x70d4,0x0,0}, {0x70d5,0x0,0}, {0x70d6,0x0,0}, {0x70d7,0x0,0}, {0x70d8,0x0,0}, {0x70d9,0x0,0}, {0x70da,0x0,0}, {0x70db,0x0,0}, {0x70dc,0x0,0}, {0x70dd,0x0,0}, {0x70de,0x0,0}, {0x70df,0x0,0}, {0x70e0,0x0,0}, {0x70e1,0x0,0}, {0x70e2,0x0,0}, {0x70e3,0x0,0}, {0x70e4,0x0,0}, {0x70e5,0x0,0}, {0x70e6,0x0,0}, {0x70e7,0x0,0}, {0x70e8,0x0,0}, {0x70e9,0x0,0}, {0x70ea,0x0,0}, {0x70eb,0x0,0}, {0x70ec,0x0,0}, {0x70ed,0x0,0}, {0x70ee,0x0,0}, {0x70ef,0x0,0}, {0x70f0,0x0,0}, {0x70f1,0x0,0}, {0x70f2,0x0,0}, {0x70f3,0x0,0}, {0x70f4,0x0,0}, {0x70f5,0x0,0}, {0x70f6,0x0,0}, {0x70f7,0x0,0}, {0x70f8,0x0,0}, {0x70f9,0x0,0}, {0x70fa,0x0,0}, {0x70fb,0x0,0}, {0x70fc,0x0,0}, {0x70fd,0x0,0}, {0x70fe,0x0,0}, {0x70ff,0x0,0}, {0x7100,0x0,0}, {0x7101,0x0,0}, {0x7102,0x0,0}, {0x7103,0x0,0}, {0x7104,0x0,0}, {0x7105,0x0,0}, {0x7106,0x0,0}, {0x7107,0x0,0}, {0x7108,0x0,0}, {0x7109,0x0,0}, {0x710a,0x0,0}, {0x710b,0x0,0}, {0x710c,0x0,0}, {0x710d,0x0,0}, {0x710e,0x0,0}, {0x710f,0x0,0}, {0x7110,0x0,0}, {0x7111,0x0,0}, {0x7112,0x0,0}, {0x7113,0x0,0}, {0x7114,0x0,0}, {0x7115,0x0,0}, {0x7116,0x0,0}, {0x7117,0x0,0}, {0x7118,0x0,0}, {0x7119,0x0,0}, {0x711a,0x0,0}, {0x711b,0x0,0}, {0x711c,0x0,0}, {0x711d,0x0,0}, {0x711e,0x0,0}, {0x711f,0x0,0}, {0x7120,0x0,0}, {0x7121,0x0,0}, {0x7122,0x0,0}, {0x7123,0x0,0}, {0x7124,0x0,0}, {0x7125,0x0,0}, {0x7126,0x0,0}, {0x7127,0x0,0}, {0x7128,0x0,0}, {0x7129,0x0,0}, {0x712a,0x0,0}, {0x712b,0x0,0}, {0x712c,0x0,0}, {0x712d,0x0,0}, {0x712e,0x0,0}, {0x712f,0x0,0}, {0x7130,0x0,0}, {0x7131,0x0,0}, {0x7132,0x0,0}, {0x501a,0x10,0}, {0x501b,0xd,0}, {0x501c,0x10,0}, {0x501d,0x13,0}, {0x5000,0x96,0}, {0x5800,0x14,0}, {0x5801,0xd,0}, {0x5802,0xa,0}, {0x5803,0xa,0}, {0x5804,0xd,0}, {0x5805,0x13,0}, {0x5806,0xa,0}, {0x5807,0x5,0}, {0x5808,0x3,0}, {0x5809,0x3,0}, {0x580a,0x5,0}, {0x580b,0x9,0}, {0x580c,0x6,0}, {0x580d,0x2,0}, {0x580e,0x0,0}, {0x580f,0x0,0}, {0x5810,0x2,0}, {0x5811,0x5,0}, {0x5812,0x6,0}, {0x5813,0x2,0}, {0x5814,0x0,0}, {0x5815,0x0,0}, {0x5816,0x2,0}, {0x5817,0x5,0}, {0x5818,0xb,0}, {0x5819,0x6,0}, {0x581a,0x3,0}, {0x581b,0x3,0}, {0x581c,0x5,0}, {0x581d,0xa,0}, {0x581e,0x16,0}, {0x581f,0xf,0}, {0x5820,0xb,0}, {0x5821,0xb,0}, {0x5822,0xf,0}, {0x5823,0x15,0}, {0x5824,0x32,0}, {0x5825,0x23,0}, {0x5826,0x23,0}, {0x5827,0x23,0}, {0x5828,0x22,0}, {0x5829,0x21,0}, {0x582a,0x21,0}, {0x582b,0x22,0}, {0x582c,0x21,0},{0x582d,0x11,0}, {0x582e,0x22,0}, {0x582f,0x31,0}, {0x5830,0x41,0}, {0x5831,0x31,0}, {0x5832,0x1,0}, {0x5833,0x21,0}, {0x5834,0x21,0}, {0x5835,0x21,0}, {0x5836,0x11,0}, {0x5837,0x11,0}, {0x5838,0x22,0}, {0x5839,0x22,0}, {0x583a,0x12,0}, {0x583b,0x22,0}, {0x583c,0x22,0}, {0x583d,0xdf,0}, -}; - diff --git a/selfdrive/hardware/base.py b/selfdrive/hardware/base.py index 7e580b1027..8684386f62 100644 --- a/selfdrive/hardware/base.py +++ b/selfdrive/hardware/base.py @@ -78,30 +78,6 @@ class HardwareBase(ABC): def set_bandwidth_limit(upload_speed_kbps: int, download_speed_kbps: int) -> None: pass - @abstractmethod - def get_battery_capacity(self): - pass - - @abstractmethod - def get_battery_status(self): - pass - - @abstractmethod - def get_battery_current(self): - pass - - @abstractmethod - def get_battery_voltage(self): - pass - - @abstractmethod - def get_battery_charging(self): - pass - - @abstractmethod - def set_battery_charging(self, on): - pass - @abstractmethod def get_usb_present(self): pass diff --git a/selfdrive/hardware/pc/hardware.py b/selfdrive/hardware/pc/hardware.py index 0d85f28bed..2f5db925a9 100644 --- a/selfdrive/hardware/pc/hardware.py +++ b/selfdrive/hardware/pc/hardware.py @@ -50,24 +50,6 @@ class Pc(HardwareBase): def get_network_strength(self, network_type): return NetworkStrength.unknown - def get_battery_capacity(self): - return 100 - - def get_battery_status(self): - return "" - - def get_battery_current(self): - return 0 - - def get_battery_voltage(self): - return 0 - - def get_battery_charging(self): - return True - - def set_battery_charging(self, on): - pass - def get_usb_present(self): return False diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index 1005866d69..037afa3891 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -355,25 +355,6 @@ class Tici(HardwareBase): pass return ret - # We don't have a battery, so let's use some sane constants - def get_battery_capacity(self): - return 100 - - def get_battery_status(self): - return "" - - def get_battery_current(self): - return 0 - - def get_battery_voltage(self): - return 0 - - def get_battery_charging(self): - return True - - def set_battery_charging(self, on): - pass - def get_usb_present(self): # Not sure if relevant on tici, but the file exists return self.read_param_file("/sys/class/power_supply/usb/present", lambda x: bool(int(x)), False) diff --git a/selfdrive/thermald/power_monitoring.py b/selfdrive/thermald/power_monitoring.py index 25b1bad04d..d7a1f2a360 100644 --- a/selfdrive/thermald/power_monitoring.py +++ b/selfdrive/thermald/power_monitoring.py @@ -1,7 +1,4 @@ -import random import threading -import time -from statistics import mean from typing import Optional from cereal import log @@ -82,52 +79,8 @@ class PowerMonitoring: self.car_battery_capacity_uWh += (CAR_CHARGING_RATE_W * 1e6 * integration_time_h) self.last_measurement_time = now else: - # No ignition, we integrate the offroad power used by the device - is_uno = peripheralState.pandaType == log.PandaState.PandaType.uno # Get current power draw somehow - current_power = HARDWARE.get_current_power_draw() # pylint: disable=assignment-from-none - if current_power is not None: - pass - elif (self.next_pulsed_measurement_time is not None) and (self.next_pulsed_measurement_time <= now): - # TODO: Figure out why this is off by a factor of 3/4??? - FUDGE_FACTOR = 1.33 - - # Turn off charging for about 10 sec in a thread that does not get killed on SIGINT, and perform measurement here to avoid blocking thermal - def perform_pulse_measurement(now): - try: - HARDWARE.set_battery_charging(False) - time.sleep(5) - - # Measure for a few sec to get a good average - voltages = [] - currents = [] - for _ in range(6): - voltages.append(HARDWARE.get_battery_voltage()) - currents.append(HARDWARE.get_battery_current()) - time.sleep(1) - current_power = ((mean(voltages) / 1000000) * (mean(currents) / 1000000)) - - self._perform_integration(now, current_power * FUDGE_FACTOR) - - # Enable charging again - HARDWARE.set_battery_charging(True) - except Exception: - cloudlog.exception("Pulsed power measurement failed") - - # Start pulsed measurement and return - threading.Thread(target=perform_pulse_measurement, args=(now,)).start() - self.next_pulsed_measurement_time = None - return - - elif self.next_pulsed_measurement_time is None and not is_uno: - # On a charging EON with black panda, or drawing more than 400mA out of a white/grey one - # Only way to get the power draw is to turn off charging for a few sec and check what the discharging rate is - # We shouldn't do this very often, so make sure it has been some long-ish random time interval - self.next_pulsed_measurement_time = now + random.randint(120, 180) - return - else: - # Do nothing - return + current_power = HARDWARE.get_current_power_draw() # Do the integration self._perform_integration(now, current_power) @@ -178,11 +131,9 @@ class PowerMonitoring: now = sec_since_boot() panda_charging = (peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client) - BATT_PERC_OFF = 10 should_shutdown = False # Wait until we have shut down charging before powering down should_shutdown |= (not panda_charging and self.should_disable_charging(ignition, in_car, offroad_timestamp)) - should_shutdown |= ((HARDWARE.get_battery_capacity() < BATT_PERC_OFF) and (not HARDWARE.get_battery_charging()) and ((now - offroad_timestamp) > 60)) should_shutdown &= started_seen or (now > MIN_ON_TIME_S) return should_shutdown diff --git a/selfdrive/thermald/tests/test_power_monitoring.py b/selfdrive/thermald/tests/test_power_monitoring.py index 9eeb5f0c6d..c0524add69 100755 --- a/selfdrive/thermald/tests/test_power_monitoring.py +++ b/selfdrive/thermald/tests/test_power_monitoring.py @@ -21,10 +21,7 @@ with patch("common.realtime.sec_since_boot", new=mock_sec_since_boot): CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING TEST_DURATION_S = 50 -ALL_PANDA_TYPES = [(hw_type,) for hw_type in [log.PandaState.PandaType.whitePanda, - log.PandaState.PandaType.greyPanda, - log.PandaState.PandaType.blackPanda, - log.PandaState.PandaType.uno]] +ALL_PANDA_TYPES = [(log.PandaState.PandaType.dos,)] def pm_patch(name, value, constant=False): if constant: @@ -121,12 +118,8 @@ class TestPowerMonitoring(unittest.TestCase): # Test to check policy of stopping charging after MAX_TIME_OFFROAD_S @parameterized.expand(ALL_PANDA_TYPES) def test_max_time_offroad(self, hw_type): - BATT_VOLTAGE = 4 - BATT_CURRENT = 0 # To stop shutting down for other reasons MOCKED_MAX_OFFROAD_TIME = 3600 - with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ - pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("MAX_TIME_OFFROAD_S", MOCKED_MAX_OFFROAD_TIME, constant=True), \ - pm_patch("HARDWARE.get_current_power_draw", None): + with pm_patch("MAX_TIME_OFFROAD_S", MOCKED_MAX_OFFROAD_TIME, constant=True), pm_patch("HARDWARE.get_current_power_draw", None): pm = PowerMonitoring() pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh start_time = ssb diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 24aafcbfe0..7c88dd5790 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -240,8 +240,6 @@ def thermald_thread(end_event, hw_queue): msg.deviceState.modemTempC = last_hw_state.modem_temps msg.deviceState.screenBrightnessPercent = HARDWARE.get_screen_brightness() - msg.deviceState.batteryPercent = HARDWARE.get_battery_capacity() - msg.deviceState.batteryCurrent = HARDWARE.get_battery_current() msg.deviceState.usbOnline = HARDWARE.get_usb_present() current_filter.update(msg.deviceState.batteryCurrent / 1e6) From b2569d871ffcdb41f0100cdec7ee56eeb5f605fd Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 15 May 2022 17:57:34 -0700 Subject: [PATCH 34/91] CI tuneup (#24541) * little housekeeping * all the commits * one more cars --- .github/workflows/prebuilt.yaml | 2 +- .github/workflows/selfdrive_tests.yaml | 93 +++++++++++++------------- .github/workflows/tools_tests.yaml | 30 +++------ Jenkinsfile | 21 ------ release/files_pc | 6 ++ 5 files changed, 64 insertions(+), 88 deletions(-) diff --git a/.github/workflows/prebuilt.yaml b/.github/workflows/prebuilt.yaml index 807ac06b94..a6808a0276 100644 --- a/.github/workflows/prebuilt.yaml +++ b/.github/workflows/prebuilt.yaml @@ -30,7 +30,7 @@ jobs: ref: master wait-interval: 30 running-workflow-name: 'build prebuilt' - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Build Docker image diff --git a/.github/workflows/selfdrive_tests.yaml b/.github/workflows/selfdrive_tests.yaml index 98cdeab306..144718df60 100644 --- a/.github/workflows/selfdrive_tests.yaml +++ b/.github/workflows/selfdrive_tests.yaml @@ -26,10 +26,11 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 50 env: - STRIPPED_DIR: tmppilot + STRIPPED_DIR: /tmp/releasepilot steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: + fetch-depth: 0 submodules: true - name: Check submodules if: github.ref == 'refs/heads/master' && github.repository == 'commaai/openpilot' @@ -46,16 +47,10 @@ jobs: restore-keys: | scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- scons- - - name: Strip non-release files + - name: Build devel run: | - mkdir $STRIPPED_DIR - cp -pR --parents $(cat release/files_common) $STRIPPED_DIR - cp -pR --parents $(cat release/files_tici) $STRIPPED_DIR - cp -pR --parents $(cat release/files_pc) $STRIPPED_DIR + TARGET_DIR=$STRIPPED_DIR release/build_devel.sh cp Dockerfile.openpilot_base $STRIPPED_DIR - - # need this to build on x86 - cp -pR --parents third_party/libyuv third_party/snpe selfdrive/modeld/runners $STRIPPED_DIR - name: Build Docker image run: eval "$BUILD" - name: Build openpilot and run checks @@ -63,32 +58,43 @@ jobs: cd $STRIPPED_DIR ${{ env.RUN }} "CI=1 python selfdrive/manager/build.py && \ python -m unittest discover selfdrive/car" - - name: Cleanup scons cache - run: | - cd $STRIPPED_DIR - ${{ env.RUN }} "scons -j$(nproc) && \ - rm -rf /tmp/scons_cache/* && \ - scons -j$(nproc) --cache-populate" build_all: name: build all runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true + - name: Cache scons + id: scons-cache + # TODO: Change the version to the released version when https://github.com/actions/cache/pull/489 (or 571) is merged. + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + env: + CACHE_SKIP_SAVE: ${{ github.ref != 'refs/heads/master' || github.repository != 'commaai/openpilot' }} + with: + path: /tmp/scons_cache + key: scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}-${{ steps.date.outputs.time }} + restore-keys: | + scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- + scons- - name: Build Docker image run: eval "$BUILD" - name: Build openpilot with all flags run: ${{ env.RUN }} "scons -j$(nproc) --extras --test" + - name: Cleanup scons cache + run: | + ${{ env.RUN }} "scons -j$(nproc) --extras --test && \ + rm -rf /tmp/scons_cache/* && \ + scons -j$(nproc) --cache-populate" #build_mac: # name: build macos # runs-on: macos-latest # timeout-minutes: 60 # steps: - # - uses: actions/checkout@v2 + # - uses: actions/checkout@v3 # with: # submodules: true # - name: Determine pre-existing Homebrew packages @@ -147,9 +153,21 @@ jobs: env: IMAGE_NAME: openpilotwebcamci steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true + - name: Cache scons + id: scons-cache + # TODO: Change the version to the released version when https://github.com/actions/cache/pull/489 (or 571) is merged. + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + env: + CACHE_SKIP_SAVE: true + with: + path: /tmp/scons_cache + key: scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- + restore-keys: | + scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- + scons- - name: Build Docker image run: | eval "$BUILD" @@ -170,7 +188,7 @@ jobs: if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/openpilot' needs: static_analysis # hack to ensure slow tests run first since this and static_analysis are fast steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Build Docker image @@ -185,20 +203,20 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Build Docker image run: eval "$BUILD" - name: pre-commit - run: ${{ env.RUN }} "git init && git add -A && pre-commit run --all" + run: ${{ env.RUN }} "pre-commit run --all" valgrind: name: valgrind runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Cache dependencies @@ -241,7 +259,7 @@ jobs: run: echo $TIMESTAMP env: TIMESTAMP: ${{ steps.date.outputs.time }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Cache scons @@ -289,7 +307,7 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Cache dependencies @@ -334,27 +352,12 @@ jobs: - name: "Upload coverage to Codecov" uses: codecov/codecov-action@v2 - #model_replay: - # name: model replay - # runs-on: ubuntu-20.04 - # timeout-minutes: 50 - # steps: - # - uses: actions/checkout@v2 - # with: - # submodules: true - # - name: Build Docker image - # run: eval "$BUILD" - # - name: Run replay - # run: | - # ${{ env.RUN }} "scons -j$(nproc) && \ - # selfdrive/test/process_replay/model_replay.py" - test_longitudinal: name: longitudinal runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Cache scons @@ -394,9 +397,9 @@ jobs: strategy: fail-fast: false matrix: - job: [0, 1, 2, 3] + job: [0, 1, 2, 3, 4] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Cache dependencies @@ -426,7 +429,7 @@ jobs: coverage xml && \ chmod -R 777 /tmp/comma_download_cache" env: - NUM_JOBS: 4 + NUM_JOBS: 5 JOB_ID: ${{ matrix.job }} - name: "Upload coverage to Codecov" uses: codecov/codecov-action@v2 @@ -436,7 +439,7 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 50 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Build docker container diff --git a/.github/workflows/tools_tests.yaml b/.github/workflows/tools_tests.yaml index 0b0df4c516..2c2bbd30bd 100644 --- a/.github/workflows/tools_tests.yaml +++ b/.github/workflows/tools_tests.yaml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 30 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Build Docker image @@ -42,28 +42,16 @@ jobs: IMAGE_NAME: openpilot-sim if: github.repository == 'commaai/openpilot' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: + lfs: true submodules: true - - # HACK: cache LFS objects since they count against our quota - # https://github.com/actions/checkout/issues/165#issuecomment-657673315 - - name: Create LFS file list - run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id - - name: Restore LFS cache - uses: actions/cache@v2 - id: lfs-cache - with: - path: .git/lfs - key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} - - name: Git LFS Pull - run: git lfs pull - - - name: Build Docker image - run: | - eval "$BUILD" - docker pull $DOCKER_REGISTRY/$IMAGE_NAME:latest || true - docker build --cache-from $DOCKER_REGISTRY/$IMAGE_NAME:latest -t $DOCKER_REGISTRY/$IMAGE_NAME:latest -f tools/sim/Dockerfile.sim . + - name: Build base image + run: eval "$BUILD" + - name: Pull latest simulator image + run: eval "$BUILD"docker pull $DOCKER_REGISTRY/$IMAGE_NAME:latest || true + - name: Build simulator image + run: docker build --cache-from $DOCKER_REGISTRY/$IMAGE_NAME:latest -t $DOCKER_REGISTRY/$IMAGE_NAME:latest -f tools/sim/Dockerfile.sim . - name: Push to container registry if: github.ref == 'refs/heads/master' && github.repository == 'commaai/openpilot' run: | diff --git a/Jenkinsfile b/Jenkinsfile index cc7347b12a..3b134d7c0d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -80,27 +80,6 @@ pipeline { stages { stage('parallel tests') { parallel { - /* - stage('Power Consumption Tests') { - steps { - lock(resource: "", label: "c2-zookeeper", inversePrecedence: true, variable: 'device_ip', quantity: 1) { - timeout(time: 90, unit: 'MINUTES') { - sh script: "/home/batman/tools/zookeeper/enable_and_wait.py $device_ip 120", label: "turn on device" - phone(device_ip, "git checkout", readFile("selfdrive/test/setup_device_ci.sh"),) - phone(device_ip, "build", "scons -j4 && sync") - sh script: "/home/batman/tools/zookeeper/disable.py $device_ip", label: "turn off device" - sh script: "/home/batman/tools/zookeeper/enable_and_wait.py $device_ip 120", label: "turn on device" - sh script: "/home/batman/tools/zookeeper/check_consumption.py 60 3", label: "idle power consumption after boot" - sh script: "/home/batman/tools/zookeeper/ignition.py 1", label: "go onroad" - sh script: "/home/batman/tools/zookeeper/check_consumption.py 60 10", label: "onroad power consumption" - sh script: "/home/batman/tools/zookeeper/ignition.py 0", label: "go offroad" - sh script: "/home/batman/tools/zookeeper/check_consumption.py 60 2", label: "idle power consumption offroad" - } - } - } - } - */ - stage('build') { environment { R3_PUSH = "${env.BRANCH_NAME == 'master' ? '1' : ' '}" diff --git a/release/files_pc b/release/files_pc index 610516bff6..e401badb80 100644 --- a/release/files_pc +++ b/release/files_pc @@ -1,3 +1,9 @@ +selfdrive/modeld/runners/onnx* + third_party/mapbox-gl-native-qt/x86_64/*.so third_party/qt-plugins/x86_64/geoservices/*.so + +third_party/libyuv/x64/** +third_party/snpe/x86_64/** +third_party/snpe/x86_64-linux-clang/** From 59319759dd432c17119ac31708a8f321839b727d Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 15 May 2022 18:43:57 -0700 Subject: [PATCH 35/91] bump opendbc --- opendbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc b/opendbc index 490ddedc59..1599f2e370 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit 490ddedc593ea003dc42c08718d7ea8d5a5778f0 +Subproject commit 1599f2e3709633cf3dabf1ebccf5a5c7619f8bb5 From 0252491f5c7b11646a61d618df5d4ad32d0b2f49 Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sun, 15 May 2022 19:22:35 -0700 Subject: [PATCH 36/91] fixup .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ce6114e58f..83ccbb4781 100644 --- a/.gitignore +++ b/.gitignore @@ -56,7 +56,7 @@ selfdrive/modeld/_dmonitoringmodeld /src/ one -body +/body/ openpilot notebooks xx @@ -77,7 +77,7 @@ cppcheck_report.txt comma*.sh selfdrive/modeld/thneed/compile -models/*.thneed +selfdrive/modeld/models/*.thneed *.bz2 From 79a6512345e80269050ab4fb753564c3d0f0ebe2 Mon Sep 17 00:00:00 2001 From: Keyvan Fatehi Date: Sun, 15 May 2022 22:47:28 -0700 Subject: [PATCH 37/91] typo fix (#24542) --- common/transformations/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/transformations/README.md b/common/transformations/README.md index 78fa6a31c4..13878cb99c 100644 --- a/common/transformations/README.md +++ b/common/transformations/README.md @@ -24,7 +24,7 @@ by generating a rotation matrix and multiplying. -Orientation Conventations +Orientation Conventions ------ Quaternions, rotation matrices and euler angles are three equivalent representations of orientation and all three are From f16e30a44ff5026f1aee502f44f525db2de31d5b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 16 May 2022 00:06:33 -0700 Subject: [PATCH 38/91] bump panda: CAN FD safety (#24545) * bump panda * bump to master --- panda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda b/panda index d5bd81e5b5..69215887dc 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit d5bd81e5b517c79e164d87b96355e6bc75915da0 +Subproject commit 69215887dc5a28170b558f3f7d4f2d87eba42995 From 1dcd5096baecf072ee576d19b2622105ffc167e7 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 16 May 2022 13:19:06 +0200 Subject: [PATCH 39/91] camerad: sanity check register data before parsing (#24547) --- selfdrive/camerad/cameras/camera_qcom2.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/selfdrive/camerad/cameras/camera_qcom2.cc b/selfdrive/camerad/cameras/camera_qcom2.cc index ce9b5663d8..5b88cb3b08 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.cc +++ b/selfdrive/camerad/cameras/camera_qcom2.cc @@ -1196,7 +1196,14 @@ static float ar0231_parse_temp_sensor(uint16_t calib1, uint16_t calib2, uint16_t } static void ar0231_process_registers(MultiCameraState *s, CameraState *c, cereal::FrameData::Builder &framed){ + const uint8_t expected_preamble[] = {0x0a, 0xaa, 0x55, 0x20, 0xa5, 0x55}; uint8_t *data = (uint8_t*)c->buf.cur_camera_buf->addr + c->ci.registers_offset; + + if (memcmp(data, expected_preamble, std::size(expected_preamble)) != 0){ + LOGE("unexpected register data found"); + return; + } + auto registers = c->ar0231_parse_registers(data, {0x2000, 0x2002, 0x20b0, 0x20b2, 0x30c6, 0x30c8, 0x30ca, 0x30cc}); uint32_t frame_id = ((uint32_t)registers[0x2000] << 16) | registers[0x2002]; From 8f9ba7540b4549b4a57312129b8ff678d045f70f Mon Sep 17 00:00:00 2001 From: Joost Wooning Date: Mon, 16 May 2022 13:19:22 +0200 Subject: [PATCH 40/91] debayering: fix divide for reading 12 bit values (#24546) --- selfdrive/camerad/cameras/real_debayer.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index b1b41f2bf1..8dd926adfd 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -60,7 +60,7 @@ inline half val_from_10(const uchar * source, int gx, int gy, half black_level) int offset = gx % 2; uint major = (uint)source[start + offset] << 4; uint minor = (source[start + 2] >> (4 * offset)) & 0xf; - half pv = (half)((major + minor)/4); + half pv = ((half)(major + minor)) / 4.0; // normalize pv = max((half)0.0, pv - black_level); From 2294fcdbe7c87cec6572f813e8f7f31e94841102 Mon Sep 17 00:00:00 2001 From: Joost Wooning Date: Mon, 16 May 2022 13:37:16 +0200 Subject: [PATCH 41/91] debayering: update test ref commit --- selfdrive/test/process_replay/debayer_replay_ref_commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/test/process_replay/debayer_replay_ref_commit b/selfdrive/test/process_replay/debayer_replay_ref_commit index a381ccd0fc..551fc680ba 100644 --- a/selfdrive/test/process_replay/debayer_replay_ref_commit +++ b/selfdrive/test/process_replay/debayer_replay_ref_commit @@ -1 +1 @@ -01ab99d416ffa6fb5f96ebd2091be94a3dc6c6bf \ No newline at end of file +8f9ba7540b4549b4a57312129b8ff678d045f70f \ No newline at end of file From b9c350bf98afeb79489eb5db134d072d54e201f1 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 16 May 2022 13:49:40 +0200 Subject: [PATCH 42/91] Tesla stock AEB forwarding (#24503) * keep long control in sync with the stock system * panda changes needed * add stock AEB state * forgot to add the counter * fix skipping some counter values if they overlap --- panda | 2 +- selfdrive/car/tesla/carcontroller.py | 9 ++++----- selfdrive/car/tesla/carstate.py | 8 ++++++++ selfdrive/car/tesla/teslacan.py | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/panda b/panda index 69215887dc..893a81aa82 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit 69215887dc5a28170b558f3f7d4f2d87eba42995 +Subproject commit 893a81aa823254cd72c9817886d4b4039ea04a7e diff --git a/selfdrive/car/tesla/carcontroller.py b/selfdrive/car/tesla/carcontroller.py index 2c1f55e7de..cf43b8ef00 100644 --- a/selfdrive/car/tesla/carcontroller.py +++ b/selfdrive/car/tesla/carcontroller.py @@ -9,7 +9,6 @@ class CarController: self.CP = CP self.frame = 0 self.last_angle = 0 - self.long_control_counter = 0 self.packer = CANPacker(dbc_name) self.pt_packer = CANPacker(DBC[CP.carFingerprint]['pt']) self.tesla_can = TeslaCAN(self.packer, self.pt_packer) @@ -41,15 +40,15 @@ class CarController: self.last_angle = apply_angle can_sends.append(self.tesla_can.create_steering_control(apply_angle, lkas_enabled, self.frame)) - # Longitudinal control (40Hz) - if self.CP.openpilotLongitudinalControl and self.frame % 5 in (0, 2): + # Longitudinal control (in sync with stock message, about 40Hz) + if self.CP.openpilotLongitudinalControl: target_accel = actuators.accel target_speed = max(CS.out.vEgo + (target_accel * CarControllerParams.ACCEL_TO_SPEED_MULTIPLIER), 0) max_accel = 0 if target_accel < 0 else target_accel min_accel = 0 if target_accel > 0 else target_accel - can_sends.extend(self.tesla_can.create_longitudinal_commands(CS.acc_state, target_speed, min_accel, max_accel, self.long_control_counter)) - self.long_control_counter += 1 + while len(CS.das_control_counters) > 0: + can_sends.extend(self.tesla_can.create_longitudinal_commands(CS.acc_state, target_speed, min_accel, max_accel, CS.das_control_counters.popleft())) # Cancel on user steering override, since there is no steering torque blending if hands_on_fault: diff --git a/selfdrive/car/tesla/carstate.py b/selfdrive/car/tesla/carstate.py index 435beedc9c..0f373842f2 100644 --- a/selfdrive/car/tesla/carstate.py +++ b/selfdrive/car/tesla/carstate.py @@ -1,4 +1,5 @@ import copy +from collections import deque from cereal import car from common.conversions import Conversions as CV from selfdrive.car.tesla.values import DBC, CANBUS, GEAR_MAP, DOORS, BUTTONS @@ -17,6 +18,7 @@ class CarState(CarStateBase): self.hands_on_level = 0 self.steer_warning = None self.acc_state = 0 + self.das_control_counters = deque(maxlen=32) def update(self, cp, cp_cam): ret = car.CarState.new_message() @@ -87,9 +89,13 @@ class CarState(CarStateBase): # TODO: blindspot + # AEB + ret.stockAeb = (cp_cam.vl["DAS_control"]["DAS_aebEvent"] == 1) + # Messages needed by carcontroller self.msg_stw_actn_req = copy.copy(cp.vl["STW_ACTN_RQ"]) self.acc_state = cp_cam.vl["DAS_control"]["DAS_accState"] + self.das_control_counters.extend(cp_cam.vl_all["DAS_control"]["DAS_controlCounter"]) return ret @@ -177,6 +183,8 @@ class CarState(CarStateBase): signals = [ # sig_name, sig_address ("DAS_accState", "DAS_control"), + ("DAS_aebEvent", "DAS_control"), + ("DAS_controlCounter", "DAS_control"), ] checks = [ # sig_address, frequency diff --git a/selfdrive/car/tesla/teslacan.py b/selfdrive/car/tesla/teslacan.py index 17a3b11985..e5d904f80e 100644 --- a/selfdrive/car/tesla/teslacan.py +++ b/selfdrive/car/tesla/teslacan.py @@ -51,7 +51,7 @@ class TeslaCAN: "DAS_jerkMax": CarControllerParams.JERK_LIMIT_MAX, "DAS_accelMin": min_accel, "DAS_accelMax": max_accel, - "DAS_controlCounter": (cnt % 8), + "DAS_controlCounter": cnt, "DAS_controlChecksum": 0, } From 31af13101ba2ad3b6282140c70c07e5298ccffce Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 16 May 2022 16:25:52 +0200 Subject: [PATCH 43/91] Add unittest for alert callbacks (#24551) add alert callback test --- selfdrive/controls/tests/test_alerts.py | 12 ++++++++++-- selfdrive/test/process_replay/process_replay.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/selfdrive/controls/tests/test_alerts.py b/selfdrive/controls/tests/test_alerts.py index 2502bed06b..f340049d06 100755 --- a/selfdrive/controls/tests/test_alerts.py +++ b/selfdrive/controls/tests/test_alerts.py @@ -10,6 +10,7 @@ from common.basedir import BASEDIR from common.params import Params from selfdrive.controls.lib.events import Alert, EVENTS, ET from selfdrive.controls.lib.alertmanager import set_offroad_alert +from selfdrive.test.process_replay.process_replay import FakeSubMaster, CONFIGS AlertSize = log.ControlsState.AlertSize @@ -19,8 +20,7 @@ OFFROAD_ALERTS_PATH = os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offro ALERTS = [] for event_types in EVENTS.values(): for alert in event_types.values(): - if isinstance(alert, Alert): - ALERTS.append(alert) + ALERTS.append(alert) class TestAlerts(unittest.TestCase): @@ -30,6 +30,11 @@ class TestAlerts(unittest.TestCase): with open(OFFROAD_ALERTS_PATH) as f: cls.offroad_alerts = json.loads(f.read()) + # Create fake objects for callback + cls.CP = car.CarParams.new_message() + cfg = [c for c in CONFIGS if c.proc_name == 'controlsd'][0] + cls.sm = FakeSubMaster(cfg.pub_sub.keys()) + def test_events_defined(self): # Ensure all events in capnp schema are defined in events.py events = car.CarEvent.EventName.schema.enumerants @@ -59,6 +64,9 @@ class TestAlerts(unittest.TestCase): } for alert in ALERTS: + if not isinstance(alert, Alert): + alert = alert(self.CP, self.sm, metric=False, soft_disable_time=100) + # for full size alerts, both text fields wrap the text, # so it's unlikely that they would go past the max width if alert.alert_size in (AlertSize.none, AlertSize.full): diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index d7b922863a..03d882591f 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -242,7 +242,7 @@ CONFIGS = [ pub_sub={ "can": ["controlsState", "carState", "carControl", "sendcan", "carEvents", "carParams"], "deviceState": [], "pandaStates": [], "peripheralState": [], "liveCalibration": [], "driverMonitoringState": [], "longitudinalPlan": [], "lateralPlan": [], "liveLocationKalman": [], "liveParameters": [], "radarState": [], - "modelV2": [], "driverCameraState": [], "roadCameraState": [], "managerState": [], + "modelV2": [], "driverCameraState": [], "roadCameraState": [], "managerState": [], "testJoystick": [], }, ignore=["logMonoTime", "valid", "controlsState.startMonoTime", "controlsState.cumLagMs"], init_callback=fingerprint, From 076f0acd5fcd5bca59d9403232c3e37e86db19d1 Mon Sep 17 00:00:00 2001 From: ntegan1 Date: Mon, 16 May 2022 10:26:18 -0400 Subject: [PATCH 44/91] Round model lagging frame drop percentage (#24549) alerts: round model frame drop percentage --- selfdrive/controls/lib/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index 2fbb07cb8c..d41751fd10 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -277,7 +277,7 @@ def high_cpu_usage_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: boo def modeld_lagging_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: - return NormalPermanentAlert("Driving model lagging", f"{sm['modelV2'].frameDropPerc}% frames dropped") + return NormalPermanentAlert("Driving model lagging", f"{sm['modelV2'].frameDropPerc:.1f}% frames dropped") def wrong_car_mode_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: From 8811142787a0690499237e1b449e0d524dc81f35 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 16 May 2022 16:31:14 +0200 Subject: [PATCH 45/91] camerad: improve error logging (#24550) --- selfdrive/camerad/cameras/camera_qcom2.cc | 33 ++++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/selfdrive/camerad/cameras/camera_qcom2.cc b/selfdrive/camerad/cameras/camera_qcom2.cc index 5b88cb3b08..45f414cc7e 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.cc +++ b/selfdrive/camerad/cameras/camera_qcom2.cc @@ -91,8 +91,7 @@ int do_cam_control(int fd, int op_code, void *handle, int size) { int ret = HANDLE_EINTR(ioctl(fd, VIDIOC_CAM_CONTROL, &camcontrol)); if (ret == -1) { - printf("OP CODE ERR - %d \n", op_code); - perror("wat"); + LOGE("VIDIOC_CAM_CONTROL error: op_code %d - errno %d", op_code, errno); } return ret; } @@ -546,7 +545,7 @@ void CameraState::config_isp(int io_mem_handle, int fence, int request_id, int b int ret = device_config(multi_cam_state->isp_fd, session_handle, isp_dev_handle, cam_packet_handle); assert(ret == 0); if (ret != 0) { - printf("ISP CONFIG FAILED\n"); + LOGE("isp config failed"); } mm.free(buf2); @@ -563,7 +562,10 @@ void CameraState::enqueue_buffer(int i, bool dp) { sync_wait.sync_obj = sync_objs[i]; sync_wait.timeout_ms = 50; // max dt tolerance, typical should be 23 ret = do_cam_control(multi_cam_state->cam_sync_fd, CAM_SYNC_WAIT, &sync_wait, sizeof(sync_wait)); - // LOGD("fence wait: %d %d", ret, sync_wait.sync_obj); + if (ret != 0) { + LOGE("failed to wait for sync: %d %d", ret, sync_wait.sync_obj); + // TODO: handle frame drop cleanly + } buf.camera_bufs_metadata[i].timestamp_eof = (uint64_t)nanos_since_boot(); // set true eof if (dp) buf.queue(i); @@ -572,14 +574,18 @@ void CameraState::enqueue_buffer(int i, bool dp) { struct cam_sync_info sync_destroy = {0}; sync_destroy.sync_obj = sync_objs[i]; ret = do_cam_control(multi_cam_state->cam_sync_fd, CAM_SYNC_DESTROY, &sync_destroy, sizeof(sync_destroy)); - // LOGD("fence destroy: %d %d", ret, sync_destroy.sync_obj); + if (ret != 0) { + LOGE("failed to destroy sync object: %d %d", ret, sync_destroy.sync_obj); + } } // create output fence struct cam_sync_info sync_create = {0}; strcpy(sync_create.name, "NodeOutputPortFence"); ret = do_cam_control(multi_cam_state->cam_sync_fd, CAM_SYNC_CREATE, &sync_create, sizeof(sync_create)); - // LOGD("fence req: %d %d", ret, sync_create.sync_obj); + if (ret != 0) { + LOGE("failed to create fence: %d %d", ret, sync_create.sync_obj) + } sync_objs[i] = sync_create.sync_obj; // schedule request with camera request manager @@ -588,11 +594,12 @@ void CameraState::enqueue_buffer(int i, bool dp) { req_mgr_sched_request.link_hdl = link_handle; req_mgr_sched_request.req_id = request_id; ret = do_cam_control(multi_cam_state->video0_fd, CAM_REQ_MGR_SCHED_REQ, &req_mgr_sched_request, sizeof(req_mgr_sched_request)); - // LOGD("sched req: %d %d", ret, request_id); + if (ret != 0) { + LOGE("failed to schedule cam mgr request: %d %d", ret, request_id); + } // poke sensor, must happen after schedule sensors_poke(request_id); - // LOGD("Poked sensor"); // submit request to the ife config_isp(buf_handle[i], sync_objs[i], request_id, buf0_handle, 65632*(i+1)); @@ -873,14 +880,14 @@ void cameras_open(MultiCameraState *s) { sub.type = V4L_EVENT_CAM_REQ_MGR_EVENT; sub.id = V4L_EVENT_CAM_REQ_MGR_SOF_BOOT_TS; ret = HANDLE_EINTR(ioctl(s->video0_fd, VIDIOC_SUBSCRIBE_EVENT, &sub)); - printf("req mgr subscribe: %d\n", ret); + LOGD("req mgr subscribe: %d", ret); s->driver_cam.camera_open(); - printf("driver camera opened \n"); + LOGD("driver camera opened"); s->road_cam.camera_open(); - printf("road camera opened \n"); + LOGD("road camera opened"); s->wide_road_cam.camera_open(); - printf("wide road camera opened \n"); + LOGD("wide road camera opened"); } void CameraState::camera_close() { @@ -1313,7 +1320,7 @@ void cameras_run(MultiCameraState *s) { } else if (event_data->session_hdl == s->driver_cam.session_handle) { s->driver_cam.handle_camera_event(event_data); } else { - printf("Unknown vidioc event source\n"); + LOGE("Unknown vidioc event source"); assert(false); } } From 961a121fde36fca88834e732fc50b34fbd82e94b Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 16 May 2022 09:08:02 -0700 Subject: [PATCH 46/91] Round system overheated temperature (#24544) * Update events.py * Apply suggestions from code review Co-authored-by: Willem Melching --- selfdrive/controls/lib/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index d41751fd10..e493214c80 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -264,7 +264,7 @@ def overheat_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, sof cpu = max(sm['deviceState'].cpuTempC, default=0.) gpu = max(sm['deviceState'].gpuTempC, default=0.) temp = max((cpu, gpu, sm['deviceState'].memoryTempC)) - return NormalPermanentAlert("System Overheated", f"{temp} °C") + return NormalPermanentAlert("System Overheated", f"{temp:.0f} °C") def low_memory_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: From 2c2c61fd77278443cbbf46a93148e1b0aaf5b798 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 16 May 2022 14:30:20 -0700 Subject: [PATCH 47/91] CI: pull LFS after checkout (#24552) --- .github/workflows/release.yaml | 3 ++- .github/workflows/tools_tests.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ac9a31e312..14555f1e7d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,9 +19,10 @@ jobs: running-workflow-name: 'build master-ci' - uses: actions/checkout@v3 with: - lfs: true submodules: true fetch-depth: 0 + - name: Pull LFS + run: git lfs pull - name: Build master-ci run: | BRANCH=master-ci release/build_devel.sh diff --git a/.github/workflows/tools_tests.yaml b/.github/workflows/tools_tests.yaml index 2c2bbd30bd..7b01728e5c 100644 --- a/.github/workflows/tools_tests.yaml +++ b/.github/workflows/tools_tests.yaml @@ -44,8 +44,9 @@ jobs: steps: - uses: actions/checkout@v3 with: - lfs: true submodules: true + - name: Pull LFS + run: git lfs pull - name: Build base image run: eval "$BUILD" - name: Pull latest simulator image From c28735358e48a6360b95e9cc15d47ec16acaa83d Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Tue, 17 May 2022 00:58:13 +0200 Subject: [PATCH 48/91] params: support OPENPILOT_PREFIX (#24495) * prefix params * set env * prefix in manager * filesystem except * dont delete manager folder * Update selfdrive/common/params.h Co-authored-by: Adeeb Shihadeh * debug same path * remove cleanup + same default * dont use filesystem lib * param symlink path * path * spelling Co-authored-by: Adeeb Shihadeh --- selfdrive/common/params.cc | 11 +++++++---- selfdrive/common/params.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index f3c599a36a..f6d7adfd4e 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -60,9 +60,9 @@ bool create_params_path(const std::string ¶m_path, const std::string &key_pa return true; } -std::string ensure_params_path(const std::string &path = {}) { +std::string ensure_params_path(const std::string &prefix, const std::string &path = {}) { std::string params_path = path.empty() ? Path::params() : path; - if (!create_params_path(params_path, params_path + "/d")) { + if (!create_params_path(params_path, params_path + prefix)) { throw std::runtime_error(util::string_format("Failed to ensure params path, errno=%d", errno)); } return params_path; @@ -180,9 +180,12 @@ std::unordered_map keys = { } // namespace + Params::Params(const std::string &path) { - static std::string default_param_path = ensure_params_path(); - params_path = path.empty() ? default_param_path : ensure_params_path(path); + const char* env = std::getenv("OPENPILOT_PREFIX"); + prefix = env ? "/" + std::string(env) : "/d"; + std::string default_param_path = ensure_params_path(prefix); + params_path = path.empty() ? default_param_path : ensure_params_path(prefix, path); } bool Params::checkKey(const std::string &key) { diff --git a/selfdrive/common/params.h b/selfdrive/common/params.h index be09c63d54..aa4b1d7af3 100644 --- a/selfdrive/common/params.h +++ b/selfdrive/common/params.h @@ -18,7 +18,7 @@ public: bool checkKey(const std::string &key); ParamKeyType getKeyType(const std::string &key); inline std::string getParamPath(const std::string &key = {}) { - return key.empty() ? params_path + "/d" : params_path + "/d/" + key; + return params_path + prefix + (key.empty() ? "" : "/" + key); } // Delete a value @@ -43,4 +43,5 @@ public: private: std::string params_path; + std::string prefix; }; From 2a978e36ac0159fa78861e9075f2685fca5b63fe Mon Sep 17 00:00:00 2001 From: George Hotz Date: Mon, 16 May 2022 15:58:09 -0700 Subject: [PATCH 49/91] compressed_vipc: set NV_LOW_LATENCY flag --- tools/camerastream/compressed_vipc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/camerastream/compressed_vipc.py b/tools/camerastream/compressed_vipc.py index 7b6f755ea7..30fe8ec7a8 100755 --- a/tools/camerastream/compressed_vipc.py +++ b/tools/camerastream/compressed_vipc.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import os +os.environ["NV_LOW_LATENCY"] = "3" # both bLowLatency and CUVID_PKT_ENDOFPICTURE import sys import argparse import numpy as np From 3718f9a6e0fdae601b1f90e1f88328609edea885 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Mon, 16 May 2022 16:58:19 -0700 Subject: [PATCH 50/91] encoderd: fix bytesused (#24553) fix bytesused Co-authored-by: Comma Device --- selfdrive/loggerd/encoder/v4l_encoder.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/selfdrive/loggerd/encoder/v4l_encoder.cc b/selfdrive/loggerd/encoder/v4l_encoder.cc index 26d79cc2a9..9ed1f80453 100644 --- a/selfdrive/loggerd/encoder/v4l_encoder.cc +++ b/selfdrive/loggerd/encoder/v4l_encoder.cc @@ -37,10 +37,11 @@ static void dequeue_buffer(int fd, v4l2_buf_type buf_type, unsigned int *index=N assert(v4l_buf.m.planes[0].data_offset == 0); } -static void queue_buffer(int fd, v4l2_buf_type buf_type, unsigned int index, VisionBuf *buf, struct timeval timestamp={0}) { +static void queue_buffer(int fd, v4l2_buf_type buf_type, unsigned int index, VisionBuf *buf, struct timeval timestamp={0}, unsigned int bytesused=0) { v4l2_plane plane = { .length = (unsigned int)buf->len, .m = { .userptr = (unsigned long)buf->addr, }, + .bytesused = bytesused, .reserved = {(unsigned int)buf->fd} }; @@ -275,6 +276,7 @@ int V4LEncoder::encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const u int in_uv_stride = VENUS_UV_STRIDE(COLOR_FMT_NV12, in_width); uint8_t *in_uv_ptr = in_y_ptr + (in_y_stride * VENUS_Y_SCANLINES(COLOR_FMT_NV12, in_height)); + // GRRR COPY int err = libyuv::I420ToNV12(y_ptr, in_width, u_ptr, in_width/2, @@ -292,7 +294,9 @@ int V4LEncoder::encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const u // push buffer extras.push(*extra); buf_in[buffer_in].sync(VISIONBUF_SYNC_TO_DEVICE); - queue_buffer(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, buffer_in, &buf_in[buffer_in], timestamp); + int bytesused = VENUS_Y_STRIDE(COLOR_FMT_NV12, in_width) * VENUS_Y_SCANLINES(COLOR_FMT_NV12, in_height) + + VENUS_UV_STRIDE(COLOR_FMT_NV12, in_width) * VENUS_UV_SCANLINES(COLOR_FMT_NV12, in_height); + queue_buffer(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, buffer_in, &buf_in[buffer_in], timestamp, bytesused); return this->counter++; } From 51d441ad789a74179dab0f56c5c85d5a670dcfce Mon Sep 17 00:00:00 2001 From: Comma Device Date: Mon, 16 May 2022 17:09:42 -0700 Subject: [PATCH 51/91] remove local caching --- selfdrive/camerad/cameras/real_debayer.cl | 74 ++++++----------------- 1 file changed, 19 insertions(+), 55 deletions(-) diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index 8dd926adfd..36fe062dd2 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -83,72 +83,36 @@ inline half get_k(half a, half b, half c, half d) { __kernel void debayer10(const __global uchar * in, __global uchar * out, - __local half * cached, float black_level ) { const int gid_x = get_global_id(0); const int gid_y = get_global_id(1); - const int lid_x = get_local_id(0); - const int lid_y = get_local_id(1); - - const int localRowLen = mad24(get_local_size(0), 2, 2); // 2 padding - const int localColLen = mad24(get_local_size(1), 2, 2); - - const int x_global = mul24(gid_x, 2); - const int y_global = mul24(gid_y, 2); - - const int x_local = mad24(lid_x, 2, 1); - const int y_local = mad24(lid_y, 2, 1); - - const int x_global_mod = (gid_x == 0 || gid_x == get_global_size(0) - 1) ? -1: 1; - const int y_global_mod = (gid_y == 0 || gid_y == get_global_size(1) - 1) ? -1: 1; - - int localColOffset = 0; - int globalColOffset; - - cached[mad24(y_local + 0, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 0, black_level); - cached[mad24(y_local + 0, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 1, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 1, black_level); + half3 rgb; + uchar3 rgb_out[4]; - if (lid_x == 0) { // left edge - localColOffset = -1; - globalColOffset = -x_global_mod; - cached[mad24(y_local + 0, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 1, black_level); - } else if (lid_x == get_local_size(0) - 1) { // right edge - localColOffset = 2; - globalColOffset = x_global_mod + 1; - cached[mad24(y_local + 0, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 1, black_level); - } + half4 va, vb, vc, vd; - if (lid_y == 0) { // top row - cached[mad24(y_local - 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global - y_global_mod, black_level); - cached[mad24(y_local - 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global - y_global_mod, black_level); - if (localColOffset != 0) { // cache corners - cached[mad24(y_local - 1, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global - y_global_mod, black_level); - } - } else if (lid_y == get_local_size(1) - 1) { // bottom row - cached[mad24(y_local + 2, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + y_global_mod + 1, black_level); - cached[mad24(y_local + 2, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + y_global_mod + 1, black_level); - if (localColOffset != 0) { // cache corners - cached[mad24(y_local + 2, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global + y_global_mod + 1, black_level); - } - } + va.s0 = val_from_10(in, gid_x*2-1, gid_y*2-1, black_level); + va.s1 = val_from_10(in, gid_x*2+0, gid_y*2-1, black_level); + va.s2 = val_from_10(in, gid_x*2+1, gid_y*2-1, black_level); + va.s3 = val_from_10(in, gid_x*2+2, gid_y*2-1, black_level); - // sync - barrier(CLK_LOCAL_MEM_FENCE); + vb.s0 = val_from_10(in, gid_x*2-1, gid_y*2+0, black_level); + vb.s1 = val_from_10(in, gid_x*2+0, gid_y*2+0, black_level); // G(R) + vb.s2 = val_from_10(in, gid_x*2+1, gid_y*2+0, black_level); // R + vb.s3 = val_from_10(in, gid_x*2+2, gid_y*2+0, black_level); - half3 rgb; - uchar3 rgb_out[4]; + vc.s0 = val_from_10(in, gid_x*2-1, gid_y*2+1, black_level); + vc.s1 = val_from_10(in, gid_x*2+0, gid_y*2+1, black_level); // B + vc.s2 = val_from_10(in, gid_x*2+1, gid_y*2+1, black_level); // G(B) + vc.s3 = val_from_10(in, gid_x*2+2, gid_y*2+1, black_level); - const half4 va = vload4(0, cached + mad24(lid_y * 2 + 0, localRowLen, lid_x * 2)); - const half4 vb = vload4(0, cached + mad24(lid_y * 2 + 1, localRowLen, lid_x * 2)); - const half4 vc = vload4(0, cached + mad24(lid_y * 2 + 2, localRowLen, lid_x * 2)); - const half4 vd = vload4(0, cached + mad24(lid_y * 2 + 3, localRowLen, lid_x * 2)); + vd.s0 = val_from_10(in, gid_x*2-1, gid_y*2+2, black_level); + vd.s1 = val_from_10(in, gid_x*2+0, gid_y*2+2, black_level); + vd.s2 = val_from_10(in, gid_x*2+1, gid_y*2+2, black_level); + vd.s3 = val_from_10(in, gid_x*2+2, gid_y*2+2, black_level); // a simplified version of https://opensignalprocessingjournal.com/contents/volumes/V6/TOSIGPJ-6-1/TOSIGPJ-6-1.pdf const half k01 = get_k(va.s0, vb.s1, va.s2, vb.s1); From 5612c4f22cdf302f49bfb7b75e9a543e8b3d87c9 Mon Sep 17 00:00:00 2001 From: Comma Device Date: Mon, 16 May 2022 17:10:38 -0700 Subject: [PATCH 52/91] Revert "remove local caching" This reverts commit 51d441ad789a74179dab0f56c5c85d5a670dcfce. --- selfdrive/camerad/cameras/real_debayer.cl | 74 +++++++++++++++++------ 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index 36fe062dd2..8dd926adfd 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -83,36 +83,72 @@ inline half get_k(half a, half b, half c, half d) { __kernel void debayer10(const __global uchar * in, __global uchar * out, + __local half * cached, float black_level ) { const int gid_x = get_global_id(0); const int gid_y = get_global_id(1); - half3 rgb; - uchar3 rgb_out[4]; + const int lid_x = get_local_id(0); + const int lid_y = get_local_id(1); + + const int localRowLen = mad24(get_local_size(0), 2, 2); // 2 padding + const int localColLen = mad24(get_local_size(1), 2, 2); + + const int x_global = mul24(gid_x, 2); + const int y_global = mul24(gid_y, 2); + + const int x_local = mad24(lid_x, 2, 1); + const int y_local = mad24(lid_y, 2, 1); + + const int x_global_mod = (gid_x == 0 || gid_x == get_global_size(0) - 1) ? -1: 1; + const int y_global_mod = (gid_y == 0 || gid_y == get_global_size(1) - 1) ? -1: 1; - half4 va, vb, vc, vd; + int localColOffset = 0; + int globalColOffset; - va.s0 = val_from_10(in, gid_x*2-1, gid_y*2-1, black_level); - va.s1 = val_from_10(in, gid_x*2+0, gid_y*2-1, black_level); - va.s2 = val_from_10(in, gid_x*2+1, gid_y*2-1, black_level); - va.s3 = val_from_10(in, gid_x*2+2, gid_y*2-1, black_level); + cached[mad24(y_local + 0, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 0, black_level); + cached[mad24(y_local + 0, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 1, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 1, black_level); - vb.s0 = val_from_10(in, gid_x*2-1, gid_y*2+0, black_level); - vb.s1 = val_from_10(in, gid_x*2+0, gid_y*2+0, black_level); // G(R) - vb.s2 = val_from_10(in, gid_x*2+1, gid_y*2+0, black_level); // R - vb.s3 = val_from_10(in, gid_x*2+2, gid_y*2+0, black_level); + if (lid_x == 0) { // left edge + localColOffset = -1; + globalColOffset = -x_global_mod; + cached[mad24(y_local + 0, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 1, black_level); + } else if (lid_x == get_local_size(0) - 1) { // right edge + localColOffset = 2; + globalColOffset = x_global_mod + 1; + cached[mad24(y_local + 0, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 0, black_level); + cached[mad24(y_local + 1, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 1, black_level); + } + + if (lid_y == 0) { // top row + cached[mad24(y_local - 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global - y_global_mod, black_level); + cached[mad24(y_local - 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global - y_global_mod, black_level); + if (localColOffset != 0) { // cache corners + cached[mad24(y_local - 1, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global - y_global_mod, black_level); + } + } else if (lid_y == get_local_size(1) - 1) { // bottom row + cached[mad24(y_local + 2, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + y_global_mod + 1, black_level); + cached[mad24(y_local + 2, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + y_global_mod + 1, black_level); + if (localColOffset != 0) { // cache corners + cached[mad24(y_local + 2, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global + y_global_mod + 1, black_level); + } + } - vc.s0 = val_from_10(in, gid_x*2-1, gid_y*2+1, black_level); - vc.s1 = val_from_10(in, gid_x*2+0, gid_y*2+1, black_level); // B - vc.s2 = val_from_10(in, gid_x*2+1, gid_y*2+1, black_level); // G(B) - vc.s3 = val_from_10(in, gid_x*2+2, gid_y*2+1, black_level); + // sync + barrier(CLK_LOCAL_MEM_FENCE); + + half3 rgb; + uchar3 rgb_out[4]; - vd.s0 = val_from_10(in, gid_x*2-1, gid_y*2+2, black_level); - vd.s1 = val_from_10(in, gid_x*2+0, gid_y*2+2, black_level); - vd.s2 = val_from_10(in, gid_x*2+1, gid_y*2+2, black_level); - vd.s3 = val_from_10(in, gid_x*2+2, gid_y*2+2, black_level); + const half4 va = vload4(0, cached + mad24(lid_y * 2 + 0, localRowLen, lid_x * 2)); + const half4 vb = vload4(0, cached + mad24(lid_y * 2 + 1, localRowLen, lid_x * 2)); + const half4 vc = vload4(0, cached + mad24(lid_y * 2 + 2, localRowLen, lid_x * 2)); + const half4 vd = vload4(0, cached + mad24(lid_y * 2 + 3, localRowLen, lid_x * 2)); // a simplified version of https://opensignalprocessingjournal.com/contents/volumes/V6/TOSIGPJ-6-1/TOSIGPJ-6-1.pdf const half k01 = get_k(va.s0, vb.s1, va.s2, vb.s1); From 7996fd37ef127c76aa62afa27f97ad4898fe1898 Mon Sep 17 00:00:00 2001 From: HaraldSchafer Date: Mon, 16 May 2022 17:26:23 -0700 Subject: [PATCH 53/91] Joint model (#24521) * update models * wip lanelines mhp parsing * typos * newer models * 95995a49-db0c-4261-8776-b90780dc2a8c/600 * Use laneful policy to prevent planner aggression * c8c3ab69-bd2c-4d1c-a7f8-9e8457e4827b/950 * ede8f75a-df3e-41fb-bc56-63e2f33858e5/950 * 7205c5af-7532-4215-ad9b-678789054db7/995 * bfb34fa3-1d72-4987-854f-43d42ee01015/950 * change cost * 8ae2477a-b452-4601-b04c-d3af66ea5e98/950 * Update heading cost * 9b991314-94f5-4f0b-872e-58d95266e4d0/333 * 9b991314-94f5-4f0b-872e-58d95266e4d0/950 * ede8f75a-df3e-41fb-bc56-63e2f33858e5/950 * undo lateral planner changes * rm whitespace * update ref * c0acc19d-f2f1-47ae-8838-5382c6c6c7f5/950 * c0acc19d-f2f1-47ae-8838-5382c6c6c7f5/950 * update model refg * Update model ref Co-authored-by: Yassine Yousfi --- selfdrive/modeld/models/driving.cc | 29 ++++++++++------- selfdrive/modeld/models/driving.h | 32 ++++++++++++------- selfdrive/modeld/models/supercombo.dlc | 4 +-- selfdrive/modeld/models/supercombo.onnx | 4 +-- .../process_replay/model_replay_ref_commit | 2 +- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index e0421e8cca..6f635cd8ee 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -228,19 +228,24 @@ void fill_plan(cereal::ModelDataV2::Builder &framed, const ModelOutputPlanPredic void fill_lane_lines(cereal::ModelDataV2::Builder &framed, const std::array &plan_t, const ModelOutputLaneLines &lanes) { + + const auto &left_far = lanes.get_lane_idx(0); + const auto &left_near = lanes.get_lane_idx(1); + const auto &right_near = lanes.get_lane_idx(2); + const auto &right_far = lanes.get_lane_idx(3); std::array left_far_y, left_far_z; std::array left_near_y, left_near_z; std::array right_near_y, right_near_z; std::array right_far_y, right_far_z; for (int j=0; j left_far; - std::array left_near; - std::array right_near; - std::array right_far; -}; -static_assert(sizeof(ModelOutputLinesXY) == sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*4); - struct ModelOutputLineProbVal { float val_deprecated; float val; @@ -99,12 +93,28 @@ struct ModelOutputLinesProb { }; static_assert(sizeof(ModelOutputLinesProb) == sizeof(ModelOutputLineProbVal)*4); +struct ModelOutputLaneLinesElement { + std::array mean; + std::array std; + std::array prob; +}; +static_assert(sizeof(ModelOutputLaneLinesElement) == (sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*2) + sizeof(float)*LANELINES_MHP_N); + struct ModelOutputLaneLines { - ModelOutputLinesXY mean; - ModelOutputLinesXY std; + std::array prediction; ModelOutputLinesProb prob; + + constexpr const ModelOutputLaneLinesElement &get_lane_idx(int lane_idx) const { + int max_idx = 0; + for (int i = 1; i < prediction.size(); i++) { + if (prediction[i].prob[lane_idx] > prediction[max_idx].prob[lane_idx]) { + max_idx = i; + } + } + return prediction[max_idx]; + } }; -static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLinesXY)*2) + sizeof(ModelOutputLinesProb)); +static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLaneLinesElement)*LANELINES_MHP_N) + (sizeof(ModelOutputLinesProb))); struct ModelOutputEdgessXY { std::array left; diff --git a/selfdrive/modeld/models/supercombo.dlc b/selfdrive/modeld/models/supercombo.dlc index a27e3d1180..df9ff4f7e7 100644 --- a/selfdrive/modeld/models/supercombo.dlc +++ b/selfdrive/modeld/models/supercombo.dlc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba3fe3e61853cc1434e3e220f40c8e9d1f1b9bab8458196ba3bea6a10b82c6ed -size 72718099 +oid sha256:c67435e36760a0335154d784d880baf10f3be3c16dd9de53cf20a85d43813c17 +size 76722695 diff --git a/selfdrive/modeld/models/supercombo.onnx b/selfdrive/modeld/models/supercombo.onnx index 3039035fbc..aa72618929 100644 --- a/selfdrive/modeld/models/supercombo.onnx +++ b/selfdrive/modeld/models/supercombo.onnx @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bda57c1a66944f5a633ecd739a24d62702c717a234f2fdcc499dfa1d61c3c19e -size 73147489 +oid sha256:a83fd5f6ce4bba18d18491341f916492414fa012552ecaa8bca3d1273292b0ec +size 77115165 diff --git a/selfdrive/test/process_replay/model_replay_ref_commit b/selfdrive/test/process_replay/model_replay_ref_commit index bf4e1eadb8..d4ae01287f 100644 --- a/selfdrive/test/process_replay/model_replay_ref_commit +++ b/selfdrive/test/process_replay/model_replay_ref_commit @@ -1 +1 @@ -5fb5cd71a6e878cf45593ecea22c93e932f70c31 \ No newline at end of file +0c93e2e8951a249ebdae55bb49354d918b5e7f85 From 20887755430e52c8c41fb67968d866d8d123734b Mon Sep 17 00:00:00 2001 From: ntegan1 Date: Mon, 16 May 2022 21:53:02 -0400 Subject: [PATCH 54/91] Include master commit and build date in master-ci commit (#24548) * save commit information in master-ci * cleanup Co-authored-by: Adeeb Shihadeh --- release/build_devel.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/release/build_devel.sh b/release/build_devel.sh index 8028b74639..d2411da697 100755 --- a/release/build_devel.sh +++ b/release/build_devel.sh @@ -51,20 +51,23 @@ if [ ! -z "$EXTRA_FILES" ]; then cp -pR --parents $EXTRA_FILES $TARGET_DIR/ fi -# append source commit hash and build date to version -GIT_HASH=$(git --git-dir=$SOURCE_DIR/.git rev-parse --short HEAD) -DATETIME=$(date '+%Y-%m-%dT%H:%M:%S') -VERSION=$(cat $SOURCE_DIR/selfdrive/common/version.h | awk -F\" '{print $2}') -#echo "#define COMMA_VERSION \"$VERSION-$GIT_HASH-$DATETIME\"" > $TARGET_DIR/selfdrive/common/version.h - # in the directory cd $TARGET_DIR rm -f panda/board/obj/panda.bin.signed +# include source commit hash and build date in commit +GIT_HASH=$(git --git-dir=$SOURCE_DIR/.git rev-parse HEAD) +DATETIME=$(date '+%Y-%m-%dT%H:%M:%S') +VERSION=$(cat $SOURCE_DIR/selfdrive/common/version.h | awk -F\" '{print $2}') + echo "[-] committing version $VERSION T=$SECONDS" git add -f . git status -git commit -a -m "openpilot v$VERSION release" +git commit -a -m "openpilot v$VERSION release + +date: $DATETIME +master commit: $GIT_HASH +" if [ ! -z "$BRANCH" ]; then echo "[-] Pushing to $BRANCH T=$SECONDS" From fe867df102a393a7a73de07b61d434cec19b3a3c Mon Sep 17 00:00:00 2001 From: George Hotz Date: Mon, 16 May 2022 20:40:11 -0700 Subject: [PATCH 55/91] compressed_vipc: print frame latency --- tools/camerastream/compressed_vipc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/camerastream/compressed_vipc.py b/tools/camerastream/compressed_vipc.py index 30fe8ec7a8..f84b83cd01 100755 --- a/tools/camerastream/compressed_vipc.py +++ b/tools/camerastream/compressed_vipc.py @@ -47,7 +47,8 @@ def decoder(addr, sock_name, vipc_server, vst, nvidia): print("waiting for iframe") continue time_q.append(time.monotonic()) - latency = ((evt.logMonoTime/1e9) - (evta.idx.timestampEof/1e9))*1000 + frame_latency = ((evta.idx.timestampEof/1e9) - (evta.idx.timestampSof/1e9))*1000 + process_latency = ((evt.logMonoTime/1e9) - (evta.idx.timestampEof/1e9))*1000 # put in header (first) if not seen_iframe: @@ -70,14 +71,14 @@ def decoder(addr, sock_name, vipc_server, vst, nvidia): print("DROP SURFACE") continue assert len(frames) == 1 - img_yuv = frames[0].to_ndarray(format=av.video.format.VideoFormat('yuv420p')) + img_yuv = frames[0].to_ndarray(format=av.video.format.VideoFormat('yuv420p')).flatten() - vipc_server.send(vst, img_yuv.flatten().data, cnt, cnt*1e9/20, cnt*1e9/20) + vipc_server.send(vst, img_yuv.data, cnt, cnt*1e9/20, cnt*1e9/20) cnt += 1 pc_latency = (time.monotonic()-time_q[0])*1000 time_q = time_q[1:] - print("%2d %4d %.3f %.3f latency %6.2fms + %6.2f ms" % (len(msgs), evta.idx.encodeId, evt.logMonoTime/1e9, evta.idx.timestampEof/1e6, latency, pc_latency), len(evta.data), sock_name) + print("%2d %4d %.3f %.3f latency %6.2f ms + %6.2f ms + %6.2f ms" % (len(msgs), evta.idx.encodeId, evt.logMonoTime/1e9, evta.idx.timestampEof/1e6, frame_latency, process_latency, pc_latency), len(evta.data), sock_name) if __name__ == "__main__": parser = argparse.ArgumentParser(description='Decode video streams and broacast on VisionIPC') From b1858df00e40f96832f812cb5b42596b8f522ab7 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 16 May 2022 21:19:38 -0700 Subject: [PATCH 56/91] improved alert verbosity (#24434) * improved alert verbosity * better testing script * better description * speed diff * touch ups * fix that --- selfdrive/controls/controlsd.py | 2 +- selfdrive/controls/lib/events.py | 80 +++++++++++++++++-------- selfdrive/controls/tests/test_alerts.py | 5 +- selfdrive/debug/cycle_alerts.py | 56 ++++++++++++----- 4 files changed, 101 insertions(+), 42 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index cf23ec6d80..94cd9c35e1 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -683,7 +683,7 @@ class Controls: if self.enabled: clear_event_types.add(ET.NO_ENTRY) - alerts = self.events.create_alerts(self.current_alert_types, [self.CP, self.sm, self.is_metric, self.soft_disable_timer]) + alerts = self.events.create_alerts(self.current_alert_types, [self.CP, CS, self.sm, self.is_metric, self.soft_disable_timer]) self.AM.add_many(self.sm.frame, alerts) current_alert = self.AM.process_alerts(self.sm.frame, clear_event_types) if current_alert: diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index e493214c80..2fcb34f36d 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -1,3 +1,4 @@ +import math import os from enum import IntEnum from typing import Dict, Union, Callable, List, Optional @@ -141,8 +142,10 @@ class Alert: class NoEntryAlert(Alert): - def __init__(self, alert_text_2: str, visual_alert: car.CarControl.HUDControl.VisualAlert=VisualAlert.none): - super().__init__("openpilot Unavailable", alert_text_2, AlertStatus.normal, + def __init__(self, alert_text_2: str, + alert_text_1: str = "openpilot Unavailable", + visual_alert: car.CarControl.HUDControl.VisualAlert=VisualAlert.none): + super().__init__(alert_text_1, alert_text_2, AlertStatus.normal, AlertSize.mid, Priority.LOW, visual_alert, AudibleAlert.refuse, 3.) @@ -201,35 +204,35 @@ def get_display_speed(speed_ms: float, metric: bool) -> str: # ********** alert callback functions ********** -AlertCallbackType = Callable[[car.CarParams, messaging.SubMaster, bool, int], Alert] +AlertCallbackType = Callable[[car.CarParams, car.CarState, messaging.SubMaster, bool, int], Alert] def soft_disable_alert(alert_text_2: str) -> AlertCallbackType: - def func(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + def func(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: if soft_disable_time < int(0.5 / DT_CTRL): return ImmediateDisableAlert(alert_text_2) return SoftDisableAlert(alert_text_2) return func def user_soft_disable_alert(alert_text_2: str) -> AlertCallbackType: - def func(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + def func(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: if soft_disable_time < int(0.5 / DT_CTRL): return ImmediateDisableAlert(alert_text_2) return UserSoftDisableAlert(alert_text_2) return func -def startup_master_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def startup_master_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: branch = get_short_branch("") if "REPLAY" in os.environ: branch = "replay" return StartupAlert("WARNING: This branch is not tested", branch, alert_status=AlertStatus.userPrompt) -def below_engage_speed_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def below_engage_speed_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: return NoEntryAlert(f"Speed Below {get_display_speed(CP.minEnableSpeed, metric)}") -def below_steer_speed_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def below_steer_speed_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: return Alert( f"Steer Unavailable Below {get_display_speed(CP.minSteerSpeed, metric)}", "", @@ -237,7 +240,7 @@ def below_steer_speed_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: Priority.MID, VisualAlert.steerRequired, AudibleAlert.prompt, 0.4) -def calibration_incomplete_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def calibration_incomplete_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: return Alert( "Calibration in Progress: %d%%" % sm['liveCalibration'].calPerc, f"Drive Above {get_display_speed(MIN_SPEED_FILTER, metric)}", @@ -245,7 +248,7 @@ def calibration_incomplete_alert(CP: car.CarParams, sm: messaging.SubMaster, met Priority.LOWEST, VisualAlert.none, AudibleAlert.none, .2) -def no_gps_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def no_gps_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: gps_integrated = sm['peripheralState'].pandaType in (log.PandaState.PandaType.uno, log.PandaState.PandaType.dos) return Alert( "Poor GPS reception", @@ -255,39 +258,66 @@ def no_gps_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_ # *** debug alerts *** -def out_of_space_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def out_of_space_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: full_perc = round(100. - sm['deviceState'].freeSpacePercent) return NormalPermanentAlert("Out of Storage", f"{full_perc}% full") -def overheat_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def posenet_invalid_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + mdl = sm['modelV2'].velocity.x[0] if len(sm['modelV2'].velocity.x) else math.nan + err = CS.vEgo - mdl + msg = f"Speed Error: {err:.1f} m/s" + return NoEntryAlert(msg, alert_text_1="Posenet Speed Invalid") + + +def process_not_running_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + not_running = [p.name for p in sm['managerState'].processes if not p.running and p.shouldBeRunning] + msg = ', '.join(not_running) + return NoEntryAlert(msg, alert_text_1="Process Not Running") + + +def comm_issue_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + bs = [s for s in sm.data.keys() if not sm.all_checks([s, ])] + msg = ', '.join(bs[:4]) # can't fit too many on one line + return NoEntryAlert(msg, alert_text_1="Communication Issue Between Processes") + + +def calibration_invalid_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + rpy = sm['liveCalibration'].rpyCalib + yaw = math.degrees(rpy[2] if len(rpy) == 3 else math.nan) + pitch = math.degrees(rpy[1] if len(rpy) == 3 else math.nan) + angles = f"Pitch: {pitch:.1f}°, Yaw: {yaw:.1f}°" + return NormalPermanentAlert("Calibration Invalid", angles) + + +def overheat_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: cpu = max(sm['deviceState'].cpuTempC, default=0.) gpu = max(sm['deviceState'].gpuTempC, default=0.) temp = max((cpu, gpu, sm['deviceState'].memoryTempC)) return NormalPermanentAlert("System Overheated", f"{temp:.0f} °C") -def low_memory_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def low_memory_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: return NormalPermanentAlert("Low Memory", f"{sm['deviceState'].memoryUsagePercent}% used") -def high_cpu_usage_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def high_cpu_usage_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: x = max(sm['deviceState'].cpuUsagePercent, default=0.) return NormalPermanentAlert("High CPU Usage", f"{x}% used") -def modeld_lagging_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: - return NormalPermanentAlert("Driving model lagging", f"{sm['modelV2'].frameDropPerc:.1f}% frames dropped") +def modeld_lagging_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + return NormalPermanentAlert("Driving Model Lagging", f"{sm['modelV2'].frameDropPerc:.1f}% frames dropped") -def wrong_car_mode_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def wrong_car_mode_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: text = "Cruise Mode Disabled" if CP.carName == "honda": text = "Main Switch Off" return NoEntryAlert(text) -def joystick_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: +def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: axes = sm['testJoystick'].axes gb, steer = list(axes)[:2] if len(axes) else (0., 0.) vals = f"Gas: {round(gb * 100.)}%, Steer: {round(steer * 100.)}%" @@ -653,7 +683,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # and attaching while making sure the device is pointed straight forward and is level. # See https://comma.ai/setup for more information EventName.calibrationInvalid: { - ET.PERMANENT: NormalPermanentAlert("Calibration Invalid", "Remount Device and Recalibrate"), + ET.PERMANENT: calibration_invalid_alert, ET.SOFT_DISABLE: soft_disable_alert("Calibration Invalid: Remount Device & Recalibrate"), ET.NO_ENTRY: NoEntryAlert("Calibration Invalid: Remount Device & Recalibrate"), }, @@ -690,7 +720,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # ten times the regular interval, or the average interval is more than 10% too high. EventName.commIssue: { ET.SOFT_DISABLE: soft_disable_alert("Communication Issue between Processes"), - ET.NO_ENTRY: NoEntryAlert("Communication Issue between Processes"), + ET.NO_ENTRY: comm_issue_alert, }, EventName.commIssueAvgFreq: { ET.SOFT_DISABLE: soft_disable_alert("Low Communication Rate between Processes"), @@ -704,7 +734,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # Thrown when manager detects a service exited unexpectedly while driving EventName.processNotRunning: { - ET.NO_ENTRY: NoEntryAlert("System Malfunction: Reboot Your Device"), + ET.NO_ENTRY: process_not_running_alert, }, EventName.radarFault: { @@ -716,8 +746,8 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # is not processing frames fast enough they have to be dropped. This alert is # thrown when over 20% of frames are dropped. EventName.modeldLagging: { - ET.SOFT_DISABLE: soft_disable_alert("Driving model lagging"), - ET.NO_ENTRY: NoEntryAlert("Driving model lagging"), + ET.SOFT_DISABLE: soft_disable_alert("Driving Model Lagging"), + ET.NO_ENTRY: NoEntryAlert("Driving Model Lagging"), ET.PERMANENT: modeld_lagging_alert, }, @@ -727,8 +757,8 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # usually means the model has trouble understanding the scene. This is used # as a heuristic to warn the driver. EventName.posenetInvalid: { - ET.SOFT_DISABLE: soft_disable_alert("Model Output Uncertain"), - ET.NO_ENTRY: NoEntryAlert("Model Output Uncertain"), + ET.SOFT_DISABLE: soft_disable_alert("Posenet Speed Invalid"), + ET.NO_ENTRY: posenet_invalid_alert, }, # When the localizer detects an acceleration of more than 40 m/s^2 (~4G) we diff --git a/selfdrive/controls/tests/test_alerts.py b/selfdrive/controls/tests/test_alerts.py index f340049d06..2bd904b575 100755 --- a/selfdrive/controls/tests/test_alerts.py +++ b/selfdrive/controls/tests/test_alerts.py @@ -31,6 +31,7 @@ class TestAlerts(unittest.TestCase): cls.offroad_alerts = json.loads(f.read()) # Create fake objects for callback + cls.CS = car.CarState.new_message() cls.CP = car.CarParams.new_message() cfg = [c for c in CONFIGS if c.proc_name == 'controlsd'][0] cls.sm = FakeSubMaster(cfg.pub_sub.keys()) @@ -53,7 +54,7 @@ class TestAlerts(unittest.TestCase): max_text_width = 1920 - 300 # full screen width is useable, minus sidebar # TODO: get exact scale factor. found this empirically, works well enough - font_scale_factor = 1.85 # factor to scale from nanovg units to PIL + font_scale_factor = 1.55 # factor to scale from nanovg units to PIL draw = ImageDraw.Draw(Image.new('RGB', (0, 0))) @@ -65,7 +66,7 @@ class TestAlerts(unittest.TestCase): for alert in ALERTS: if not isinstance(alert, Alert): - alert = alert(self.CP, self.sm, metric=False, soft_disable_time=100) + alert = alert(self.CP, self.CS, self.sm, metric=False, soft_disable_time=100) # for full size alerts, both text fields wrap the text, # so it's unlikely that they would go past the max width diff --git a/selfdrive/debug/cycle_alerts.py b/selfdrive/debug/cycle_alerts.py index d097367474..f764139f69 100755 --- a/selfdrive/debug/cycle_alerts.py +++ b/selfdrive/debug/cycle_alerts.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import time +import random from cereal import car, log import cereal.messaging as messaging @@ -7,9 +8,13 @@ from common.realtime import DT_CTRL from selfdrive.car.honda.interface import CarInterface from selfdrive.controls.lib.events import ET, Events from selfdrive.controls.lib.alertmanager import AlertManager +from selfdrive.manager.process_config import managed_processes EventName = car.CarEvent.EventName +def randperc() -> float: + return 100. * random.random() + def cycle_alerts(duration=200, is_metric=False): # all alerts #alerts = list(EVENTS.keys()) @@ -31,23 +36,21 @@ def cycle_alerts(duration=200, is_metric=False): # debug alerts alerts = [ - (EventName.highCpuUsage, ET.NO_ENTRY), - (EventName.lowMemory, ET.PERMANENT), - (EventName.overheat, ET.PERMANENT), - (EventName.outOfSpace, ET.PERMANENT), - (EventName.modeldLagging, ET.PERMANENT), + #(EventName.highCpuUsage, ET.NO_ENTRY), + #(EventName.lowMemory, ET.PERMANENT), + #(EventName.overheat, ET.PERMANENT), + #(EventName.outOfSpace, ET.PERMANENT), + #(EventName.modeldLagging, ET.PERMANENT), + #(EventName.processNotRunning, ET.NO_ENTRY), + (EventName.commIssue, ET.NO_ENTRY), + (EventName.calibrationInvalid, ET.PERMANENT), + (EventName.posenetInvalid, ET.NO_ENTRY), ] + CS = car.CarState.new_message() CP = CarInterface.get_params("HONDA CIVIC 2016") sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration', - 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman']) - - sm['deviceState'].freeSpacePercent = 55 - sm['deviceState'].memoryUsagePercent = 55 - sm['deviceState'].cpuTempC = [1, 2, 100] - sm['deviceState'].gpuTempC = [211, 2, 100] - sm['deviceState'].cpuUsagePercent = [23, 54] - sm['modelV2'].frameDropPerc = 20 + 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman', 'managerState']) pm = messaging.PubMaster(['controlsState', 'pandaStates', 'deviceState']) @@ -60,7 +63,32 @@ def cycle_alerts(duration=200, is_metric=False): events.clear() events.add(alert) - a = events.create_alerts([et, ], [CP, sm, is_metric, 0]) + sm['deviceState'].freeSpacePercent = randperc() + sm['deviceState'].memoryUsagePercent = int(randperc()) + sm['deviceState'].cpuTempC = [randperc() for _ in range(3)] + sm['deviceState'].gpuTempC = [randperc() for _ in range(3)] + sm['deviceState'].cpuUsagePercent = [int(randperc()) for _ in range(8)] + sm['modelV2'].frameDropPerc = randperc() + + if random.random() > 0.25: + sm['modelV2'].velocity.x = [random.random(), ] + if random.random() > 0.25: + CS.vEgo = random.random() + + procs = [p.get_process_state_msg() for p in managed_processes.values()] + random.shuffle(procs) + for i in range(random.randint(0, 10)): + procs[i].shouldBeRunning = True + sm['managerState'].processes = procs + + sm['liveCalibration'].rpyCalib = [-1 * random.random() for _ in range(random.randint(0, 3))] + + for s in sm.data.keys(): + sm.alive[s] = random.random() > 0.08 + sm.valid[s] = random.random() > 0.08 + sm.freq_ok[s] = random.random() > 0.08 + + a = events.create_alerts([et, ], [CP, CS, sm, is_metric, 0]) AM.add_many(frame, a) alert = AM.process_alerts(frame, []) print(alert) From e4f844cdd8060bd6699cb80d29d3ee46cbb24ba2 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 16 May 2022 22:00:37 -0700 Subject: [PATCH 57/91] bump opendbc --- opendbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc b/opendbc index 1599f2e370..87af8c4ac1 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit 1599f2e3709633cf3dabf1ebccf5a5c7619f8bb5 +Subproject commit 87af8c4ac192e263bdd4e832d71bb10f480172ec From 0b1f6e3620793a0a06708464387613cec2937591 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 16 May 2022 22:01:04 -0700 Subject: [PATCH 58/91] show which cameras are malfunctioning (#24558) --- selfdrive/controls/lib/events.py | 14 ++++++++++---- selfdrive/debug/cycle_alerts.py | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index 2fcb34f36d..4a67978daf 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -282,6 +282,12 @@ def comm_issue_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaste return NoEntryAlert(msg, alert_text_1="Communication Issue Between Processes") +def camera_malfunction_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + all_cams = ('roadCameraState', 'driverCameraState', 'wideRoadCameraState') + bad_cams = [s for s in all_cams if s in sm.data.keys() and not sm.all_checks([s, ])] + return NormalPermanentAlert("Camera Malfunction", ', '.join(bad_cams)) + + def calibration_invalid_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: rpy = sm['liveCalibration'].rpyCalib yaw = math.degrees(rpy[2] if len(rpy) == 3 else math.nan) @@ -551,7 +557,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # Camera is not outputting frames EventName.cameraMalfunction: { - ET.PERMANENT: NormalPermanentAlert("Camera Malfunction", "Likely Hardware Issue"), + ET.PERMANENT: camera_malfunction_alert, }, # Camera framerate too low EventName.cameraFrameRate: { @@ -882,9 +888,9 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = { # are received on the car side this usually means the relay hasn't opened correctly # and this alert is thrown. EventName.relayMalfunction: { - ET.IMMEDIATE_DISABLE: ImmediateDisableAlert("Harness Malfunction"), - ET.PERMANENT: NormalPermanentAlert("Harness Malfunction", "Check Hardware"), - ET.NO_ENTRY: NoEntryAlert("Harness Malfunction"), + ET.IMMEDIATE_DISABLE: ImmediateDisableAlert("Harness Relay Malfunction"), + ET.PERMANENT: NormalPermanentAlert("Harness Relay Malfunction", "Check Hardware"), + ET.NO_ENTRY: NoEntryAlert("Harness Relay Malfunction"), }, EventName.noTarget: { diff --git a/selfdrive/debug/cycle_alerts.py b/selfdrive/debug/cycle_alerts.py index f764139f69..b40c8e304c 100755 --- a/selfdrive/debug/cycle_alerts.py +++ b/selfdrive/debug/cycle_alerts.py @@ -42,15 +42,19 @@ def cycle_alerts(duration=200, is_metric=False): #(EventName.outOfSpace, ET.PERMANENT), #(EventName.modeldLagging, ET.PERMANENT), #(EventName.processNotRunning, ET.NO_ENTRY), - (EventName.commIssue, ET.NO_ENTRY), - (EventName.calibrationInvalid, ET.PERMANENT), - (EventName.posenetInvalid, ET.NO_ENTRY), + #(EventName.commIssue, ET.NO_ENTRY), + #(EventName.calibrationInvalid, ET.PERMANENT), + (EventName.cameraMalfunction, ET.PERMANENT), + (EventName.cameraFrameRate, ET.PERMANENT), ] + cameras = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState'] + CS = car.CarState.new_message() CP = CarInterface.get_params("HONDA CIVIC 2016") sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration', - 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman', 'managerState']) + 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman', + 'managerState'] + cameras) pm = messaging.PubMaster(['controlsState', 'pandaStates', 'deviceState']) @@ -84,9 +88,10 @@ def cycle_alerts(duration=200, is_metric=False): sm['liveCalibration'].rpyCalib = [-1 * random.random() for _ in range(random.randint(0, 3))] for s in sm.data.keys(): - sm.alive[s] = random.random() > 0.08 - sm.valid[s] = random.random() > 0.08 - sm.freq_ok[s] = random.random() > 0.08 + prob = 0.3 if s in cameras else 0.08 + sm.alive[s] = random.random() > prob + sm.valid[s] = random.random() > prob + sm.freq_ok[s] = random.random() > prob a = events.create_alerts([et, ], [CP, CS, sm, is_metric, 0]) AM.add_many(frame, a) From 72b52f8b7d74bf3ea6fe8bd4d59af1c44c83afdb Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Tue, 17 May 2022 10:18:36 -0700 Subject: [PATCH 59/91] make debayer faster (#24557) * remove local caching * remove local caching * reduce camerad power * break stupid imx390 black level support * handle edges * now 13ms, vignetting is 'slightly' less correct * halfs->floats and inlines, down to 12.9ms * oops, fix float * val from 12 is ushort * don't decide vignetting in the debayer kernel * 7.77 ms * adding back black level support was free * Revert "adding back black level support was free" This reverts commit a841d17727886807a040dcf856ab22480fa93eff. * minor * rip out unused gain and black level, remove print * save 150mW * fix replay test * fix top/bottom rows * lame left right edge fix Co-authored-by: Comma Device Co-authored-by: Joost Wooning --- selfdrive/camerad/cameras/camera_common.cc | 19 +- selfdrive/camerad/cameras/real_debayer.cl | 205 +++++++----------- selfdrive/hardware/tici/test_power_draw.py | 2 +- selfdrive/test/process_replay/test_debayer.py | 3 +- 4 files changed, 83 insertions(+), 146 deletions(-) diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 3e4814e65c..bba65f170e 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -38,26 +38,23 @@ public: "-cl-fast-relaxed-math -cl-denorms-are-zero " "-DFRAME_WIDTH=%d -DFRAME_HEIGHT=%d -DFRAME_STRIDE=%d -DFRAME_OFFSET=%d " "-DRGB_WIDTH=%d -DRGB_HEIGHT=%d -DRGB_STRIDE=%d " - "-DBAYER_FLIP=%d -DHDR=%d -DCAM_NUM=%d", + "-DBAYER_FLIP=%d -DHDR=%d -DCAM_NUM=%d%s", ci->frame_width, ci->frame_height, ci->frame_stride, ci->frame_offset, b->rgb_width, b->rgb_height, b->rgb_stride, - ci->bayer_flip, ci->hdr, s->camera_num); + ci->bayer_flip, ci->hdr, s->camera_num, s->camera_num==1 ? " -DVIGNETTING" : ""); const char *cl_file = "cameras/real_debayer.cl"; cl_program prg_debayer = cl_program_from_file(context, device_id, cl_file, args); krnl_ = CL_CHECK_ERR(clCreateKernel(prg_debayer, "debayer10", &err)); CL_CHECK(clReleaseProgram(prg_debayer)); } - void queue(cl_command_queue q, cl_mem cam_buf_cl, cl_mem buf_cl, int width, int height, float gain, float black_level, cl_event *debayer_event) { + void queue(cl_command_queue q, cl_mem cam_buf_cl, cl_mem buf_cl, int width, int height, cl_event *debayer_event) { CL_CHECK(clSetKernelArg(krnl_, 0, sizeof(cl_mem), &cam_buf_cl)); CL_CHECK(clSetKernelArg(krnl_, 1, sizeof(cl_mem), &buf_cl)); const size_t globalWorkSize[] = {size_t(width / 2), size_t(height / 2)}; const int debayer_local_worksize = 16; - constexpr int localMemSize = (debayer_local_worksize * 2 + 2) * (debayer_local_worksize * 2 + 2) * 2; const size_t localWorkSize[] = {debayer_local_worksize, debayer_local_worksize}; - CL_CHECK(clSetKernelArg(krnl_, 2, localMemSize, 0)); - CL_CHECK(clSetKernelArg(krnl_, 3, sizeof(float), &black_level)); CL_CHECK(clEnqueueNDRangeKernel(q, krnl_, 2, NULL, globalWorkSize, localWorkSize, 0, 0, debayer_event)); } @@ -150,15 +147,7 @@ bool CameraBuf::acquire() { cur_camera_buf = &camera_bufs[cur_buf_idx]; if (debayer) { - float gain = 0.0; - float black_level = 42.0; -#ifndef QCOM2 - gain = camera_state->digital_gain; - if ((int)gain == 0) gain = 1.0; -#else - if (camera_state->camera_id == CAMERA_ID_IMX390) black_level = 64.0; -#endif - debayer->queue(q, camrabuf_cl, cur_yuv_buf->buf_cl, rgb_width, rgb_height, gain, black_level, &event); + debayer->queue(q, camrabuf_cl, cur_yuv_buf->buf_cl, rgb_width, rgb_height, &event); } else { assert(rgb_stride == camera_state->ci.frame_stride); rgb2yuv->queue(q, camrabuf_cl, cur_rgb_buf->buf_cl); diff --git a/selfdrive/camerad/cameras/real_debayer.cl b/selfdrive/camerad/cameras/real_debayer.cl index 8dd926adfd..dc6044ed53 100644 --- a/selfdrive/camerad/cameras/real_debayer.cl +++ b/selfdrive/camerad/cameras/real_debayer.cl @@ -1,12 +1,3 @@ -#ifdef HALF_AS_FLOAT -#define half float -#define half2 float2 -#define half3 float3 -#define half4 float4 -#else -#pragma OPENCL EXTENSION cl_khr_fp16 : enable -#endif - #define UV_WIDTH RGB_WIDTH / 2 #define UV_HEIGHT RGB_HEIGHT / 2 #define U_OFFSET RGB_WIDTH * RGB_HEIGHT @@ -17,171 +8,129 @@ #define RGB_TO_V(r, g, b) ((mul24(r, 56) - mul24(g, 47) - mul24(b, 9) + 0x8080) >> 8) #define AVERAGE(x, y, z, w) ((convert_ushort(x) + convert_ushort(y) + convert_ushort(z) + convert_ushort(w) + 1) >> 1) -// post wb CCM -const __constant half3 color_correction_0 = (half3)(1.82717181, -0.31231438, 0.07307673); -const __constant half3 color_correction_1 = (half3)(-0.5743977, 1.36858544, -0.53183455); -const __constant half3 color_correction_2 = (half3)(-0.25277411, -0.05627105, 1.45875782); +float3 color_correct(float3 rgb) { + // color correction + float3 x = rgb.x * (float3)(1.82717181, -0.31231438, 0.07307673); + x += rgb.y * (float3)(-0.5743977, 1.36858544, -0.53183455); + x += rgb.z * (float3)(-0.25277411, -0.05627105, 1.45875782); -// tone mapping params -const half gamma_k = 0.75; -const half gamma_b = 0.125; -const half mp = 0.01; // ideally midpoint should be adaptive -const half rk = 9 - 100*mp; + // tone mapping params + const float gamma_k = 0.75; + const float gamma_b = 0.125; + const float mp = 0.01; // ideally midpoint should be adaptive + const float rk = 9 - 100*mp; -inline half3 gamma_apply(half3 x) { // poly approximation for s curve return (x > mp) ? ((rk * (x-mp) * (1-(gamma_k*mp+gamma_b)) * (1+1/(rk*(1-mp))) / (1+rk*(x-mp))) + gamma_k*mp + gamma_b) : ((rk * (x-mp) * (gamma_k*mp+gamma_b) * (1+1/(rk*mp)) / (1-rk*(x-mp))) + gamma_k*mp + gamma_b); } -inline half3 color_correct(half3 rgb) { - half3 ret = (half)rgb.x * color_correction_0; - ret += (half)rgb.y * color_correction_1; - ret += (half)rgb.z * color_correction_2; - return gamma_apply(ret); -} - -inline half get_vignetting_s(float r) { +float get_vignetting_s(float r) { if (r < 62500) { - return (half)(1.0f + 0.0000008f*r); + return (1.0f + 0.0000008f*r); } else if (r < 490000) { - return (half)(0.9625f + 0.0000014f*r); + return (0.9625f + 0.0000014f*r); } else if (r < 1102500) { - return (half)(1.26434f + 0.0000000000016f*r*r); + return (1.26434f + 0.0000000000016f*r*r); } else { - return (half)(0.53503625f + 0.0000000000022f*r*r); + return (0.53503625f + 0.0000000000022f*r*r); } } -inline half val_from_10(const uchar * source, int gx, int gy, half black_level) { - // parse 12bit - int start = gy * FRAME_STRIDE + (3 * (gx / 2)) + (FRAME_STRIDE * FRAME_OFFSET); - int offset = gx % 2; - uint major = (uint)source[start + offset] << 4; - uint minor = (source[start + 2] >> (4 * offset)) & 0xf; - half pv = ((half)(major + minor)) / 4.0; - - // normalize - pv = max((half)0.0, pv - black_level); - pv /= (1024.0 - black_level); - - // correct vignetting - if (CAM_NUM == 1) { // fcamera - gx = (gx - RGB_WIDTH/2); - gy = (gy - RGB_HEIGHT/2); - pv *= get_vignetting_s(gx*gx + gy*gy); - } - - pv = clamp(pv, (half)0.0, (half)1.0); - return pv; +float4 val4_from_12(uchar8 pvs, float gain) { + uint4 parsed = (uint4)(((uint)pvs.s0<<4) + (pvs.s1>>4), // is from the previous 10 bit + ((uint)pvs.s2<<4) + (pvs.s4&0xF), + ((uint)pvs.s3<<4) + (pvs.s4>>4), + ((uint)pvs.s5<<4) + (pvs.s7&0xF)); + // normalize and scale + float4 pv = (convert_float4(parsed) - 168.0) / (4096.0 - 168.0); + return clamp(pv*gain, 0.0, 1.0); } -inline half get_k(half a, half b, half c, half d) { +float get_k(float a, float b, float c, float d) { return 2.0 - (fabs(a - b) + fabs(c - d)); } -__kernel void debayer10(const __global uchar * in, - __global uchar * out, - __local half * cached, - float black_level - ) +__kernel void debayer10(const __global uchar * in, __global uchar * out) { const int gid_x = get_global_id(0); const int gid_y = get_global_id(1); - const int lid_x = get_local_id(0); - const int lid_y = get_local_id(1); - - const int localRowLen = mad24(get_local_size(0), 2, 2); // 2 padding - const int localColLen = mad24(get_local_size(1), 2, 2); - - const int x_global = mul24(gid_x, 2); - const int y_global = mul24(gid_y, 2); + const int y_top_mod = (gid_y == 0) ? 2: 0; + const int y_bot_mod = (gid_y == (RGB_HEIGHT/2 - 1)) ? 1: 3; - const int x_local = mad24(lid_x, 2, 1); - const int y_local = mad24(lid_y, 2, 1); - - const int x_global_mod = (gid_x == 0 || gid_x == get_global_size(0) - 1) ? -1: 1; - const int y_global_mod = (gid_y == 0 || gid_y == get_global_size(1) - 1) ? -1: 1; + float3 rgb; + uchar3 rgb_out[4]; - int localColOffset = 0; - int globalColOffset; + int start = (2 * gid_y - 1) * FRAME_STRIDE + (3 * gid_x - 2) + (FRAME_STRIDE * FRAME_OFFSET); - cached[mad24(y_local + 0, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 0, black_level); - cached[mad24(y_local + 0, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + 1, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + 1, black_level); + // read in 8x4 chars + uchar8 dat[4]; + dat[0] = vload8(0, in + start + FRAME_STRIDE*y_top_mod); + dat[1] = vload8(0, in + start + FRAME_STRIDE*1); + dat[2] = vload8(0, in + start + FRAME_STRIDE*2); + dat[3] = vload8(0, in + start + FRAME_STRIDE*y_bot_mod); - if (lid_x == 0) { // left edge - localColOffset = -1; - globalColOffset = -x_global_mod; - cached[mad24(y_local + 0, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local - 1)] = val_from_10(in, x_global - x_global_mod, y_global + 1, black_level); - } else if (lid_x == get_local_size(0) - 1) { // right edge - localColOffset = 2; - globalColOffset = x_global_mod + 1; - cached[mad24(y_local + 0, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 0, black_level); - cached[mad24(y_local + 1, localRowLen, x_local + 2)] = val_from_10(in, x_global + x_global_mod + 1, y_global + 1, black_level); - } - - if (lid_y == 0) { // top row - cached[mad24(y_local - 1, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global - y_global_mod, black_level); - cached[mad24(y_local - 1, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global - y_global_mod, black_level); - if (localColOffset != 0) { // cache corners - cached[mad24(y_local - 1, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global - y_global_mod, black_level); - } - } else if (lid_y == get_local_size(1) - 1) { // bottom row - cached[mad24(y_local + 2, localRowLen, x_local + 0)] = val_from_10(in, x_global + 0, y_global + y_global_mod + 1, black_level); - cached[mad24(y_local + 2, localRowLen, x_local + 1)] = val_from_10(in, x_global + 1, y_global + y_global_mod + 1, black_level); - if (localColOffset != 0) { // cache corners - cached[mad24(y_local + 2, localRowLen, x_local + localColOffset)] = val_from_10(in, x_global + globalColOffset, y_global + y_global_mod + 1, black_level); - } + // correct vignetting + #if VIGNETTING + int gx = (gid_x*2 - RGB_WIDTH/2); + int gy = (gid_y*2 - RGB_HEIGHT/2); + const float gain = get_vignetting_s(gx*gx + gy*gy); + #else + const float gain = 1.0; + #endif + + // process them to floats + float4 va = val4_from_12(dat[0], gain); + float4 vb = val4_from_12(dat[1], gain); + float4 vc = val4_from_12(dat[2], gain); + float4 vd = val4_from_12(dat[3], gain); + + if (gid_x == 0) { + va.s0 = va.s2; + vb.s0 = vb.s2; + vc.s0 = vc.s2; + vd.s0 = vd.s2; + } else if (gid_x == RGB_WIDTH/2 - 1) { + va.s3 = va.s1; + vb.s3 = vb.s1; + vc.s3 = vc.s1; + vd.s3 = vd.s1; } - // sync - barrier(CLK_LOCAL_MEM_FENCE); - - half3 rgb; - uchar3 rgb_out[4]; - - const half4 va = vload4(0, cached + mad24(lid_y * 2 + 0, localRowLen, lid_x * 2)); - const half4 vb = vload4(0, cached + mad24(lid_y * 2 + 1, localRowLen, lid_x * 2)); - const half4 vc = vload4(0, cached + mad24(lid_y * 2 + 2, localRowLen, lid_x * 2)); - const half4 vd = vload4(0, cached + mad24(lid_y * 2 + 3, localRowLen, lid_x * 2)); - // a simplified version of https://opensignalprocessingjournal.com/contents/volumes/V6/TOSIGPJ-6-1/TOSIGPJ-6-1.pdf - const half k01 = get_k(va.s0, vb.s1, va.s2, vb.s1); - const half k02 = get_k(va.s2, vb.s1, vc.s2, vb.s1); - const half k03 = get_k(vc.s0, vb.s1, vc.s2, vb.s1); - const half k04 = get_k(va.s0, vb.s1, vc.s0, vb.s1); + const float k01 = get_k(va.s0, vb.s1, va.s2, vb.s1); + const float k02 = get_k(va.s2, vb.s1, vc.s2, vb.s1); + const float k03 = get_k(vc.s0, vb.s1, vc.s2, vb.s1); + const float k04 = get_k(va.s0, vb.s1, vc.s0, vb.s1); rgb.x = (k02*vb.s2+k04*vb.s0)/(k02+k04); // R_G1 rgb.y = vb.s1; // G1(R) rgb.z = (k01*va.s1+k03*vc.s1)/(k01+k03); // B_G1 rgb_out[0] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); - const half k11 = get_k(va.s1, vc.s1, va.s3, vc.s3); - const half k12 = get_k(va.s2, vb.s1, vb.s3, vc.s2); - const half k13 = get_k(va.s1, va.s3, vc.s1, vc.s3); - const half k14 = get_k(va.s2, vb.s3, vc.s2, vb.s1); + const float k11 = get_k(va.s1, vc.s1, va.s3, vc.s3); + const float k12 = get_k(va.s2, vb.s1, vb.s3, vc.s2); + const float k13 = get_k(va.s1, va.s3, vc.s1, vc.s3); + const float k14 = get_k(va.s2, vb.s3, vc.s2, vb.s1); rgb.x = vb.s2; // R rgb.y = (k11*(va.s2+vc.s2)*0.5+k13*(vb.s3+vb.s1)*0.5)/(k11+k13); // G_R rgb.z = (k12*(va.s3+vc.s1)*0.5+k14*(va.s1+vc.s3)*0.5)/(k12+k14); // B_R rgb_out[1] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); - const half k21 = get_k(vb.s0, vd.s0, vb.s2, vd.s2); - const half k22 = get_k(vb.s1, vc.s0, vc.s2, vd.s1); - const half k23 = get_k(vb.s0, vb.s2, vd.s0, vd.s2); - const half k24 = get_k(vb.s1, vc.s2, vd.s1, vc.s0); + const float k21 = get_k(vb.s0, vd.s0, vb.s2, vd.s2); + const float k22 = get_k(vb.s1, vc.s0, vc.s2, vd.s1); + const float k23 = get_k(vb.s0, vb.s2, vd.s0, vd.s2); + const float k24 = get_k(vb.s1, vc.s2, vd.s1, vc.s0); rgb.x = (k22*(vb.s2+vd.s0)*0.5+k24*(vb.s0+vd.s2)*0.5)/(k22+k24); // R_B rgb.y = (k21*(vb.s1+vd.s1)*0.5+k23*(vc.s2+vc.s0)*0.5)/(k21+k23); // G_B rgb.z = vc.s1; // B rgb_out[2] = convert_uchar3_sat(color_correct(clamp(rgb, 0.0, 1.0)) * 255.0); - const half k31 = get_k(vb.s1, vc.s2, vb.s3, vc.s2); - const half k32 = get_k(vb.s3, vc.s2, vd.s3, vc.s2); - const half k33 = get_k(vd.s1, vc.s2, vd.s3, vc.s2); - const half k34 = get_k(vb.s1, vc.s2, vd.s1, vc.s2); + const float k31 = get_k(vb.s1, vc.s2, vb.s3, vc.s2); + const float k32 = get_k(vb.s3, vc.s2, vd.s3, vc.s2); + const float k33 = get_k(vd.s1, vc.s2, vd.s3, vc.s2); + const float k34 = get_k(vb.s1, vc.s2, vd.s1, vc.s2); rgb.x = (k31*vb.s2+k33*vd.s2)/(k31+k33); // R_G2 rgb.y = vc.s2; // G2(B) rgb.z = (k32*vc.s3+k34*vc.s1)/(k32+k34); // B_G2 diff --git a/selfdrive/hardware/tici/test_power_draw.py b/selfdrive/hardware/tici/test_power_draw.py index 0435193bc8..15892ac5ee 100755 --- a/selfdrive/hardware/tici/test_power_draw.py +++ b/selfdrive/hardware/tici/test_power_draw.py @@ -19,7 +19,7 @@ class Proc: warmup: float = 3. PROCS = [ - Proc('camerad', 2.17), + Proc('camerad', 2.02), Proc('modeld', 0.95), Proc('dmonitoringmodeld', 0.25), Proc('encoderd', 0.42), diff --git a/selfdrive/test/process_replay/test_debayer.py b/selfdrive/test/process_replay/test_debayer.py index a70d478ff9..a17c71b602 100755 --- a/selfdrive/test/process_replay/test_debayer.py +++ b/selfdrive/test/process_replay/test_debayer.py @@ -80,8 +80,7 @@ def debayer_frame(ctx, debayer_prg, data, rgb=False): yuv_g = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, FRAME_WIDTH * FRAME_HEIGHT + UV_SIZE * 2) local_worksize = (20, 20) if TICI else (4, 4) - local_mem = cl.LocalMemory(3528 if TICI else 400) - ev1 = debayer_prg.debayer10(q, (UV_WIDTH, UV_HEIGHT), local_worksize, cam_g, yuv_g, local_mem, np.float32(42)) + ev1 = debayer_prg.debayer10(q, (UV_WIDTH, UV_HEIGHT), local_worksize, cam_g, yuv_g) cl.enqueue_copy(q, yuv_buff, yuv_g, wait_for=[ev1]).wait() cl.enqueue_barrier(q) From 07f7570840320aeb16803e9c93f1d8e648568dba Mon Sep 17 00:00:00 2001 From: ntegan1 Date: Tue, 17 May 2022 13:50:23 -0400 Subject: [PATCH 60/91] Tools: allow using plotjuggler on local data (#24473) local juggler --- tools/lib/route.py | 10 ++++++++- tools/lib/tests/test_route_library.py | 32 +++++++++++++++++++++++++++ tools/plotjuggler/juggle.py | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 tools/lib/tests/test_route_library.py diff --git a/tools/lib/route.py b/tools/lib/route.py index 067fccf188..388cb003e6 100644 --- a/tools/lib/route.py +++ b/tools/lib/route.py @@ -3,6 +3,7 @@ import re from urllib.parse import urlparse from collections import defaultdict from itertools import chain +from typing import Optional from tools.lib.auth_config import get_token from tools.lib.api import CommaApi @@ -196,7 +197,11 @@ class SegmentName: # TODO: add constructor that takes dongle_id, time_str, segment_num and then create instances # of this class instead of manually constructing a segment name (use canonical_name prop instead) def __init__(self, name_str: str, allow_route_name=False): - self._name_str = name_str + data_dir_path_separator_index = name_str.rsplit("|", 1)[0].rfind("/") + use_data_dir = (data_dir_path_separator_index != -1) and ("|" in name_str) + self._name_str = name_str[data_dir_path_separator_index + 1:] if use_data_dir else name_str + self._data_dir = name_str[:data_dir_path_separator_index] if use_data_dir else None + seg_num_delim = "--" if self._name_str.count("--") == 2 else "/" name_parts = self._name_str.rsplit(seg_num_delim, 1) if allow_route_name and len(name_parts) == 1: @@ -220,4 +225,7 @@ class SegmentName: @property def route_name(self) -> RouteName: return self._route_name + @property + def data_dir(self) -> Optional[str]: return self._data_dir + def __str__(self) -> str: return self._canonical_name diff --git a/tools/lib/tests/test_route_library.py b/tools/lib/tests/test_route_library.py new file mode 100755 index 0000000000..fbe7f3e776 --- /dev/null +++ b/tools/lib/tests/test_route_library.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +import unittest +from collections import namedtuple + +from tools.lib.route import SegmentName + +class TestRouteLibrary(unittest.TestCase): + def test_segment_name_formats(self): + Case = namedtuple('Case', ['input', 'expected_route', 'expected_segment_num', 'expected_data_dir']) + + cases = [ Case("4cf7a6ad03080c90|2021-09-29--13-46-36", "4cf7a6ad03080c90|2021-09-29--13-46-36", -1, None), + Case("4cf7a6ad03080c90/2021-09-29--13-46-36--1", "4cf7a6ad03080c90|2021-09-29--13-46-36", 1, None), + Case("4cf7a6ad03080c90|2021-09-29--13-46-36/2", "4cf7a6ad03080c90|2021-09-29--13-46-36", 2, None), + Case("4cf7a6ad03080c90/2021-09-29--13-46-36/3", "4cf7a6ad03080c90|2021-09-29--13-46-36", 3, None), + Case("/data/media/0/realdata/4cf7a6ad03080c90|2021-09-29--13-46-36", "4cf7a6ad03080c90|2021-09-29--13-46-36", -1, "/data/media/0/realdata"), + Case("/data/media/0/realdata/4cf7a6ad03080c90|2021-09-29--13-46-36--1", "4cf7a6ad03080c90|2021-09-29--13-46-36", 1, "/data/media/0/realdata"), + Case("/data/media/0/realdata/4cf7a6ad03080c90|2021-09-29--13-46-36/2", "4cf7a6ad03080c90|2021-09-29--13-46-36", 2, "/data/media/0/realdata") ] + + def _validate(case): + route_or_segment_name = case.input + + s = SegmentName(route_or_segment_name, allow_route_name=True) + + self.assertEqual(str(s.route_name), case.expected_route) + self.assertEqual(s.segment_num, case.expected_segment_num) + self.assertEqual(s.data_dir, case.expected_data_dir) + + for case in cases: + _validate(case) + +if __name__ == "__main__": + unittest.main() diff --git a/tools/plotjuggler/juggle.py b/tools/plotjuggler/juggle.py index 3e8775eb8b..a2bf37bf0e 100755 --- a/tools/plotjuggler/juggle.py +++ b/tools/plotjuggler/juggle.py @@ -88,7 +88,7 @@ def juggle_route(route_or_segment_name, segment_count, qlog, can, layout, dbc=No if route_or_segment_name.segment_num != -1 and segment_count is None: segment_count = 1 - r = Route(route_or_segment_name.route_name.canonical_name) + r = Route(route_or_segment_name.route_name.canonical_name, route_or_segment_name.data_dir) logs = r.qlog_paths() if qlog else r.log_paths() segment_end = segment_start + segment_count if segment_count else None From e08c712a085b7f54f71b7f2e1cf3a7c35ecd4b8a Mon Sep 17 00:00:00 2001 From: omatzyo Date: Tue, 17 May 2022 13:59:15 -0400 Subject: [PATCH 61/91] Toyota: add 2021 RX350 fingerprint (#24540) Update values.py Adding 2021 RX350 --- selfdrive/car/toyota/values.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index e047396c7b..ef47ff9249 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -1718,6 +1718,7 @@ FW_VERSIONS = { b'\x01896634D12000\x00\x00\x00\x00', b'\x01896634D12100\x00\x00\x00\x00', b'\x01896634D43000\x00\x00\x00\x00', + b'\x01896630ED0100\x00\x00\x00\x00', ], (Ecu.esp, 0x7b0, None): [ b'\x01F15260E031\x00\x00\x00\x00\x00\x00', From 61becd444f0ec2f4454884667096e15c5e61bc07 Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Tue, 17 May 2022 13:46:14 -0700 Subject: [PATCH 62/91] Fix tests --- selfdrive/car/tests/test_car_interfaces.py | 2 ++ selfdrive/car/tests/test_models.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/selfdrive/car/tests/test_car_interfaces.py b/selfdrive/car/tests/test_car_interfaces.py index 92024ab0c2..18bf9c1f01 100755 --- a/selfdrive/car/tests/test_car_interfaces.py +++ b/selfdrive/car/tests/test_car_interfaces.py @@ -38,6 +38,8 @@ class TestCarInterfaces(unittest.TestCase): tuning = car_params.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(car_params.lateralTuning.pid.kpV)) + elif tuning == 'lqr': + self.assertTrue(len(car_params.lateralTuning.lqr.a)) elif tuning == 'torque': self.assertTrue(car_params.lateralTuning.torque.kf > 0) elif tuning == 'indi': diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index ff2d49305c..eabfd06f26 100755 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -114,6 +114,8 @@ class TestCarModel(unittest.TestCase): tuning = self.CP.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(self.CP.lateralTuning.pid.kpV)) + elif tuning == 'lqr': + self.assertTrue(len(self.CP.lateralTuning.lqr.a)) elif tuning == 'torque': self.assertTrue(self.CP.lateralTuning.torque.kf > 0) elif tuning == 'indi': From acfa0b74fe5cf0a37b5aa421ee4725cc0ef0640f Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Tue, 17 May 2022 13:48:26 -0700 Subject: [PATCH 63/91] Revert "Fix tests" This reverts commit 61becd444f0ec2f4454884667096e15c5e61bc07. --- selfdrive/car/tests/test_car_interfaces.py | 2 -- selfdrive/car/tests/test_models.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/selfdrive/car/tests/test_car_interfaces.py b/selfdrive/car/tests/test_car_interfaces.py index 18bf9c1f01..92024ab0c2 100755 --- a/selfdrive/car/tests/test_car_interfaces.py +++ b/selfdrive/car/tests/test_car_interfaces.py @@ -38,8 +38,6 @@ class TestCarInterfaces(unittest.TestCase): tuning = car_params.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(car_params.lateralTuning.pid.kpV)) - elif tuning == 'lqr': - self.assertTrue(len(car_params.lateralTuning.lqr.a)) elif tuning == 'torque': self.assertTrue(car_params.lateralTuning.torque.kf > 0) elif tuning == 'indi': diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index eabfd06f26..ff2d49305c 100755 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -114,8 +114,6 @@ class TestCarModel(unittest.TestCase): tuning = self.CP.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(self.CP.lateralTuning.pid.kpV)) - elif tuning == 'lqr': - self.assertTrue(len(self.CP.lateralTuning.lqr.a)) elif tuning == 'torque': self.assertTrue(self.CP.lateralTuning.torque.kf > 0) elif tuning == 'indi': From 06b4466388beafc1b043e850d14b341a8e918f5f Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Wed, 18 May 2022 01:48:48 +0200 Subject: [PATCH 64/91] params: expose getParamPath in python (#24572) * params path * cereal --- common/params_pyx.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index a8c43c2f2f..a64ab58e97 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -20,6 +20,7 @@ cdef extern from "selfdrive/common/params.h": int put(string, string) nogil int putBool(string, bool) nogil bool checkKey(string) nogil + string getParamPath(string) nogil void clearAll(ParamKeyType) @@ -94,6 +95,10 @@ cdef class Params: with nogil: self.p.remove(k) + def get_param_path(self, key=""): + cdef string key_bytes = ensure_bytes(key) + return self.p.getParamPath(key_bytes).decode("utf-8") + def put_nonblocking(key, val, d=""): def f(key, val): params = Params(d) From 0fc4b4df9896ff1466c0443df8c945e4e8a0c3c9 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Tue, 17 May 2022 17:39:18 -0700 Subject: [PATCH 65/91] thneed: add flag to enable optimizer (#24568) * improve the thneed compiler * only init thneed if we are using the GPU Co-authored-by: Comma Device --- selfdrive/modeld/SConscript | 2 +- selfdrive/modeld/runners/snpemodel.cc | 11 +++++-- selfdrive/modeld/runners/snpemodel.h | 3 +- selfdrive/modeld/runners/thneedmodel.cc | 1 - selfdrive/modeld/thneed/compile.cc | 41 ++++++++++++++++++++++--- selfdrive/modeld/thneed/thneed.cc | 14 ++------- selfdrive/modeld/thneed/thneed.h | 3 +- 7 files changed, 53 insertions(+), 22 deletions(-) diff --git a/selfdrive/modeld/SConscript b/selfdrive/modeld/SConscript index 859488356e..1f1c661c8b 100644 --- a/selfdrive/modeld/SConscript +++ b/selfdrive/modeld/SConscript @@ -65,7 +65,7 @@ common_model = lenv.Object(common_src) if use_thneed and arch == "larch64": fn = File("models/supercombo").abspath compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs) - cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} {fn}.dlc {fn}_badweights.thneed --binary" + cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} --in {fn}.dlc --out {fn}_badweights.thneed --binary --optimize" lib_paths = ':'.join(Dir(p).abspath for p in lenv["LIBPATH"]) kernel_path = os.path.join(Dir('.').abspath, "thneed", "kernels") diff --git a/selfdrive/modeld/runners/snpemodel.cc b/selfdrive/modeld/runners/snpemodel.cc index 44fa6ce298..d8ed708fa8 100644 --- a/selfdrive/modeld/runners/snpemodel.cc +++ b/selfdrive/modeld/runners/snpemodel.cc @@ -123,6 +123,12 @@ SNPEModel::SNPEModel(const char *path, float *loutput, size_t loutput_size, int outputBuffer = ubFactory.createUserBuffer(output, output_size * sizeof(float), outputStrides, &userBufferEncodingFloat); outputMap.add(output_tensor_name, outputBuffer.get()); } + +#ifdef USE_THNEED + if (Runtime == zdl::DlSystem::Runtime_t::GPU) { + thneed.reset(new Thneed()); + } +#endif } void SNPEModel::addRecurrent(float *state, int state_size) { @@ -176,7 +182,7 @@ std::unique_ptr SNPEModel::addExtra(float *state, in void SNPEModel::execute() { #ifdef USE_THNEED if (Runtime == zdl::DlSystem::Runtime_t::GPU) { - if (thneed == NULL) { + if (!thneed_recorded) { bool ret = inputBuffer->setBufferAddress(input); assert(ret == true); if (use_extra) { @@ -188,7 +194,7 @@ void SNPEModel::execute() { PrintErrorStringAndExit(); } memset(recurrent, 0, recurrent_size*sizeof(float)); - thneed = new Thneed(); + thneed->record = true; if (!snpe->execute(inputMap, outputMap)) { PrintErrorStringAndExit(); } @@ -220,6 +226,7 @@ void SNPEModel::execute() { assert(false); } free(outputs_golden); + thneed_recorded = true; } else { if (use_extra) { float *inputs[5] = {recurrent, trafficConvention, desire, extra, input}; diff --git a/selfdrive/modeld/runners/snpemodel.h b/selfdrive/modeld/runners/snpemodel.h index 6e9c33f89c..ee5381d6a2 100644 --- a/selfdrive/modeld/runners/snpemodel.h +++ b/selfdrive/modeld/runners/snpemodel.h @@ -32,7 +32,8 @@ public: void execute(); #ifdef USE_THNEED - Thneed *thneed = NULL; + std::unique_ptr thneed; + bool thneed_recorded = false; #endif private: diff --git a/selfdrive/modeld/runners/thneedmodel.cc b/selfdrive/modeld/runners/thneedmodel.cc index edc091bda9..dbe80a9463 100644 --- a/selfdrive/modeld/runners/thneedmodel.cc +++ b/selfdrive/modeld/runners/thneedmodel.cc @@ -4,7 +4,6 @@ ThneedModel::ThneedModel(const char *path, float *loutput, size_t loutput_size, int runtime, bool luse_extra) { thneed = new Thneed(true); - thneed->record = 0; thneed->load(path); thneed->clexec(); thneed->find_inputs_outputs(); diff --git a/selfdrive/modeld/thneed/compile.cc b/selfdrive/modeld/thneed/compile.cc index c22156d2c9..8698ce482e 100644 --- a/selfdrive/modeld/thneed/compile.cc +++ b/selfdrive/modeld/thneed/compile.cc @@ -1,4 +1,5 @@ #include +#include #include "selfdrive/modeld/runners/snpemodel.h" #include "selfdrive/modeld/thneed/thneed.h" @@ -10,10 +11,36 @@ // TODO: This should probably use SNPE directly. int main(int argc, char* argv[]) { + bool run_optimizer = false, save_binaries = false; + const char *input_file = NULL, *output_file = NULL; + static struct option long_options[] = { + {"in", required_argument, 0, 'i' }, + {"out", required_argument, 0, 'o' }, + {"binary", no_argument, 0, 'b' }, + {"optimize", no_argument, 0, 'f' }, + {0, 0, 0, 0 } + }; + int long_index = 0, opt = 0; + while ((opt = getopt_long_only(argc, argv,"", long_options, &long_index)) != -1) { + switch (opt) { + case 'i': input_file = optarg; break; + case 'o': output_file = optarg; break; + case 'b': save_binaries = true; break; + case 'f': run_optimizer = true; break; + } + } + + // no input? + if (!input_file) { + printf("usage: -i -o --binary --optimize\n"); + return -1; + } + #define OUTPUT_SIZE 0x10000 float *output = (float*)calloc(OUTPUT_SIZE, sizeof(float)); - SNPEModel mdl(argv[1], output, 0, USE_GPU_RUNTIME, true); + SNPEModel mdl(input_file, output, 0, USE_GPU_RUNTIME, true); + mdl.thneed->run_optimizer = run_optimizer; float state[TEMPORAL_SIZE] = {0}; float desire[DESIRE_LEN] = {0}; @@ -32,14 +59,20 @@ int main(int argc, char* argv[]) { memset(output, 0, OUTPUT_SIZE * sizeof(float)); mdl.execute(); + // don't save? + if (!output_file) { + printf("no output file, exiting\n"); + return 0; + } + // save model - bool save_binaries = (argc > 3) && (strcmp(argv[3], "--binary") == 0); - mdl.thneed->save(argv[2], save_binaries); + printf("saving %s with binary %d\n", output_file, save_binaries); + mdl.thneed->save(output_file, save_binaries); // test model auto thneed = new Thneed(true); thneed->record = false; - thneed->load(argv[2]); + thneed->load(output_file); thneed->clexec(); thneed->find_inputs_outputs(); diff --git a/selfdrive/modeld/thneed/thneed.cc b/selfdrive/modeld/thneed/thneed.cc index 470ff219b0..90b1200a1a 100644 --- a/selfdrive/modeld/thneed/thneed.cc +++ b/selfdrive/modeld/thneed/thneed.cc @@ -11,8 +11,6 @@ #include "selfdrive/common/clutil.h" #include "selfdrive/common/timing.h" -//#define RUN_DISASSEMBLER -#define RUN_OPTIMIZER Thneed *g_thneed = NULL; int g_fd = -1; @@ -203,11 +201,6 @@ void CachedCommand::exec() { for (auto &it : kq) { it->debug_print(false); } - #ifdef RUN_DISASSEMBLER - // assuming 2 commands - disassemble(0); - disassemble(1); - #endif } assert(ret == 0); @@ -220,7 +213,6 @@ Thneed::Thneed(bool do_clinit) { assert(g_fd != -1); fd = g_fd; ram = make_unique(0x80000, fd); - record = true; timestamp = -1; g_thneed = this; char *thneed_debug_env = getenv("THNEED_DEBUG"); @@ -230,7 +222,7 @@ Thneed::Thneed(bool do_clinit) { void Thneed::stop() { find_inputs_outputs(); printf("Thneed::stop: recorded %lu commands\n", cmds.size()); - record = 0; + record = false; } void Thneed::find_inputs_outputs() { @@ -416,9 +408,7 @@ cl_int thneed_clFinish(cl_command_queue command_queue) { Thneed *thneed = g_thneed; if (thneed != NULL && thneed->record) { - #ifdef RUN_OPTIMIZER - thneed->optimize(); - #endif + if (thneed->run_optimizer) thneed->optimize(); return thneed->clexec(); } else { return clFinish(command_queue); diff --git a/selfdrive/modeld/thneed/thneed.h b/selfdrive/modeld/thneed/thneed.h index b09d32b0ef..0ccea59a3c 100644 --- a/selfdrive/modeld/thneed/thneed.h +++ b/selfdrive/modeld/thneed/thneed.h @@ -94,6 +94,7 @@ class Thneed { void execute(float **finputs, float *foutput, bool slow=false); void wait(); int optimize(); + bool run_optimizer = false; vector input_clmem; vector inputs; @@ -106,7 +107,7 @@ class Thneed { int context_id; // protected? - bool record; + bool record = false; int debug; int timestamp; unique_ptr ram; From 9f8b03753dbdb131fac7bdc021e841cb30b3bf2c Mon Sep 17 00:00:00 2001 From: HaraldSchafer Date: Tue, 17 May 2022 19:00:57 -0700 Subject: [PATCH 66/91] Revert torque control (#24565) * torque reversal start * Fix carmodel tests * Update ref * update ref * Elif is better than if --- release/files_common | 1 + selfdrive/car/tests/test_car_interfaces.py | 2 + selfdrive/car/tests/test_models.py | 2 + selfdrive/car/toyota/interface.py | 11 +-- selfdrive/car/toyota/tunes.py | 10 +++ selfdrive/controls/controlsd.py | 5 ++ selfdrive/controls/lib/latcontrol_lqr.py | 84 +++++++++++++++++++ .../controls/lib/tests/test_latcontrol.py | 4 +- selfdrive/test/process_replay/ref_commit | 2 +- 9 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 selfdrive/controls/lib/latcontrol_lqr.py diff --git a/release/files_common b/release/files_common index 828479f0ef..72902cb94c 100644 --- a/release/files_common +++ b/release/files_common @@ -168,6 +168,7 @@ selfdrive/controls/lib/events.py selfdrive/controls/lib/lane_planner.py selfdrive/controls/lib/latcontrol_angle.py selfdrive/controls/lib/latcontrol_indi.py +selfdrive/controls/lib/latcontrol_lqr.py selfdrive/controls/lib/latcontrol_torque.py selfdrive/controls/lib/latcontrol_pid.py selfdrive/controls/lib/latcontrol.py diff --git a/selfdrive/car/tests/test_car_interfaces.py b/selfdrive/car/tests/test_car_interfaces.py index 92024ab0c2..18bf9c1f01 100755 --- a/selfdrive/car/tests/test_car_interfaces.py +++ b/selfdrive/car/tests/test_car_interfaces.py @@ -38,6 +38,8 @@ class TestCarInterfaces(unittest.TestCase): tuning = car_params.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(car_params.lateralTuning.pid.kpV)) + elif tuning == 'lqr': + self.assertTrue(len(car_params.lateralTuning.lqr.a)) elif tuning == 'torque': self.assertTrue(car_params.lateralTuning.torque.kf > 0) elif tuning == 'indi': diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index ff2d49305c..c73c2b6723 100755 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -116,6 +116,8 @@ class TestCarModel(unittest.TestCase): self.assertTrue(len(self.CP.lateralTuning.pid.kpV)) elif tuning == 'torque': self.assertTrue(self.CP.lateralTuning.torque.kf > 0) + elif tuning == 'lqr': + self.assertTrue(len(self.CP.lateralTuning.lqr.a)) elif tuning == 'indi': self.assertTrue(len(self.CP.lateralTuning.indi.outerLoopGainV)) else: diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index cecb0aa3e8..aa8b449ef9 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -47,7 +47,7 @@ class CarInterface(CarInterfaceBase): ret.steerRatio = 17.4 tire_stiffness_factor = 0.5533 ret.mass = 3340. * CV.LB_TO_KG + STD_CARGO_KG - set_lat_tune(ret.lateralTuning, LatTunes.TORQUE, MAX_LAT_ACCEL=1.8, FRICTION=0.06) + set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4) elif candidate in (CAR.RAV4, CAR.RAV4H): stop_and_go = True if (candidate in CAR.RAV4H) else False @@ -55,7 +55,7 @@ class CarInterface(CarInterfaceBase): ret.steerRatio = 16.88 # 14.5 is spec end-to-end tire_stiffness_factor = 0.5533 ret.mass = 3650. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid - set_lat_tune(ret.lateralTuning, LatTunes.TORQUE, MAX_LAT_ACCEL=1.8, FRICTION=0.06) + set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4) elif candidate == CAR.COROLLA: ret.wheelbase = 2.70 @@ -87,10 +87,7 @@ class CarInterface(CarInterfaceBase): ret.steerRatio = 13.7 tire_stiffness_factor = 0.7933 ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid - if candidate in (CAR.CAMRY_TSS2, CAR.CAMRYH_TSS2): - set_lat_tune(ret.lateralTuning, LatTunes.TORQUE, MAX_LAT_ACCEL=2.4, FRICTION=0.05) - else: - set_lat_tune(ret.lateralTuning, LatTunes.PID_C) + set_lat_tune(ret.lateralTuning, LatTunes.PID_C) elif candidate in (CAR.HIGHLANDER_TSS2, CAR.HIGHLANDERH_TSS2): stop_and_go = True @@ -139,7 +136,7 @@ class CarInterface(CarInterfaceBase): ret.steerRatio = 13.9 tire_stiffness_factor = 0.444 # not optimized yet ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG - set_lat_tune(ret.lateralTuning, LatTunes.TORQUE, MAX_LAT_ACCEL=2.0, FRICTION=0.07) + set_lat_tune(ret.lateralTuning, LatTunes.PID_D) elif candidate in (CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2, CAR.LEXUS_ESH): stop_and_go = True diff --git a/selfdrive/car/toyota/tunes.py b/selfdrive/car/toyota/tunes.py index 7411c0c543..c200e39c0c 100644 --- a/selfdrive/car/toyota/tunes.py +++ b/selfdrive/car/toyota/tunes.py @@ -58,6 +58,16 @@ def set_lat_tune(tune, name, MAX_LAT_ACCEL=2.5, FRICTION=.1): tune.torque.kf = 1.0 / MAX_LAT_ACCEL tune.torque.ki = 0.1 / MAX_LAT_ACCEL tune.torque.friction = FRICTION + elif name == LatTunes.LQR_RAV4: + tune.init('lqr') + tune.lqr.scale = 1500.0 + tune.lqr.ki = 0.05 + tune.lqr.a = [0., 1., -0.22619643, 1.21822268] + tune.lqr.b = [-1.92006585e-04, 3.95603032e-05] + tune.lqr.c = [1., 0.] + tune.lqr.k = [-110.73572306, 451.22718255] + tune.lqr.l = [0.3233671, 0.3185757] + tune.lqr.dcGain = 0.002237852961363602 elif name == LatTunes.INDI_PRIUS: tune.init('indi') tune.indi.innerLoopGainBP = [0.] diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 94cd9c35e1..22377fc2b2 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -23,6 +23,7 @@ from selfdrive.controls.lib.latcontrol_pid import LatControlPID from selfdrive.controls.lib.latcontrol_indi import LatControlINDI from selfdrive.controls.lib.latcontrol_angle import LatControlAngle from selfdrive.controls.lib.latcontrol_torque import LatControlTorque +from selfdrive.controls.lib.latcontrol_lqr import LatControlLQR from selfdrive.controls.lib.events import Events, ET from selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert from selfdrive.controls.lib.vehicle_model import VehicleModel @@ -145,6 +146,8 @@ class Controls: self.LaC = LatControlPID(self.CP, self.CI) elif self.CP.lateralTuning.which() == 'indi': self.LaC = LatControlINDI(self.CP, self.CI) + elif self.CP.lateralTuning.which() == 'lqr': + self.LaC = LatControlLQR(self.CP, self.CI) elif self.CP.lateralTuning.which() == 'torque': self.LaC = LatControlTorque(self.CP, self.CI) @@ -747,6 +750,8 @@ class Controls: controlsState.lateralControlState.pidState = lac_log elif lat_tuning == 'torque': controlsState.lateralControlState.torqueState = lac_log + elif lat_tuning == 'lqr': + controlsState.lateralControlState.lqrState = lac_log elif lat_tuning == 'indi': controlsState.lateralControlState.indiState = lac_log diff --git a/selfdrive/controls/lib/latcontrol_lqr.py b/selfdrive/controls/lib/latcontrol_lqr.py new file mode 100644 index 0000000000..5b4f65a03c --- /dev/null +++ b/selfdrive/controls/lib/latcontrol_lqr.py @@ -0,0 +1,84 @@ +import math +import numpy as np + +from common.numpy_fast import clip +from common.realtime import DT_CTRL +from cereal import log +from selfdrive.controls.lib.latcontrol import LatControl, MIN_STEER_SPEED + + +class LatControlLQR(LatControl): + def __init__(self, CP, CI): + super().__init__(CP, CI) + self.scale = CP.lateralTuning.lqr.scale + self.ki = CP.lateralTuning.lqr.ki + + self.A = np.array(CP.lateralTuning.lqr.a).reshape((2, 2)) + self.B = np.array(CP.lateralTuning.lqr.b).reshape((2, 1)) + self.C = np.array(CP.lateralTuning.lqr.c).reshape((1, 2)) + self.K = np.array(CP.lateralTuning.lqr.k).reshape((1, 2)) + self.L = np.array(CP.lateralTuning.lqr.l).reshape((2, 1)) + self.dc_gain = CP.lateralTuning.lqr.dcGain + + self.x_hat = np.array([[0], [0]]) + self.i_unwind_rate = 0.3 * DT_CTRL + self.i_rate = 1.0 * DT_CTRL + + self.reset() + + def reset(self): + super().reset() + self.i_lqr = 0.0 + + def update(self, active, CS, VM, params, last_actuators, desired_curvature, desired_curvature_rate, llk): + lqr_log = log.ControlsState.LateralLQRState.new_message() + + torque_scale = (0.45 + CS.vEgo / 60.0)**2 # Scale actuator model with speed + + # Subtract offset. Zero angle should correspond to zero torque + steering_angle_no_offset = CS.steeringAngleDeg - params.angleOffsetAverageDeg + + desired_angle = math.degrees(VM.get_steer_from_curvature(-desired_curvature, CS.vEgo, params.roll)) + + instant_offset = params.angleOffsetDeg - params.angleOffsetAverageDeg + desired_angle += instant_offset # Only add offset that originates from vehicle model errors + lqr_log.steeringAngleDesiredDeg = desired_angle + + # Update Kalman filter + angle_steers_k = float(self.C.dot(self.x_hat)) + e = steering_angle_no_offset - angle_steers_k + self.x_hat = self.A.dot(self.x_hat) + self.B.dot(CS.steeringTorqueEps / torque_scale) + self.L.dot(e) + + if CS.vEgo < MIN_STEER_SPEED or not active: + lqr_log.active = False + lqr_output = 0. + output_steer = 0. + self.reset() + else: + lqr_log.active = True + + # LQR + u_lqr = float(desired_angle / self.dc_gain - self.K.dot(self.x_hat)) + lqr_output = torque_scale * u_lqr / self.scale + + # Integrator + if CS.steeringPressed: + self.i_lqr -= self.i_unwind_rate * float(np.sign(self.i_lqr)) + else: + error = desired_angle - angle_steers_k + i = self.i_lqr + self.ki * self.i_rate * error + control = lqr_output + i + + if (error >= 0 and (control <= self.steer_max or i < 0.0)) or \ + (error <= 0 and (control >= -self.steer_max or i > 0.0)): + self.i_lqr = i + + output_steer = lqr_output + self.i_lqr + output_steer = clip(output_steer, -self.steer_max, self.steer_max) + + lqr_log.steeringAngleDeg = angle_steers_k + lqr_log.i = self.i_lqr + lqr_log.output = output_steer + lqr_log.lqrOutput = lqr_output + lqr_log.saturated = self._check_saturation(self.steer_max - abs(output_steer) < 1e-3, CS) + return output_steer, desired_angle, lqr_log diff --git a/selfdrive/controls/lib/tests/test_latcontrol.py b/selfdrive/controls/lib/tests/test_latcontrol.py index 503eaaa6a4..8345840eca 100755 --- a/selfdrive/controls/lib/tests/test_latcontrol.py +++ b/selfdrive/controls/lib/tests/test_latcontrol.py @@ -9,7 +9,7 @@ from selfdrive.car.honda.values import CAR as HONDA from selfdrive.car.toyota.values import CAR as TOYOTA from selfdrive.car.nissan.values import CAR as NISSAN from selfdrive.controls.lib.latcontrol_pid import LatControlPID -from selfdrive.controls.lib.latcontrol_torque import LatControlTorque +from selfdrive.controls.lib.latcontrol_lqr import LatControlLQR from selfdrive.controls.lib.latcontrol_indi import LatControlINDI from selfdrive.controls.lib.latcontrol_angle import LatControlAngle from selfdrive.controls.lib.vehicle_model import VehicleModel @@ -17,7 +17,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel class TestLatControl(unittest.TestCase): - @parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlTorque), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)]) + @parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlLQR), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)]) def test_saturation(self, car_name, controller): CarInterface, CarController, CarState = interfaces[car_name] CP = CarInterface.get_params(car_name) diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 5c039f66b8..276905a432 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -16a3e2f9ef2bf013bc71bed6085a5296eb276f85 +b8c35486e8354713221d4237e97e5abced6f5228 From 3771ccc6550dfe4f0797bb249354f3f52cbf53a3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 17 May 2022 19:42:58 -0700 Subject: [PATCH 67/91] controlsd cpu has crept up --- selfdrive/test/test_onroad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index f098d353d2..725b0dd1ea 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -21,7 +21,7 @@ from tools.lib.logreader import LogReader # Baseline CPU usage by process PROCS = { - "selfdrive.controls.controlsd": 31.0, + "selfdrive.controls.controlsd": 35.0, "./loggerd": 10.0, "./encoderd": 37.3, "./camerad": 16.5, From 194e5fdf1c9ba2e01e2ec7faa62432d2a3b1870b Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Wed, 18 May 2022 12:21:01 +0200 Subject: [PATCH 68/91] make normal logreader more robust (#24577) --- selfdrive/debug/filter_log_message.py | 12 ++++-- tools/lib/logreader.py | 18 ++++++-- tools/lib/robust_logreader.py | 60 --------------------------- tools/plotjuggler/juggle.py | 4 +- 4 files changed, 24 insertions(+), 70 deletions(-) delete mode 100755 tools/lib/robust_logreader.py diff --git a/selfdrive/debug/filter_log_message.py b/selfdrive/debug/filter_log_message.py index 452358cd5c..4ec41699ba 100755 --- a/selfdrive/debug/filter_log_message.py +++ b/selfdrive/debug/filter_log_message.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 +import os import argparse import json import cereal.messaging as messaging -from tools.lib.robust_logreader import RobustLogReader as LogReader +from tools.lib.logreader import LogReader from tools.lib.route import Route LEVELS = { @@ -46,17 +47,20 @@ def print_androidlog(t, msg): if __name__ == "__main__": - parser = argparse.ArgumentParser() parser.add_argument('--level', default='DEBUG') parser.add_argument('--addr', default='127.0.0.1') parser.add_argument("route", type=str, nargs='*', help="route name + segment number for offline usage") args = parser.parse_args() + print(args) logs = None if len(args.route): - r = Route(args.route[0]) - logs = [q_log if r_log is None else r_log for (q_log, r_log) in zip(r.qlog_paths(), r.log_paths())] + if os.path.exists(args.route[0]): + logs = [args.route[0]] + else: + r = Route(args.route[0]) + logs = [q_log if r_log is None else r_log for (q_log, r_log) in zip(r.qlog_paths(), r.log_paths())] if len(args.route) == 2 and logs: n = int(args.route[1]) diff --git a/tools/lib/logreader.py b/tools/lib/logreader.py index 1ad9474701..b4d3de67fb 100755 --- a/tools/lib/logreader.py +++ b/tools/lib/logreader.py @@ -4,6 +4,8 @@ import sys import bz2 import urllib.parse import capnp +import warnings + from cereal import log as capnp_log from tools.lib.filereader import FileReader @@ -70,9 +72,12 @@ class MultiLogIterator: def reset(self): self.__init__(self._log_paths, sort_by_time=self.sort_by_time) + class LogReader: def __init__(self, fn, canonicalize=True, only_union_types=False, sort_by_time=False): - data_version = None + self.data_version = None + self._only_union_types = only_union_types + _, ext = os.path.splitext(urllib.parse.urlparse(fn).path) with FileReader(fn) as f: dat = f.read() @@ -86,10 +91,15 @@ class LogReader: else: raise Exception(f"unknown extension {ext}") - self._ents = list(sorted(ents, key=lambda x: x.logMonoTime) if sort_by_time else ents) + _ents = [] + try: + for e in ents: + _ents.append(e) + except capnp.KjException: + warnings.warn("Corrupted events detected", RuntimeWarning) + + self._ents = list(sorted(_ents, key=lambda x: x.logMonoTime) if sort_by_time else _ents) self._ts = [x.logMonoTime for x in self._ents] - self.data_version = data_version - self._only_union_types = only_union_types def __iter__(self): for ent in self._ents: diff --git a/tools/lib/robust_logreader.py b/tools/lib/robust_logreader.py deleted file mode 100755 index c7feb6c3ed..0000000000 --- a/tools/lib/robust_logreader.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python3 -import os -import bz2 -import urllib.parse -import subprocess -import tqdm -import glob -from tempfile import TemporaryDirectory -import capnp - -from tools.lib.logreader import FileReader, LogReader -from cereal import log as capnp_log - - -class RobustLogReader(LogReader): - def __init__(self, fn, canonicalize=True, only_union_types=False, sort_by_time=False): # pylint: disable=super-init-not-called - data_version = None - _, ext = os.path.splitext(urllib.parse.urlparse(fn).path) - with FileReader(fn) as f: - dat = f.read() - - if ext == "": - pass - elif ext == ".bz2": - try: - dat = bz2.decompress(dat) - except ValueError: - print("Failed to decompress, falling back to bzip2recover") - with TemporaryDirectory() as directory: - # Run bzip2recovery on log - with open(os.path.join(directory, 'out.bz2'), 'wb') as f: - f.write(dat) - subprocess.check_call(["bzip2recover", "out.bz2"], cwd=directory) - - # Decompress and concatenate parts - dat = b"" - for n in sorted(glob.glob(f"{directory}/rec*.bz2")): - print(f"Decompressing {n}") - with open(n, 'rb') as f: - dat += bz2.decompress(f.read()) - else: - raise Exception(f"unknown extension {ext}") - - progress = None - while True: - try: - ents = capnp_log.Event.read_multiple_bytes(dat) - self._ents = list(sorted(ents, key=lambda x: x.logMonoTime) if sort_by_time else ents) - break - except capnp.lib.capnp.KjException: - if progress is None: - progress = tqdm.tqdm(total=len(dat)) - - # Cut off bytes at the end until capnp is able to read - dat = dat[:-1] - progress.update(1) - - self._ts = [x.logMonoTime for x in self._ents] - self.data_version = data_version - self._only_union_types = only_union_types diff --git a/tools/plotjuggler/juggle.py b/tools/plotjuggler/juggle.py index a2bf37bf0e..96ced28349 100755 --- a/tools/plotjuggler/juggle.py +++ b/tools/plotjuggler/juggle.py @@ -12,7 +12,7 @@ import argparse from common.basedir import BASEDIR from selfdrive.test.process_replay.compare_logs import save_log -from tools.lib.robust_logreader import RobustLogReader +from tools.lib.logreader import LogReader from tools.lib.route import Route, SegmentName from urllib.parse import urlparse, parse_qs @@ -50,7 +50,7 @@ def load_segment(segment_name): return [] try: - return list(RobustLogReader(segment_name)) + return list(LogReader(segment_name)) except ValueError as e: print(f"Error parsing {segment_name}: {e}") return [] From fd63de71f092f55613d3a4e8fcb034339c253a50 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Wed, 18 May 2022 12:29:24 +0200 Subject: [PATCH 69/91] remove debug print --- selfdrive/debug/filter_log_message.py | 1 - 1 file changed, 1 deletion(-) diff --git a/selfdrive/debug/filter_log_message.py b/selfdrive/debug/filter_log_message.py index 4ec41699ba..af52953936 100755 --- a/selfdrive/debug/filter_log_message.py +++ b/selfdrive/debug/filter_log_message.py @@ -52,7 +52,6 @@ if __name__ == "__main__": parser.add_argument('--addr', default='127.0.0.1') parser.add_argument("route", type=str, nargs='*', help="route name + segment number for offline usage") args = parser.parse_args() - print(args) logs = None if len(args.route): From e2e5378dd3dbcc35777495a578bd842ba3096fac Mon Sep 17 00:00:00 2001 From: HaraldSchafer Date: Wed, 18 May 2022 10:56:45 -0700 Subject: [PATCH 70/91] Revert "Joint model (#24521)" (#24581) This reverts commit 7996fd37ef127c76aa62afa27f97ad4898fe1898. --- selfdrive/modeld/models/driving.cc | 29 +++++++---------- selfdrive/modeld/models/driving.h | 32 +++++++------------ selfdrive/modeld/models/supercombo.dlc | 4 +-- selfdrive/modeld/models/supercombo.onnx | 4 +-- .../process_replay/model_replay_ref_commit | 2 +- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index 6f635cd8ee..e0421e8cca 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -228,24 +228,19 @@ void fill_plan(cereal::ModelDataV2::Builder &framed, const ModelOutputPlanPredic void fill_lane_lines(cereal::ModelDataV2::Builder &framed, const std::array &plan_t, const ModelOutputLaneLines &lanes) { - - const auto &left_far = lanes.get_lane_idx(0); - const auto &left_near = lanes.get_lane_idx(1); - const auto &right_near = lanes.get_lane_idx(2); - const auto &right_far = lanes.get_lane_idx(3); std::array left_far_y, left_far_z; std::array left_near_y, left_near_z; std::array right_near_y, right_near_z; std::array right_far_y, right_far_z; for (int j=0; j left_far; + std::array left_near; + std::array right_near; + std::array right_far; +}; +static_assert(sizeof(ModelOutputLinesXY) == sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*4); + struct ModelOutputLineProbVal { float val_deprecated; float val; @@ -93,28 +99,12 @@ struct ModelOutputLinesProb { }; static_assert(sizeof(ModelOutputLinesProb) == sizeof(ModelOutputLineProbVal)*4); -struct ModelOutputLaneLinesElement { - std::array mean; - std::array std; - std::array prob; -}; -static_assert(sizeof(ModelOutputLaneLinesElement) == (sizeof(ModelOutputYZ)*TRAJECTORY_SIZE*2) + sizeof(float)*LANELINES_MHP_N); - struct ModelOutputLaneLines { - std::array prediction; + ModelOutputLinesXY mean; + ModelOutputLinesXY std; ModelOutputLinesProb prob; - - constexpr const ModelOutputLaneLinesElement &get_lane_idx(int lane_idx) const { - int max_idx = 0; - for (int i = 1; i < prediction.size(); i++) { - if (prediction[i].prob[lane_idx] > prediction[max_idx].prob[lane_idx]) { - max_idx = i; - } - } - return prediction[max_idx]; - } }; -static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLaneLinesElement)*LANELINES_MHP_N) + (sizeof(ModelOutputLinesProb))); +static_assert(sizeof(ModelOutputLaneLines) == (sizeof(ModelOutputLinesXY)*2) + sizeof(ModelOutputLinesProb)); struct ModelOutputEdgessXY { std::array left; diff --git a/selfdrive/modeld/models/supercombo.dlc b/selfdrive/modeld/models/supercombo.dlc index df9ff4f7e7..a27e3d1180 100644 --- a/selfdrive/modeld/models/supercombo.dlc +++ b/selfdrive/modeld/models/supercombo.dlc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c67435e36760a0335154d784d880baf10f3be3c16dd9de53cf20a85d43813c17 -size 76722695 +oid sha256:ba3fe3e61853cc1434e3e220f40c8e9d1f1b9bab8458196ba3bea6a10b82c6ed +size 72718099 diff --git a/selfdrive/modeld/models/supercombo.onnx b/selfdrive/modeld/models/supercombo.onnx index aa72618929..3039035fbc 100644 --- a/selfdrive/modeld/models/supercombo.onnx +++ b/selfdrive/modeld/models/supercombo.onnx @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a83fd5f6ce4bba18d18491341f916492414fa012552ecaa8bca3d1273292b0ec -size 77115165 +oid sha256:bda57c1a66944f5a633ecd739a24d62702c717a234f2fdcc499dfa1d61c3c19e +size 73147489 diff --git a/selfdrive/test/process_replay/model_replay_ref_commit b/selfdrive/test/process_replay/model_replay_ref_commit index d4ae01287f..bf4e1eadb8 100644 --- a/selfdrive/test/process_replay/model_replay_ref_commit +++ b/selfdrive/test/process_replay/model_replay_ref_commit @@ -1 +1 @@ -0c93e2e8951a249ebdae55bb49354d918b5e7f85 +5fb5cd71a6e878cf45593ecea22c93e932f70c31 \ No newline at end of file From e469803c27d5587df536d41d1d5214b671e59a1e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 18 May 2022 11:45:01 -0700 Subject: [PATCH 71/91] bump cereal --- cereal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cereal b/cereal index b1b0a407b2..e5d0a4ff42 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit b1b0a407b23d9c085fa0661d381d494e74ca719a +Subproject commit e5d0a4ff42d9e1ccbcc7bd603ff5c4e82c0794aa From bb5a05084063ddf5ab2a353c1ca48c3cc8566d74 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 18 May 2022 12:58:12 -0700 Subject: [PATCH 72/91] add to compressed_vipc --- tools/camerastream/compressed_vipc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/camerastream/compressed_vipc.py b/tools/camerastream/compressed_vipc.py index f84b83cd01..34878d6491 100755 --- a/tools/camerastream/compressed_vipc.py +++ b/tools/camerastream/compressed_vipc.py @@ -47,6 +47,7 @@ def decoder(addr, sock_name, vipc_server, vst, nvidia): print("waiting for iframe") continue time_q.append(time.monotonic()) + network_latency = (int(time.time()*1e9) - evta.unixTimestampNanos)/1e6 frame_latency = ((evta.idx.timestampEof/1e9) - (evta.idx.timestampSof/1e9))*1000 process_latency = ((evt.logMonoTime/1e9) - (evta.idx.timestampEof/1e9))*1000 @@ -78,7 +79,7 @@ def decoder(addr, sock_name, vipc_server, vst, nvidia): pc_latency = (time.monotonic()-time_q[0])*1000 time_q = time_q[1:] - print("%2d %4d %.3f %.3f latency %6.2f ms + %6.2f ms + %6.2f ms" % (len(msgs), evta.idx.encodeId, evt.logMonoTime/1e9, evta.idx.timestampEof/1e6, frame_latency, process_latency, pc_latency), len(evta.data), sock_name) + print("%2d %4d %.3f %.3f roll %6.2f ms latency %6.2f ms + %6.2f ms + %6.2f ms = %6.2f ms" % (len(msgs), evta.idx.encodeId, evt.logMonoTime/1e9, evta.idx.timestampEof/1e6, frame_latency, process_latency, network_latency, pc_latency, process_latency+network_latency+pc_latency ), len(evta.data), sock_name) if __name__ == "__main__": parser = argparse.ArgumentParser(description='Decode video streams and broacast on VisionIPC') From c2279ef39dd7a2cda88ec6949b24ff0f71c19983 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Wed, 18 May 2022 12:58:52 -0700 Subject: [PATCH 73/91] add unixTimestampNanos to encoderd (#24583) Co-authored-by: Comma Device --- selfdrive/loggerd/encoder/encoder.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/selfdrive/loggerd/encoder/encoder.cc b/selfdrive/loggerd/encoder/encoder.cc index 86fd441979..943f37803d 100644 --- a/selfdrive/loggerd/encoder/encoder.cc +++ b/selfdrive/loggerd/encoder/encoder.cc @@ -20,6 +20,9 @@ void VideoEncoder::publisher_publish(VideoEncoder *e, int segment_num, uint32_t ((e->type == WideRoadCam) ? event.initWideRoadEncodeData() : (e->in_width == e->out_width ? event.initRoadEncodeData() : event.initQRoadEncodeData())); auto edata = edat.initIdx(); + struct timespec ts; + timespec_get(&ts, TIME_UTC); + edat.setUnixTimestampNanos((uint64_t)ts.tv_sec*1000000000 + ts.tv_nsec); edata.setFrameId(extra.frame_id); edata.setTimestampSof(extra.timestamp_sof); edata.setTimestampEof(extra.timestamp_eof); From e4b7791044003663d354c1734d1744dbe69f36e6 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 18 May 2022 13:18:00 -0700 Subject: [PATCH 74/91] compressed_vipc: use correct system timestamps --- tools/camerastream/compressed_vipc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/camerastream/compressed_vipc.py b/tools/camerastream/compressed_vipc.py index 34878d6491..3a501d3380 100755 --- a/tools/camerastream/compressed_vipc.py +++ b/tools/camerastream/compressed_vipc.py @@ -74,7 +74,7 @@ def decoder(addr, sock_name, vipc_server, vst, nvidia): assert len(frames) == 1 img_yuv = frames[0].to_ndarray(format=av.video.format.VideoFormat('yuv420p')).flatten() - vipc_server.send(vst, img_yuv.data, cnt, cnt*1e9/20, cnt*1e9/20) + vipc_server.send(vst, img_yuv.data, cnt, int(time_q[0]*1e9), int(time.monotonic()*1e9)) cnt += 1 pc_latency = (time.monotonic()-time_q[0])*1000 From cb8885cffb313bea258c012c3026461a22bf8135 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 18 May 2022 14:11:57 -0700 Subject: [PATCH 75/91] Merge common/ and selfdrive/common (#24556) * Merge common/ and selfdrive/common * fix that * fix version * fix unit tests --- .github/workflows/selfdrive_tests.yaml | 4 +- SConstruct | 13 ++-- common/SConscript | 39 +++++++++++- {selfdrive/common => common}/clutil.cc | 4 +- {selfdrive/common => common}/clutil.h | 0 {selfdrive/common => common}/gpio.cc | 4 +- {selfdrive/common => common}/gpio.h | 0 {selfdrive/common => common}/i2c.cc | 8 +-- {selfdrive/common => common}/i2c.h | 0 {selfdrive/common => common}/mat.h | 0 {selfdrive/common => common}/modeldata.h | 2 +- {selfdrive/common => common}/params.cc | 6 +- {selfdrive/common => common}/params.h | 0 common/params_pyx.pyx | 2 +- {selfdrive/common => common}/queue.h | 0 {selfdrive/common => common}/statlog.cc | 4 +- {selfdrive/common => common}/statlog.h | 0 {selfdrive/common => common}/swaglog.cc | 6 +- {selfdrive/common => common}/swaglog.h | 2 +- common/tests/.gitignore | 2 + .../common => common}/tests/test_swaglog.cc | 6 +- .../common => common}/tests/test_util.cc | 2 +- {selfdrive/common => common}/timing.h | 0 {selfdrive/common => common}/util.cc | 2 +- {selfdrive/common => common}/util.h | 0 {selfdrive/common => common}/version.h | 0 {selfdrive/common => common}/visionimg.cc | 2 +- {selfdrive/common => common}/visionimg.h | 0 {selfdrive/common => common}/watchdog.cc | 6 +- {selfdrive/common => common}/watchdog.h | 0 docs/c_docs.rst | 2 +- release/build_devel.sh | 2 +- release/build_release.sh | 4 +- release/files_common | 56 +++++++++--------- scripts/waste.c | 2 +- selfdrive/boardd/boardd.cc | 8 +-- selfdrive/boardd/main.cc | 4 +- selfdrive/boardd/panda.cc | 6 +- selfdrive/boardd/pigeon.cc | 6 +- selfdrive/boardd/tests/test_boardd | Bin 13919544 -> 13919474 bytes selfdrive/camerad/cameras/camera_common.cc | 8 +-- selfdrive/camerad/cameras/camera_common.h | 8 +-- selfdrive/camerad/cameras/camera_qcom2.cc | 2 +- selfdrive/camerad/cameras/camera_qcom2.h | 2 +- selfdrive/camerad/cameras/camera_replay.cc | 4 +- selfdrive/camerad/cameras/camera_webcam.cc | 8 +-- selfdrive/camerad/imgproc/utils.h | 2 +- selfdrive/camerad/main.cc | 4 +- selfdrive/camerad/test/ae_gray_test.cc | 2 +- selfdrive/camerad/transforms/rgb_to_yuv.h | 2 +- .../camerad/transforms/rgb_to_yuv_test.cc | 2 +- selfdrive/clocksd/clocksd.cc | 4 +- selfdrive/common/SConscript | 35 ----------- selfdrive/hardware/hw.h | 2 +- selfdrive/hardware/tici/hardware.h | 4 +- selfdrive/locationd/locationd.h | 8 +-- selfdrive/locationd/ublox_msg.cc | 2 +- selfdrive/locationd/ublox_msg.h | 2 +- selfdrive/locationd/ubloxd.cc | 4 +- selfdrive/logcatd/logcatd_systemd.cc | 4 +- selfdrive/loggerd/bootlog.cc | 2 +- selfdrive/loggerd/encoder/encoder.h | 2 +- selfdrive/loggerd/encoder/ffmpeg_encoder.cc | 4 +- selfdrive/loggerd/encoder/v4l_encoder.cc | 4 +- selfdrive/loggerd/encoder/v4l_encoder.h | 2 +- selfdrive/loggerd/logger.cc | 6 +- selfdrive/loggerd/logger.h | 4 +- selfdrive/loggerd/loggerd.h | 8 +-- selfdrive/loggerd/tests/test_logger.cc | 2 +- selfdrive/loggerd/video_writer.cc | 4 +- selfdrive/modeld/dmonitoringmodeld.cc | 4 +- selfdrive/modeld/modeld.cc | 8 +-- selfdrive/modeld/models/commonmodel.cc | 6 +- selfdrive/modeld/models/commonmodel.h | 2 +- selfdrive/modeld/models/dmonitoring.cc | 8 +-- selfdrive/modeld/models/dmonitoring.h | 2 +- selfdrive/modeld/models/driving.cc | 8 +-- selfdrive/modeld/models/driving.h | 6 +- selfdrive/modeld/runners/onnxmodel.cc | 4 +- selfdrive/modeld/runners/snpemodel.cc | 4 +- selfdrive/modeld/thneed/optimizer.cc | 4 +- selfdrive/modeld/thneed/serialize.cc | 4 +- selfdrive/modeld/thneed/thneed.cc | 4 +- selfdrive/modeld/transforms/loadyuv.h | 2 +- selfdrive/modeld/transforms/transform.cc | 2 +- selfdrive/modeld/transforms/transform.h | 2 +- selfdrive/proclogd/main.cc | 2 +- selfdrive/proclogd/proclog.cc | 4 +- selfdrive/proclogd/tests/test_proclog.cc | 2 +- selfdrive/sensord/sensors/bmx055_accel.cc | 4 +- selfdrive/sensord/sensors/bmx055_gyro.cc | 2 +- selfdrive/sensord/sensors/bmx055_magn.cc | 4 +- selfdrive/sensord/sensors/bmx055_temp.cc | 4 +- selfdrive/sensord/sensors/i2c_sensor.h | 2 +- selfdrive/sensord/sensors/light_sensor.cc | 2 +- selfdrive/sensord/sensors/lsm6ds3_accel.cc | 4 +- selfdrive/sensord/sensors/lsm6ds3_gyro.cc | 4 +- selfdrive/sensord/sensors/lsm6ds3_temp.cc | 4 +- selfdrive/sensord/sensors/mmc5603nj_magn.cc | 4 +- selfdrive/sensord/sensors_qcom2.cc | 8 +-- selfdrive/ui/navd/main.cc | 2 +- selfdrive/ui/navd/map_renderer.cc | 2 +- selfdrive/ui/navd/route_engine.cc | 2 +- selfdrive/ui/qt/api.cc | 4 +- selfdrive/ui/qt/api.h | 2 +- selfdrive/ui/qt/body.cc | 4 +- selfdrive/ui/qt/body.h | 2 +- selfdrive/ui/qt/home.cc | 2 +- selfdrive/ui/qt/maps/map.cc | 2 +- selfdrive/ui/qt/maps/map.h | 4 +- selfdrive/ui/qt/maps/map_helpers.cc | 2 +- selfdrive/ui/qt/maps/map_helpers.h | 2 +- selfdrive/ui/qt/maps/map_settings.cc | 2 +- selfdrive/ui/qt/maps/map_settings.h | 2 +- selfdrive/ui/qt/offroad/driverview.h | 2 +- selfdrive/ui/qt/offroad/onboarding.cc | 4 +- selfdrive/ui/qt/offroad/onboarding.h | 2 +- selfdrive/ui/qt/offroad/settings.cc | 4 +- selfdrive/ui/qt/offroad/wifiManager.cc | 4 +- selfdrive/ui/qt/onroad.cc | 2 +- selfdrive/ui/qt/onroad.h | 2 +- selfdrive/ui/qt/request_repeater.h | 2 +- selfdrive/ui/qt/setup/setup.cc | 2 +- selfdrive/ui/qt/sidebar.h | 2 +- selfdrive/ui/qt/util.cc | 4 +- selfdrive/ui/qt/widgets/controls.h | 2 +- selfdrive/ui/qt/widgets/drive_stats.cc | 2 +- selfdrive/ui/qt/widgets/offroad_alerts.cc | 2 +- selfdrive/ui/qt/widgets/offroad_alerts.h | 2 +- selfdrive/ui/qt/widgets/ssh_keys.cc | 2 +- selfdrive/ui/replay/camera.h | 2 +- selfdrive/ui/replay/consoleui.cc | 2 +- selfdrive/ui/replay/filereader.cc | 2 +- selfdrive/ui/replay/replay.cc | 4 +- selfdrive/ui/replay/tests/test_replay.cc | 2 +- selfdrive/ui/replay/util.cc | 4 +- selfdrive/ui/soundd/sound.cc | 2 +- selfdrive/ui/ui.cc | 8 +-- selfdrive/ui/ui.h | 6 +- selfdrive/version.py | 2 +- 140 files changed, 290 insertions(+), 289 deletions(-) rename {selfdrive/common => common}/clutil.cc (99%) rename {selfdrive/common => common}/clutil.h (100%) rename {selfdrive/common => common}/gpio.cc (92%) rename {selfdrive/common => common}/gpio.h (100%) rename {selfdrive/common => common}/i2c.cc (92%) rename {selfdrive/common => common}/i2c.h (100%) rename {selfdrive/common => common}/mat.h (100%) rename {selfdrive/common => common}/modeldata.h (98%) rename {selfdrive/common => common}/params.cc (98%) rename {selfdrive/common => common}/params.h (100%) rename {selfdrive/common => common}/queue.h (100%) rename {selfdrive/common => common}/statlog.cc (93%) rename {selfdrive/common => common}/statlog.h (100%) rename {selfdrive/common => common}/swaglog.cc (97%) rename {selfdrive/common => common}/swaglog.h (98%) create mode 100644 common/tests/.gitignore rename {selfdrive/common => common}/tests/test_swaglog.cc (95%) rename {selfdrive/common => common}/tests/test_util.cc (99%) rename {selfdrive/common => common}/timing.h (100%) rename {selfdrive/common => common}/util.cc (99%) rename {selfdrive/common => common}/util.h (100%) rename {selfdrive/common => common}/version.h (100%) rename {selfdrive/common => common}/visionimg.cc (90%) rename {selfdrive/common => common}/visionimg.h (100%) rename {selfdrive/common => common}/watchdog.cc (71%) rename {selfdrive/common => common}/watchdog.h (100%) delete mode 100644 selfdrive/common/SConscript diff --git a/.github/workflows/selfdrive_tests.yaml b/.github/workflows/selfdrive_tests.yaml index 144718df60..d5030230a9 100644 --- a/.github/workflows/selfdrive_tests.yaml +++ b/.github/workflows/selfdrive_tests.yaml @@ -291,9 +291,9 @@ jobs: $UNIT_TEST selfdrive/hardware/tici && \ $UNIT_TEST selfdrive/modeld && \ $UNIT_TEST tools/lib/tests && \ + ./common/tests/test_util && \ + ./common/tests/test_swaglog && \ ./selfdrive/boardd/tests/test_boardd_usbprotocol && \ - ./selfdrive/common/tests/test_util && \ - ./selfdrive/common/tests/test_swaglog && \ ./selfdrive/loggerd/tests/test_logger &&\ ./selfdrive/proclogd/tests/test_proclog && \ ./selfdrive/ui/replay/tests/test_replay && \ diff --git a/SConstruct b/SConstruct index 520716859a..a1284ec2e4 100644 --- a/SConstruct +++ b/SConstruct @@ -130,7 +130,7 @@ else: "#third_party/libyuv/x64/lib", "#third_party/mapbox-gl-native-qt/x86_64", "#cereal", - "#selfdrive/common", + "#common", "/usr/lib", "/usr/local/lib", ] @@ -138,7 +138,7 @@ else: rpath += [ Dir("#third_party/snpe/x86_64-linux-clang").abspath, Dir("#cereal").abspath, - Dir("#selfdrive/common").abspath + Dir("#common").abspath ] if GetOption('asan'): @@ -156,8 +156,8 @@ if arch != "Darwin": ldflags += ["-Wl,--as-needed", "-Wl,--no-undefined"] # Enable swaglog include in submodules -cflags += ['-DSWAGLOG="\\"selfdrive/common/swaglog.h\\""'] -cxxflags += ['-DSWAGLOG="\\"selfdrive/common/swaglog.h\\""'] +cflags += ['-DSWAGLOG="\\"common/swaglog.h\\""'] +cxxflags += ['-DSWAGLOG="\\"common/swaglog.h\\""'] env = Environment( ENV=lenv, @@ -212,7 +212,7 @@ env = Environment( "#third_party", "#opendbc/can", "#selfdrive/boardd", - "#selfdrive/common", + "#common", ], CYTHONCFILESUFFIX=".cpp", COMPILATIONDB_USE_ABSPATH=True, @@ -330,7 +330,7 @@ if GetOption("clazy"): Export('env', 'qt_env', 'arch', 'real_arch', 'SHARED', 'USE_WEBCAM') -SConscript(['selfdrive/common/SConscript']) +SConscript(['common/SConscript']) Import('_common', '_gpucommon', '_gpu_libs') if SHARED: @@ -384,7 +384,6 @@ SConscript(['opendbc/can/SConscript']) SConscript(['third_party/SConscript']) -SConscript(['common/SConscript']) SConscript(['common/kalman/SConscript']) SConscript(['common/transformations/SConscript']) diff --git a/common/SConscript b/common/SConscript index a41fc8b7eb..575bdfa65c 100644 --- a/common/SConscript +++ b/common/SConscript @@ -1,4 +1,39 @@ -Import('envCython', 'common') +Import('env', 'envCython', 'arch', 'SHARED') +if SHARED: + fxn = env.SharedLibrary +else: + fxn = env.Library + +common_libs = [ + 'params.cc', + 'statlog.cc', + 'swaglog.cc', + 'util.cc', + 'gpio.cc', + 'i2c.cc', + 'watchdog.cc', +] + +_common = fxn('common', common_libs, LIBS="json11") + +files = [ + 'clutil.cc', + 'visionimg.cc', +] + +if arch == "larch64": + _gpu_libs = ["GLESv2"] +else: + _gpu_libs = ["GL"] + +_gpucommon = fxn('gpucommon', files, LIBS=_gpu_libs) +Export('_common', '_gpucommon', '_gpu_libs') + +if GetOption('test'): + env.Program('tests/test_util', ['tests/test_util.cc'], LIBS=[_common]) + env.Program('tests/test_swaglog', ['tests/test_swaglog.cc'], LIBS=[_common, 'json11', 'zmq', 'pthread']) + +# Cython envCython.Program('clock.so', 'clock.pyx') -envCython.Program('params_pyx.so', 'params_pyx.pyx', LIBS=envCython['LIBS'] + [common, 'zmq']) +envCython.Program('params_pyx.so', 'params_pyx.pyx', LIBS=envCython['LIBS'] + [_common, 'zmq', 'json11']) diff --git a/selfdrive/common/clutil.cc b/common/clutil.cc similarity index 99% rename from selfdrive/common/clutil.cc rename to common/clutil.cc index 4e952a2a88..b8f9fde4cf 100644 --- a/selfdrive/common/clutil.cc +++ b/common/clutil.cc @@ -1,10 +1,10 @@ -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" #include #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" namespace { // helper functions diff --git a/selfdrive/common/clutil.h b/common/clutil.h similarity index 100% rename from selfdrive/common/clutil.h rename to common/clutil.h diff --git a/selfdrive/common/gpio.cc b/common/gpio.cc similarity index 92% rename from selfdrive/common/gpio.cc rename to common/gpio.cc index 033d6da4f7..73ff1b3f52 100644 --- a/selfdrive/common/gpio.cc +++ b/common/gpio.cc @@ -1,11 +1,11 @@ -#include "selfdrive/common/gpio.h" +#include "common/gpio.h" #include #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" // We assume that all pins have already been exported on boot, // and that we have permission to write to them. diff --git a/selfdrive/common/gpio.h b/common/gpio.h similarity index 100% rename from selfdrive/common/gpio.h rename to common/gpio.h diff --git a/selfdrive/common/i2c.cc b/common/i2c.cc similarity index 92% rename from selfdrive/common/i2c.cc rename to common/i2c.cc index 5e6488fabf..eb10cd64bb 100644 --- a/selfdrive/common/i2c.cc +++ b/common/i2c.cc @@ -1,4 +1,4 @@ -#include "selfdrive/common/i2c.h" +#include "common/i2c.h" #include #include @@ -8,9 +8,9 @@ #include #include -#include "selfdrive/common/util.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/util.h" +#include "common/swaglog.h" +#include "common/util.h" #define UNUSED(x) (void)(x) diff --git a/selfdrive/common/i2c.h b/common/i2c.h similarity index 100% rename from selfdrive/common/i2c.h rename to common/i2c.h diff --git a/selfdrive/common/mat.h b/common/mat.h similarity index 100% rename from selfdrive/common/mat.h rename to common/mat.h diff --git a/selfdrive/common/modeldata.h b/common/modeldata.h similarity index 98% rename from selfdrive/common/modeldata.h rename to common/modeldata.h index 6b30e60506..4b776ef945 100644 --- a/selfdrive/common/modeldata.h +++ b/common/modeldata.h @@ -1,7 +1,7 @@ #pragma once #include -#include "selfdrive/common/mat.h" +#include "common/mat.h" #include "selfdrive/hardware/hw.h" const int TRAJECTORY_SIZE = 33; diff --git a/selfdrive/common/params.cc b/common/params.cc similarity index 98% rename from selfdrive/common/params.cc rename to common/params.cc index f6d7adfd4e..4b62fc97a4 100644 --- a/selfdrive/common/params.cc +++ b/common/params.cc @@ -1,4 +1,4 @@ -#include "selfdrive/common/params.h" +#include "common/params.h" #include #include @@ -6,8 +6,8 @@ #include #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" namespace { diff --git a/selfdrive/common/params.h b/common/params.h similarity index 100% rename from selfdrive/common/params.h rename to common/params.h diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index a64ab58e97..b3b8248529 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -4,7 +4,7 @@ from libcpp cimport bool from libcpp.string cimport string import threading -cdef extern from "selfdrive/common/params.h": +cdef extern from "common/params.h": cpdef enum ParamKeyType: PERSISTENT CLEAR_ON_MANAGER_START diff --git a/selfdrive/common/queue.h b/common/queue.h similarity index 100% rename from selfdrive/common/queue.h rename to common/queue.h diff --git a/selfdrive/common/statlog.cc b/common/statlog.cc similarity index 93% rename from selfdrive/common/statlog.cc rename to common/statlog.cc index 54463e9816..26945882d9 100644 --- a/selfdrive/common/statlog.cc +++ b/common/statlog.cc @@ -2,8 +2,8 @@ #define _GNU_SOURCE #endif -#include "selfdrive/common/statlog.h" -#include "selfdrive/common/util.h" +#include "common/statlog.h" +#include "common/util.h" #include #include diff --git a/selfdrive/common/statlog.h b/common/statlog.h similarity index 100% rename from selfdrive/common/statlog.h rename to common/statlog.h diff --git a/selfdrive/common/swaglog.cc b/common/swaglog.cc similarity index 97% rename from selfdrive/common/swaglog.cc rename to common/swaglog.cc index 21115da10f..f0d0f0f508 100644 --- a/selfdrive/common/swaglog.cc +++ b/common/swaglog.cc @@ -2,7 +2,7 @@ #define _GNU_SOURCE #endif -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" #include #include @@ -13,8 +13,8 @@ #include #include "json11.hpp" -#include "selfdrive/common/util.h" -#include "selfdrive/common/version.h" +#include "common/util.h" +#include "common/version.h" #include "selfdrive/hardware/hw.h" class SwaglogState : public LogState { diff --git a/selfdrive/common/swaglog.h b/common/swaglog.h similarity index 98% rename from selfdrive/common/swaglog.h rename to common/swaglog.h index edae9fdc34..68b05ed2e9 100644 --- a/selfdrive/common/swaglog.h +++ b/common/swaglog.h @@ -1,6 +1,6 @@ #pragma once -#include "selfdrive/common/timing.h" +#include "common/timing.h" #define CLOUDLOG_DEBUG 10 #define CLOUDLOG_INFO 20 diff --git a/common/tests/.gitignore b/common/tests/.gitignore new file mode 100644 index 0000000000..1350b3b825 --- /dev/null +++ b/common/tests/.gitignore @@ -0,0 +1,2 @@ +test_util +test_swaglog diff --git a/selfdrive/common/tests/test_swaglog.cc b/common/tests/test_swaglog.cc similarity index 95% rename from selfdrive/common/tests/test_swaglog.cc rename to common/tests/test_swaglog.cc index 47c5504638..a95ae45e03 100644 --- a/selfdrive/common/tests/test_swaglog.cc +++ b/common/tests/test_swaglog.cc @@ -4,9 +4,9 @@ #include "catch2/catch.hpp" #include "json11.hpp" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" -#include "selfdrive/common/version.h" +#include "common/swaglog.h" +#include "common/util.h" +#include "common/version.h" #include "selfdrive/hardware/hw.h" const char *SWAGLOG_ADDR = "ipc:///tmp/logmessage"; diff --git a/selfdrive/common/tests/test_util.cc b/common/tests/test_util.cc similarity index 99% rename from selfdrive/common/tests/test_util.cc rename to common/tests/test_util.cc index 06317accd0..62e73275d4 100644 --- a/selfdrive/common/tests/test_util.cc +++ b/common/tests/test_util.cc @@ -10,7 +10,7 @@ #define CATCH_CONFIG_MAIN #include "catch2/catch.hpp" -#include "selfdrive/common/util.h" +#include "common/util.h" std::string random_bytes(int size) { std::random_device rd; diff --git a/selfdrive/common/timing.h b/common/timing.h similarity index 100% rename from selfdrive/common/timing.h rename to common/timing.h diff --git a/selfdrive/common/util.cc b/common/util.cc similarity index 99% rename from selfdrive/common/util.cc rename to common/util.cc index 534a7f4456..92add63997 100644 --- a/selfdrive/common/util.cc +++ b/common/util.cc @@ -1,4 +1,4 @@ -#include "selfdrive/common/util.h" +#include "common/util.h" #include #include diff --git a/selfdrive/common/util.h b/common/util.h similarity index 100% rename from selfdrive/common/util.h rename to common/util.h diff --git a/selfdrive/common/version.h b/common/version.h similarity index 100% rename from selfdrive/common/version.h rename to common/version.h diff --git a/selfdrive/common/visionimg.cc b/common/visionimg.cc similarity index 90% rename from selfdrive/common/visionimg.cc rename to common/visionimg.cc index b67f0e202d..1009767e0d 100644 --- a/selfdrive/common/visionimg.cc +++ b/common/visionimg.cc @@ -1,4 +1,4 @@ -#include "selfdrive/common/visionimg.h" +#include "common/visionimg.h" #include diff --git a/selfdrive/common/visionimg.h b/common/visionimg.h similarity index 100% rename from selfdrive/common/visionimg.h rename to common/visionimg.h diff --git a/selfdrive/common/watchdog.cc b/common/watchdog.cc similarity index 71% rename from selfdrive/common/watchdog.cc rename to common/watchdog.cc index c937103a5d..5a10207828 100644 --- a/selfdrive/common/watchdog.cc +++ b/common/watchdog.cc @@ -1,6 +1,6 @@ -#include "selfdrive/common/watchdog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/watchdog.h" +#include "common/timing.h" +#include "common/util.h" const std::string watchdog_fn_prefix = "/dev/shm/wd_"; // + diff --git a/selfdrive/common/watchdog.h b/common/watchdog.h similarity index 100% rename from selfdrive/common/watchdog.h rename to common/watchdog.h diff --git a/docs/c_docs.rst b/docs/c_docs.rst index 6cf5f268c5..db7100ab27 100644 --- a/docs/c_docs.rst +++ b/docs/c_docs.rst @@ -86,7 +86,7 @@ modeld common ^^^^^^ .. autodoxygenindex:: - :project: selfdrive_common + :project: common sensorsd ^^^^^^^^ diff --git a/release/build_devel.sh b/release/build_devel.sh index d2411da697..9d8b06451b 100755 --- a/release/build_devel.sh +++ b/release/build_devel.sh @@ -58,7 +58,7 @@ rm -f panda/board/obj/panda.bin.signed # include source commit hash and build date in commit GIT_HASH=$(git --git-dir=$SOURCE_DIR/.git rev-parse HEAD) DATETIME=$(date '+%Y-%m-%dT%H:%M:%S') -VERSION=$(cat $SOURCE_DIR/selfdrive/common/version.h | awk -F\" '{print $2}') +VERSION=$(cat $SOURCE_DIR/common/version.h | awk -F\" '{print $2}') echo "[-] committing version $VERSION T=$SECONDS" git add -f . diff --git a/release/build_release.sh b/release/build_release.sh index f16bc14170..b5e15e05c6 100755 --- a/release/build_release.sh +++ b/release/build_release.sh @@ -41,8 +41,8 @@ cd $BUILD_DIR rm -f panda/board/obj/panda.bin.signed -VERSION=$(cat selfdrive/common/version.h | awk -F[\"-] '{print $2}') -echo "#define COMMA_VERSION \"$VERSION-release\"" > selfdrive/common/version.h +VERSION=$(cat common/version.h | awk -F[\"-] '{print $2}') +echo "#define COMMA_VERSION \"$VERSION-release\"" > common/version.h echo "[-] committing version $VERSION T=$SECONDS" git add -f . diff --git a/release/files_common b/release/files_common index 72902cb94c..b9f5c5746d 100644 --- a/release/files_common +++ b/release/files_common @@ -125,34 +125,34 @@ selfdrive/clocksd/clocksd.cc selfdrive/debug/*.py -selfdrive/common/SConscript -selfdrive/common/version.h - -selfdrive/common/swaglog.h -selfdrive/common/swaglog.cc -selfdrive/common/statlog.h -selfdrive/common/statlog.cc -selfdrive/common/util.cc -selfdrive/common/util.h -selfdrive/common/queue.h -selfdrive/common/clutil.cc -selfdrive/common/clutil.h -selfdrive/common/params.h -selfdrive/common/params.cc -selfdrive/common/watchdog.cc -selfdrive/common/watchdog.h - -selfdrive/common/modeldata.h -selfdrive/common/mat.h -selfdrive/common/timing.h - -selfdrive/common/visionimg.cc -selfdrive/common/visionimg.h - -selfdrive/common/gpio.cc -selfdrive/common/gpio.h -selfdrive/common/i2c.cc -selfdrive/common/i2c.h +common/SConscript +common/version.h + +common/swaglog.h +common/swaglog.cc +common/statlog.h +common/statlog.cc +common/util.cc +common/util.h +common/queue.h +common/clutil.cc +common/clutil.h +common/params.h +common/params.cc +common/watchdog.cc +common/watchdog.h + +common/modeldata.h +common/mat.h +common/timing.h + +common/visionimg.cc +common/visionimg.h + +common/gpio.cc +common/gpio.h +common/i2c.cc +common/i2c.h selfdrive/controls/__init__.py diff --git a/scripts/waste.c b/scripts/waste.c index 62233b7fc4..2e492916a7 100644 --- a/scripts/waste.c +++ b/scripts/waste.c @@ -11,7 +11,7 @@ #include #include #include -#include "../selfdrive/common/timing.h" +#include "../common/timing.h" int get_nprocs(void); double *ttime, *oout; diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 1154318428..2622f7eba1 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -23,10 +23,10 @@ #include "cereal/gen/cpp/car.capnp.h" #include "cereal/messaging/messaging.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/timing.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/boardd/pigeon.h" diff --git a/selfdrive/boardd/main.cc b/selfdrive/boardd/main.cc index d802e42f86..b151832b72 100644 --- a/selfdrive/boardd/main.cc +++ b/selfdrive/boardd/main.cc @@ -1,8 +1,8 @@ #include #include "selfdrive/boardd/boardd.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" int main(int argc, char *argv[]) { diff --git a/selfdrive/boardd/panda.cc b/selfdrive/boardd/panda.cc index 536cbd5b7e..d90c4cdab2 100644 --- a/selfdrive/boardd/panda.cc +++ b/selfdrive/boardd/panda.cc @@ -8,9 +8,9 @@ #include "cereal/messaging/messaging.h" #include "panda/board/dlc_to_len.h" -#include "selfdrive/common/gpio.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/gpio.h" +#include "common/swaglog.h" +#include "common/util.h" static int init_usb_ctx(libusb_context **context) { assert(context != nullptr); diff --git a/selfdrive/boardd/pigeon.cc b/selfdrive/boardd/pigeon.cc index 912f4b03e7..d23ff90d3d 100644 --- a/selfdrive/boardd/pigeon.cc +++ b/selfdrive/boardd/pigeon.cc @@ -8,9 +8,9 @@ #include #include -#include "selfdrive/common/gpio.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/gpio.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/locationd/ublox_msg.h" // Termios on macos doesn't define all baud rate constants diff --git a/selfdrive/boardd/tests/test_boardd b/selfdrive/boardd/tests/test_boardd index f249724f6a264d86d5e1dc1cc3b08731b5130c1b..b4455ce67c3a6e23d362422a03ad485b559ae416 100755 GIT binary patch delta 921 zcmXxgS62=I0D$3>k-hhh?7fK)O2%hqZ$)NhX77=`$;jS2^DBE(X5t4p{R3ByD~}5o z&&_-JX65FE{>sS<&D$G6tHLiUi}I1^$GmB^Cr2%n*h$jNyzRj**OFG-DXcIL0%9iA-WLQ<%y$;z?jS zGe~46vzW~s<}!~Yl1X7c3s}e^7PEv@ma>fH!Nh_U2|I%M$tx3nq(w!qVl``6%R1Jx zfsJfpGh0YwE8E!44tBDO-Rxm6``FI`4swXYq;rI$9OF0{oZuvAX#MdkVib`2~T;(b6)V0SG?v8Z+XXia>(TaANj;* RzVMYizL6h{ivIpP>@TI9nNtc4K#=Vu68TcXxbt7dFN(V0UoxIC))^ z;V$n@@BPfq3BB_+C-iDYd{|2Ij7bycOLRG3!of_06ifC$4n>y5`9`$KJLmJVTCN!lP&1pdl zEont-+R&DEw5J0d=|pF`(3Nh)(w!c}@%Nja^rAO?g6Z*rgoOY1WoA7LRLqQc)}u-= zGApn)>VFf|B!-0lJGx2m$D=@8be)oEPH>V_oaPK?ImdY}aFI(~<_cH2#&vFRlUv*-$Q|x-kNZ5}A&+>>6Q1&n=e*!0 euXxQHvU$rp-t&QveBv`XeBo>GckH)c)&Bt7INyN) diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index bba65f170e..e2ec10bcb0 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -11,10 +11,10 @@ #include #include "selfdrive/camerad/imgproc/utils.h" -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/modeldata.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/clutil.h" +#include "common/modeldata.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #if QCOM2 diff --git a/selfdrive/camerad/cameras/camera_common.h b/selfdrive/camerad/cameras/camera_common.h index 8c836e0bb8..85c55f4b03 100644 --- a/selfdrive/camerad/cameras/camera_common.h +++ b/selfdrive/camerad/cameras/camera_common.h @@ -10,10 +10,10 @@ #include "cereal/visionipc/visionipc.h" #include "cereal/visionipc/visionipc_server.h" #include "selfdrive/camerad/transforms/rgb_to_yuv.h" -#include "selfdrive/common/mat.h" -#include "selfdrive/common/queue.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/visionimg.h" +#include "common/mat.h" +#include "common/queue.h" +#include "common/swaglog.h" +#include "common/visionimg.h" #include "selfdrive/hardware/hw.h" #define CAMERA_ID_IMX298 0 diff --git a/selfdrive/camerad/cameras/camera_qcom2.cc b/selfdrive/camerad/cameras/camera_qcom2.cc index 45f414cc7e..597085dd28 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.cc +++ b/selfdrive/camerad/cameras/camera_qcom2.cc @@ -19,7 +19,7 @@ #include "media/cam_sensor.h" #include "media/cam_sensor_cmn_header.h" #include "media/cam_sync.h" -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" #include "selfdrive/camerad/cameras/sensor2_i2c.h" // For debugging: diff --git a/selfdrive/camerad/cameras/camera_qcom2.h b/selfdrive/camerad/cameras/camera_qcom2.h index e0553f000e..d869620e9a 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.h +++ b/selfdrive/camerad/cameras/camera_qcom2.h @@ -7,7 +7,7 @@ #include #include "selfdrive/camerad/cameras/camera_common.h" -#include "selfdrive/common/util.h" +#include "common/util.h" #define FRAME_BUF_COUNT 4 diff --git a/selfdrive/camerad/cameras/camera_replay.cc b/selfdrive/camerad/cameras/camera_replay.cc index 56bda697c9..e18d6a487e 100644 --- a/selfdrive/camerad/cameras/camera_replay.cc +++ b/selfdrive/camerad/cameras/camera_replay.cc @@ -3,8 +3,8 @@ #include #include -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/util.h" +#include "common/clutil.h" +#include "common/util.h" extern ExitHandler do_exit; diff --git a/selfdrive/camerad/cameras/camera_webcam.cc b/selfdrive/camerad/cameras/camera_webcam.cc index 6001f9fd3b..b0906ce887 100644 --- a/selfdrive/camerad/cameras/camera_webcam.cc +++ b/selfdrive/camerad/cameras/camera_webcam.cc @@ -13,10 +13,10 @@ #include #pragma clang diagnostic pop -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/clutil.h" +#include "common/swaglog.h" +#include "common/timing.h" +#include "common/util.h" // id of the video capturing device const int ROAD_CAMERA_ID = util::getenv("ROADCAM_ID", 1); diff --git a/selfdrive/camerad/imgproc/utils.h b/selfdrive/camerad/imgproc/utils.h index b735975b3e..94323b15c5 100644 --- a/selfdrive/camerad/imgproc/utils.h +++ b/selfdrive/camerad/imgproc/utils.h @@ -4,7 +4,7 @@ #include #include -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" #define NUM_SEGMENTS_X 8 #define NUM_SEGMENTS_Y 6 diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index 58edaedd9b..f59e03f8fa 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -2,8 +2,8 @@ #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" int main(int argc, char *argv[]) { diff --git a/selfdrive/camerad/test/ae_gray_test.cc b/selfdrive/camerad/test/ae_gray_test.cc index 358d93d759..b7759d8e1a 100644 --- a/selfdrive/camerad/test/ae_gray_test.cc +++ b/selfdrive/camerad/test/ae_gray_test.cc @@ -7,7 +7,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/camerad/cameras/camera_common.h" // needed by camera_common.cc diff --git a/selfdrive/camerad/transforms/rgb_to_yuv.h b/selfdrive/camerad/transforms/rgb_to_yuv.h index 3bb50669ef..e1de180d40 100644 --- a/selfdrive/camerad/transforms/rgb_to_yuv.h +++ b/selfdrive/camerad/transforms/rgb_to_yuv.h @@ -1,6 +1,6 @@ #pragma once -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" class Rgb2Yuv { public: diff --git a/selfdrive/camerad/transforms/rgb_to_yuv_test.cc b/selfdrive/camerad/transforms/rgb_to_yuv_test.cc index 74db2bc1c2..c960d168de 100644 --- a/selfdrive/camerad/transforms/rgb_to_yuv_test.cc +++ b/selfdrive/camerad/transforms/rgb_to_yuv_test.cc @@ -31,7 +31,7 @@ #include "libyuv.h" #include "selfdrive/camerad/transforms/rgb_to_yuv.h" -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" static inline double millis_since_boot() { struct timespec t; diff --git a/selfdrive/clocksd/clocksd.cc b/selfdrive/clocksd/clocksd.cc index a6a92fc058..a5912cf51a 100644 --- a/selfdrive/clocksd/clocksd.cc +++ b/selfdrive/clocksd/clocksd.cc @@ -16,8 +16,8 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/timing.h" +#include "common/util.h" ExitHandler do_exit; diff --git a/selfdrive/common/SConscript b/selfdrive/common/SConscript deleted file mode 100644 index e53cb7615d..0000000000 --- a/selfdrive/common/SConscript +++ /dev/null @@ -1,35 +0,0 @@ -Import('env', 'arch', 'SHARED') - -if SHARED: - fxn = env.SharedLibrary -else: - fxn = env.Library - -common_libs = [ - 'params.cc', - 'statlog.cc', - 'swaglog.cc', - 'util.cc', - 'gpio.cc', - 'i2c.cc', - 'watchdog.cc', -] - -_common = fxn('common', common_libs, LIBS="json11") - -files = [ - 'clutil.cc', - 'visionimg.cc', -] - -if arch == "larch64": - _gpu_libs = ["GLESv2"] -else: - _gpu_libs = ["GL"] - -_gpucommon = fxn('gpucommon', files, LIBS=_gpu_libs) -Export('_common', '_gpucommon', '_gpu_libs') - -if GetOption('test'): - env.Program('tests/test_util', ['tests/test_util.cc'], LIBS=[_common]) - env.Program('tests/test_swaglog', ['tests/test_swaglog.cc'], LIBS=[_common, 'json11', 'zmq', 'pthread']) diff --git a/selfdrive/hardware/hw.h b/selfdrive/hardware/hw.h index b221b63db2..5f178ec0f9 100644 --- a/selfdrive/hardware/hw.h +++ b/selfdrive/hardware/hw.h @@ -1,7 +1,7 @@ #pragma once #include "selfdrive/hardware/base.h" -#include "selfdrive/common/util.h" +#include "common/util.h" #if QCOM2 #include "selfdrive/hardware/tici/hardware.h" diff --git a/selfdrive/hardware/tici/hardware.h b/selfdrive/hardware/tici/hardware.h index c37dbb0a36..ec53e9ae8f 100644 --- a/selfdrive/hardware/tici/hardware.h +++ b/selfdrive/hardware/tici/hardware.h @@ -3,8 +3,8 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/util.h" #include "selfdrive/hardware/base.h" class HardwareTici : public HardwareNone { diff --git a/selfdrive/locationd/locationd.h b/selfdrive/locationd/locationd.h index 2ab3ba56ad..7c0cb6b7fe 100755 --- a/selfdrive/locationd/locationd.h +++ b/selfdrive/locationd/locationd.h @@ -8,10 +8,10 @@ #include "cereal/messaging/messaging.h" #include "common/transformations/coordinates.hpp" #include "common/transformations/orientation.hpp" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/timing.h" +#include "common/util.h" #include "selfdrive/sensord/sensors/constants.h" #define VISION_DECIMATION 2 diff --git a/selfdrive/locationd/ublox_msg.cc b/selfdrive/locationd/ublox_msg.cc index 9e32c7b070..c9833410e7 100644 --- a/selfdrive/locationd/ublox_msg.cc +++ b/selfdrive/locationd/ublox_msg.cc @@ -10,7 +10,7 @@ #include #include -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" const double gpsPi = 3.1415926535898; #define UBLOX_MSG_SIZE(hdr) (*(uint16_t *)&hdr[4]) diff --git a/selfdrive/locationd/ublox_msg.h b/selfdrive/locationd/ublox_msg.h index da1c180c0b..542e72816b 100644 --- a/selfdrive/locationd/ublox_msg.h +++ b/selfdrive/locationd/ublox_msg.h @@ -8,7 +8,7 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/locationd/generated/gps.h" #include "selfdrive/locationd/generated/ubx.h" diff --git a/selfdrive/locationd/ubloxd.cc b/selfdrive/locationd/ubloxd.cc index ae07284c8e..d9b3e7647d 100644 --- a/selfdrive/locationd/ubloxd.cc +++ b/selfdrive/locationd/ubloxd.cc @@ -3,8 +3,8 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/locationd/ublox_msg.h" ExitHandler do_exit; diff --git a/selfdrive/logcatd/logcatd_systemd.cc b/selfdrive/logcatd/logcatd_systemd.cc index dabb11adcb..70467a9c15 100644 --- a/selfdrive/logcatd/logcatd_systemd.cc +++ b/selfdrive/logcatd/logcatd_systemd.cc @@ -8,8 +8,8 @@ #include "json11.hpp" #include "cereal/messaging/messaging.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/timing.h" +#include "common/util.h" ExitHandler do_exit; int main(int argc, char *argv[]) { diff --git a/selfdrive/loggerd/bootlog.cc b/selfdrive/loggerd/bootlog.cc index e8fc955263..eee6b86720 100644 --- a/selfdrive/loggerd/bootlog.cc +++ b/selfdrive/loggerd/bootlog.cc @@ -2,7 +2,7 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" #include "selfdrive/loggerd/logger.h" diff --git a/selfdrive/loggerd/encoder/encoder.h b/selfdrive/loggerd/encoder/encoder.h index 94c9c551d9..9792d61c46 100644 --- a/selfdrive/loggerd/encoder/encoder.h +++ b/selfdrive/loggerd/encoder/encoder.h @@ -6,7 +6,7 @@ #include "cereal/messaging/messaging.h" #include "cereal/visionipc/visionipc.h" -#include "selfdrive/common/queue.h" +#include "common/queue.h" #include "selfdrive/loggerd/video_writer.h" #include "selfdrive/camerad/cameras/camera_common.h" diff --git a/selfdrive/loggerd/encoder/ffmpeg_encoder.cc b/selfdrive/loggerd/encoder/ffmpeg_encoder.cc index 7011f43a23..a2b14ef3fd 100644 --- a/selfdrive/loggerd/encoder/ffmpeg_encoder.cc +++ b/selfdrive/loggerd/encoder/ffmpeg_encoder.cc @@ -19,8 +19,8 @@ extern "C" { #include } -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" const int env_debug_encoder = (getenv("DEBUG_ENCODER") != NULL) ? atoi(getenv("DEBUG_ENCODER")) : 0; diff --git a/selfdrive/loggerd/encoder/v4l_encoder.cc b/selfdrive/loggerd/encoder/v4l_encoder.cc index 9ed1f80453..5fb9cc8de7 100644 --- a/selfdrive/loggerd/encoder/v4l_encoder.cc +++ b/selfdrive/loggerd/encoder/v4l_encoder.cc @@ -3,8 +3,8 @@ #include #include "selfdrive/loggerd/encoder/v4l_encoder.h" -#include "selfdrive/common/util.h" -#include "selfdrive/common/timing.h" +#include "common/util.h" +#include "common/timing.h" #include "libyuv.h" #include "msm_media_info.h" diff --git a/selfdrive/loggerd/encoder/v4l_encoder.h b/selfdrive/loggerd/encoder/v4l_encoder.h index 2f62e334fc..9f267cfb03 100644 --- a/selfdrive/loggerd/encoder/v4l_encoder.h +++ b/selfdrive/loggerd/encoder/v4l_encoder.h @@ -1,6 +1,6 @@ #pragma once -#include "selfdrive/common/queue.h" +#include "common/queue.h" #include "selfdrive/loggerd/encoder/encoder.h" #define BUF_IN_COUNT 7 diff --git a/selfdrive/loggerd/logger.cc b/selfdrive/loggerd/logger.cc index f8af20a406..d8a409e93e 100644 --- a/selfdrive/loggerd/logger.cc +++ b/selfdrive/loggerd/logger.cc @@ -15,9 +15,9 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/version.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/version.h" // ***** logging helpers ***** diff --git a/selfdrive/loggerd/logger.h b/selfdrive/loggerd/logger.h index 288b884dd2..ca08e64717 100644 --- a/selfdrive/loggerd/logger.h +++ b/selfdrive/loggerd/logger.h @@ -11,8 +11,8 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/util.h" -#include "selfdrive/common/swaglog.h" +#include "common/util.h" +#include "common/swaglog.h" #include "selfdrive/hardware/hw.h" const std::string LOG_ROOT = Path::log_root(); diff --git a/selfdrive/loggerd/loggerd.h b/selfdrive/loggerd/loggerd.h index 98e3deee00..21aa66ea12 100644 --- a/selfdrive/loggerd/loggerd.h +++ b/selfdrive/loggerd/loggerd.h @@ -16,10 +16,10 @@ #include "cereal/visionipc/visionipc.h" #include "cereal/visionipc/visionipc_client.h" #include "selfdrive/camerad/cameras/camera_common.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/timing.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/loggerd/encoder/encoder.h" diff --git a/selfdrive/loggerd/tests/test_logger.cc b/selfdrive/loggerd/tests/test_logger.cc index 2513e507a0..11a50fa2e7 100644 --- a/selfdrive/loggerd/tests/test_logger.cc +++ b/selfdrive/loggerd/tests/test_logger.cc @@ -7,7 +7,7 @@ #include "catch2/catch.hpp" #include "cereal/messaging/messaging.h" -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/loggerd/logger.h" #include "selfdrive/ui/replay/util.h" diff --git a/selfdrive/loggerd/video_writer.cc b/selfdrive/loggerd/video_writer.cc index 24ea98eb30..a4f0734fc9 100644 --- a/selfdrive/loggerd/video_writer.cc +++ b/selfdrive/loggerd/video_writer.cc @@ -2,8 +2,8 @@ #include #include "selfdrive/loggerd/video_writer.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" VideoWriter::VideoWriter(const char *path, const char *filename, bool remuxing, int width, int height, int fps, cereal::EncodeIndex::Type codec) : remuxing(remuxing) { diff --git a/selfdrive/modeld/dmonitoringmodeld.cc b/selfdrive/modeld/dmonitoringmodeld.cc index 8016180f40..61f3343c8d 100644 --- a/selfdrive/modeld/dmonitoringmodeld.cc +++ b/selfdrive/modeld/dmonitoringmodeld.cc @@ -5,8 +5,8 @@ #include #include "cereal/visionipc/visionipc_client.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/modeld/models/dmonitoring.h" ExitHandler do_exit; diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index 6ee07b3d02..03d0ec4325 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -7,10 +7,10 @@ #include "cereal/messaging/messaging.h" #include "cereal/visionipc/visionipc_client.h" -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/clutil.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/modeld/models/driving.h" diff --git a/selfdrive/modeld/models/commonmodel.cc b/selfdrive/modeld/models/commonmodel.cc index a075c08deb..bc013395df 100644 --- a/selfdrive/modeld/models/commonmodel.cc +++ b/selfdrive/modeld/models/commonmodel.cc @@ -5,9 +5,9 @@ #include #include -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/mat.h" -#include "selfdrive/common/timing.h" +#include "common/clutil.h" +#include "common/mat.h" +#include "common/timing.h" ModelFrame::ModelFrame(cl_device_id device_id, cl_context context) { input_frames = std::make_unique(buf_size); diff --git a/selfdrive/modeld/models/commonmodel.h b/selfdrive/modeld/models/commonmodel.h index 182e8978b7..059a85e7dd 100644 --- a/selfdrive/modeld/models/commonmodel.h +++ b/selfdrive/modeld/models/commonmodel.h @@ -12,7 +12,7 @@ #include #endif -#include "selfdrive/common/mat.h" +#include "common/mat.h" #include "selfdrive/modeld/transforms/loadyuv.h" #include "selfdrive/modeld/transforms/transform.h" diff --git a/selfdrive/modeld/models/dmonitoring.cc b/selfdrive/modeld/models/dmonitoring.cc index 63c06b1550..4792806c8b 100644 --- a/selfdrive/modeld/models/dmonitoring.cc +++ b/selfdrive/modeld/models/dmonitoring.cc @@ -2,10 +2,10 @@ #include "libyuv.h" -#include "selfdrive/common/mat.h" -#include "selfdrive/common/modeldata.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/timing.h" +#include "common/mat.h" +#include "common/modeldata.h" +#include "common/params.h" +#include "common/timing.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/modeld/models/dmonitoring.h" diff --git a/selfdrive/modeld/models/dmonitoring.h b/selfdrive/modeld/models/dmonitoring.h index b233056862..db4e2ef72a 100644 --- a/selfdrive/modeld/models/dmonitoring.h +++ b/selfdrive/modeld/models/dmonitoring.h @@ -3,7 +3,7 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/modeld/models/commonmodel.h" #include "selfdrive/modeld/runners/run.h" diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index e0421e8cca..b601c4898b 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -8,10 +8,10 @@ #include -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/swaglog.h" +#include "common/clutil.h" +#include "common/params.h" +#include "common/timing.h" +#include "common/swaglog.h" constexpr float FCW_THRESHOLD_5MS2_HIGH = 0.15; constexpr float FCW_THRESHOLD_5MS2_LOW = 0.05; diff --git a/selfdrive/modeld/models/driving.h b/selfdrive/modeld/models/driving.h index 47dec0d9d7..97e65fbc0e 100644 --- a/selfdrive/modeld/models/driving.h +++ b/selfdrive/modeld/models/driving.h @@ -10,9 +10,9 @@ #include "cereal/messaging/messaging.h" #include "cereal/visionipc/visionipc_client.h" -#include "selfdrive/common/mat.h" -#include "selfdrive/common/modeldata.h" -#include "selfdrive/common/util.h" +#include "common/mat.h" +#include "common/modeldata.h" +#include "common/util.h" #include "selfdrive/modeld/models/commonmodel.h" #include "selfdrive/modeld/runners/run.h" diff --git a/selfdrive/modeld/runners/onnxmodel.cc b/selfdrive/modeld/runners/onnxmodel.cc index 9ba08570e3..9b4d6fd015 100644 --- a/selfdrive/modeld/runners/onnxmodel.cc +++ b/selfdrive/modeld/runners/onnxmodel.cc @@ -11,8 +11,8 @@ #include #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" ONNXModel::ONNXModel(const char *path, float *_output, size_t _output_size, int runtime, bool _use_extra) { LOGD("loading model %s", path); diff --git a/selfdrive/modeld/runners/snpemodel.cc b/selfdrive/modeld/runners/snpemodel.cc index d8ed708fa8..1861494d59 100644 --- a/selfdrive/modeld/runners/snpemodel.cc +++ b/selfdrive/modeld/runners/snpemodel.cc @@ -6,8 +6,8 @@ #include #include -#include "selfdrive/common/util.h" -#include "selfdrive/common/timing.h" +#include "common/util.h" +#include "common/timing.h" void PrintErrorStringAndExit() { std::cerr << zdl::DlSystem::getLastErrorString() << std::endl; diff --git a/selfdrive/modeld/thneed/optimizer.cc b/selfdrive/modeld/thneed/optimizer.cc index b516b5fa50..03d20ff386 100644 --- a/selfdrive/modeld/thneed/optimizer.cc +++ b/selfdrive/modeld/thneed/optimizer.cc @@ -4,8 +4,8 @@ #include #include "thneed.h" -#include "selfdrive/common/util.h" -#include "selfdrive/common/clutil.h" +#include "common/util.h" +#include "common/clutil.h" extern map g_program_source; diff --git a/selfdrive/modeld/thneed/serialize.cc b/selfdrive/modeld/thneed/serialize.cc index 89b761b9d2..136576fe1c 100644 --- a/selfdrive/modeld/thneed/serialize.cc +++ b/selfdrive/modeld/thneed/serialize.cc @@ -2,8 +2,8 @@ #include #include "json11.hpp" -#include "selfdrive/common/util.h" -#include "selfdrive/common/clutil.h" +#include "common/util.h" +#include "common/clutil.h" #include "selfdrive/modeld/thneed/thneed.h" using namespace json11; diff --git a/selfdrive/modeld/thneed/thneed.cc b/selfdrive/modeld/thneed/thneed.cc index 90b1200a1a..d673c4f56f 100644 --- a/selfdrive/modeld/thneed/thneed.cc +++ b/selfdrive/modeld/thneed/thneed.cc @@ -9,8 +9,8 @@ #include #include -#include "selfdrive/common/clutil.h" -#include "selfdrive/common/timing.h" +#include "common/clutil.h" +#include "common/timing.h" Thneed *g_thneed = NULL; int g_fd = -1; diff --git a/selfdrive/modeld/transforms/loadyuv.h b/selfdrive/modeld/transforms/loadyuv.h index a3161b2935..7d27ef5d46 100644 --- a/selfdrive/modeld/transforms/loadyuv.h +++ b/selfdrive/modeld/transforms/loadyuv.h @@ -1,6 +1,6 @@ #pragma once -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" typedef struct { int width, height; diff --git a/selfdrive/modeld/transforms/transform.cc b/selfdrive/modeld/transforms/transform.cc index 5f4929bab3..8929f56a9e 100644 --- a/selfdrive/modeld/transforms/transform.cc +++ b/selfdrive/modeld/transforms/transform.cc @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/clutil.h" +#include "common/clutil.h" void transform_init(Transform* s, cl_context ctx, cl_device_id device_id) { memset(s, 0, sizeof(*s)); diff --git a/selfdrive/modeld/transforms/transform.h b/selfdrive/modeld/transforms/transform.h index f34613684c..a1629a517e 100644 --- a/selfdrive/modeld/transforms/transform.h +++ b/selfdrive/modeld/transforms/transform.h @@ -7,7 +7,7 @@ #include #endif -#include "selfdrive/common/mat.h" +#include "common/mat.h" typedef struct { cl_kernel krnl; diff --git a/selfdrive/proclogd/main.cc b/selfdrive/proclogd/main.cc index 4e31597c2b..288238dc9a 100644 --- a/selfdrive/proclogd/main.cc +++ b/selfdrive/proclogd/main.cc @@ -1,7 +1,7 @@ #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/proclogd/proclog.h" ExitHandler do_exit; diff --git a/selfdrive/proclogd/proclog.cc b/selfdrive/proclogd/proclog.cc index 26fc1d94d0..215d9e9df0 100644 --- a/selfdrive/proclogd/proclog.cc +++ b/selfdrive/proclogd/proclog.cc @@ -7,8 +7,8 @@ #include #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" namespace Parser { diff --git a/selfdrive/proclogd/tests/test_proclog.cc b/selfdrive/proclogd/tests/test_proclog.cc index 88a09dd03b..3e346988c6 100644 --- a/selfdrive/proclogd/tests/test_proclog.cc +++ b/selfdrive/proclogd/tests/test_proclog.cc @@ -1,6 +1,6 @@ #define CATCH_CONFIG_MAIN #include "catch2/catch.hpp" -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/proclogd/proclog.h" const std::string allowed_states = "RSDTZtWXxKWPI"; diff --git a/selfdrive/sensord/sensors/bmx055_accel.cc b/selfdrive/sensord/sensors/bmx055_accel.cc index f5d68bdee5..d17e3fe617 100644 --- a/selfdrive/sensord/sensors/bmx055_accel.cc +++ b/selfdrive/sensord/sensors/bmx055_accel.cc @@ -2,8 +2,8 @@ #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" BMX055_Accel::BMX055_Accel(I2CBus *bus) : I2CSensor(bus) {} diff --git a/selfdrive/sensord/sensors/bmx055_gyro.cc b/selfdrive/sensord/sensors/bmx055_gyro.cc index f0e3034e3f..74b22d8fef 100644 --- a/selfdrive/sensord/sensors/bmx055_gyro.cc +++ b/selfdrive/sensord/sensors/bmx055_gyro.cc @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" #define DEG2RAD(x) ((x) * M_PI / 180.0) diff --git a/selfdrive/sensord/sensors/bmx055_magn.cc b/selfdrive/sensord/sensors/bmx055_magn.cc index 29e0d809d8..a2c793eff6 100644 --- a/selfdrive/sensord/sensors/bmx055_magn.cc +++ b/selfdrive/sensord/sensors/bmx055_magn.cc @@ -6,8 +6,8 @@ #include #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" +#include "common/swaglog.h" +#include "common/util.h" static int16_t compensate_x(trim_data_t trim_data, int16_t mag_data_x, uint16_t data_rhall) { uint16_t process_comp_x0 = data_rhall; diff --git a/selfdrive/sensord/sensors/bmx055_temp.cc b/selfdrive/sensord/sensors/bmx055_temp.cc index 339a987ce0..85bdea9e61 100644 --- a/selfdrive/sensord/sensors/bmx055_temp.cc +++ b/selfdrive/sensord/sensors/bmx055_temp.cc @@ -3,8 +3,8 @@ #include #include "selfdrive/sensord/sensors/bmx055_accel.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" BMX055_Temp::BMX055_Temp(I2CBus *bus) : I2CSensor(bus) {} diff --git a/selfdrive/sensord/sensors/i2c_sensor.h b/selfdrive/sensord/sensors/i2c_sensor.h index 83c66eac87..7832475a98 100644 --- a/selfdrive/sensord/sensors/i2c_sensor.h +++ b/selfdrive/sensord/sensors/i2c_sensor.h @@ -3,7 +3,7 @@ #include #include "cereal/gen/cpp/log.capnp.h" -#include "selfdrive/common/i2c.h" +#include "common/i2c.h" #include "selfdrive/sensord/sensors/constants.h" #include "selfdrive/sensord/sensors/sensor.h" diff --git a/selfdrive/sensord/sensors/light_sensor.cc b/selfdrive/sensord/sensors/light_sensor.cc index 4d00d37bda..4497343684 100644 --- a/selfdrive/sensord/sensors/light_sensor.cc +++ b/selfdrive/sensord/sensors/light_sensor.cc @@ -2,7 +2,7 @@ #include -#include "selfdrive/common/timing.h" +#include "common/timing.h" #include "selfdrive/sensord/sensors/constants.h" void LightSensor::get_event(cereal::SensorEventData::Builder &event) { diff --git a/selfdrive/sensord/sensors/lsm6ds3_accel.cc b/selfdrive/sensord/sensors/lsm6ds3_accel.cc index 83222858e7..bcac7de9f7 100644 --- a/selfdrive/sensord/sensors/lsm6ds3_accel.cc +++ b/selfdrive/sensord/sensors/lsm6ds3_accel.cc @@ -2,8 +2,8 @@ #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" LSM6DS3_Accel::LSM6DS3_Accel(I2CBus *bus) : I2CSensor(bus) {} diff --git a/selfdrive/sensord/sensors/lsm6ds3_gyro.cc b/selfdrive/sensord/sensors/lsm6ds3_gyro.cc index 6732ead0f1..c7711d34e3 100644 --- a/selfdrive/sensord/sensors/lsm6ds3_gyro.cc +++ b/selfdrive/sensord/sensors/lsm6ds3_gyro.cc @@ -3,8 +3,8 @@ #include #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" #define DEG2RAD(x) ((x) * M_PI / 180.0) diff --git a/selfdrive/sensord/sensors/lsm6ds3_temp.cc b/selfdrive/sensord/sensors/lsm6ds3_temp.cc index 6b093fce05..1dd179d69e 100644 --- a/selfdrive/sensord/sensors/lsm6ds3_temp.cc +++ b/selfdrive/sensord/sensors/lsm6ds3_temp.cc @@ -2,8 +2,8 @@ #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" LSM6DS3_Temp::LSM6DS3_Temp(I2CBus *bus) : I2CSensor(bus) {} diff --git a/selfdrive/sensord/sensors/mmc5603nj_magn.cc b/selfdrive/sensord/sensors/mmc5603nj_magn.cc index 68878867e4..7c654ce7a3 100644 --- a/selfdrive/sensord/sensors/mmc5603nj_magn.cc +++ b/selfdrive/sensord/sensors/mmc5603nj_magn.cc @@ -2,8 +2,8 @@ #include -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" +#include "common/swaglog.h" +#include "common/timing.h" MMC5603NJ_Magn::MMC5603NJ_Magn(I2CBus *bus) : I2CSensor(bus) {} diff --git a/selfdrive/sensord/sensors_qcom2.cc b/selfdrive/sensord/sensors_qcom2.cc index c3e5bbcdfa..65fe43f65f 100644 --- a/selfdrive/sensord/sensors_qcom2.cc +++ b/selfdrive/sensord/sensors_qcom2.cc @@ -5,10 +5,10 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/i2c.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/i2c.h" +#include "common/swaglog.h" +#include "common/timing.h" +#include "common/util.h" #include "selfdrive/sensord/sensors/bmx055_accel.h" #include "selfdrive/sensord/sensors/bmx055_gyro.h" #include "selfdrive/sensord/sensors/bmx055_magn.h" diff --git a/selfdrive/ui/navd/main.cc b/selfdrive/ui/navd/main.cc index 7ae0393a47..fe354b7b7d 100644 --- a/selfdrive/ui/navd/main.cc +++ b/selfdrive/ui/navd/main.cc @@ -9,7 +9,7 @@ #include "selfdrive/ui/navd/route_engine.h" #include "selfdrive/ui/navd/map_renderer.h" #include "selfdrive/hardware/hw.h" -#include "selfdrive/common/params.h" +#include "common/params.h" void sigHandler(int s) { qInfo() << "Shutting down"; diff --git a/selfdrive/ui/navd/map_renderer.cc b/selfdrive/ui/navd/map_renderer.cc index 1d78d68dfe..8d2a8810c9 100644 --- a/selfdrive/ui/navd/map_renderer.cc +++ b/selfdrive/ui/navd/map_renderer.cc @@ -5,7 +5,7 @@ #include #include "selfdrive/ui/qt/maps/map_helpers.h" -#include "selfdrive/common/timing.h" +#include "common/timing.h" const float ZOOM = 13.5; // Don't go below 13 or features will start to disappear const int WIDTH = 256; diff --git a/selfdrive/ui/navd/route_engine.cc b/selfdrive/ui/navd/route_engine.cc index afa6c02e86..577f267c9b 100644 --- a/selfdrive/ui/navd/route_engine.cc +++ b/selfdrive/ui/navd/route_engine.cc @@ -6,7 +6,7 @@ #include "selfdrive/ui/qt/maps/map_helpers.h" #include "selfdrive/ui/qt/api.h" -#include "selfdrive/common/params.h" +#include "common/params.h" const qreal REROUTE_DISTANCE = 25; const float MANEUVER_TRANSITION_THRESHOLD = 10; diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index 79e9506598..94beb12186 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -12,8 +12,8 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/util.h" diff --git a/selfdrive/ui/qt/api.h b/selfdrive/ui/qt/api.h index 5963d1cf44..ad64d7e722 100644 --- a/selfdrive/ui/qt/api.h +++ b/selfdrive/ui/qt/api.h @@ -5,7 +5,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" namespace CommaApi { diff --git a/selfdrive/ui/qt/body.cc b/selfdrive/ui/qt/body.cc index 7ca064a6cf..f2628d304f 100644 --- a/selfdrive/ui/qt/body.cc +++ b/selfdrive/ui/qt/body.cc @@ -6,8 +6,8 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/timing.h" +#include "common/params.h" +#include "common/timing.h" RecordButton::RecordButton(QWidget *parent) : QPushButton(parent) { setCheckable(true); diff --git a/selfdrive/ui/qt/body.h b/selfdrive/ui/qt/body.h index 6555487bf1..567a54d49b 100644 --- a/selfdrive/ui/qt/body.h +++ b/selfdrive/ui/qt/body.h @@ -4,7 +4,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/ui.h" class RecordButton : public QPushButton { diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index fbd458cc02..e522d6160d 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -5,7 +5,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/drive_stats.h" #include "selfdrive/ui/qt/widgets/prime.h" diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index 055f93b291..8e5a02f8a0 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -6,7 +6,7 @@ #include #include -#include "selfdrive/common/swaglog.h" +#include "common/swaglog.h" #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/maps/map_helpers.h" diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index c62089cb25..01a13f3b7c 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -18,8 +18,8 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/util.h" #include "cereal/messaging/messaging.h" class MapInstructions : public QWidget { diff --git a/selfdrive/ui/qt/maps/map_helpers.cc b/selfdrive/ui/qt/maps/map_helpers.cc index f0545924c0..be1098994b 100644 --- a/selfdrive/ui/qt/maps/map_helpers.cc +++ b/selfdrive/ui/qt/maps/map_helpers.cc @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/api.h" diff --git a/selfdrive/ui/qt/maps/map_helpers.h b/selfdrive/ui/qt/maps/map_helpers.h index 1c8cacbebc..cda4cd1cfb 100644 --- a/selfdrive/ui/qt/maps/map_helpers.h +++ b/selfdrive/ui/qt/maps/map_helpers.h @@ -5,7 +5,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "common/transformations/coordinates.hpp" #include "common/transformations/orientation.hpp" #include "cereal/messaging/messaging.h" diff --git a/selfdrive/ui/qt/maps/map_settings.cc b/selfdrive/ui/qt/maps/map_settings.cc index 1e3a99e31a..674c7fa7cb 100644 --- a/selfdrive/ui/qt/maps/map_settings.cc +++ b/selfdrive/ui/qt/maps/map_settings.cc @@ -2,7 +2,7 @@ #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/widgets/controls.h" diff --git a/selfdrive/ui/qt/maps/map_settings.h b/selfdrive/ui/qt/maps/map_settings.h index 03720edee7..962d127679 100644 --- a/selfdrive/ui/qt/maps/map_settings.h +++ b/selfdrive/ui/qt/maps/map_settings.h @@ -8,7 +8,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/widgets/controls.h" class MapPanel : public QWidget { diff --git a/selfdrive/ui/qt/offroad/driverview.h b/selfdrive/ui/qt/offroad/driverview.h index 4d4a4358ef..5d090ad772 100644 --- a/selfdrive/ui/qt/offroad/driverview.h +++ b/selfdrive/ui/qt/offroad/driverview.h @@ -4,7 +4,7 @@ #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/qt/widgets/cameraview.h" class DriverViewScene : public QWidget { diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index 8e7601ca8a..d32cc26e43 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -6,8 +6,8 @@ #include #include -#include "selfdrive/common/util.h" -#include "selfdrive/common/params.h" +#include "common/util.h" +#include "common/params.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/input.h" diff --git a/selfdrive/ui/qt/offroad/onboarding.h b/selfdrive/ui/qt/offroad/onboarding.h index 904aec4ade..48f4094899 100644 --- a/selfdrive/ui/qt/offroad/onboarding.h +++ b/selfdrive/ui/qt/offroad/onboarding.h @@ -7,7 +7,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/qt_window.h" class TrainingGuide : public QFrame { diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index ec686ba1f0..00e120d867 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -12,8 +12,8 @@ #include "selfdrive/ui/qt/maps/map_settings.h" #endif -#include "selfdrive/common/params.h" -#include "selfdrive/common/util.h" +#include "common/params.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/widgets/controls.h" #include "selfdrive/ui/qt/widgets/input.h" diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index 1628f35d99..124138eea4 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -3,8 +3,8 @@ #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/widgets/prime.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" +#include "common/params.h" +#include "common/swaglog.h" #include "selfdrive/ui/qt/util.h" bool compare_by_strength(const Network &a, const Network &b) { diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 098747946f..91e2a76f02 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -4,7 +4,7 @@ #include -#include "selfdrive/common/timing.h" +#include "common/timing.h" #include "selfdrive/ui/qt/util.h" #ifdef ENABLE_MAPS #include "selfdrive/ui/qt/maps/map.h" diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index f4c62d1c7d..6ca2b3c738 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/qt/widgets/cameraview.h" #include "selfdrive/ui/ui.h" diff --git a/selfdrive/ui/qt/request_repeater.h b/selfdrive/ui/qt/request_repeater.h index fa80100d22..c0e2758273 100644 --- a/selfdrive/ui/qt/request_repeater.h +++ b/selfdrive/ui/qt/request_repeater.h @@ -1,6 +1,6 @@ #pragma once -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/qt/api.h" #include "selfdrive/ui/ui.h" diff --git a/selfdrive/ui/qt/setup/setup.cc b/selfdrive/ui/qt/setup/setup.cc index 17304665c7..0da1752fed 100644 --- a/selfdrive/ui/qt/setup/setup.cc +++ b/selfdrive/ui/qt/setup/setup.cc @@ -10,7 +10,7 @@ #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/api.h" #include "selfdrive/ui/qt/qt_window.h" diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 5d1b921750..ab3e990e61 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/ui.h" typedef QPair ItemStatus; diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index e38052ea59..7ce7a267df 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -4,8 +4,8 @@ #include #include -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" +#include "common/params.h" +#include "common/swaglog.h" #include "selfdrive/hardware/hw.h" QString getVersion() { diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 024cefbb70..b6684e28b2 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -6,7 +6,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/widgets/toggle.h" QFrame *horizontal_line(QWidget *parent = nullptr); diff --git a/selfdrive/ui/qt/widgets/drive_stats.cc b/selfdrive/ui/qt/widgets/drive_stats.cc index f4c8f502a3..61d47db1c3 100644 --- a/selfdrive/ui/qt/widgets/drive_stats.cc +++ b/selfdrive/ui/qt/widgets/drive_stats.cc @@ -5,7 +5,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/util.h" diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.cc b/selfdrive/ui/qt/widgets/offroad_alerts.cc index 2d7ae39c36..53f7eb677c 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.cc +++ b/selfdrive/ui/qt/widgets/offroad_alerts.cc @@ -4,7 +4,7 @@ #include #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/widgets/scrollview.h" diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.h b/selfdrive/ui/qt/widgets/offroad_alerts.h index 4110bdaa4e..69c12b0602 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.h +++ b/selfdrive/ui/qt/widgets/offroad_alerts.h @@ -6,7 +6,7 @@ #include #include -#include "selfdrive/common/params.h" +#include "common/params.h" class AbstractAlert : public QFrame { Q_OBJECT diff --git a/selfdrive/ui/qt/widgets/ssh_keys.cc b/selfdrive/ui/qt/widgets/ssh_keys.cc index 7630e65731..46ccf6aee3 100644 --- a/selfdrive/ui/qt/widgets/ssh_keys.cc +++ b/selfdrive/ui/qt/widgets/ssh_keys.cc @@ -1,6 +1,6 @@ #include "selfdrive/ui/qt/widgets/ssh_keys.h" -#include "selfdrive/common/params.h" +#include "common/params.h" #include "selfdrive/ui/qt/api.h" #include "selfdrive/ui/qt/widgets/input.h" diff --git a/selfdrive/ui/replay/camera.h b/selfdrive/ui/replay/camera.h index 84f0172d5b..7f078511cf 100644 --- a/selfdrive/ui/replay/camera.h +++ b/selfdrive/ui/replay/camera.h @@ -2,7 +2,7 @@ #include #include "cereal/visionipc/visionipc_server.h" -#include "selfdrive/common/queue.h" +#include "common/queue.h" #include "selfdrive/ui/replay/framereader.h" #include "selfdrive/ui/replay/logreader.h" diff --git a/selfdrive/ui/replay/consoleui.cc b/selfdrive/ui/replay/consoleui.cc index fbbc4c15f8..05eb09c9ed 100644 --- a/selfdrive/ui/replay/consoleui.cc +++ b/selfdrive/ui/replay/consoleui.cc @@ -3,7 +3,7 @@ #include #include -#include "selfdrive/common/version.h" +#include "common/version.h" namespace { diff --git a/selfdrive/ui/replay/filereader.cc b/selfdrive/ui/replay/filereader.cc index b57a62d501..5f862bec35 100644 --- a/selfdrive/ui/replay/filereader.cc +++ b/selfdrive/ui/replay/filereader.cc @@ -2,7 +2,7 @@ #include -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/replay/util.h" std::string cacheFilePath(const std::string &url) { diff --git a/selfdrive/ui/replay/replay.cc b/selfdrive/ui/replay/replay.cc index 1c8de6bf94..5365724241 100644 --- a/selfdrive/ui/replay/replay.cc +++ b/selfdrive/ui/replay/replay.cc @@ -5,8 +5,8 @@ #include #include "cereal/services.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/timing.h" +#include "common/params.h" +#include "common/timing.h" #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/replay/util.h" diff --git a/selfdrive/ui/replay/tests/test_replay.cc b/selfdrive/ui/replay/tests/test_replay.cc index e80c526079..bf984f5f3d 100644 --- a/selfdrive/ui/replay/tests/test_replay.cc +++ b/selfdrive/ui/replay/tests/test_replay.cc @@ -5,7 +5,7 @@ #include #include "catch2/catch.hpp" -#include "selfdrive/common/util.h" +#include "common/util.h" #include "selfdrive/ui/replay/replay.h" #include "selfdrive/ui/replay/util.h" diff --git a/selfdrive/ui/replay/util.cc b/selfdrive/ui/replay/util.cc index f52e5efab0..099219ccde 100644 --- a/selfdrive/ui/replay/util.cc +++ b/selfdrive/ui/replay/util.cc @@ -12,8 +12,8 @@ #include #include -#include "selfdrive/common/timing.h" -#include "selfdrive/common/util.h" +#include "common/timing.h" +#include "common/util.h" ReplayMessageHandler message_handler = nullptr; DownloadProgressHandler download_progress_handler = nullptr; diff --git a/selfdrive/ui/soundd/sound.cc b/selfdrive/ui/soundd/sound.cc index f303aa92bf..6830450d8f 100644 --- a/selfdrive/ui/soundd/sound.cc +++ b/selfdrive/ui/soundd/sound.cc @@ -7,7 +7,7 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/util.h" +#include "common/util.h" // TODO: detect when we can't play sounds // TODO: detect when we can't display the UI diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index ab99b8fc24..985b0259d2 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -6,10 +6,10 @@ #include #include "common/transformations/orientation.hpp" -#include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" -#include "selfdrive/common/util.h" -#include "selfdrive/common/watchdog.h" +#include "common/params.h" +#include "common/swaglog.h" +#include "common/util.h" +#include "common/watchdog.h" #include "selfdrive/hardware/hw.h" #define BACKLIGHT_DT 0.05 diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index e3415b8830..51a1f6e21f 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -11,9 +11,9 @@ #include #include "cereal/messaging/messaging.h" -#include "selfdrive/common/modeldata.h" -#include "selfdrive/common/params.h" -#include "selfdrive/common/timing.h" +#include "common/modeldata.h" +#include "common/params.h" +#include "common/timing.h" const int bdr_s = 30; const int header_h = 420; diff --git a/selfdrive/version.py b/selfdrive/version.py index f944e870ae..08ab097344 100644 --- a/selfdrive/version.py +++ b/selfdrive/version.py @@ -68,7 +68,7 @@ def get_normalized_origin(default: Optional[str] = None) -> Optional[str]: @cache def get_version() -> str: - with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "common", "version.h")) as _versionf: + with open(os.path.join(BASEDIR, "common", "version.h")) as _versionf: version = _versionf.read().split('"')[1] return version From b4091847dfe67374d673ae3bf2dd2607068260f7 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 18 May 2022 15:12:48 -0700 Subject: [PATCH 76/91] camerad: remove webcam + replay cameras (#24554) * camerad: remove replay camera * remove webcam + fix AE tests --- release/files_common | 2 - selfdrive/camerad/SConscript | 37 +--- selfdrive/camerad/cameras/camera_common.cc | 6 +- selfdrive/camerad/cameras/camera_replay.h | 25 --- selfdrive/camerad/cameras/camera_webcam.cc | 197 --------------------- selfdrive/camerad/cameras/camera_webcam.h | 28 --- selfdrive/camerad/test/ae_gray_test.cc | 6 - selfdrive/camerad/test/camera_test.h | 26 +++ 8 files changed, 36 insertions(+), 291 deletions(-) delete mode 100644 selfdrive/camerad/cameras/camera_replay.h delete mode 100644 selfdrive/camerad/cameras/camera_webcam.cc delete mode 100644 selfdrive/camerad/cameras/camera_webcam.h create mode 100644 selfdrive/camerad/test/camera_test.h diff --git a/release/files_common b/release/files_common index b9f5c5746d..e5384e614a 100644 --- a/release/files_common +++ b/release/files_common @@ -301,8 +301,6 @@ selfdrive/camerad/snapshot/* selfdrive/camerad/include/* selfdrive/camerad/cameras/camera_common.h selfdrive/camerad/cameras/camera_common.cc -selfdrive/camerad/cameras/camera_replay.cc -selfdrive/camerad/cameras/camera_replay.h selfdrive/camerad/cameras/sensor2_i2c.h selfdrive/camerad/transforms/rgb_to_yuv.cc diff --git a/selfdrive/camerad/SConscript b/selfdrive/camerad/SConscript index bb55c825d4..b181fbab75 100644 --- a/selfdrive/camerad/SConscript +++ b/selfdrive/camerad/SConscript @@ -2,39 +2,18 @@ Import('env', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc', libs = ['m', 'pthread', common, 'jpeg', 'OpenCL', 'yuv', cereal, messaging, 'zmq', 'capnp', 'kj', visionipc, gpucommon] +cameras = [] if arch == "larch64": libs += ['atomic'] cameras = ['cameras/camera_qcom2.cc'] -else: - env['CXXFLAGS'] += ["-Wno-deprecated-declarations"] - if USE_WEBCAM: - libs += ['opencv_core', 'opencv_highgui', 'opencv_imgproc', 'opencv_videoio'] - cameras = ['cameras/camera_webcam.cc'] - env = env.Clone() - env.Append(CXXFLAGS = '-DWEBCAM') - env.Append(CFLAGS = '-DWEBCAM') - env.Append(CPPPATH = ['/usr/include/opencv4', '/usr/local/include/opencv4']) - else: - libs += ['avutil', 'avcodec', 'avformat', 'bz2', 'ssl', 'curl', 'crypto'] - # TODO: import replay_lib from root SConstruct - cameras = ['cameras/camera_replay.cc', - env.Object('camera-util', '#/selfdrive/ui/replay/util.cc'), - env.Object('camera-framereader', '#/selfdrive/ui/replay/framereader.cc'), - env.Object('camera-filereader', '#/selfdrive/ui/replay/filereader.cc')] - if arch == "Darwin": - del libs[libs.index('OpenCL')] - del libs[libs.index(gpucommon)][gpucommon.index('GL')] - env = env.Clone() - env['FRAMEWORKS'] = ['OpenCL', 'OpenGL'] - -env.Program('camerad', [ - 'main.cc', - 'cameras/camera_common.cc', - 'transforms/rgb_to_yuv.cc', - 'imgproc/utils.cc', - cameras, - ], LIBS=libs) + env.Program('camerad', [ + 'main.cc', + 'cameras/camera_common.cc', + 'transforms/rgb_to_yuv.cc', + 'imgproc/utils.cc', + cameras, + ], LIBS=libs) if GetOption("test"): env.Program('test/ae_gray_test', [ diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index e2ec10bcb0..d3fd34f6e4 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -17,13 +17,11 @@ #include "common/util.h" #include "selfdrive/hardware/hw.h" -#if QCOM2 +#ifdef QCOM2 #include "CL/cl_ext_qcom.h" #include "selfdrive/camerad/cameras/camera_qcom2.h" -#elif WEBCAM -#include "selfdrive/camerad/cameras/camera_webcam.h" #else -#include "selfdrive/camerad/cameras/camera_replay.h" +#include "selfdrive/camerad/test/camera_test.h" #endif ExitHandler do_exit; diff --git a/selfdrive/camerad/cameras/camera_replay.h b/selfdrive/camerad/cameras/camera_replay.h deleted file mode 100644 index 7c41af0ab4..0000000000 --- a/selfdrive/camerad/cameras/camera_replay.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "selfdrive/camerad/cameras/camera_common.h" -#include "selfdrive/ui/replay/framereader.h" - -#define FRAME_BUF_COUNT 16 - -typedef struct CameraState { - int camera_num; - CameraInfo ci; - - int fps; - float digital_gain = 0; - - CameraBuf buf; - FrameReader *frame = nullptr; -} CameraState; - -typedef struct MultiCameraState { - CameraState road_cam; - CameraState driver_cam; - - SubMaster *sm = nullptr; - PubMaster *pm = nullptr; -} MultiCameraState; diff --git a/selfdrive/camerad/cameras/camera_webcam.cc b/selfdrive/camerad/cameras/camera_webcam.cc deleted file mode 100644 index b0906ce887..0000000000 --- a/selfdrive/camerad/cameras/camera_webcam.cc +++ /dev/null @@ -1,197 +0,0 @@ -#include "selfdrive/camerad/cameras/camera_webcam.h" - -#include - -#include -#include - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-inline" -#include -#include -#include -#include -#pragma clang diagnostic pop - -#include "common/clutil.h" -#include "common/swaglog.h" -#include "common/timing.h" -#include "common/util.h" - -// id of the video capturing device -const int ROAD_CAMERA_ID = util::getenv("ROADCAM_ID", 1); -const int DRIVER_CAMERA_ID = util::getenv("DRIVERCAM_ID", 2); - -#define FRAME_WIDTH 1164 -#define FRAME_HEIGHT 874 -#define FRAME_WIDTH_FRONT 1152 -#define FRAME_HEIGHT_FRONT 864 - -extern ExitHandler do_exit; - -namespace { - -CameraInfo cameras_supported[CAMERA_ID_MAX] = { - // road facing - [CAMERA_ID_LGC920] = { - .frame_width = FRAME_WIDTH, - .frame_height = FRAME_HEIGHT, - .frame_stride = FRAME_WIDTH*3, - .bayer = false, - .bayer_flip = false, - }, - // driver facing - [CAMERA_ID_LGC615] = { - .frame_width = FRAME_WIDTH_FRONT, - .frame_height = FRAME_HEIGHT_FRONT, - .frame_stride = FRAME_WIDTH_FRONT*3, - .bayer = false, - .bayer_flip = false, - }, -}; - -void camera_open(CameraState *s, bool rear) { - // empty -} - -void camera_close(CameraState *s) { - // empty -} - -void camera_init(VisionIpcServer * v, CameraState *s, int camera_id, unsigned int fps, cl_device_id device_id, cl_context ctx, VisionStreamType rgb_type, VisionStreamType yuv_type) { - assert(camera_id < std::size(cameras_supported)); - s->ci = cameras_supported[camera_id]; - assert(s->ci.frame_width != 0); - - s->camera_num = camera_id; - s->fps = fps; - s->buf.init(device_id, ctx, s, v, FRAME_BUF_COUNT, rgb_type, yuv_type); -} - -void run_camera(CameraState *s, cv::VideoCapture &video_cap, float *ts) { - assert(video_cap.isOpened()); - - cv::Size size(s->ci.frame_width, s->ci.frame_height); - const cv::Mat transform = cv::Mat(3, 3, CV_32F, ts); - uint32_t frame_id = 0; - size_t buf_idx = 0; - - while (!do_exit) { - cv::Mat frame_mat, transformed_mat; - video_cap >> frame_mat; - if (frame_mat.empty()) continue; - - cv::warpPerspective(frame_mat, transformed_mat, transform, size, cv::INTER_LINEAR, cv::BORDER_CONSTANT, 0); - - s->buf.camera_bufs_metadata[buf_idx] = {.frame_id = frame_id}; - - auto &buf = s->buf.camera_bufs[buf_idx]; - int transformed_size = transformed_mat.total() * transformed_mat.elemSize(); - CL_CHECK(clEnqueueWriteBuffer(buf.copy_q, buf.buf_cl, CL_TRUE, 0, transformed_size, transformed_mat.data, 0, NULL, NULL)); - - s->buf.queue(buf_idx); - - ++frame_id; - buf_idx = (buf_idx + 1) % FRAME_BUF_COUNT; - } -} - -static void road_camera_thread(CameraState *s) { - util::set_thread_name("webcam_road_camera_thread"); - - cv::VideoCapture cap_road(ROAD_CAMERA_ID, cv::CAP_V4L2); // road - cap_road.set(cv::CAP_PROP_FRAME_WIDTH, 853); - cap_road.set(cv::CAP_PROP_FRAME_HEIGHT, 480); - cap_road.set(cv::CAP_PROP_FPS, s->fps); - cap_road.set(cv::CAP_PROP_AUTOFOCUS, 0); // off - cap_road.set(cv::CAP_PROP_FOCUS, 0); // 0 - 255? - // cv::Rect roi_rear(160, 0, 960, 720); - - // transforms calculation see tools/webcam/warp_vis.py - float ts[9] = {1.50330396, 0.0, -59.40969163, - 0.0, 1.50330396, 76.20704846, - 0.0, 0.0, 1.0}; - // if camera upside down: - // float ts[9] = {-1.50330396, 0.0, 1223.4, - // 0.0, -1.50330396, 797.8, - // 0.0, 0.0, 1.0}; - - run_camera(s, cap_road, ts); -} - -void driver_camera_thread(CameraState *s) { - cv::VideoCapture cap_driver(DRIVER_CAMERA_ID, cv::CAP_V4L2); // driver - cap_driver.set(cv::CAP_PROP_FRAME_WIDTH, 853); - cap_driver.set(cv::CAP_PROP_FRAME_HEIGHT, 480); - cap_driver.set(cv::CAP_PROP_FPS, s->fps); - // cv::Rect roi_front(320, 0, 960, 720); - - // transforms calculation see tools/webcam/warp_vis.py - float ts[9] = {1.42070485, 0.0, -30.16740088, - 0.0, 1.42070485, 91.030837, - 0.0, 0.0, 1.0}; - // if camera upside down: - // float ts[9] = {-1.42070485, 0.0, 1182.2, - // 0.0, -1.42070485, 773.0, - // 0.0, 0.0, 1.0}; - run_camera(s, cap_driver, ts); -} - -} // namespace - -void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) { - camera_init(v, &s->road_cam, CAMERA_ID_LGC920, 20, device_id, ctx, - VISION_STREAM_RGB_ROAD, VISION_STREAM_ROAD); - camera_init(v, &s->driver_cam, CAMERA_ID_LGC615, 10, device_id, ctx, - VISION_STREAM_RGB_DRIVER, VISION_STREAM_DRIVER); - s->pm = new PubMaster({"roadCameraState", "driverCameraState", "thumbnail"}); -} - -void camera_autoexposure(CameraState *s, float grey_frac) {} - -void cameras_open(MultiCameraState *s) { - // LOG("*** open driver camera ***"); - camera_open(&s->driver_cam, false); - // LOG("*** open road camera ***"); - camera_open(&s->road_cam, true); -} - -void cameras_close(MultiCameraState *s) { - camera_close(&s->road_cam); - camera_close(&s->driver_cam); - delete s->pm; -} - -void process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) { - MessageBuilder msg; - auto framed = msg.initEvent().initDriverCameraState(); - framed.setFrameType(cereal::FrameData::FrameType::FRONT); - fill_frame_data(framed, c->buf.cur_frame_data); - s->pm->send("driverCameraState", msg); -} - -void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) { - const CameraBuf *b = &c->buf; - MessageBuilder msg; - auto framed = msg.initEvent().initRoadCameraState(); - fill_frame_data(framed, b->cur_frame_data); - framed.setImage(kj::arrayPtr((const uint8_t *)b->cur_yuv_buf->addr, b->cur_yuv_buf->len)); - framed.setTransform(b->yuv_transform.v); - s->pm->send("roadCameraState", msg); -} - -void cameras_run(MultiCameraState *s) { - std::vector threads; - threads.push_back(start_process_thread(s, &s->road_cam, process_road_camera)); - threads.push_back(start_process_thread(s, &s->driver_cam, process_driver_camera)); - - std::thread t_rear = std::thread(road_camera_thread, &s->road_cam); - util::set_thread_name("webcam_thread"); - driver_camera_thread(&s->driver_cam); - - t_rear.join(); - - for (auto &t : threads) t.join(); - - cameras_close(s); -} diff --git a/selfdrive/camerad/cameras/camera_webcam.h b/selfdrive/camerad/cameras/camera_webcam.h deleted file mode 100644 index 819387f3d6..0000000000 --- a/selfdrive/camerad/cameras/camera_webcam.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#include "selfdrive/camerad/cameras/camera_common.h" - -#define FRAME_BUF_COUNT 16 - -typedef struct CameraState { - CameraInfo ci; - int camera_num; - int fps; - float digital_gain; - CameraBuf buf; -} CameraState; - - -typedef struct MultiCameraState { - CameraState road_cam; - CameraState driver_cam; - - SubMaster *sm; - PubMaster *pm; -} MultiCameraState; diff --git a/selfdrive/camerad/test/ae_gray_test.cc b/selfdrive/camerad/test/ae_gray_test.cc index b7759d8e1a..69ef2ac6de 100644 --- a/selfdrive/camerad/test/ae_gray_test.cc +++ b/selfdrive/camerad/test/ae_gray_test.cc @@ -10,12 +10,6 @@ #include "common/util.h" #include "selfdrive/camerad/cameras/camera_common.h" -// needed by camera_common.cc -void camera_autoexposure(CameraState *s, float grey_frac) {} -void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) {} -void cameras_open(MultiCameraState *s) {} -void cameras_run(MultiCameraState *s) {} - int main() { // set up fake camerabuf CameraBuf cb = {}; diff --git a/selfdrive/camerad/test/camera_test.h b/selfdrive/camerad/test/camera_test.h new file mode 100644 index 0000000000..cc521db397 --- /dev/null +++ b/selfdrive/camerad/test/camera_test.h @@ -0,0 +1,26 @@ +// TODO: cleanup AE tests +// needed by camera_common.cc +void camera_autoexposure(CameraState *s, float grey_frac) {} +void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) {} +void cameras_open(MultiCameraState *s) {} +void cameras_run(MultiCameraState *s) {} + +typedef struct CameraState { + int camera_num; + CameraInfo ci; + + int fps; + float digital_gain = 0; + + CameraBuf buf; +} CameraState; + +typedef struct MultiCameraState { + CameraState road_cam; + CameraState driver_cam; + + SubMaster *sm = nullptr; + PubMaster *pm = nullptr; +} MultiCameraState; + + From 370fc2d352f7cff33be1108d8f61bef94c2d369c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 18 May 2022 16:43:23 -0700 Subject: [PATCH 77/91] remove that too --- selfdrive/camerad/cameras/camera_replay.cc | 124 --------------------- 1 file changed, 124 deletions(-) delete mode 100644 selfdrive/camerad/cameras/camera_replay.cc diff --git a/selfdrive/camerad/cameras/camera_replay.cc b/selfdrive/camerad/cameras/camera_replay.cc deleted file mode 100644 index e18d6a487e..0000000000 --- a/selfdrive/camerad/cameras/camera_replay.cc +++ /dev/null @@ -1,124 +0,0 @@ -#include "selfdrive/camerad/cameras/camera_replay.h" - -#include -#include - -#include "common/clutil.h" -#include "common/util.h" - -extern ExitHandler do_exit; - -void camera_autoexposure(CameraState *s, float grey_frac) {} - -namespace { - -const char *BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/"; - -const std::string road_camera_route = "0c94aa1e1296d7c6|2021-05-05--19-48-37"; -// const std::string driver_camera_route = "534ccd8a0950a00c|2021-06-08--12-15-37"; - -std::string get_url(std::string route_name, const std::string &camera, int segment_num) { - std::replace(route_name.begin(), route_name.end(), '|', '/'); - return util::string_format("%s%s/%d/%s.hevc", BASE_URL, route_name.c_str(), segment_num, camera.c_str()); -} - -void camera_init(VisionIpcServer *v, CameraState *s, int camera_id, unsigned int fps, cl_device_id device_id, cl_context ctx, VisionStreamType rgb_type, VisionStreamType yuv_type, const std::string &url) { - s->frame = new FrameReader(); - if (!s->frame->load(url)) { - printf("failed to load stream from %s", url.c_str()); - assert(0); - } - - CameraInfo ci = { - .frame_width = (uint32_t)s->frame->width, - .frame_height = (uint32_t)s->frame->height, - .frame_stride = (uint32_t)s->frame->width * 3, - }; - s->ci = ci; - s->camera_num = camera_id; - s->fps = fps; - s->buf.init(device_id, ctx, s, v, FRAME_BUF_COUNT, rgb_type, yuv_type); -} - -void camera_close(CameraState *s) { - delete s->frame; -} - -void run_camera(CameraState *s) { - uint32_t stream_frame_id = 0, frame_id = 0; - size_t buf_idx = 0; - std::unique_ptr yuv_buf = std::make_unique(s->frame->getYUVSize()); - while (!do_exit) { - if (stream_frame_id == s->frame->getFrameCount()) { - // loop stream - stream_frame_id = 0; - } - if (s->frame->get(stream_frame_id++, yuv_buf.get())) { - s->buf.camera_bufs_metadata[buf_idx] = {.frame_id = frame_id}; - auto &buf = s->buf.camera_bufs[buf_idx]; - CL_CHECK(clEnqueueWriteBuffer(buf.copy_q, buf.buf_cl, CL_TRUE, 0, s->frame->getYUVSize(), yuv_buf.get(), 0, NULL, NULL)); - s->buf.queue(buf_idx); - ++frame_id; - buf_idx = (buf_idx + 1) % FRAME_BUF_COUNT; - } - util::sleep_for(1000 / s->fps); - } -} - -void road_camera_thread(CameraState *s) { - util::set_thread_name("replay_road_camera_thread"); - run_camera(s); -} - -// void driver_camera_thread(CameraState *s) { -// util::set_thread_name("replay_driver_camera_thread"); -// run_camera(s); -// } - -void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) { - const CameraBuf *b = &c->buf; - MessageBuilder msg; - auto framed = msg.initEvent().initRoadCameraState(); - fill_frame_data(framed, b->cur_frame_data); - framed.setImage(kj::arrayPtr((const uint8_t *)b->cur_yuv_buf->addr, b->cur_yuv_buf->len)); - framed.setTransform(b->yuv_transform.v); - s->pm->send("roadCameraState", msg); -} - -// void process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) { -// MessageBuilder msg; -// auto framed = msg.initEvent().initDriverCameraState(); -// framed.setFrameType(cereal::FrameData::FrameType::FRONT); -// fill_frame_data(framed, c->buf.cur_frame_data); -// s->pm->send("driverCameraState", msg); -// } - -} // namespace - -void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) { - camera_init(v, &s->road_cam, CAMERA_ID_LGC920, 20, device_id, ctx, - VISION_STREAM_RGB_ROAD, VISION_STREAM_ROAD, get_url(road_camera_route, "fcamera", 0)); - // camera_init(v, &s->driver_cam, CAMERA_ID_LGC615, 10, device_id, ctx, - // VISION_STREAM_RGB_DRIVER, VISION_STREAM_DRIVER, get_url(driver_camera_route, "dcamera", 0)); - s->pm = new PubMaster({"roadCameraState", "driverCameraState", "thumbnail"}); -} - -void cameras_open(MultiCameraState *s) {} - -void cameras_close(MultiCameraState *s) { - camera_close(&s->road_cam); - camera_close(&s->driver_cam); - delete s->pm; -} - -void cameras_run(MultiCameraState *s) { - std::vector threads; - threads.push_back(start_process_thread(s, &s->road_cam, process_road_camera)); - // threads.push_back(start_process_thread(s, &s->driver_cam, process_driver_camera)); - // threads.push_back(std::thread(driver_camera_thread, &s->driver_cam)); - road_camera_thread(&s->road_cam); - - for (auto &t : threads) t.join(); - - cameras_close(s); -} From ab7c653cc59c0935495ca359d30d5f87fbdaf69e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 18 May 2022 18:50:42 -0700 Subject: [PATCH 78/91] define new prime types --- selfdrive/ui/qt/widgets/prime.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/widgets/prime.h b/selfdrive/ui/qt/widgets/prime.h index 566238fc33..ce4baecfa2 100644 --- a/selfdrive/ui/qt/widgets/prime.h +++ b/selfdrive/ui/qt/widgets/prime.h @@ -9,8 +9,10 @@ enum PrimeType { NONE = 0, - MAGENTA, - LITE, + MAGENTA = 1, + LITE = 2, + BLUE = 3, + MAGENTA_NEW = 4, }; // pairing QR code From bdaf17415422ce16a1b2c412a89e099e552135a9 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 18 May 2022 19:04:11 -0700 Subject: [PATCH 79/91] Support RAV4 2022 with stock longitudinal (#24367) * support for ICE 2022 RAV4 * add to releases * swap * add fingerprints from a5c341bb250ca2f0 * update test route * update docs * add test for rav4 * values.py is a comma file --- RELEASES.md | 1 + docs/CARS.md | 1 + selfdrive/car/tests/routes.py | 1 + selfdrive/car/tests/test_docs.py | 5 ++++- selfdrive/car/toyota/interface.py | 2 +- selfdrive/car/toyota/values.py | 26 ++++++++++++++++++++++++-- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 6a72f8989a..07202c02f5 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -19,6 +19,7 @@ Version 0.8.14 (2022-0X-XX) * Hyundai Tucson Diesel 2019 support thanks to sunnyhaibin! * Toyota Alphard Hybrid 2021 support * Toyota Avalon Hybrid 2022 support + * Toyota RAV4 2022 support * Toyota RAV4 Hybrid 2022 support Version 0.8.13 (2022-02-18) diff --git a/docs/CARS.md b/docs/CARS.md index 7e40120250..5100a8306d 100644 --- a/docs/CARS.md +++ b/docs/CARS.md @@ -134,6 +134,7 @@ How We Rate The Cars |Toyota|Camry Hybrid 2018-20|All||[4](#footnotes)|||| |Toyota|Highlander 2017-19|All|[3](#footnotes)||||| |Toyota|Highlander Hybrid 2017-19|All|[3](#footnotes)||||| +|Toyota|RAV4 2022|All|||||| |Toyota|RAV4 Hybrid 2016-18|TSS-P|[3](#footnotes)||||| |Toyota|RAV4 Hybrid 2022|All|||||| |Toyota|Sienna 2018-20|All|[3](#footnotes)||||| diff --git a/selfdrive/car/tests/routes.py b/selfdrive/car/tests/routes.py index 6f8816a008..e3b8dcd121 100644 --- a/selfdrive/car/tests/routes.py +++ b/selfdrive/car/tests/routes.py @@ -127,6 +127,7 @@ routes = [ TestRoute("b14c5b4742e6fc85|2020-07-28--19-50-11", TOYOTA.RAV4), TestRoute("32a7df20486b0f70|2020-02-06--16-06-50", TOYOTA.RAV4H), TestRoute("cdf2f7de565d40ae|2019-04-25--03-53-41", TOYOTA.RAV4_TSS2), + TestRoute("a5c341bb250ca2f0|2022-05-18--16-05-17", TOYOTA.RAV4_TSS2_2022), TestRoute("7e34a988419b5307|2019-12-18--19-13-30", TOYOTA.RAV4H_TSS2), TestRoute("2475fb3eb2ffcc2e|2022-04-29--12-46-23", TOYOTA.RAV4H_TSS2_2022), TestRoute("e6a24be49a6cd46e|2019-10-29--10-52-42", TOYOTA.LEXUS_ES_TSS2), diff --git a/selfdrive/car/tests/test_docs.py b/selfdrive/car/tests/test_docs.py index 1530eb18af..74ef29fcab 100755 --- a/selfdrive/car/tests/test_docs.py +++ b/selfdrive/car/tests/test_docs.py @@ -19,13 +19,16 @@ class TestCarDocs(unittest.TestCase): def test_naming_conventions(self): # Asserts market-standard car naming conventions by make for car in self.all_cars: + tokens = car.model.lower().split(" ") if car.car_name == "hyundai": - tokens = car.model.lower().split(" ") self.assertNotIn("phev", tokens, "Use `Plug-in Hybrid`") self.assertNotIn("hev", tokens, "Use `Hybrid`") self.assertNotIn("ev", tokens, "Use `Electric`") if "plug-in hybrid" in car.model.lower(): self.assertIn("Plug-in Hybrid", car.model, "Use correct capitalization") + elif car.car_name == "toyota": + if "rav4" in tokens: + self.assertIn("RAV4", car.model, "Use correct capitalization") if __name__ == "__main__": diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index aa8b449ef9..fd3bd15cf1 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -115,7 +115,7 @@ class CarInterface(CarInterfaceBase): ret.mass = 3505. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid set_lat_tune(ret.lateralTuning, LatTunes.PID_H) - elif candidate in (CAR.RAV4_TSS2, CAR.RAV4H_TSS2, CAR.RAV4H_TSS2_2022): + elif candidate in (CAR.RAV4_TSS2, CAR.RAV4_TSS2_2022, CAR.RAV4H_TSS2, CAR.RAV4H_TSS2_2022): stop_and_go = True ret.wheelbase = 2.68986 ret.steerRatio = 14.3 diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index ef47ff9249..595c0c995e 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -62,6 +62,7 @@ class CAR: RAV4 = "TOYOTA RAV4 2017" RAV4H = "TOYOTA RAV4 HYBRID 2017" RAV4_TSS2 = "TOYOTA RAV4 2019" + RAV4_TSS2_2022 = "TOYOTA RAV4 2022" RAV4H_TSS2 = "TOYOTA RAV4 HYBRID 2019" RAV4H_TSS2_2022 = "TOYOTA RAV4 HYBRID 2022" MIRAI = "TOYOTA MIRAI 2021" # TSS 2.5 @@ -143,6 +144,7 @@ CAR_INFO: Dict[str, Union[ToyotaCarInfo, List[ToyotaCarInfo]]] = { CAR.RAV4: ToyotaCarInfo("Toyota RAV4 2016-18", "TSS-P", footnotes=[Footnote.DSU]), CAR.RAV4H: ToyotaCarInfo("Toyota RAV4 Hybrid 2016-18", "TSS-P", footnotes=[Footnote.DSU]), CAR.RAV4_TSS2: ToyotaCarInfo("Toyota RAV4 2019-21", video_link="https://www.youtube.com/watch?v=wJxjDd42gGA"), + CAR.RAV4_TSS2_2022: ToyotaCarInfo("Toyota RAV4 2022"), CAR.RAV4H_TSS2: ToyotaCarInfo("Toyota RAV4 Hybrid 2019-21"), CAR.RAV4H_TSS2_2022: ToyotaCarInfo("Toyota RAV4 Hybrid 2022"), CAR.MIRAI: ToyotaCarInfo("Toyota Mirai 2021"), @@ -1276,6 +1278,25 @@ FW_VERSIONS = { b'\x028646F4203800\x00\x00\x00\x008646G2601500\x00\x00\x00\x00', ], }, + CAR.RAV4_TSS2_2022: { + (Ecu.esp, 0x7b0, None): [ + b'\x01F15260R350\x00\x00\x00\x00\x00\x00', + b'\x01F15260R361\x00\x00\x00\x00\x00\x00', + ], + (Ecu.eps, 0x7a1, None): [ + b'\x028965B0R01500\x00\x00\x00\x008965B0R02500\x00\x00\x00\x00', + ], + (Ecu.engine, 0x700, None): [ + b'\x01896634AA1000\x00\x00\x00\x00', + b'\x01896634A88000\x00\x00\x00\x00', + ], + (Ecu.fwdRadar, 0x750, 0xf): [ + b'\x018821F0R01100\x00\x00\x00\x00', + ], + (Ecu.fwdCamera, 0x750, 0x6d): [ + b'\x028646F0R02100\x00\x00\x00\x008646G0R01100\x00\x00\x00\x00', + ], + }, CAR.RAV4H_TSS2: { (Ecu.engine, 0x700, None): [ b'\x01896634A15000\x00\x00\x00\x00', @@ -1866,6 +1887,7 @@ DBC = { CAR.AVALON_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.AVALONH_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.RAV4_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), + CAR.RAV4_TSS2_2022: dbc_dict('toyota_nodsu_pt_generated', None), CAR.COROLLA_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.COROLLAH_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.LEXUS_ES_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), @@ -1889,14 +1911,14 @@ DBC = { EPS_SCALE = defaultdict(lambda: 73, {CAR.PRIUS: 66, CAR.COROLLA: 88, CAR.LEXUS_IS: 77, CAR.LEXUS_RC: 77, CAR.LEXUS_CTH: 100, CAR.PRIUS_V: 100}) # Toyota/Lexus Safety Sense 2.0 and 2.5 -TSS2_CAR = {CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2, CAR.RAV4H_TSS2, CAR.RAV4H_TSS2_2022, +TSS2_CAR = {CAR.RAV4_TSS2, CAR.RAV4_TSS2_2022, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2, CAR.RAV4H_TSS2, CAR.RAV4H_TSS2_2022, CAR.LEXUS_RX_TSS2, CAR.LEXUS_RXH_TSS2, CAR.HIGHLANDER_TSS2, CAR.HIGHLANDERH_TSS2, CAR.PRIUS_TSS2, CAR.CAMRY_TSS2, CAR.CAMRYH_TSS2, CAR.MIRAI, CAR.LEXUS_NX_TSS2, CAR.ALPHARD_TSS2, CAR.AVALON_TSS2, CAR.AVALONH_TSS2, CAR.ALPHARDH_TSS2} NO_DSU_CAR = TSS2_CAR | {CAR.CHR, CAR.CHRH, CAR.CAMRY, CAR.CAMRYH} # these cars have a radar which sends ACC messages instead of the camera -RADAR_ACC_CAR = {CAR.RAV4H_TSS2_2022} +RADAR_ACC_CAR = {CAR.RAV4H_TSS2_2022, CAR.RAV4_TSS2_2022} EV_HYBRID_CAR = {CAR.AVALONH_2019, CAR.AVALONH_TSS2, CAR.CAMRYH, CAR.CAMRYH_TSS2, CAR.CHRH, CAR.COROLLAH_TSS2, CAR.HIGHLANDERH, CAR.HIGHLANDERH_TSS2, CAR.PRIUS, CAR.PRIUS_V, CAR.RAV4H, CAR.RAV4H_TSS2, CAR.RAV4H_TSS2_2022, CAR.LEXUS_CTH, CAR.MIRAI, CAR.LEXUS_ESH, CAR.LEXUS_ESH_TSS2, CAR.LEXUS_NXH, CAR.LEXUS_RXH, From 444d26582121550a371f14e17d614ba6984cc10a Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Thu, 19 May 2022 04:59:30 +0200 Subject: [PATCH 80/91] process replay: support running in parallel (#24534) * prefix params * set env * prefix in manager * filesystem except * dont delete manager folder * Update selfdrive/common/params.h Co-authored-by: Adeeb Shihadeh * debug same path * remove cleanup + same default * dont use filesystem lib * param symlink path * prefix helpers * path * dont delete d * parallel loop * refactor loop * msgq * clean msgs * spelling * nestable pool * spelling * logreaders in parallel * bugfix * assert msgq * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol * assert in cereal * folder exists * create dirs in test * bump cereal * Update selfdrive/test/process_replay/process_replay.py Co-authored-by: Adeeb Shihadeh * PR feedback * params path in basedir * ref commit * param path * bugfix * upload_only * param path * Update selfdrive/test/process_replay/process_replay.py Co-authored-by: Adeeb Shihadeh * msgq path name * python concurrency.features * progress bar * remove progress bar from compare logs * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Adeeb Shihadeh * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Adeeb Shihadeh * defaultdict * context manager * update refs * dont get logs if upload only * upload refs in parallel * cleanup * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol * cleanup * text Co-authored-by: Adeeb Shihadeh Co-authored-by: Shane Smiskol --- selfdrive/test/process_replay/compare_logs.py | 11 +-- .../test/process_replay/process_replay.py | 38 +++++++-- .../test/process_replay/test_processes.py | 81 ++++++++++++------- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/selfdrive/test/process_replay/compare_logs.py b/selfdrive/test/process_replay/compare_logs.py index f1ca69987c..057e46cd9c 100755 --- a/selfdrive/test/process_replay/compare_logs.py +++ b/selfdrive/test/process_replay/compare_logs.py @@ -1,25 +1,18 @@ #!/usr/bin/env python3 import bz2 -import os import sys import math import numbers import dictdiffer from collections import Counter -if "CI" in os.environ: - def tqdm(x): - return x -else: - from tqdm import tqdm # type: ignore - from tools.lib.logreader import LogReader EPSILON = sys.float_info.epsilon def save_log(dest, log_msgs, compress=True): - dat = b"".join(msg.as_builder().to_bytes() for msg in tqdm(log_msgs)) + dat = b"".join(msg.as_builder().to_bytes() for msg in log_msgs) if compress: dat = bz2.compress(dat) @@ -67,7 +60,7 @@ def compare_logs(log1, log2, ignore_fields=None, ignore_msgs=None, tolerance=Non raise Exception(f"logs are not same length: {len(log1)} VS {len(log2)}\n\t\t{cnt1}\n\t\t{cnt2}") diff = [] - for msg1, msg2 in tqdm(zip(log1, log2)): + for msg1, msg2 in zip(log1, log2): if msg1.which() != msg2.which(): print(msg1, msg2) raise Exception("msgs not aligned between logs") diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 03d882591f..15086412a3 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -4,11 +4,12 @@ import os import sys import threading import time +import shutil import signal +import uuid from collections import namedtuple import capnp -from tqdm import tqdm import cereal.messaging as messaging from cereal import car, log @@ -336,12 +337,35 @@ CONFIGS = [ ), ] +def setup_prefix(): + os.environ['OPENPILOT_PREFIX'] = str(uuid.uuid4()) + msgq_path = os.path.join('/dev/shm', os.environ['OPENPILOT_PREFIX']) + try: + os.mkdir(msgq_path) + except FileExistsError: + pass + + +def teardown_prefix(): + if not os.environ.get("OPENPILOT_PREFIX", 0): + return + symlink_path = Params().get_param_path() + if os.path.exists(symlink_path): + shutil.rmtree(os.path.realpath(symlink_path), ignore_errors=True) + os.remove(symlink_path) + msgq_path = os.path.join('/dev/shm', os.environ['OPENPILOT_PREFIX']) + shutil.rmtree(msgq_path, ignore_errors=True) + def replay_process(cfg, lr, fingerprint=None): - if cfg.fake_pubsubmaster: - return python_replay_process(cfg, lr, fingerprint) - else: - return cpp_replay_process(cfg, lr, fingerprint) + setup_prefix() + try: + if cfg.fake_pubsubmaster: + return python_replay_process(cfg, lr, fingerprint) + else: + return cpp_replay_process(cfg, lr, fingerprint) + finally: + teardown_prefix() def setup_env(simulation=False): params = Params() @@ -421,7 +445,7 @@ def python_replay_process(cfg, lr, fingerprint=None): fsm.wait_for_update() log_msgs, msg_queue = [], [] - for msg in tqdm(pub_msgs, disable=CI): + for msg in pub_msgs: if cfg.should_recv_callback is not None: recv_socks, should_recv = cfg.should_recv_callback(msg, CP, cfg, fsm) else: @@ -473,7 +497,7 @@ def cpp_replay_process(cfg, lr, fingerprint=None): for s in sub_sockets: messaging.recv_one_or_none(sockets[s]) - for i, msg in enumerate(tqdm(pub_msgs, disable=False)): + for i, msg in enumerate(pub_msgs): pm.send(msg.which(), msg.as_builder()) resp_sockets = cfg.pub_sub[msg.which()] if cfg.should_recv_callback is None else cfg.should_recv_callback(msg) diff --git a/selfdrive/test/process_replay/test_processes.py b/selfdrive/test/process_replay/test_processes.py index ec94cc333b..e6dcf10e48 100755 --- a/selfdrive/test/process_replay/test_processes.py +++ b/selfdrive/test/process_replay/test_processes.py @@ -1,7 +1,10 @@ #!/usr/bin/env python3 import argparse +import concurrent.futures import os import sys +from collections import defaultdict +from tqdm import tqdm from typing import Any, Dict from selfdrive.car.car_helpers import interface_names @@ -11,7 +14,6 @@ from selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DI from selfdrive.version import get_commit from tools.lib.logreader import LogReader - original_segments = [ ("BODY", "bd6a637565e91581|2022-04-04--22-05-08--0"), # COMMA.BODY ("HYUNDAI", "02c45f73a2e5c6e9|2021-01-01--19-08-22--1"), # HYUNDAI.SONATA @@ -54,6 +56,28 @@ BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" REF_COMMIT_FN = os.path.join(PROC_REPLAY_DIR, "ref_commit") +def run_test_process(data): + segment, cfg, args, cur_log_fn, lr, ref_commit = data + res = None + if not args.upload_only: + ref_log_fn = os.path.join(PROC_REPLAY_DIR, f"{segment}_{cfg.proc_name}_{ref_commit}.bz2") + res, log_msgs = test_process(cfg, lr, ref_log_fn, args.ignore_fields, args.ignore_msgs) + # save logs so we can upload when updating refs + save_log(cur_log_fn, log_msgs) + if args.update_refs or args.upload_only: + print(f'Uploading: {os.path.basename(cur_log_fn)}') + assert os.path.exists(cur_log_fn), f"Cannot find log to upload: {cur_log_fn}" + upload_file(cur_log_fn, os.path.basename(cur_log_fn)) + os.remove(cur_log_fn) + return (segment, cfg.proc_name, res) + + +def get_logreader(segment): + r, n = segment.rsplit("--", 1) + lr = LogReader(get_url(r, n)) + return (segment, lr) + + def test_process(cfg, lr, ref_log_fn, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] @@ -127,6 +151,7 @@ if __name__ == "__main__": help="Updates reference logs using current commit") parser.add_argument("--upload-only", action="store_true", help="Skips testing processes and uploads logs from previous test run") + parser.add_argument("-j", "--jobs", type=int, default=1) args = parser.parse_args() full_test = all(len(x) == 0 for x in (args.whitelist_procs, args.whitelist_cars, args.blacklist_procs, args.blacklist_cars, args.ignore_fields, args.ignore_msgs)) @@ -154,37 +179,31 @@ if __name__ == "__main__": untested = (set(interface_names) - set(excluded_interfaces)) - tested_cars assert len(untested) == 0, f"Cars missing routes: {str(untested)}" - results: Any = {} - for car_brand, segment in segments: - if (len(args.whitelist_cars) and car_brand.upper() not in args.whitelist_cars) or \ - (not len(args.whitelist_cars) and car_brand.upper() in args.blacklist_cars): - continue - - print(f"***** testing route segment {segment} *****\n") - - results[segment] = {} - - r, n = segment.rsplit("--", 1) - lr = LogReader(get_url(r, n)) - - for cfg in CONFIGS: - if (len(args.whitelist_procs) and cfg.proc_name not in args.whitelist_procs) or \ - (not len(args.whitelist_procs) and cfg.proc_name in args.blacklist_procs): + with concurrent.futures.ProcessPoolExecutor(max_workers=args.jobs) as pool: + if not args.upload_only: + lreaders: Any = {} + p1 = pool.map(get_logreader, [seg for car, seg in segments]) + for (segment, lr) in tqdm(p1, desc="Getting Logs", total=len(segments)): + lreaders[segment] = lr + + pool_args: Any = [] + for car_brand, segment in segments: + if (len(args.whitelist_cars) and car_brand.upper() not in args.whitelist_cars) or \ + (not len(args.whitelist_cars) and car_brand.upper() in args.blacklist_cars): continue - - cur_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{cur_commit}.bz2") - if not args.upload_only: - ref_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{ref_commit}.bz2") - results[segment][cfg.proc_name], log_msgs = test_process(cfg, lr, ref_log_fn, args.ignore_fields, args.ignore_msgs) - - # save logs so we can upload when updating refs - save_log(cur_log_fn, log_msgs) - - if upload: - print(f'Uploading: {os.path.basename(cur_log_fn)}') - assert os.path.exists(cur_log_fn), f"Cannot find log to upload: {cur_log_fn}" - upload_file(cur_log_fn, os.path.basename(cur_log_fn)) - os.remove(cur_log_fn) + for cfg in CONFIGS: + if (len(args.whitelist_procs) and cfg.proc_name not in args.whitelist_procs) or \ + (not len(args.whitelist_procs) and cfg.proc_name in args.blacklist_procs): + continue + cur_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{cur_commit}.bz2") + lr = None if args.upload_only else lreaders[segment] + pool_args.append((segment, cfg, args, cur_log_fn, lr, ref_commit)) + + results: Any = defaultdict(dict) + p2 = pool.map(run_test_process, pool_args) + for (segment, proc, result) in tqdm(p2, desc="Running Tests", total=len(pool_args)): + if isinstance(result, list): + results[segment][proc] = result diff1, diff2, failed = format_diff(results, ref_commit) if not args.upload_only: From 285bbe5283c754d8e132627f4aef722f0dac8641 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 19 May 2022 00:45:04 -0700 Subject: [PATCH 81/91] bump opendbc --- opendbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc b/opendbc index 87af8c4ac1..210237fa63 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit 87af8c4ac192e263bdd4e832d71bb10f480172ec +Subproject commit 210237fa635eeb76ad855c2031d2cad3bde3a2c0 From d3d210c18304e5ce37c844b3efb706b30fee1460 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 19 May 2022 03:28:50 -0700 Subject: [PATCH 82/91] controls: pressing set while gas pressed resets to vEgo (#24100) * set while gas pressed to resume * better order * what was I thinking? * Update selfdrive/controls/lib/drive_helpers.py Co-authored-by: Gijs Koning * Update selfdrive/controls/lib/drive_helpers.py Co-authored-by: Gijs Koning * only if under set speed * some clean up and ciel the v_cruise_kph * clean up * actually floor * Should be cruise min * On phone, will clean up * Think no floor is fine * clean up and catch setCruise * update comment and just always do rounding and clipping update comment * flip order Co-authored-by: Gijs Koning --- selfdrive/controls/controlsd.py | 3 ++- selfdrive/controls/lib/drive_helpers.py | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 22377fc2b2..6869846ad1 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -445,7 +445,8 @@ class Controls: # if stock cruise is completely disabled, then we can use our own set speed logic if not self.CP.pcmCruise: - self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.buttonEvents, self.button_timers, self.enabled, self.is_metric) + self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.vEgo, CS.gasPressed, CS.buttonEvents, + self.button_timers, self.enabled, self.is_metric) else: if CS.cruiseState.available: self.v_cruise_kph = CS.cruiseState.speed * CV.MS_TO_KPH diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index a9725a475f..4afa8d89ed 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -1,8 +1,9 @@ import math + from cereal import car +from common.conversions import Conversions as CV from common.numpy_fast import clip, interp from common.realtime import DT_MDL -from common.conversions import Conversions as CV from selfdrive.modeld.constants import T_IDXS # WARNING: this value was determined based on the model's training distribution, @@ -19,14 +20,15 @@ CAR_ROTATION_RADIUS = 0.0 # EU guidelines MAX_LATERAL_JERK = 5.0 +ButtonType = car.CarState.ButtonEvent.Type CRUISE_LONG_PRESS = 50 CRUISE_NEAREST_FUNC = { - car.CarState.ButtonEvent.Type.accelCruise: math.ceil, - car.CarState.ButtonEvent.Type.decelCruise: math.floor, + ButtonType.accelCruise: math.ceil, + ButtonType.decelCruise: math.floor, } CRUISE_INTERVAL_SIGN = { - car.CarState.ButtonEvent.Type.accelCruise: +1, - car.CarState.ButtonEvent.Type.decelCruise: -1, + ButtonType.accelCruise: +1, + ButtonType.decelCruise: -1, } @@ -40,7 +42,7 @@ def rate_limit(new_value, last_value, dw_step, up_step): return clip(new_value, last_value + dw_step, last_value + up_step) -def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): +def update_v_cruise(v_cruise_kph, v_ego, gas_pressed, buttonEvents, button_timers, enabled, metric): # handle button presses. TODO: this should be in state_control, but a decelCruise press # would have the effect of both enabling and changing speed is checked after the state transition if not enabled: @@ -55,7 +57,7 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): for b in buttonEvents: if b.type.raw in button_timers and not b.pressed: if button_timers[b.type.raw] > CRUISE_LONG_PRESS: - return v_cruise_kph # end long press + return v_cruise_kph # end long press button_type = b.type.raw break else: @@ -67,10 +69,15 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): if button_type: v_cruise_delta = v_cruise_delta * (5 if long_press else 1) - if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval + if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](v_cruise_kph / v_cruise_delta) * v_cruise_delta else: v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type] + + # If set is pressed while overriding, clip cruise speed to minimum of vEgo + if gas_pressed and button_type in (ButtonType.decelCruise, ButtonType.setCruise): + v_cruise_kph = max(v_cruise_kph, v_ego * CV.MS_TO_KPH) + v_cruise_kph = clip(round(v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX) return v_cruise_kph @@ -79,7 +86,7 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): def initialize_v_cruise(v_ego, buttonEvents, v_cruise_last): for b in buttonEvents: # 250kph or above probably means we never had a set speed - if b.type in (car.CarState.ButtonEvent.Type.accelCruise, car.CarState.ButtonEvent.Type.resumeCruise) and v_cruise_last < 250: + if b.type in (ButtonType.accelCruise, ButtonType.resumeCruise) and v_cruise_last < 250: return v_cruise_last return int(round(clip(v_ego * CV.MS_TO_KPH, V_CRUISE_ENABLE_MIN, V_CRUISE_MAX))) From dd55d14bb1a1bc7c7d4fdfbf1b1344562d11f847 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 19 May 2022 15:36:07 +0200 Subject: [PATCH 83/91] statsd: fix duplicate filename (#24595) --- selfdrive/statsd.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfdrive/statsd.py b/selfdrive/statsd.py index b880c4110a..5755e5111b 100755 --- a/selfdrive/statsd.py +++ b/selfdrive/statsd.py @@ -88,6 +88,7 @@ def main() -> NoReturn: # subscribe to deviceState for started state sm = SubMaster(['deviceState']) + idx = 0 last_flush_time = time.monotonic() gauges = {} samples: Dict[str, List[float]] = defaultdict(list) @@ -149,9 +150,10 @@ def main() -> NoReturn: # check that we aren't filling up the drive if len(os.listdir(STATS_DIR)) < STATS_DIR_FILE_LIMIT: if len(result) > 0: - stats_path = os.path.join(STATS_DIR, str(int(current_time.timestamp()))) + stats_path = os.path.join(STATS_DIR, f"{current_time.timestamp():.0f}_{idx}") with atomic_write_in_dir(stats_path) as f: f.write(result) + idx += 1 else: cloudlog.error("stats dir full") From a1fadc7b547f10782222b3f38df68e89d649dd92 Mon Sep 17 00:00:00 2001 From: Jason Young <46612682+jyoung8607@users.noreply.github.com> Date: Thu, 19 May 2022 16:42:52 -0400 Subject: [PATCH 84/91] VW MQB: Cleanup, add FW for 2022 Volkswagen Taos (#24596) * null-effect ordering and indentation fixes * VW MQB: Add FW for 2022 Volkswagen Taos --- selfdrive/car/volkswagen/values.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/selfdrive/car/volkswagen/values.py b/selfdrive/car/volkswagen/values.py index 51e7c85dbc..1dc431eb77 100755 --- a/selfdrive/car/volkswagen/values.py +++ b/selfdrive/car/volkswagen/values.py @@ -469,16 +469,16 @@ FW_VERSIONS = { }, CAR.POLO_MK6: { (Ecu.engine, 0x7e0, None): [ - b'\xf1\x8704C906025H \xf1\x895177', + b'\xf1\x8704C906025H \xf1\x895177', ], (Ecu.transmission, 0x7e1, None): [ - b'\xf1\x870CW300050D \xf1\x891908', + b'\xf1\x870CW300050D \xf1\x891908', ], (Ecu.srs, 0x715, None): [ b'\xf1\x872Q0959655AJ\xf1\x890250\xf1\x82\x1248130411110416--04040404784811152H14', ], (Ecu.eps, 0x712, None): [ - b'\xf1\x872Q1909144M \xf1\x896041', + b'\xf1\x872Q1909144M \xf1\x896041', ], (Ecu.fwdRadar, 0x757, None): [ b'\xf1\x872Q0907572R \xf1\x890372', @@ -486,19 +486,23 @@ FW_VERSIONS = { }, CAR.TAOS_MK1: { (Ecu.engine, 0x7e0, None): [ - b'\xf1\x8705E906013E \xf1\x891624', + b'\xf1\x8704E906027NJ\xf1\x891445', + b'\xf1\x8705E906013E \xf1\x891624', ], (Ecu.transmission, 0x7e1, None): [ - b'\xf1\x8709S927158BL\xf1\x893791', + b'\xf1\x8709S927158BL\xf1\x893791', + b'\xf1\x8709S927158FF\xf1\x893876', ], - (Ecu.fwdRadar, 0x757, None): [ - b'\xf1\x872Q0907572T \xf1\x890383', + (Ecu.srs, 0x715, None): [ + b'\xf1\x875Q0959655CB\xf1\x890421\xf1\x82\x1311111111333500314646021450149333613100', + b'\xf1\x875Q0959655CE\xf1\x890421\xf1\x82\x1311110011333300314240021350139333613100', ], (Ecu.eps, 0x712, None): [ - b'\xf1\x875QM909144C \xf1\x891082\xf1\x82\x0521060605A1', + b'\xf1\x875QM909144C \xf1\x891082\xf1\x82\x0521060405A1', + b'\xf1\x875QM909144C \xf1\x891082\xf1\x82\x0521060605A1', ], - (Ecu.srs, 0x715, None): [ - b'\xf1\x875Q0959655CB\xf1\x890421\xf1\x82\x1311111111333500314646021450149333613100', + (Ecu.fwdRadar, 0x757, None): [ + b'\xf1\x872Q0907572T \xf1\x890383', ], }, CAR.TCROSS_MK1: { From fa901fd88b0c593367c88e3a5c34cf4706c30e3e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 19 May 2022 16:01:50 -0700 Subject: [PATCH 85/91] bump panda --- panda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda b/panda index 893a81aa82..36c62afa0c 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit 893a81aa823254cd72c9817886d4b4039ea04a7e +Subproject commit 36c62afa0c170aa1b7a39bcae3316ffb844499e8 From 238faf4810a8de5492ffb419466c08711afcfd59 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 19 May 2022 21:57:11 -0700 Subject: [PATCH 86/91] update release notes --- RELEASES.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 07202c02f5..77a4c80cf1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,17 +1,12 @@ -Version 0.8.14 (2022-0X-XX) +Version 0.8.14 (2022-05-30) ======================== * New driving model * Bigger model, using both of comma three's road-facing cameras * Better at cut-in detection and tight turns * New driver monitoring model - * Tweaked network structure to improve output resolution for dsp + * Tweaked network structure to improve output resolution for DSP * Fixed bug in quantization aware training to reduce quantizing errors * Resulted in 7x less MSE and no more random biases at runtime - * New lateral controller based on physical wheel torque model - * Much smoother control, consistent across the speed range - * Effective feedforward that uses road roll - * Simplified tuning, all car-specific parameters can be derived from data - * Initially used on TSS2 Corolla and TSS-P RAV4 * Added toggle to disable disengaging on the accelerator pedal * comma body support * Audi RS3 support thanks to jyoung8607! From d87f30ea069a4bbfc20c8caa32e9fdf89a498ed5 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 19 May 2022 22:33:17 -0700 Subject: [PATCH 87/91] encoder test speedup (#24601) Co-authored-by: Comma Device --- selfdrive/loggerd/tests/test_encoder.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/selfdrive/loggerd/tests/test_encoder.py b/selfdrive/loggerd/tests/test_encoder.py index 969ac1c6a2..49baa8a6e3 100755 --- a/selfdrive/loggerd/tests/test_encoder.py +++ b/selfdrive/loggerd/tests/test_encoder.py @@ -143,20 +143,18 @@ class TestEncoder(unittest.TestCase): shutil.rmtree(f"{route_prefix_path}--{i}") try: - for i in trange(num_segments + 1): + for i in trange(num_segments): # poll for next segment with Timeout(int(SEGMENT_LENGTH*10), error_msg=f"timed out waiting for segment {i}"): - while Path(f"{route_prefix_path}--{i}") not in Path(ROOT).iterdir(): + while Path(f"{route_prefix_path}--{i+1}") not in Path(ROOT).iterdir(): time.sleep(0.1) + check_seg(i) finally: managed_processes['loggerd'].stop() managed_processes['encoderd'].stop() managed_processes['camerad'].stop() managed_processes['sensord'].stop() - for i in trange(num_segments): - check_seg(i) - if __name__ == "__main__": unittest.main() From 0000ad2ac0996075481841221e9bcc842f2812d7 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Fri, 20 May 2022 00:02:50 -0700 Subject: [PATCH 88/91] loggerd: Fix loggerd encode packet drops (#24599) * hmm, try this * hmm, try this * rewrite handle_encoder_msg * fix new logic * add comments and an assert * handle startup condition better * handle restarts of encoderd Co-authored-by: Comma Device --- selfdrive/loggerd/loggerd.cc | 121 ++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 43 deletions(-) diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 06fd9c74e5..1a10ab0c07 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -43,27 +43,20 @@ void rotate_if_needed(LoggerdState *s) { struct RemoteEncoder { std::unique_ptr writer; - int segment = -1; + int encoderd_segment_offset; + int current_segment = -1; std::vector q; - int logger_segment = -1; int dropped_frames = 0; bool recording = false; + bool marked_ready_to_rotate = false; + bool seen_first_packet = false; }; int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct RemoteEncoder &re) { const LogCameraInfo &cam_info = (name == "driverEncodeData") ? cameras_logged[1] : ((name == "wideRoadEncodeData") ? cameras_logged[2] : ((name == "qRoadEncodeData") ? qcam_info : cameras_logged[0])); - - // rotation happened, process the queue (happens before the current message) int bytes_count = 0; - if (re.logger_segment != s->rotate_segment) { - re.logger_segment = s->rotate_segment; - for (auto &qmsg: re.q) { - bytes_count += handle_encoder_msg(s, qmsg, name, re); - } - re.q.clear(); - } // extract the message capnp::FlatArrayMessageReader cmsg(kj::ArrayPtr((capnp::word *)msg->getData(), msg->getSize())); @@ -74,42 +67,66 @@ int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct auto idx = edata.getIdx(); auto flags = idx.getFlags(); - if (!re.recording) { - // only create on iframe - if (flags & V4L2_BUF_FLAG_KEYFRAME) { - if (re.dropped_frames) { - // this should only happen for the first segment, maybe - LOGD("%s: dropped %d non iframe packets before init", name.c_str(), re.dropped_frames); - re.dropped_frames = 0; + // encoderd can have started long before loggerd + if (!re.seen_first_packet) { + re.seen_first_packet = true; + re.encoderd_segment_offset = idx.getSegmentNum(); + LOGD("%s: has encoderd offset %d", name.c_str(), re.encoderd_segment_offset); + } + int offset_segment_num = idx.getSegmentNum() - re.encoderd_segment_offset; + + if (offset_segment_num == s->rotate_segment) { + // loggerd is now on the segment that matches this packet + + // if this is a new segment, we close any possible old segments, move to the new, and process any queued packets + if (re.current_segment != s->rotate_segment) { + if (re.recording) { + re.writer.reset(); + re.recording = false; } - // if we aren't recording, don't create the writer - if (cam_info.record) { - re.writer.reset(new VideoWriter(s->segment_path, - cam_info.filename, idx.getType() != cereal::EncodeIndex::Type::FULL_H_E_V_C, - cam_info.frame_width, cam_info.frame_height, cam_info.fps, idx.getType())); - // write the header - auto header = edata.getHeader(); - re.writer->write((uint8_t *)header.begin(), header.size(), idx.getTimestampEof()/1000, true, false); + re.current_segment = s->rotate_segment; + re.marked_ready_to_rotate = false; + // we are in this segment now, process any queued messages before this one + if (!re.q.empty()) { + for (auto &qmsg: re.q) { + bytes_count += handle_encoder_msg(s, qmsg, name, re); + } + re.q.clear(); } - re.segment = idx.getSegmentNum(); - re.recording = true; - } else { - ++re.dropped_frames; - return bytes_count; } - } - if (re.segment != idx.getSegmentNum()) { - if (re.recording) { - // encoder is on the next segment, this segment is over so we close the videowriter - re.writer.reset(); - re.recording = false; - ++s->ready_to_rotate; - LOGD("rotate %d -> %d ready %d/%d for %s", re.segment, idx.getSegmentNum(), s->ready_to_rotate.load(), s->max_waiting, name.c_str()); + // if we aren't recording yet, try to start, since we are in the correct segment + if (!re.recording) { + if (flags & V4L2_BUF_FLAG_KEYFRAME) { + // only create on iframe + if (re.dropped_frames) { + // this should only happen for the first segment, maybe + LOGW("%s: dropped %d non iframe packets before init", name.c_str(), re.dropped_frames); + re.dropped_frames = 0; + } + // if we aren't actually recording, don't create the writer + if (cam_info.record) { + re.writer.reset(new VideoWriter(s->segment_path, + cam_info.filename, idx.getType() != cereal::EncodeIndex::Type::FULL_H_E_V_C, + cam_info.frame_width, cam_info.frame_height, cam_info.fps, idx.getType())); + // write the header + auto header = edata.getHeader(); + re.writer->write((uint8_t *)header.begin(), header.size(), idx.getTimestampEof()/1000, true, false); + } + re.recording = true; + } else { + // this is a sad case when we aren't recording, but don't have an iframe + // nothing we can do but drop the frame + delete msg; + ++re.dropped_frames; + return bytes_count; + } } - // queue up all the new segment messages, they go in after the rotate - re.q.push_back(msg); - } else { + + // we have to be recording if we are here + assert(re.recording); + + // if we are actually writing the video file, do so if (re.writer) { auto data = edata.getData(); re.writer->write((uint8_t *)data.begin(), data.size(), idx.getTimestampEof()/1000, false, flags & V4L2_BUF_FLAG_KEYFRAME); @@ -127,7 +144,25 @@ int handle_encoder_msg(LoggerdState *s, Message *msg, std::string &name, struct logger_log(&s->logger, (uint8_t *)new_msg.begin(), new_msg.size(), true); // always in qlog? bytes_count += new_msg.size(); - // this frees the message + // free the message, we used it + delete msg; + } else if (offset_segment_num > s->rotate_segment) { + // encoderd packet has a newer segment, this means encoderd has rolled over + if (!re.marked_ready_to_rotate) { + re.marked_ready_to_rotate = true; + ++s->ready_to_rotate; + LOGD("rotate %d -> %d ready %d/%d for %s", + s->rotate_segment.load(), offset_segment_num, + s->ready_to_rotate.load(), s->max_waiting, name.c_str()); + } + // queue up all the new segment messages, they go in after the rotate + re.q.push_back(msg); + } else { + LOGE("%s: encoderd packet has a older segment!!! idx.getSegmentNum():%d s->rotate_segment:%d re.encoderd_segment_offset:%d", + name.c_str(), idx.getSegmentNum(), s->rotate_segment.load(), re.encoderd_segment_offset); + // free the message, it's useless. this should never happen + // actually, this can happen if you restart encoderd + re.encoderd_segment_offset = -s->rotate_segment.load(); delete msg; } From ef97329c0e825d477577bf27cbaf772753f077ca Mon Sep 17 00:00:00 2001 From: Gijs Koning Date: Fri, 20 May 2022 03:21:17 -0700 Subject: [PATCH 89/91] Add gnss kalman filter to laikad (#24578) * Add gnss kalman filter to laikad * Fix analysis * Fix analysis * Update laika * Refactor a bit * cleanup, improve unit test * Also commit test * fix * Always return messages. Use Measurement struct that contains std and valid keys * Push cereal * Change prints to cloudlog * Always send valid messages * Only send gnssMeasurement msg when measurementReport type --- cereal | 2 +- laika_repo | 2 +- selfdrive/locationd/laikad.py | 163 +++++++++++++++++------- selfdrive/locationd/test/test_laikad.py | 40 +++++- 4 files changed, 158 insertions(+), 49 deletions(-) diff --git a/cereal b/cereal index e5d0a4ff42..b43ac3de52 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit e5d0a4ff42d9e1ccbcc7bd603ff5c4e82c0794aa +Subproject commit b43ac3de527ad4f885af544cd0e9e9d4a9b1a6c2 diff --git a/laika_repo b/laika_repo index be1a213a5f..f5f76d28b4 160000 --- a/laika_repo +++ b/laika_repo @@ -1 +1 @@ -Subproject commit be1a213a5ffa3cafe2b4f2d53f6df5d2452ad910 +Subproject commit f5f76d28b4827c3fb706d542729651ceef6c06bd diff --git a/selfdrive/locationd/laikad.py b/selfdrive/locationd/laikad.py index 4695fd945b..d07fe4a78a 100755 --- a/selfdrive/locationd/laikad.py +++ b/selfdrive/locationd/laikad.py @@ -1,79 +1,154 @@ #!/usr/bin/env python3 from typing import List +import numpy as np +from collections import defaultdict + from cereal import log, messaging from laika import AstroDog from laika.helpers import ConstellationId from laika.raw_gnss import GNSSMeasurement, calc_pos_fix, correct_measurements, process_measurements, read_raw_ublox +from selfdrive.locationd.models.constants import GENERATED_DIR, ObservationKind +from selfdrive.locationd.models.gnss_kf import GNSSKalman +from selfdrive.locationd.models.gnss_kf import States as GStates +import common.transformations.coordinates as coord +from selfdrive.swaglog import cloudlog + +MAX_TIME_GAP = 10 + + +class Laikad: + + def __init__(self): + self.gnss_kf = GNSSKalman(GENERATED_DIR) + + def process_ublox_msg(self, ublox_msg, dog: AstroDog, ublox_mono_time: int): + if ublox_msg.which == 'measurementReport': + report = ublox_msg.measurementReport + new_meas = read_raw_ublox(report) + measurements = process_measurements(new_meas, dog) + + + pos_fix = calc_pos_fix(measurements) + # To get a position fix a minimum of 5 measurements are needed. + # Each report can contain less and some measurement can't be processed. + if len(pos_fix) > 0: + measurements = correct_measurements(measurements, pos_fix[0][:3], dog) + meas_msgs = [create_measurement_msg(m) for m in measurements] + + t = ublox_mono_time * 1e-9 + + self.update_localizer(pos_fix, t, measurements) + localizer_valid = self.localizer_valid(t) + + ecef_pos = self.gnss_kf.x[GStates.ECEF_POS].tolist() + ecef_vel = self.gnss_kf.x[GStates.ECEF_VELOCITY].tolist() + + pos_std = float(np.linalg.norm(self.gnss_kf.P[GStates.ECEF_POS])) + vel_std = float(np.linalg.norm(self.gnss_kf.P[GStates.ECEF_VELOCITY])) + + bearing_deg, bearing_std = get_bearing_from_gnss(ecef_pos, ecef_vel, vel_std) + + dat = messaging.new_message("gnssMeasurements") + measurement_msg = log.GnssMeasurements.Measurement.new_message + dat.gnssMeasurements = { + "positionECEF": measurement_msg(value=ecef_pos, std=pos_std, valid=localizer_valid), + "velocityECEF": measurement_msg(value=ecef_vel, std=vel_std, valid=localizer_valid), + "bearingDeg": measurement_msg(value=[bearing_deg], std=bearing_std, valid=localizer_valid), + "ubloxMonoTime": ublox_mono_time, + "correctedMeasurements": meas_msgs + } + return dat + + def update_localizer(self, pos_fix, t: float, measurements: List[GNSSMeasurement]): + # Check time and outputs are valid + if not self.localizer_valid(t): + # A position fix is needed when resetting the kalman filter. + if len(pos_fix) == 0: + return + post_est = pos_fix[0][:3].tolist() + if self.gnss_kf.filter.filter_time is None: + cloudlog.info("Init gnss kalman filter") + elif (self.gnss_kf.filter.filter_time - t) > MAX_TIME_GAP: + cloudlog.error("Time gap of over 10s detected, gnss kalman reset") + else: + cloudlog.error("Gnss kalman filter state is nan") + self.init_gnss_localizer(post_est) + if len(measurements) > 0: + kf_add_observations(self.gnss_kf, t, measurements) + else: + # Ensure gnss filter is updated even with no new measurements + self.gnss_kf.predict(t) + def localizer_valid(self, t: float): + filter_time = self.gnss_kf.filter.filter_time + return filter_time is not None and (filter_time - t) < MAX_TIME_GAP and \ + all(np.isfinite(self.gnss_kf.x[GStates.ECEF_POS])) -def correct_and_pos_fix(processed_measurements: List[GNSSMeasurement], dog: AstroDog): - # pos fix needs more than 5 processed_measurements - pos_fix = calc_pos_fix(processed_measurements) - - if len(pos_fix) == 0: - return [], [] - est_pos = pos_fix[0][:3] - corrected = correct_measurements(processed_measurements, est_pos, dog) - return calc_pos_fix(corrected), corrected - - -def process_ublox_msg(ublox_msg, dog, ublox_mono_time: int): - if ublox_msg.which == 'measurementReport': - report = ublox_msg.measurementReport - if len(report.measurements) == 0: - return None - new_meas = read_raw_ublox(report) - processed_measurements = process_measurements(new_meas, dog) - - corrected = correct_and_pos_fix(processed_measurements, dog) - pos_fix, _ = corrected - # todo send corrected messages instead of processed_measurements. Need fix for when having less than 6 measurements - correct_meas_msgs = [create_measurement_msg(m) for m in processed_measurements] - # pos fix can be an empty list if not enough correct measurements are available - if len(pos_fix) > 0: - corrected_pos = pos_fix[0][:3].tolist() - else: - corrected_pos = [0., 0., 0.] - dat = messaging.new_message('gnssMeasurements') - dat.gnssMeasurements = { - "position": corrected_pos, - "ubloxMonoTime": ublox_mono_time, - "correctedMeasurements": correct_meas_msgs - } - return dat + def init_gnss_localizer(self, est_pos): + x_initial, p_initial_diag = np.copy(GNSSKalman.x_initial), np.copy(np.diagonal(GNSSKalman.P_initial)) + x_initial[GStates.ECEF_POS] = est_pos + p_initial_diag[GStates.ECEF_POS] = 1000 ** 2 + + self.gnss_kf.init_state(x_initial, covs_diag=p_initial_diag) def create_measurement_msg(meas: GNSSMeasurement): c = log.GnssMeasurements.CorrectedMeasurement.new_message() c.constellationId = meas.constellation_id.value - c.svId = int(meas.prn[1:]) + c.svId = meas.sv_id + observables = meas.observables_final c.glonassFrequency = meas.glonass_freq if meas.constellation_id == ConstellationId.GLONASS else 0 - c.pseudorange = float(meas.observables['C1C']) # todo should be observables_final when using corrected measurements + c.pseudorange = float(observables['C1C']) c.pseudorangeStd = float(meas.observables_std['C1C']) - c.pseudorangeRate = float(meas.observables['D1C']) # todo should be observables_final when using corrected measurements + c.pseudorangeRate = float(observables['D1C']) c.pseudorangeRateStd = float(meas.observables_std['D1C']) c.satPos = meas.sat_pos_final.tolist() c.satVel = meas.sat_vel.tolist() return c +def kf_add_observations(gnss_kf: GNSSKalman, t: float, measurements: List[GNSSMeasurement]): + ekf_data = defaultdict(list) + for m in measurements: + m_arr = m.as_array() + if m.constellation_id == ConstellationId.GPS: + ekf_data[ObservationKind.PSEUDORANGE_GPS].append(m_arr) + ekf_data[ObservationKind.PSEUDORANGE_RATE_GPS].append(m_arr) + elif m.constellation_id == ConstellationId.GLONASS: + ekf_data[ObservationKind.PSEUDORANGE_GLONASS].append(m_arr) + ekf_data[ObservationKind.PSEUDORANGE_RATE_GLONASS].append(m_arr) + + for kind, data in ekf_data.items(): + gnss_kf.predict_and_observe(t, kind, data) + + +def get_bearing_from_gnss(ecef_pos, ecef_vel, vel_std): + # init orientation with direction of velocity + converter = coord.LocalCoord.from_ecef(ecef_pos) + + ned_vel = np.einsum('ij,j ->i', converter.ned_from_ecef_matrix, ecef_vel) + bearing = np.arctan2(ned_vel[1], ned_vel[0]) + bearing_std = np.arctan2(vel_std, np.linalg.norm(ned_vel)) + return float(np.rad2deg(bearing)), float(bearing_std) + + def main(): - dog = AstroDog() + dog = AstroDog(use_internet=True) sm = messaging.SubMaster(['ubloxGnss']) pm = messaging.PubMaster(['gnssMeasurements']) + laikad = Laikad() + while True: sm.update() # Todo if no internet available use latest ephemeris if sm.updated['ubloxGnss']: ublox_msg = sm['ubloxGnss'] - msg = process_ublox_msg(ublox_msg, dog, sm.logMonoTime['ubloxGnss']) - if msg is None: - msg = messaging.new_message('gnssMeasurements') - pm.send('gnssMeasurements', msg) - + msg = laikad.process_ublox_msg(ublox_msg, dog, sm.logMonoTime['ubloxGnss']) + if msg is not None: + pm.send('gnssMeasurements', msg) if __name__ == "__main__": diff --git a/selfdrive/locationd/test/test_laikad.py b/selfdrive/locationd/test/test_laikad.py index fdbb46f5aa..3d94399e41 100755 --- a/selfdrive/locationd/test/test_laikad.py +++ b/selfdrive/locationd/test/test_laikad.py @@ -2,22 +2,56 @@ import unittest from datetime import datetime -from laika.helpers import ConstellationId - +from laika import AstroDog from laika.gps_time import GPSTime +from laika.helpers import ConstellationId from laika.raw_gnss import GNSSMeasurement -from selfdrive.locationd.laikad import create_measurement_msg +from selfdrive.locationd.laikad import Laikad, create_measurement_msg +from selfdrive.test.openpilotci import get_url +from tools.lib.logreader import LogReader + + +def get_log(segs=range(0)): + logs = [] + for i in segs: + logs.extend(LogReader(get_url("4cf7a6ad03080c90|2021-09-29--13-46-36", i))) + return [m for m in logs if m.which() == 'ubloxGnss'] + + +def verify_messages(lr, dog, laikad): + good_msgs = [] + for m in lr: + msg = laikad.process_ublox_msg(m.ubloxGnss, dog, m.logMonoTime) + if msg is not None and len(msg.gnssMeasurements.correctedMeasurements) > 0: + good_msgs.append(msg) + return good_msgs class TestLaikad(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.logs = get_log(range(1)) + def test_create_msg_without_errors(self): gpstime = GPSTime.from_datetime(datetime.now()) meas = GNSSMeasurement(ConstellationId.GPS, 1, gpstime.week, gpstime.tow, {'C1C': 0., 'D1C': 0.}, {'C1C': 0., 'D1C': 0.}) + # Fake observables_final to be correct + meas.observables_final = meas.observables msg = create_measurement_msg(meas) self.assertEqual(msg.constellationId, 'gps') + def test_laika_online(self): + # Set to offline forces to use ephemeris messages + dog = AstroDog(use_internet=True) + laikad = Laikad() + correct_msgs = verify_messages(self.logs, dog, laikad) + + correct_msgs_expected = 560 + self.assertEqual(correct_msgs_expected, len(correct_msgs)) + self.assertEqual(correct_msgs_expected, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) + if __name__ == "__main__": unittest.main() From 4ef94a436fa266e1d0fcd93126f2826128512e79 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 20 May 2022 10:16:56 -0700 Subject: [PATCH 90/91] affine aux panda IRQ to boardd core (#24600) --- selfdrive/hardware/tici/hardware.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index 037afa3891..3a2e6ed035 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -409,6 +409,7 @@ class Tici(HardwareBase): # *** IRQ config *** affine_irq(5, 565) # kgsl-3d0 affine_irq(4, 740) # xhci-hcd:usb1 goes on the boardd core + affine_irq(4, 1069) # xhci-hcd:usb3 goes on the boardd core for irq in range(237, 246): affine_irq(5, irq) # camerad From 2181bbca71d9d9c8bfe7a6b2bb26241a84138607 Mon Sep 17 00:00:00 2001 From: HaraldSchafer Date: Fri, 20 May 2022 13:50:47 -0700 Subject: [PATCH 91/91] Latcontrol torque: integrator need not be reset (#24606) slow integrators need not be reset --- selfdrive/controls/lib/latcontrol_torque.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/selfdrive/controls/lib/latcontrol_torque.py b/selfdrive/controls/lib/latcontrol_torque.py index 9a1ac2f9ea..e3dbe373b6 100644 --- a/selfdrive/controls/lib/latcontrol_torque.py +++ b/selfdrive/controls/lib/latcontrol_torque.py @@ -42,8 +42,6 @@ class LatControlTorque(LatControl): if CS.vEgo < MIN_STEER_SPEED or not active: output_torque = 0.0 pid_log.active = False - if not active: - self.pid.reset() else: if self.use_steering_angle: actual_curvature = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) @@ -62,10 +60,11 @@ class LatControlTorque(LatControl): # convert friction into lateral accel units for feedforward friction_compensation = interp(desired_lateral_jerk, [-JERK_THRESHOLD, JERK_THRESHOLD], [-self.friction, self.friction]) ff += friction_compensation / self.kf + freeze_integrator = CS.steeringRateLimited or CS.steeringPressed or CS.vEgo < 5 output_torque = self.pid.update(error, - override=CS.steeringPressed, feedforward=ff, + feedforward=ff, speed=CS.vEgo, - freeze_integrator=CS.steeringRateLimited) + freeze_integrator=freeze_integrator) pid_log.active = True pid_log.p = self.pid.p