Skip to content

Commit

Permalink
GM: go passive if detected ASCM or LKA camera (commaai#350)
Browse files Browse the repository at this point in the history
Since fingerprint is powertrain CAN only, camera still present
on object bus is not an issue.
  • Loading branch information
vntarasov authored and energee committed Sep 11, 2018
1 parent 4974add commit 1c785f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
7 changes: 6 additions & 1 deletion selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def actuator_hystereses(final_pedal, pedal_steady):


class CarController(object):
def __init__(self, canbus, car_fingerprint):
def __init__(self, canbus, car_fingerprint, allow_controls):
self.pedal_steady = 0.
self.start_time = sec_since_boot()
self.chime = 0
Expand All @@ -64,6 +64,7 @@ def __init__(self, canbus, car_fingerprint):
self.steer_idx = 0
self.apply_steer_last = 0
self.car_fingerprint = car_fingerprint
self.allow_controls = allow_controls

# Setup detection helper. Routes commands to
# an appropriate CAN bus number.
Expand All @@ -77,6 +78,10 @@ def update(self, sendcan, enabled, CS, frame, actuators, \
hud_v_cruise, hud_show_lanes, hud_show_car, chime, chime_cnt):
""" Controls thread """

# Sanity check.
if not self.allow_controls:
return

P = self.params

# Send CAN commands.
Expand Down
19 changes: 10 additions & 9 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ class CM:
LOW_CHIME = 0x86
HIGH_CHIME = 0x87

# GM cars have 4 CAN buses, which creates many ways
# of how the car can be connected to.
# This ia a helper class for the interface to be setup-agnostic.
# Supports single Panda setup (connected to OBDII port),
# and a CAN forwarding setup (connected to camera module connector).

class CanBus(object):
def __init__(self):
self.powertrain = 0
self.obstacle = 1
self.chassis = 2
self.sw_gmlan = 3

# 384 = "ASCMLKASteeringCmd"
# 715 = "ASCMGasRegenCmd"
CONTROL_MSGS = [384, 715]

class CarInterface(object):
def __init__(self, CP, sendcan=None):
self.CP = CP
Expand All @@ -54,7 +52,7 @@ def __init__(self, CP, sendcan=None):
# sending if read only is False
if sendcan is not None:
self.sendcan = sendcan
self.CC = CarController(canbus, CP.carFingerprint)
self.CC = CarController(canbus, CP.carFingerprint, CP.enableCamera)

@staticmethod
def compute_gb(accel, speed):
Expand All @@ -73,8 +71,11 @@ def get_params(candidate, fingerprint):

ret.enableCruise = False

# TODO: gate this on detection
ret.enableCamera = True
# Presence of a camera on the object bus is ok.
# Have to go passive if ASCM is online (ACC-enabled cars),
# or camera is on powertrain bus (LKA cars without ACC).
ret.enableCamera = not any(x for x in CONTROL_MSGS if x in fingerprint)

std_cargo = 136

if candidate == CAR.VOLT:
Expand Down

0 comments on commit 1c785f9

Please sign in to comment.