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

Kia Sorento and future Multi-Car Support #346

Merged
merged 28 commits into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bea839c
hyundai WIP
rbiasini Aug 28, 2018
7376209
steer_driver_factor is 1
rbiasini Aug 28, 2018
4314efa
removed unnecessary file
rbiasini Aug 28, 2018
3f3075e
removed unnecessary code
rbiasini Aug 29, 2018
95b7919
Update carcontroller.py
rbiasini Aug 29, 2018
5e76750
safety tuning and fixed interface stiffness
rbiasini Aug 29, 2018
c92c08f
better lateral tuning, some fixes
rbiasini Aug 30, 2018
26c36df
Fix set speed
rbiasini Aug 30, 2018
2ca147f
Merge branch 'devel' of github.com:commaai/openpilot into hyundai-rea…
rbiasini Sep 1, 2018
96f54e3
added camera state reading, autoresume from stop, cancel on accel, hu…
rbiasini Sep 1, 2018
22688e0
WIP
emmertex Sep 2, 2018
07a8b3a
Updated for Kia Sorento *WIP*
emmertex Sep 2, 2018
9c02498
Cleanup
emmertex Sep 2, 2018
87d7549
clean2
emmertex Sep 2, 2018
c4a6506
Bug Fixes
emmertex Sep 4, 2018
119f48d
pre-merge
emmertex Sep 4, 2018
3df5a09
Merge remote-tracking branch 'upstream/devel' into hyundai-dev
emmertex Sep 4, 2018
9f1bba6
Add all the cars!
emmertex Sep 4, 2018
c08d305
Panda to auto-detect Camera Bus
emmertex Sep 4, 2018
d7ca4ce
Move Checksum Check
emmertex Sep 4, 2018
bb27195
Final Sorento Tuning
emmertex Sep 5, 2018
1fddd38
Make CAN3 for Cam default
emmertex Sep 5, 2018
6b51095
Update README.md
emmertex Sep 5, 2018
e6b0432
update panda, minor aesthetic updates
rbiasini Sep 5, 2018
ad17983
few other minor changes
rbiasini Sep 6, 2018
7980457
added steer not allowed alert
rbiasini Sep 6, 2018
1d67a26
bup panda version to force panda update
rbiasini Sep 6, 2018
f4e8926
fixed camera alerts
rbiasini Sep 8, 2018
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
2 changes: 1 addition & 1 deletion panda/board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int can_err_cnt = 0;
CAN_TypeDef *cans[] = {CAN1, CAN2, CAN3};
uint8_t bus_lookup[] = {0,1,2};
uint8_t can_num_lookup[] = {0,1,2,-1};
int8_t can_forwarding[] = {-1,-1,-1,-1};
int8_t can_forwarding[] = {1,-1,-1,-1};
uint32_t can_speed[] = {5000, 5000, 5000, 333};
bool can_autobaud_enabled[] = {false, false, false, false};
#define CAN_MAX 3
Expand Down
1 change: 0 additions & 1 deletion panda/board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}

static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {

// forward cam to ccan and viceversa, except lkas cmd
if ((bus_num == 0 || bus_num == 2) && hyundai_giraffe_switch_2) {
int addr = to_fwd->RIR>>21;
Expand Down
5 changes: 3 additions & 2 deletions selfdrive/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from selfdrive.car.hyundai.hyundaican import create_lkas11, create_lkas12, \
create_1191, create_1156, \
create_clu11
from selfdrive.car.hyundai.values import Buttons
from selfdrive.car.hyundai.values import Buttons, CHECKSUM
from selfdrive.can.packer import CANPacker


Expand Down Expand Up @@ -61,8 +61,9 @@ def update(self, sendcan, enabled, CS, actuators, pcm_cancel_cmd, hud_alert):
if (self.cnt % 7) == 0:
can_sends.append(create_1156())

can_sends.append(create_lkas12())
can_sends.append(create_lkas11(self.packer, apply_steer, steer_req, self.lkas11_cnt,
enabled, CS.lkas11, hud_alert, keep_stock=(not self.camera_disconnected)))
enabled, CS.lkas11, hud_alert, CHECKSUM[self.car_fingerprint], keep_stock=(not self.camera_disconnected)))

if pcm_cancel_cmd:
can_sends.append(create_clu11(self.packer, CS.clu11, Buttons.CANCEL))
Expand Down
5 changes: 3 additions & 2 deletions selfdrive/car/hyundai/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_can_parser(CP):
("CF_Gway_TurnSigLh", "CGW1", 0),
("CF_Gway_TSigRHSw", "CGW1", 0),
("CF_Gway_TurnSigRh", "CGW1", 0),
("CF_Gway_ParkBrakeSw", "CGW1", 0),

("BRAKE_ACT", "EMS12", 0),
("PV_AV_CAN", "EMS12", 0),
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_camera_parser(CP):

checks = []

return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2)
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm... I think keep supporting the connection with camera on bus 1 will be hard.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave this as 2, and update locally, unless I can figure out a clean way of doing this (like I did for panda)
I will fix this for the PR


class CarState(object):
def __init__(self, CP):
Expand Down Expand Up @@ -149,7 +150,7 @@ def update(self, cp, cp_cam):
self.brake_pressed = cp.vl["TCS13"]['DriverBraking']
self.esp_disabled = cp.vl["TCS15"]['ESC_Off_Step']

self.park_brake = False
self.park_brake = cp.vl["CGW1"]['CF_Gway_ParkBrakeSw']
self.main_on = True
self.acc_active = cp.vl["SCC12"]['ACCMode'] != 0
self.pcm_acc_status = int(self.acc_active)
Expand Down
23 changes: 18 additions & 5 deletions selfdrive/car/hyundai/hyundaican.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

hyundai_checksum = crcmod.mkCrcFun(0x11D, initCrc=0xFD, rev=False, xorOut=0xdf)

<<<<<<< HEAD

emmertex marked this conversation as resolved.
Show resolved Hide resolved
def make_can_msg(addr, dat, alt):
return [addr, 0, dat, alt]

def create_lkas11(packer, apply_steer, steer_req, cnt, enabled, lkas11, hud_alert, keep_stock=False):
def create_lkas11(packer, apply_steer, steer_req, cnt, enabled, lkas11, hud_alert, checksum_type, keep_stock=False):
values = {
"CF_Lkas_Icon": 3 if enabled else 0,
"CF_Lkas_LdwsSysState": lkas11["CF_Lkas_LdwsSysState"] if keep_stock else 1,
"CF_Lkas_LdwsSysState": 3 if steer_req else 1,
"CF_Lkas_SysWarning": hud_alert,
"CF_Lkas_LdwsLHWarning": lkas11["CF_Lkas_LdwsLHWarning"] if keep_stock else 0,
"CF_Lkas_LdwsRHWarning": lkas11["CF_Lkas_LdwsRHWarning"] if keep_stock else 0,
"CF_Lkas_HbaLamp": lkas11["CF_Lkas_HbaLamp"] if keep_stock else 0,
"CF_Lkas_FcwBasReq": lkas11["CF_Lkas_FcwBasReq"] if keep_stock else 0,
"CR_Lkas_StrToqReq": apply_steer,
"CF_Lkas_ActToi": steer_req,
"CF_Lkas_ToiFlt": lkas11["CF_Lkas_ToiFlt"] if keep_stock else 0,
"CF_Lkas_ToiFlt": 0,
"CF_Lkas_HbaSysState": lkas11["CF_Lkas_HbaSysState"] if keep_stock else 1,
"CF_Lkas_FcwOpt": lkas11["CF_Lkas_FcwOpt"] if keep_stock else 0,
"CF_Lkas_HbaOpt": lkas11["CF_Lkas_HbaOpt"] if keep_stock else 3,
Expand All @@ -30,9 +32,20 @@ def create_lkas11(packer, apply_steer, steer_req, cnt, enabled, lkas11, hud_aler
}

dat = packer.make_can_msg("LKAS11", 0, values)[2]
dat = dat[:6] + dat[7]
checksum = hyundai_checksum(dat)

# CRC Checksum as seen on 2019 Hyundai Santa Fe
if checksum_type == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you can use CHECKSUM, imported from values.py

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review now, I now pass fingerprint and imported values.py

dat = dat[:6] + dat[7]
checksum = hyundai_checksum(dat)
# Checksum of first 6 Bytes, as seen on 2018 Kia Sorento
if checksum_type == 6:
dat = [ord(i) for i in dat]
checksum = sum(dat[:6]) % 256
# Checksum of first 6 Bytes and last Byte as seen on 2018 Kia Stinger
if checksum_type == 7:
dat = [ord(i) for i in dat]
checksum = (sum(dat[:6]) + dat[7]) % 256

values["CF_Lkas_Chksum"] = checksum

return packer.make_can_msg("LKAS11", 0, values)
Expand Down
29 changes: 21 additions & 8 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from selfdrive.controls.lib.drive_helpers import EventTypes as ET, create_event
from selfdrive.controls.lib.vehicle_model import VehicleModel
from selfdrive.car.hyundai.carstate import CarState, get_can_parser, get_camera_parser
from selfdrive.car.hyundai.values import CAMERA_MSGS, get_hud_alerts
from selfdrive.car.hyundai.values import CAMERA_MSGS, CAR, get_hud_alerts

try:
from selfdrive.car.hyundai.carcontroller import CarController
Expand Down Expand Up @@ -48,6 +48,7 @@ def calc_accel_override(a_ego, a_target, v_ego, v_target):
def get_params(candidate, fingerprint):

# kg of standard extra cargo to count for drive, gas, etc...
# This should be tweaked, unless the car is empty, this will be too low
std_cargo = 136

ret = car.CarParams.new_message()
Expand All @@ -73,13 +74,25 @@ def get_params(candidate, fingerprint):
ret.steerActuatorDelay = 0.1 # Default delay, Prius has larger delay

#borrowing a lot from corolla, given similar car size
ret.steerKf = 0.00005 # full torque for 20 deg at 80mph means 0.00007818594
ret.steerRateCost = 0.5
ret.mass = 3982 * CV.LB_TO_KG + std_cargo
ret.wheelbase = 2.766
ret.steerRatio = 13.8 * 1.15 # 15% higher at the center seems reasonable
ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
ret.steerKpV, ret.steerKiV = [[0.37], [0.1]]

if candidate == CAR.SANTA_FE:
ret.steerKf = 0.00005 # full torque for 20 deg at 80mph means 0.00007818594
ret.steerRateCost = 0.5
ret.mass = 3982 * CV.LB_TO_KG + std_cargo
ret.wheelbase = 2.766
ret.steerRatio = 13.8 * 1.15 # 15% higher at the center seems reasonable
ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
ret.steerKpV, ret.steerKiV = [[0.37], [0.1]]
elif candidate == CAR.SORENTO:
ret.steerKf = 0.00005 # full torque for 20 deg at 80mph means 0.00007818594
ret.steerRateCost = 0.5
ret.mass = 1985 + std_cargo
ret.wheelbase = 2.78
ret.steerRatio = 14.4 * 1.15 # 15% higher at the center seems reasonable
ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
ret.steerKpV, ret.steerKiV = [[0.25], [0.05]]


ret.longitudinalKpBP = [0.]
ret.longitudinalKpV = [0.]
ret.longitudinalKiBP = [0.]
Expand Down
11 changes: 10 additions & 1 deletion selfdrive/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def get_hud_alerts(visual_alert, audble_alert):

class CAR:
SANTA_FE = "HYUNDAI SANTA FE LIMITED 2019"
SORENTO = "KIA SORENTO GT LINE 2018" # Top Trim Kia Sorento for Australian Market, AWD Diesel 8sp Auto

class Buttons:
NONE = 0
Expand All @@ -16,14 +17,22 @@ class Buttons:
CANCEL = 4

FINGERPRINTS = {
CAR.SORENTO: [{
67: 8, 68: 8, 127: 8, 304: 8, 320: 8, 339: 8, 356: 4, 544: 8, 593: 8, 608: 8, 688: 5, 809: 8, 832: 8, 854: 7, 870: 7, 871: 8, 872: 8, 897: 8, 902: 8, 903: 8, 916: 8, 1040: 8, 1042: 8, 1056: 8, 1057: 8, 1064: 8, 1078: 4, 1107: 5, 1136: 8, 1151: 6, 1168: 7, 1170: 8, 1173: 8, 1265: 4, 1280: 1, 1287: 4, 1290: 8, 1292: 8, 1294: 8, 1312: 8, 1322: 8, 1331: 8, 1332: 8, 1333: 8, 1342: 6, 1345: 8, 1348: 8, 1363: 8, 1369: 8, 1370: 8, 1371: 8, 1384: 8, 1407: 8, 1411: 8, 1419: 8, 1425: 2, 1427: 6, 1444: 8, 1456: 4, 1470: 8, 1489: 1
}],
CAR.SANTA_FE: [{
67: 8, 127: 8, 304: 8, 320: 8, 339: 8, 356: 4, 544: 8, 593: 8, 608: 8, 688: 6, 809: 8, 832: 8, 854: 7, 870: 7, 871: 8, 872: 8, 897: 8, 902: 8, 903: 8, 905: 8, 909: 8, 916: 8, 1040: 8, 1042: 8, 1056: 8, 1057: 8, 1078: 4, 1107: 5, 1136: 8, 1151: 6, 1155: 8, 1156: 8, 1162: 8, 1164: 8, 1168: 7, 1170: 8, 1173: 8, 1183: 8, 1186: 2, 1191: 2, 1227: 8, 1265: 4, 1280: 1, 1287: 4, 1290: 8, 1292: 8, 1294: 8, 1312: 8, 1322: 8, 1342: 6, 1345: 8, 1348: 8, 1363: 8, 1369: 8, 1379: 8, 1384: 8, 1407: 8, 1414: 3, 1419: 8, 1427: 6, 1456: 4, 1470: 8
}],
}

CAMERA_MSGS = [832, 1156, 1191, 1342] # msgs sent by the camera

CHECKSUM = {
CAR.SANTA_FE: 0,
CAR.SORENTO: 6,
}

DBC = {
CAR.SANTA_FE: dbc_dict('hyundai_santa_fe_2019_ccan', None),
CAR.SORENTO: dbc_dict('hyundai_santa_fe_2019_ccan', None),
}