Skip to content

Commit

Permalink
Auto Update. (commaai#770)
Browse files Browse the repository at this point in the history
* auto update.

Co-Authored-By: Shane Smiskol <shane@smiskol.com>

* test auto update.

* skip E1101

* Revert "08 e2e (#94)"

This reverts commit 677c020.

Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: sebastian4k <69202924+sebastian4k@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 14, 2021
1 parent 5915671 commit 4c2a4cd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand All @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions common/op_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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',
Expand Down
29 changes: 28 additions & 1 deletion selfdrive/updated.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit 4c2a4cd

Please sign in to comment.