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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrysler updates 馃殣馃殣馃殣 #533

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 5 additions & 2 deletions selfdrive/car/chrysler/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, dbc_name, car_fingerprint, enable_camera):
self.apply_steer_last = 0
self.ccframe = 0
self.prev_frame = -1
self.hud_count = 0
self.car_fingerprint = car_fingerprint
self.alert_active = False
self.send_chime = False
Expand All @@ -39,7 +40,7 @@ def __init__(self, dbc_name, car_fingerprint, enable_camera):
def update(self, sendcan, enabled, CS, frame, actuators,
pcm_cancel_cmd, hud_alert, audible_alert):

# this seems needed to avoid steerign faults and to force the sync with the EPS counter
# this seems needed to avoid steering faults and to force the sync with the EPS counter
if self.prev_frame == frame:
return

Expand Down Expand Up @@ -81,8 +82,10 @@ def update(self, sendcan, enabled, CS, frame, actuators,
can_sends.append(new_msg)

if (self.ccframe % 25 == 0): # 0.25s period
new_msg = create_lkas_hud(CS.gear_shifter, lkas_active, hud_alert, self.car_fingerprint)
new_msg = create_lkas_hud(self.packer, CS.gear_shifter, lkas_active, hud_alert, self.car_fingerprint,
self.hud_count)
can_sends.append(new_msg)
self.hud_count += 1

new_msg = create_lkas_command(self.packer, int(apply_steer), frame)
can_sends.append(new_msg)
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/chrysler/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def parse_gear_shifter(can_gear):
return "neutral"
elif can_gear == 0x4:
return "drive"
elif can_gear == 0x5:
return "low"
return "unknown"


Expand Down
62 changes: 35 additions & 27 deletions selfdrive/car/chrysler/chryslercan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
VisualAlert = car.CarControl.HUDControl.VisualAlert
AudibleAlert = car.CarControl.HUDControl.AudibleAlert

MODEL_TO_CONSTANT = {
CAR.PACIFICA_2017_HYBRID: 0,
CAR.PACIFICA_2018: 0x64,
CAR.PACIFICA_2018_HYBRID: 0xa8,
CAR.PACIFICA_2019_HYBRID: 0x68,
CAR.JEEP_CHEROKEE: 0xa4,
}

def calc_checksum(data):
"""This function does not want the checksum byte in the input data.
Expand Down Expand Up @@ -51,40 +58,41 @@ def create_lkas_heartbit(car_fingerprint):
msg = '0000000820'.decode('hex') # 2017
return make_can_msg(0x2d9, msg)

def create_lkas_hud(gear, lkas_active, hud_alert, car_fingerprint):
# LKAS_HUD (678) Controls what lane-keeping icon is displayed.
def create_lkas_hud(packer, gear, lkas_active, hud_alert, car_fingerprint, hud_count):
# LKAS_HUD 0x2a6 (678) Controls what lane-keeping icon is displayed.

if hud_alert == VisualAlert.steerRequired:
msg = '0000000300000000'.decode('hex')
return make_can_msg(0x2a6, msg)

# TODO: use can packer
msg = '0000000000000000'.decode('hex') # park or neutral
if car_fingerprint == CAR.PACIFICA_2018:
msg = '0064000000000000'.decode('hex') # Have not verified 2018 park with a real car.
elif car_fingerprint == CAR.JEEP_CHEROKEE:
msg = '00a4000000000000'.decode('hex') # Have not verified 2018 park with a real car.
elif car_fingerprint == CAR.PACIFICA_2018_HYBRID:
msg = '01a8010000000000'.decode('hex')
if (gear == 'drive' or gear == 'reverse'):
color = 0 # default values are for park or neutral
lines = 0
alerts = 0

if hud_count < (3 *4): # first 3 seconds, 4Hz
lines = 1
alerts = 1
elif hud_count < (6 * 4): # next 3 seconds, 4Hz
lines = 1
alerts = 0
# CAR.PACIFICA_2018_HYBRID and CAR.PACIFICA_2019_HYBRID
# had color = 1 and lines = 1 but trying 2017 hybrid style for now.
if gear in ('drive', 'reverse', 'low'):
if lkas_active:
msg = '0200060000000000'.decode('hex') # control active, display green.
if car_fingerprint == CAR.PACIFICA_2018:
msg = '0264060000000000'.decode('hex')
elif car_fingerprint == CAR.JEEP_CHEROKEE:
msg = '02a4060000000000'.decode('hex')
elif car_fingerprint == CAR.PACIFICA_2018_HYBRID:
msg = '02a8060000000000'.decode('hex')
color = 2 # control active, display green.
lines = 6
else:
msg = '0100010000000000'.decode('hex') # control off, display white.
if car_fingerprint == CAR.PACIFICA_2018:
msg = '0164010000000000'.decode('hex')
elif car_fingerprint == CAR.JEEP_CHEROKEE:
msg = '01a4010000000000'.decode('hex')
elif car_fingerprint == CAR.PACIFICA_2018_HYBRID:
msg = '01a8010000000000'.decode('hex')

return make_can_msg(0x2a6, msg)
color = 1 # control off, display white.
lines = 1

values = {
"LKAS_ICON_COLOR": color, # byte 0, last 2 bits
"CAR_MODEL": MODEL_TO_CONSTANT[car_fingerprint], # byte 1
"LKAS_LANE_LINES": lines, # byte 2, last 4 bits
"LKAS_ALERTS": alerts, # byte 3, last 4 bits
}

return packer.make_can_msg("LKAS_HUD", 0, values) # 0x2a6


def create_lkas_command(packer, apply_steer, frame):
Expand Down
48 changes: 48 additions & 0 deletions selfdrive/car/chrysler/chryslercan_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import chryslercan
from values import CAR
from carcontroller import CarController
from selfdrive.can.packer import CANPacker

from cereal import car
VisualAlert = car.CarControl.HUDControl.VisualAlert
AudibleAlert = car.CarControl.HUDControl.AudibleAlert

import unittest


class TestChryslerCan(unittest.TestCase):

def test_checksum(self):
self.assertEqual(0x75, chryslercan.calc_checksum([0x01, 0x20]))
self.assertEqual(0xcc, chryslercan.calc_checksum([0x14, 0, 0, 0, 0x20]))

def test_heartbit(self):
self.assertEqual(
[0x2d9, 0, '0000000820'.decode('hex'), 0],
chryslercan.create_lkas_heartbit(CAR.PACIFICA_2017_HYBRID))

def test_hud(self):
packer = CANPacker('chrysler_pacifica_2017_hybrid')
self.assertEqual(
[0x2a6, 0, '0000010100000000'.decode('hex'), 0],
chryslercan.create_lkas_hud(packer,
'park', False, False, CAR.PACIFICA_2017_HYBRID, 1))
self.assertEqual(
[0x2a6, 0, '0000010000000000'.decode('hex'), 0],
chryslercan.create_lkas_hud(packer,
'park', False, False, CAR.PACIFICA_2017_HYBRID, 5*4))
self.assertEqual(
[0x2a6, 0, '0000000000000000'.decode('hex'), 0],
chryslercan.create_lkas_hud(packer,
'park', False, False, CAR.PACIFICA_2017_HYBRID, 99999))
self.assertEqual(
[0x2a6, 0, '0200060000000000'.decode('hex'), 0],
chryslercan.create_lkas_hud(packer,
'drive', True, False, CAR.PACIFICA_2017_HYBRID, 99999))
self.assertEqual(
[0x2a6, 0, '0264060000000000'.decode('hex'), 0],
chryslercan.create_lkas_hud(packer,
'drive', True, False, CAR.PACIFICA_2018, 99999))

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def update(self, c):
events.append(create_event('commIssue', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE]))
else:
self.can_invalid_count = 0
if not ret.gearShifter == 'drive':
if not (ret.gearShifter in ('drive', 'low')):
events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE]))
if ret.doorOpen:
events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE]))
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/chrysler/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PYTHONPATH=`realpath ../../../` python chryslercan_test.py
Loading