From 4c2a4cd08ef7baa96e01ca8dfe357d84e2c00fd3 Mon Sep 17 00:00:00 2001 From: Kumar <36933347+rav4kumar@users.noreply.github.com> Date: Thu, 14 Jan 2021 11:46:48 -0700 Subject: [PATCH] Auto Update. (#770) * auto update. Co-Authored-By: Shane Smiskol * test auto update. * skip E1101 * Revert "08 e2e (#94)" This reverts commit 677c0208030ac8099ab4a0dffda375dfa01cb018. Co-authored-by: Shane Smiskol Co-authored-by: sebastian4k <69202924+sebastian4k@users.noreply.github.com> --- README.md | 9 +++++---- common/op_params.py | 3 +++ selfdrive/manager.py | 6 +++++- selfdrive/updated.py | 29 ++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 30e23a1fced845..7958f839057cc8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![kumar's testing_closet](https://github.com/arne182/ArnePilot/workflows/kumar's%20testing_closet/badge.svg?branch=DP08-clean) +![kumar's testing_closet](https://github.com/rav4kumar/Openpilot/workflows/kumar's%20testing_closet/badge.svg?branch=DP08) This README describes the custom features build by me (Arne Schwarck) on top of [ArnePilot](http://github.com/commaai/ArnePilot) of [comma.ai](http://comma.ai). This fork is optimized for the Toyota RAV4 Hybrid 2016 and Prius TSS2 and for driving in Germany but also works with other cars and in other countries. If you would like to support the developement on this project feel free to https://www.patreon.com/arneschwarck @@ -51,7 +51,7 @@ Fork is known to work in both US and Europe - RX hyrid 2017 - CT 2018 - Chevrolet Volt 2017 -- Subaru Crosstrek Limited 2019 with 0.8 it will use Eyesight for radar. +- Subaru Crosstrek Limited 2019 with 0.8 it will use Eyesight for radar. ### Todo - [ ] Once QT drops add OSM and Speed offset apk toggles @@ -87,6 +87,7 @@ Since openpilot v0.8.0 Arne has decide to base his fork on [DragonPilot](https:/ - Cruise set speed available down to 7 kph - Virtual lane lines and Lane center. This feature is for European roads and is recommended for used in Europe only. - Alwasys on Dashcam recording ( it will save video's to the `/sdcard/media/dashcam`) +- Auto update when their is new commits pushed. If you do not wish to automatically update you may change it under op_edit. ### OpEdit features all OpEdit features can be manged by running the command `python /data/openpilot/op_edit.py` @@ -97,9 +98,9 @@ all OpEdit features can be manged by running the command `python /data/openpilot This aims to provide a smoother driving experience in stop and go traffic (under 20 mph) by modifying the maximum gas that can be applied based on your current velocity and the relative velocity of the lead car. It'll also of course increase the maximum gas when the lead is accelerating to help you get up to speed quicker than stock. And smoother; this eliminates the jerking you get from stock ArnePilot with comma pedal. It tries to coast if the lead is only moving slowly, it doesn't use maximum gas as soon as the lead inches forward :). When you are above 20 mph, relative velocity and the following distance is taken into consideration. - 2020 Corolla tuning by Spairrow326 - Added ability to turn on and off RSA at certain speeds. -- Control 3 gas profiles with sport eco and normal buttons on car (only on limited car) +- Control 3 gas profiles with sport eco and normal buttons on car (only on limited car) - Ability to change the SpeedLimit Offset directly -- Able to stop using RSA after certain mph. +- Able to stop using RSA after certain mph. - Live indi tune toggle thanks @jamcar23 - cloak mode: which will make comma think you are using their fork. Avoid bans. diff --git a/common/op_params.py b/common/op_params.py index c9acab25e31e4b..a5cfcf408c8faf 100644 --- a/common/op_params.py +++ b/common/op_params.py @@ -117,6 +117,9 @@ def __init__(self): #'The range is limited from 0.85 to 1.3. Set to None to disable', live=True), #'use_virtual_middle_line': Param(False, bool, 'For roads over 4m wide, hug right. For roads under 2m wide, hug left.'), 'uniqueID': Param(None, [type(None), str], 'User\'s unique ID'), + 'update_behavior': Param('auto', str, 'Can be: (\'off\', \'alert\', \'auto\') without quotes\n' + 'off will never update, alert shows an alert on-screen\n' + 'auto will reboot the device when an update is seen'), 'enable_indi_live': Param(False, bool, live=True), 'indi_inner_gain_bp': Param([18, 22, 26], [list, float, int], live=True, depends_on='enable_indi_live'), 'indi_inner_gain_v': Param([5, 10, 15], [list, float, int], live=True, depends_on='enable_indi_live'), diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 1484fd507ea618..a88b0cf55789e5 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -11,6 +11,7 @@ import textwrap from typing import Dict, List from selfdrive.swaglog import cloudlog, add_logentries_handler +from common.op_params import opParams import re from common.dp_conf import init_params_vals @@ -23,6 +24,7 @@ TOTAL_SCONS_NODES = 1040 prebuilt = os.path.exists(os.path.join(BASEDIR, 'prebuilt')) +kill_updated = opParams().get('update_behavior').lower().strip() == 'off' or os.path.exists('/data/no_ota_updates') # Create folders needed for msgq try: @@ -237,11 +239,13 @@ def get_running(): if not PC: persistent_processes += [ - 'updated', + #'updated', 'logcatd', 'tombstoned', 'sensord', ] + if not kill_updated: + persistent_processes.append('updated') car_started_processes = [ 'controlsd', diff --git a/selfdrive/updated.py b/selfdrive/updated.py index 3e0b083d15af75..dbb1791906d659 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +# pylint: disable=E1101 # Safe Update: A simple service that waits for network access and tries to # update every 10 minutes. It's intended to make the OP update process more # robust against Git repository corruption. This service DOES NOT try to fix @@ -39,6 +39,9 @@ from common.params import Params from selfdrive.swaglog import cloudlog from selfdrive.controls.lib.alertmanager import set_offroad_alert +from common.realtime import sec_since_boot +from common.op_params import opParams +from common.colors import COLORS LOCK_FILE = os.getenv("UPDATER_LOCK_FILE", "/tmp/safe_staging_overlay.lock") STAGING_ROOT = os.getenv("UPDATER_STAGING_ROOT", "/data/safe_staging") @@ -51,6 +54,8 @@ OVERLAY_MERGED = os.path.join(STAGING_ROOT, "merged") FINALIZED = os.path.join(STAGING_ROOT, "finalized") +REBOOT_ON_UPDATE = opParams().get('update_behavior').lower().strip() == 'auto' # if not auto, has to be alert + class WaitTimeHelper: def __init__(self, proc): @@ -316,7 +321,20 @@ def fetch_update(wait_helper: WaitTimeHelper) -> bool: return new_version +class AutoReboot: + def __init__(self): + self.min_reboot_time = 5. * 60 + self.need_reboot = False + self.time_offroad = 0.0 + + @property + def should_reboot(self): + return (sec_since_boot() - self.time_offroad > self.min_reboot_time + and self.need_reboot and REBOOT_ON_UPDATE) + + def main(): + auto_reboot = AutoReboot() params = Params() if params.get("DisableUpdates") == b"1": @@ -359,6 +377,7 @@ def main(): time_wrong = datetime.datetime.utcnow().year < 2019 is_onroad = params.get("IsOffroad") != b"1" if is_onroad or time_wrong: + auto_reboot.time_offroad = sec_since_boot() wait_helper.sleep(30) cloudlog.info("not running updater, not offroad") continue @@ -377,6 +396,14 @@ def main(): # Fetch updates at most every 10 minutes if internet_ok and (update_now or time.monotonic() - last_fetch_time > 60*10): new_version = fetch_update(wait_helper) + + auto_reboot.need_reboot |= new_version + if auto_reboot.should_reboot: + cloudlog.info(COLORS.RED + "AUTO UPDATE: REBOOTING" + COLORS.ENDC) + run(["am", "start", "-a", "android.intent.action.REBOOT"]) + elif auto_reboot.need_reboot: + cloudlog.info(COLORS.BLUE_GREEN + "UPDATE FOUND, waiting {} sec. until reboot".format(auto_reboot.min_reboot_time - (sec_since_boot() - auto_reboot.time_offroad)) + COLORS.ENDC) + update_failed_count = 0 last_fetch_time = time.monotonic()