Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New kegman threading with automatic merging if file and conf variable mismatch #227

Merged
merged 9 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions selfdrive/car/chrysler/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from selfdrive.car.modules.UIBT_module import UIButtons,UIButton
from selfdrive.car.modules.UIEV_module import UIEvents
import numpy as np
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman


def parse_gear_shifter(can_gear):
Expand Down Expand Up @@ -80,9 +80,8 @@ def get_camera_parser(CP):

class CarState(object):
def __init__(self, CP):
self.kegman = kegman_conf()
self.alcaLabels = ["MadMax","Normal","Wifey","off"]
self.alcaMode = int(self.kegman.conf['lastALCAMode'])
self.alcaMode = int(kegman.conf['lastALCAMode'])
self.prev_distance_button = 0
self.distance_button = 0
self.prev_lka_button = 0
Expand Down Expand Up @@ -172,10 +171,10 @@ def update_ui_buttons(self,id,btn_status):
if (id == 1) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="alca":
if self.cstm_btns.btns[id].btn_label2 == self.alcaLabels[self.alcaMode]:
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
else:
self.alcaMode = 0
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True
if self.alcaMode == 3:
Expand All @@ -187,7 +186,7 @@ def update_ui_buttons(self,id,btn_status):
self.cstm_btns.btns[id].btn_status = btn_status
if (id == 1) and self.cstm_btns.btns[id].btn_name=="alca":
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True

Expand Down
13 changes: 6 additions & 7 deletions selfdrive/car/gm/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from selfdrive.car.gm.values import DBC, CAR, parse_gear_shifter, \
CruiseButtons, is_eps_status_ok, \
STEER_THRESHOLD, SUPERCRUISE_CARS
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman

def get_powertrain_can_parser(CP, canbus):
# this function generates lists for signal, messages and initial values
Expand Down Expand Up @@ -59,11 +59,10 @@ def get_powertrain_can_parser(CP, canbus):

class CarState(object):
def __init__(self, CP, canbus):
self.kegman = kegman_conf()
self.CP = CP
# initialize can parser
self.alcaLabels = ["MadMax","Normal","Wifey","off"]
self.alcaMode = int(self.kegman.conf['lastALCAMode']) # default to last ALCAmode on startup
self.alcaMode = int(kegman.conf['lastALCAMode']) # default to last ALCAmode on startup
self.car_fingerprint = CP.carFingerprint
self.cruise_buttons = CruiseButtons.UNPRESS
self.prev_distance_button = 0
Expand All @@ -72,7 +71,7 @@ def __init__(self, CP, canbus):
self.prev_left_blinker_on = False
self.right_blinker_on = False
self.prev_right_blinker_on = False
self.follow_level = int(self.kegman.conf['lastTrMode'])
self.follow_level = int(kegman.conf['lastTrMode'])
self.prev_lka_button = 0
self.lka_button = 0
self.lkMode = True
Expand Down Expand Up @@ -151,10 +150,10 @@ def update_ui_buttons(self,id,btn_status):
if (id == 1) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="alca":
if self.cstm_btns.btns[id].btn_label2 == self.alcaLabels[self.alcaMode]:
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
else:
self.alcaMode = 0
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True
if self.alcaMode == 3:
Expand All @@ -165,7 +164,7 @@ def update_ui_buttons(self,id,btn_status):
self.cstm_btns.btns[id].btn_status = btn_status
if (id == 1) and self.cstm_btns.btns[id].btn_name=="alca":
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last ALCAMode setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True

Expand Down
7 changes: 3 additions & 4 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from selfdrive.controls.lib.vehicle_model import VehicleModel
from selfdrive.car.gm.values import DBC, CAR, STOCK_CONTROL_MSGS, AUDIO_HUD, SUPERCRUISE_CARS
from selfdrive.car.gm.carstate import CarState, CruiseButtons, get_powertrain_can_parser
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman

try:
from selfdrive.car.gm.carcontroller import CarController
Expand All @@ -22,8 +22,7 @@ def __init__(self):

class CarInterface(object):
def __init__(self, CP, sendcan=None):
self.kegman = kegman_conf()
self.angleSteersoffset = float(self.kegman.conf['angle_steers_offset']) # deg offset
self.angleSteersoffset = float(kegman.conf['angle_steers_offset']) # deg offset
self.CP = CP
self.frame = 0
self.gas_pressed_prev = False
Expand Down Expand Up @@ -305,7 +304,7 @@ def update(self, c):
self.CS.follow_level -= 1
if self.CS.follow_level < 1:
self.CS.follow_level = 3
self.kegman.conf['lastTrMode'] = str(self.CS.follow_level) # write last distance bar setting to file
kegman.save({'lastTrMode': str(self.CS.follow_level)}) # write last distance bar setting to file
ret.gasbuttonstatus = self.CS.cstm_btns.get_button_status("gas")
events = []
if not self.CS.can_valid:
Expand Down
4 changes: 1 addition & 3 deletions selfdrive/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from selfdrive.car.honda.values import AH, CruiseButtons, CAR
from selfdrive.can.packer import CANPacker
from selfdrive.car.modules.ALCA_module import ALCAController
from selfdrive.kegman_conf import kegman_conf

kegman = kegman_conf(read_only=True)
import selfdrive.kegman_conf as kegman

def actuator_hystereses(brake, braking, brake_steady, v_ego, car_fingerprint):
# hyst params
Expand Down
23 changes: 11 additions & 12 deletions selfdrive/car/honda/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from selfdrive.can.parser import CANParser, CANDefine
from selfdrive.config import Conversions as CV
from selfdrive.car.honda.values import CAR, DBC, STEER_THRESHOLD, SPEED_FACTOR, HONDA_BOSCH
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman
from selfdrive.car.modules.UIBT_module import UIButtons,UIButton
from selfdrive.car.modules.UIEV_module import UIEvents
import numpy as np
Expand Down Expand Up @@ -150,21 +150,20 @@ def get_cam_can_parser(CP):

class CarState(object):
def __init__(self, CP):
self.kegman = kegman_conf()
self.Angle = [0, 5, 10, 15,20,25,30,35,60,100,180,270,500]
self.Angle_Speed = [255,160,100,80,70,60,55,50,40,30,20,10,5]
self.blind_spot_on = bool(0)
#labels for ALCA modes
self.alcaLabels = ["MadMax","Normal","Wifey","off"]
self.trLabels = ["0.9","dyn","2.7"]
self.alcaMode = int(self.kegman.conf['lastALCAMode']) # default to last ALCA Mode on startup
self.alcaMode = int(kegman.conf['lastALCAMode']) # default to last ALCA Mode on startup
if self.alcaMode > 3:
self.alcaMode = 3
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
self.trMode = int(self.kegman.conf['lastTrMode']) # default to last distance interval on startup
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.trMode = int(kegman.conf['lastTrMode']) # default to last distance interval on startup
if self.trMode > 2:
self.trMode = 2
self.kegman.conf['lastTrMode'] = str(self.trMode) # write last distance bar setting to file
kegman.save({'lastTrMode': str(self.trMode)}) # write last distance bar setting to file
#if (CP.carFingerprint == CAR.MODELS):
# ALCA PARAMS
# max REAL delta angle for correction vs actuator
Expand Down Expand Up @@ -263,10 +262,10 @@ def update_ui_buttons(self,id,btn_status):
if (id == 0) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="alca":
if self.cstm_btns.btns[id].btn_label2 == self.alcaLabels[self.alcaMode]:
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
else:
self.alcaMode = 0
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last distance bar setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True
if self.alcaMode == 3:
Expand All @@ -275,10 +274,10 @@ def update_ui_buttons(self,id,btn_status):
elif (id == 4) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="tr":
if self.cstm_btns.btns[id].btn_label2 == self.trLabels[self.trMode]:
self.trMode = (self.trMode + 1 ) % 3
self.kegman.conf['lastTrMode'] = str(self.trMode) # write last distance bar setting to file
kegman.save({'lastTrMode': str(self.trMode)}) # write last distance bar setting to file
else:
self.trMode = 0
self.kegman.conf['lastTrMode'] = str(self.trMode) # write last distance bar setting to file
kegman.save({'lastTrMode': str(self.trMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.trLabels[self.trMode]
self.cstm_btns.hasChanges = True

Expand All @@ -288,7 +287,7 @@ def update_ui_buttons(self,id,btn_status):
self.cstm_btns.btns[id].btn_status = btn_status
if (id == 0) and self.cstm_btns.btns[id].btn_name=="alca":
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last ALCAMode setting to file
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last distance bar setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True

Expand Down Expand Up @@ -432,7 +431,7 @@ def update(self, cp, cp_cam):
if self.cruise_setting == 3:
if cp.vl["SCM_BUTTONS"]["CRUISE_SETTING"] == 0:
self.trMode = (self.trMode + 1 ) % 3
self.kegman.conf['lastTrMode'] = str(self.trMode) # write last distance bar setting to file
kegman.save({'lastTrMode': str(self.trMode)}) # write last distance bar setting to file
self.cstm_btns.btns[4].btn_label2 = self.trLabels[self.trMode]
self.prev_cruise_setting = self.cruise_setting
self.cruise_setting = cp.vl["SCM_BUTTONS"]['CRUISE_SETTING']
Expand Down
4 changes: 1 addition & 3 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from selfdrive.car.honda.carstate import CarState, get_can_parser, get_cam_can_parser
from selfdrive.car.honda.values import CruiseButtons, CAR, HONDA_BOSCH, AUDIO_HUD, VISUAL_HUD
from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING
from selfdrive.kegman_conf import kegman_conf

kegman = kegman_conf(read_only=True)
import selfdrive.kegman_conf as kegman

angleSteersoffset = float(kegman.conf['angle_steers_offset']) # deg offset

Expand Down
35 changes: 13 additions & 22 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from selfdrive.config import Conversions as CV
from selfdrive.car.toyota.values import CAR, DBC, STEER_THRESHOLD
from common.kalman.simple_kalman import KF1D
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman
from selfdrive.car.modules.UIBT_module import UIButtons,UIButton
from selfdrive.car.modules.UIEV_module import UIEvents
import os
Expand Down Expand Up @@ -147,22 +147,21 @@ def get_cam_can_parser(CP):

class CarState(object):
def __init__(self, CP):
self.kegman = kegman_conf()
self.brakefactor = float(self.kegman.conf['brakefactor'])
self.brakefactor = float(kegman.conf['brakefactor'])
self.trfix = False
self.Angles = np.zeros(250)
self.Angles_later = np.zeros(250)
self.Angle_counter = 0
self.Angle = [0, 5, 10, 15,20,25,30,35,60,100,180,270,500]
self.Angle_Speed = [255,160,100,80,70,60,55,50,40,33,27,17,12]
#labels for gas mode
self.gasMode = int(self.kegman.conf['lastGasMode'])
self.sloMode = int(self.kegman.conf['lastSloMode'])
self.gasMode = int(kegman.conf['lastGasMode'])
self.sloMode = int(kegman.conf['lastSloMode'])
self.sloLabels = ["offset","normal"]
self.gasLabels = ["dynamic","sport","eco"]
#labelslabels for ALCA modes
self.alcaLabels = ["MadMax","Normal","Wifey","off"]
self.alcaMode = int(self.kegman.conf['lastALCAMode']) # default to last ALCAmode on startup
self.alcaMode = int(kegman.conf['lastALCAMode']) # default to last ALCAmode on startup
#if (CP.carFingerprint == CAR.MODELS):
# ALCA PARAMS
# max REAL delta angle for correction vs actuator
Expand Down Expand Up @@ -268,38 +267,32 @@ def update_ui_buttons(self,id,btn_status):
if (id == 1) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="alca":
if self.cstm_btns.btns[id].btn_label2 == self.alcaLabels[self.alcaMode]:
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last ALCAMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last ALCAMode setting to file
else:
self.alcaMode = 0
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last ALCAMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last ALCAMode setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True
if self.alcaMode == 3:
self.cstm_btns.set_button_status("alca", 0)
elif (id == 2) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="slow":
if self.cstm_btns.btns[id].btn_label2 == self.sloLabels[self.sloMode]:
self.sloMode = (self.sloMode + 1 ) % 2
self.kegman.conf['lastSloMode'] = str(self.sloMode) # write last SloMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastSloMode': str(self.sloMode)}) # write last SloMode setting to file
else:
self.sloMode = 0
self.kegman.conf['lastSloMode'] = str(self.sloMode) # write last SloMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastSloMode': str(self.sloMode)}) # write last SloMode setting to file
self.cstm_btns.btns[id].btn_label2 = self.sloLabels[self.sloMode]
self.cstm_btns.hasChanges = True
if self.sloMode == 0:
self.cstm_btns.set_button_status("slow", 0) # this might not be needed
elif (id == 5) and (btn_status == 0) and self.cstm_btns.btns[id].btn_name=="gas":
if self.cstm_btns.btns[id].btn_label2 == self.gasLabels[self.gasMode]:
self.gasMode = (self.gasMode + 1 ) % 3
self.kegman.conf['lastGasMode'] = str(self.gasMode) # write last GasMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastGasMode': str(self.gasMode)}) # write last GasMode setting to file
else:
self.gasMode = 0
self.kegman.conf['lastGasMode'] = str(self.gasMode) # write last GasMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastGasMode': str(self.gasMode)}) # write last GasMode setting to file

self.cstm_btns.btns[id].btn_label2 = self.gasLabels[self.gasMode]
self.cstm_btns.hasChanges = True
Expand All @@ -309,14 +302,12 @@ def update_ui_buttons(self,id,btn_status):
self.cstm_btns.btns[id].btn_status = btn_status
if (id == 1) and self.cstm_btns.btns[id].btn_name=="alca":
self.alcaMode = (self.alcaMode + 1 ) % 4
self.kegman.conf['lastALCAMode'] = str(self.alcaMode) # write last ALCAMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastALCAMode': str(self.alcaMode)}) # write last ALCAMode setting to file
self.cstm_btns.btns[id].btn_label2 = self.alcaLabels[self.alcaMode]
self.cstm_btns.hasChanges = True
elif (id == 2) and self.cstm_btns.btns[id].btn_name=="slow":
self.sloMode = (self.sloMode + 1 ) % 2
self.kegman.conf['lastSloMode'] = str(self.sloMode) # write last SloMode setting to file
self.kegman.write_config(self.kegman.conf)
kegman.save({'lastSloMode': str(self.sloMode)}) # write last SloMode setting to file
self.cstm_btns.btns[id].btn_label2 = self.sloLabels[self.sloMode]
self.cstm_btns.hasChanges = True

Expand Down
5 changes: 1 addition & 4 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from selfdrive.car.toyota.carstate import CarState, get_can_parser, get_cam_can_parser
from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR
from selfdrive.swaglog import cloudlog

from selfdrive.kegman_conf import kegman_conf

kegman = kegman_conf()
import selfdrive.kegman_conf as kegman

steeringAngleoffset = float(kegman.conf['angle_steers_offset']) # deg offset

Expand Down
4 changes: 1 addition & 3 deletions selfdrive/controls/lib/driver_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from common.realtime import sec_since_boot
from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET
from common.filter_simple import FirstOrderFilter
from selfdrive.kegman_conf import kegman_conf

kegman = kegman_conf(read_only=True)
import selfdrive.kegman_conf as kegman

_DT = 0.01 # update runs at 100Hz
_DTM = 0.1 # DM runs at 10Hz
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/controls/lib/longcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from cereal import log
from common.numpy_fast import clip, interp
from selfdrive.controls.lib.pid import PIController
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman
import selfdrive.messaging as messaging
from selfdrive.services import service_list

kegman = kegman_conf(read_only=True)
LongCtrlState = log.Live100Data.LongControlState

STOPPING_EGO_SPEED = 0.5
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/controls/lib/model_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from common.numpy_fast import interp
from selfdrive.controls.lib.latcontrol_helpers import model_polyfit, calc_desired_path, compute_path_pinv
from selfdrive.kegman_conf import kegman_conf
import selfdrive.kegman_conf as kegman

kegman = kegman_conf()
CAMERA_OFFSET = float(kegman.conf['cameraOffset']) # m from center car to camera


Expand Down
6 changes: 2 additions & 4 deletions selfdrive/controls/lib/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from selfdrive.controls.lib.fcw import FCWChecker
from selfdrive.controls.lib.long_mpc import LongitudinalMpc

from selfdrive.kegman_conf import kegman_conf

kegman = kegman_conf()
import selfdrive.kegman_conf as kegman

NO_CURVATURE_SPEED = 200. * CV.MPH_TO_MS

Expand All @@ -38,7 +36,7 @@
_A_CRUISE_MAX_BP = [0., 5., 10., 20., 40.]

# Lookup table for turns
_brake_factor = float(kegman.conf['brakefactor'])
_brake_factor = float(kegman.get("brakefactor"))
_A_TOTAL_MAX_V = [2.0 * _brake_factor, 2.7 * _brake_factor, 3.5 * _brake_factor]
_A_TOTAL_MAX_BP = [0., 25., 40.]

Expand Down
Loading