Skip to content

Commit

Permalink
GM: Auto-resume from stop-and-go
Browse files Browse the repository at this point in the history
Only works on 2017 Volt.
  • Loading branch information
vntarasov authored and kegman committed Feb 25, 2019
1 parent 4d8f769 commit aaa17b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
20 changes: 13 additions & 7 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from selfdrive.boardd.boardd import can_list_to_can_capnp
from selfdrive.car import apply_std_steer_torque_limits
from selfdrive.car.gm import gmcan
from selfdrive.car.gm.values import DBC, SUPERCRUISE_CARS
from selfdrive.car.gm.values import CAR, DBC, AccState, SUPERCRUISE_CARS
from selfdrive.can.packer import CANPacker


Expand Down Expand Up @@ -35,11 +35,11 @@ def __init__(self, car_fingerprint):

# pedal lookups, only for Volt
MAX_GAS = 3072 # Only a safety limit
ZERO_GAS = 2048
self.ZERO_GAS = 2048
MAX_BRAKE = 350 # Should be around 3.5m/s^2, including regen
self.MAX_ACC_REGEN = 1404 # ACC Regen braking is slightly less powerful than max regen paddle
self.GAS_LOOKUP_BP = [-0.25, 0., 0.5]
self.GAS_LOOKUP_V = [self.MAX_ACC_REGEN, ZERO_GAS, MAX_GAS]
self.GAS_LOOKUP_V = [self.MAX_ACC_REGEN, self.ZERO_GAS, MAX_GAS]
self.BRAKE_LOOKUP_BP = [-1., -0.25]
self.BRAKE_LOOKUP_V = [MAX_BRAKE, 0]

Expand Down Expand Up @@ -135,12 +135,18 @@ def update(self, sendcan, enabled, CS, frame, actuators, \
if (frame % 4) == 0:
idx = (frame / 4) % 4

at_full_stop = enabled and CS.standstill
near_stop = enabled and (CS.v_ego < P.NEAR_STOP_BRAKE_PHASE)
car_stopping = apply_gas < P.ZERO_GAS
standstill = CS.pcm_acc_status == AccState.STANDSTILL
at_full_stop = enabled and standstill and car_stopping
near_stop = enabled and (CS.v_ego < P.NEAR_STOP_BRAKE_PHASE) and car_stopping
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, canbus.chassis, apply_brake, idx, near_stop, at_full_stop))

at_full_stop = enabled and CS.standstill
can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, canbus.powertrain, apply_gas, idx, enabled, at_full_stop))
# Auto-resume from full stop by resetting ACC control
acc_enabled = enabled
if standstill and not car_stopping:
acc_enabled = False

can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, canbus.powertrain, apply_gas, idx, acc_enabled, at_full_stop))

# Send dashboard UI commands (ACC status), 25hz
follow_level = CS.get_follow_level()
Expand Down
16 changes: 7 additions & 9 deletions selfdrive/car/gm/gmcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ def create_gas_regen_command(packer, bus, throttle, idx, acc_engaged, at_full_st

def create_friction_brake_command(packer, bus, apply_brake, idx, near_stop, at_full_stop):

if apply_brake == 0:
mode = 0x1
else:
mode = 0x1
if apply_brake > 0:
mode = 0xa

if at_full_stop:
mode = 0xd
# TODO: this is to have GM bringing the car to complete stop,
# but currently it conflicts with OP controls, so turned off.
#elif near_stop:
# mode = 0xb
if near_stop:
mode = 0xb

if at_full_stop:
mode = 0xd

brake = (0x1000 - apply_brake) & 0xfff
checksum = (0x10000 - (mode << 12) - brake - idx) & 0xffff
Expand Down
4 changes: 1 addition & 3 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def update(self, c):
ret.cruiseState.available = bool(self.CS.main_on)
cruiseEnabled = self.CS.pcm_acc_status != 0
ret.cruiseState.enabled = cruiseEnabled
ret.cruiseState.standstill = self.CS.pcm_acc_status == 4
ret.cruiseState.standstill = False

ret.leftBlinker = self.CS.left_blinker_on
ret.rightBlinker = self.CS.right_blinker_on
Expand Down Expand Up @@ -335,8 +335,6 @@ def update(self, c):
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))
if ret.gasPressed:
events.append(create_event('pedalPressed', [ET.PRE_ENABLE]))
if ret.cruiseState.standstill:
events.append(create_event('resumeRequired', [ET.WARNING]))

# handle button presses
for b in ret.buttonEvents:
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/car/gm/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class CM:
AudibleAlert.chimeWarning2: (CM.LOW_CHIME, -1),
AudibleAlert.chimeWarningRepeat: (CM.LOW_CHIME, -1)}

class AccState:
OFF = 0
ACTIVE = 1
FAULTED = 3
STANDSTILL = 4

def is_eps_status_ok(eps_status, car_fingerprint):
valid_eps_status = []
if car_fingerprint in SUPERCRUISE_CARS:
Expand Down

0 comments on commit aaa17b1

Please sign in to comment.