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 and Hyundai Port #309

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
0fba33b
Merge pull request #120 from commaai/devel
espes Jul 29, 2017
b111277
Merge pull request #121 from commaai/devel
espes Jul 31, 2017
cd25fac
Merge pull request #123 from commaai/devel
espes Aug 11, 2017
606c21b
Merge pull request #126 from commaai/devel
espes Aug 17, 2017
577608b
Merge pull request #137 from commaai/devel
espes Oct 4, 2017
5864323
Merge pull request #146 from commaai/devel
espes Nov 4, 2017
5ae7119
Merge pull request #154 from commaai/devel
geohot Dec 8, 2017
c2e120c
Merge pull request #165 from commaai/devel
espes Jan 17, 2018
675d9fe
Merge pull request #176 from commaai/devel
geohot Jan 22, 2018
10cb834
Merge pull request #183 from commaai/devel
geohot Feb 2, 2018
89605ed
Merge pull request #184 from commaai/devel
geohot Feb 3, 2018
e343c95
Update fingerprints.py
ErichMoraga Feb 3, 2018
affc00d
Merge pull request #188 from commaai/devel
geohot Feb 9, 2018
640ab12
openpilot 0.4.3.1 (#220)
geohot Mar 23, 2018
f550656
Revert "openpilot 0.4.3.1 (#220)"
geohot Mar 26, 2018
3e49143
Merge pull request #226 from commaai/revert-220-devel
geohot Mar 26, 2018
88d1dd2
Merge pull request #239 from commaai/devel
geohot May 2, 2018
afdda0e
Merge pull request #256 from commaai/devel
geohot May 30, 2018
30b72e4
Merge pull request #267 from commaai/devel
geohot Jun 19, 2018
7a62bf0
start of hyundai 2 for 0.4.7.1
csouers Jun 23, 2018
6f2431e
more
csouers Jun 23, 2018
af723bd
fix
csouers Jun 23, 2018
f623414
more
csouers Jun 23, 2018
306db9e
manual controlsd
csouers Jun 23, 2018
9770e53
fix my error
csouers Jun 23, 2018
14c2d1f
fix
csouers Jun 23, 2018
6120df1
mod fingerprint for testing.
csouers Jun 23, 2018
2b4b7e4
fix
csouers Jun 23, 2018
ca9cae5
FIX
csouers Jun 23, 2018
d9ae140
more tests
csouers Jun 23, 2018
04ef0eb
fix
csouers Jun 23, 2018
f58f679
fix
csouers Jun 23, 2018
d340f87
remove more toyota
csouers Jun 23, 2018
4830d72
@ku7 and @csouers merge
nullku7 Jun 24, 2018
c1a46bb
Interface fix
nullku7 Jun 24, 2018
ee827cf
Fix
geohot Jun 24, 2018
27c7425
Merge pull request #277 from commaai/devel
geohot Jun 28, 2018
4b0cd28
Testiong
geohot Jul 1, 2018
a874cf4
Merge remote-tracking branch 'upstream/release2' into hyundai2
nullku7 Jul 1, 2018
50ef912
Finally Working
geohot Jul 2, 2018
306f0d5
Adding a file used for testing
geohot Jul 2, 2018
460d821
Adding a file used for testing
emmertex Jul 2, 2018
00f435f
Merge branch 'hyundai2' of https://github.com/nullku7/openpilot into …
nullku7 Jul 2, 2018
b027e72
Fix
emmertex Jun 24, 2018
a24b151
Testiong
emmertex Jul 1, 2018
541a9af
Merge remote-tracking branch 'upstream/release2' into hyundai2
nullku7 Jul 1, 2018
fd73f48
Finally Working
emmertex Jul 2, 2018
7e427f8
Adding a file used for testing
emmertex Jul 2, 2018
f42d56d
Adding a file used for testing
emmertex Jul 2, 2018
70f7615
Merge branch 'hyundai2' of https://github.com/nullku7/openpilot into …
nullku7 Jul 2, 2018
9498649
Merge branch 'hyundai2' of https://github.com/nullku7/openpilot into …
nullku7 Jul 2, 2018
de3b4af
minor
nullku7 Jul 12, 2018
920d532
minor
nullku7 Jul 12, 2018
4ca3e04
Merge branch 'hyundai2' of https://github.com/nullku7/openpilot into …
nullku7 Jul 12, 2018
8a3c827
ignore-me
nullku7 Jul 13, 2018
71a38b7
Added Kia Stinger 2018 GT2
nullku7 Jul 13, 2018
cd73d25
Merge remote-tracking branch 'upstream/devel' into hyundai05
nullku7 Jul 13, 2018
17ee07f
Merge remote-tracking branch 'upstream/devel' into hyundai05
nullku7 Jul 13, 2018
9888743
0.5 updates to hyundai
nullku7 Jul 13, 2018
ee81e1c
minor carstate fix for hyundai/kiax
nullku7 Jul 13, 2018
0ea21f3
Merge pull request #293 from commaai/devel
geohot Jul 14, 2018
e247e93
temp
nullku7 Jul 14, 2018
924a29a
Merge branch 'release2' of https://github.com/commaai/openpilot into …
nullku7 Jul 14, 2018
335a56f
major cleanup, and more porting with @bugsy
nullku7 Jul 14, 2018
3a4da2b
more porting
nullku7 Jul 14, 2018
08deeda
fix
nullku7 Jul 14, 2018
c3fcf11
still broken - WIP
nullku7 Jul 15, 2018
cabe873
WIP
nullku7 Jul 16, 2018
0a5e384
wip
nullku7 Jul 16, 2018
0eae9e5
Its ALIVE! DO NOT USE .... if you do, CAUTION!
nullku7 Jul 19, 2018
3524c8b
Sorento Tuning
nullku7 Jul 20, 2018
6f6a902
Possible Stinger and Elantra Fix (excluding Drive on Elantra)
nullku7 Jul 20, 2018
8d4f98f
Fix Fingerprint Bug
nullku7 Jul 21, 2018
282e1c1
Different LKAS11 Checksum on non-sorento
nullku7 Jul 21, 2018
ad05aab
WIP
nullku7 Jul 21, 2018
bcd083a
WIP
nullku7 Jul 22, 2018
721ca90
Tuning Tested - More to go
nullku7 Jul 22, 2018
0e42e0c
Nicer Driver Override
nullku7 Jul 24, 2018
6faf87c
WIP - Message Forwarding
nullku7 Jul 24, 2018
d85e5d9
Merge EON and PC changes
nullku7 Jul 24, 2018
69d3ca5
Added gear state via CLU15 for non 8 speed support
nullku7 Jul 24, 2018
9578c2c
panda update
nullku7 Jul 25, 2018
7e9eefe
Merge branch 'hyundai05b' of https://github.com/nullku7/openpilot int…
nullku7 Jul 25, 2018
342121d
broken WIP
nullku7 Jul 25, 2018
8867ba3
untested wip fix
nullku7 Jul 25, 2018
9d8af80
bug fix
nullku7 Jul 26, 2018
6348878
WIP
nullku7 Jul 26, 2018
71f3744
WIP
nullku7 Jul 26, 2018
a7ac59d
WIP
nullku7 Jul 26, 2018
da5c204
Merge branch 'hyundai05b' of https://github.com/nullku7/openpilot int…
nullku7 Jul 26, 2018
ed3fe0c
Major code cleanup
nullku7 Jul 26, 2018
6a77630
Tweak the 'Error Mask Time'
emmertex Jul 27, 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
1 change: 1 addition & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct CarParams {
hondaBosch @5;
ford @6;
cadillac @7;
hyundai @8;
}

# things about the car in the manual
Expand Down
10 changes: 5 additions & 5 deletions launch_chffrplus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ fi

function launch {
# apply update
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
git reset --hard @{u} &&
git clean -xdf &&
exec "${BASH_SOURCE[0]}"
fi
#if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
# git reset --hard @{u} &&
# git clean -xdf &&
# exec "${BASH_SOURCE[0]}"
#fi

# no cpu rationing for now
echo 0-3 > /dev/cpuset/background/cpus
Expand Down
1,391 changes: 1,391 additions & 0 deletions opendbc/kia_sorento_2018.dbc

Large diffs are not rendered by default.

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
5 changes: 4 additions & 1 deletion panda/board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int max_limit_check(int val, const int MAX, const int MIN);
int dist_to_meas_check(int val, int val_last, struct sample_t *val_meas,
const int MAX_RATE_UP, const int MAX_RATE_DOWN, const int MAX_ERROR);
int driver_limit_check(int val, int val_last, struct sample_t *val_driver,
const int MAX, const int MAX_RATE_UP, const int MAX_RATE_DOWN,
const int MAX, const int MAX_RATE_UP, const int MAX_RATE_DOWN,
const int MAX_ALLOWANCE, const int DRIVER_FACTOR);
int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA);

Expand Down Expand Up @@ -49,6 +49,7 @@ int controls_allowed = 0;
#include "safety/safety_gm.h"
#include "safety/safety_ford.h"
#include "safety/safety_cadillac.h"
#include "safety/safety_hyundai.h"
#include "safety/safety_elm327.h"

const safety_hooks *current_hooks = &nooutput_hooks;
Expand Down Expand Up @@ -87,6 +88,7 @@ typedef struct {
#define SAFETY_HONDA_BOSCH 4
#define SAFETY_FORD 5
#define SAFETY_CADILLAC 6
#define SAFETY_HYUNDAI 7
#define SAFETY_TOYOTA_IPAS 0x1335
#define SAFETY_TOYOTA_NOLIMITS 0x1336
#define SAFETY_ALLOUTPUT 0x1337
Expand All @@ -100,6 +102,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_GM, &gm_hooks},
{SAFETY_FORD, &ford_hooks},
{SAFETY_CADILLAC, &cadillac_hooks},
{SAFETY_HYUNDAI, &hyundai_hooks},
{SAFETY_TOYOTA_NOLIMITS, &toyota_nolimits_hooks},
#ifdef PANDA
{SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks},
Expand Down
32 changes: 32 additions & 0 deletions panda/board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Kia Hyundai Safety

static int hyundai_ign_hook() {
return true;
}
static void hyundai_init(int16_t param) {
controls_allowed = 1;
}

static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
// Steering Value Safety Check

return true;
}

static int hyundai_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return true;
}

static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
return -1;
}

const safety_hooks hyundai_hooks = {
.init = hyundai_init,
.rx = default_rx_hook,
.tx = hyundai_tx_hook,
.tx_lin = hyundai_tx_lin_hook,
.ignition = hyundai_ign_hook,
.fwd = hyundai_fwd_hook,
};

2 changes: 1 addition & 1 deletion panda/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Panda(object):
SAFETY_HONDA = 1
SAFETY_TOYOTA = 2
SAFETY_HONDA_BOSCH = 4
SAFETY_HYUNDAI = 7
SAFETY_TOYOTA_NOLIMITS = 0x1336
SAFETY_ALLOUTPUT = 0x1337
SAFETY_ELM327 = 0xE327
Expand Down Expand Up @@ -534,4 +535,3 @@ def kline_recv(self, bus=2):
msg = self.kline_ll_recv(2, bus=bus)
msg += self.kline_ll_recv(ord(msg[1])-2, bus=bus)
return msg

2 changes: 2 additions & 0 deletions run_controlsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#/bin/sh
PYTHONPATH=/data/openpilot PREPAREONLY=1 /data/openpilot/selfdrive/controls/controlsd.py
4 changes: 4 additions & 0 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define SAFETY_HONDA_BOSCH 4
#define SAFETY_FORD 5
#define SAFETY_CADILLAC 6
#define SAFETY_HYUNDAI 7
#define SAFETY_TOYOTA_NOLIMITS 0x1336
#define SAFETY_ALLOUTPUT 0x1337

Expand Down Expand Up @@ -113,6 +114,9 @@ void *safety_setter_thread(void *s) {
case (int)cereal::CarParams::SafetyModels::CADILLAC:
safety_setting = SAFETY_CADILLAC;
break;
case (int)cereal::CarParams::SafetyModels::HYUNDAI:
safety_setting = SAFETY_HYUNDAI;
break;
default:
LOGE("unknown safety model: %d", safety_model);
}
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class CANParser {
}
}
if (!msg) {
fprintf(stderr, "CANParser: could not find message 0x%X in dnc %s\n", op.address, dbc_name.c_str());
fprintf(stderr, "CANParser: could not find message 0x%X in dbc %s\n", op.address, dbc_name.c_str());
assert(false);
}

Expand Down
3 changes: 2 additions & 1 deletion selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def load_interfaces(x):
try:
imp = __import__('selfdrive.car.%s.interface' % interface, fromlist=['CarInterface']).CarInterface
except ImportError:
cloudlog.warning("Import Error %s", ImportError)
imp = None
for car in x[interface]:
ret[car] = imp
Expand Down Expand Up @@ -70,7 +71,7 @@ def fingerprint(logcan, timeout):
# broadcast immediately
if len(candidate_cars) == 1 and st is not None:
# TODO: better way to decide to wait more if Toyota
time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0]) else 0.1
time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0] or "HYUNDAI" in candidate_cars[0]) else 0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

this is only because Toyota Camera takes a while to start sending msgs. Is this really needed for hyundai?

Copy link
Author

Choose a reason for hiding this comment

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

Most likely not, an artefact because this was based off Toyota.
I will kill it and update it if all okay.

if (ts-st) > time_fingerprint:
break

Expand Down
Empty file.
61 changes: 61 additions & 0 deletions selfdrive/car/hyundai/camstate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from selfdrive.car.hyundai.values import CAR, DBC
from selfdrive.can.parser import CANParser
from selfdrive.config import Conversions as CV

def get_can_parser2(CP):

signals = [
("Byte0", "LKAS11", 0),
("Byte1", "LKAS11", 0),
("Byte2", "LKAS11", 0),
("Byte3", "LKAS11", 0),
("Byte4", "LKAS11", 0),
("Byte5", "LKAS11", 0),
("Byte6", "LKAS11", 0), # Checksum
("Byte7", "LKAS11", 0),

("Byte0", "LKAS12", 0),
("Byte1", "LKAS12", 0),
("Byte2", "LKAS12", 0),
("Byte3", "LKAS12", 0),
("Byte4", "LKAS12", 0),
("Byte5", "LKAS12", 0)
]

checks = [
("LKAS11", 100), # LKAS11 = 100Hz
("LKAS12", 10) # LKAS12 = 10Hz
]

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


class CamState(object):
def __init__(self, CP):
self.CP = CP

# initialize can parser
self.car_fingerprint = CP.carFingerprint


def update(self, cp):
# copy can_valid
self.can_valid = cp.can_valid

# LKAS11 From Camera
self.lkas11_b0 = int(cp.vl["LKAS11"]['Byte0'])
self.lkas11_b1 = int(cp.vl["LKAS11"]['Byte1'])
self.lkas11_b2 = int(cp.vl["LKAS11"]['Byte2'])
self.lkas11_b3 = int(cp.vl["LKAS11"]['Byte3'])
self.lkas11_b4 = int(cp.vl["LKAS11"]['Byte4'])
self.lkas11_b5 = int(cp.vl["LKAS11"]['Byte5'])
self.lkas11_b6 = int(cp.vl["LKAS11"]['Byte6'])
self.lkas11_b7 = int(cp.vl["LKAS11"]['Byte7'])

# LKAS10 From Camera
self.lkas12_b0 = int(cp.vl["LKAS12"]['Byte0'])
self.lkas12_b1 = int(cp.vl["LKAS12"]['Byte1'])
self.lkas12_b2 = int(cp.vl["LKAS12"]['Byte2'])
self.lkas12_b3 = int(cp.vl["LKAS12"]['Byte3'])
self.lkas12_b4 = int(cp.vl["LKAS12"]['Byte4'])
self.lkas12_b5 = int(cp.vl["LKAS12"]['Byte5'])
174 changes: 174 additions & 0 deletions selfdrive/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
from common.numpy_fast import clip, interp
from selfdrive.boardd.boardd import can_list_to_can_capnp
from selfdrive.car.hyundai.hyundaican import make_can_msg, create_lkas11, create_lkas12b
from selfdrive.car.hyundai.values import ECU, STATIC_MSGS, CAR
from selfdrive.can.packer import CANPacker


# Steer torque limits
STEER_MAX = 200 # Actual limit is about 1023, but not tested, and not needed
Copy link
Contributor

@rbiasini rbiasini Jul 27, 2018

Choose a reason for hiding this comment

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

so, I assume 1023 is absurdly high? would be nice to add the 200 limit so the safety_hyundai.h in panda as well

Copy link
Author

@emmertex emmertex Jul 27, 2018

Choose a reason for hiding this comment

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

It might be safe to push it to 250, but it is VERY strong, any more would be unsafe.
1023 is the maximum due to the size of the integer, but it does not accept messages over 767

The large amount of power it has is why I later reduce the output torque when the driver starts steering.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I definitely recommend to add the 200 limit panda safety.

STEER_DELTA = 5 # We have no Panda Safety, don't be silly here! Good idea, YOU add Panda Safety!


TARGET_IDS = [0x340]


class CarController(object):
def __init__(self, dbc_name, car_fingerprint, enable_camera):
self.braking = False
self.controls_allowed = True
self.last_steer = 0
self.car_fingerprint = car_fingerprint
self.angle_control = False
self.idx = 0
self.lkas_request = 0
self.lanes = 0
self.steer_angle_enabled = False
self.ipas_reset_counter = 0
self.turning_inhibit = 0
self.limited_steer = 0
self.hide_lkas_fault = 100
print self.car_fingerprint

self.fake_ecus = set()
if enable_camera: self.fake_ecus.add(ECU.CAM)
self.packer = CANPacker(dbc_name)

def update(self, sendcan, enabled, CS, frame, actuators, CamS):
# When the driver starts inputting torque, reduce the requested torque
# We do not want to remove torque because we want to know if OP is still steering
# And how we do it, meh, who cares, this might do.
if abs(CS.steer_torque_driver) > 1:
self.limited_steer = actuators.steer / (abs(CS.steer_torque_driver) * 2)
Copy link
Contributor

@rbiasini rbiasini Jul 27, 2018

Choose a reason for hiding this comment

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

mmm... this causes a torque jump as soon as abs(CS.steer_torque_driver) > 1 is true.

Maybe you can have a look how this is done for GM. You can see how the driver torque is taken into account to limit the commanded torque. Would be nice to re-use the same logic, just different parameters, which will make writing safety code in panda a lot easier.

Copy link
Author

Choose a reason for hiding this comment

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

GM looks nice, I will implement that.

This never used to have * 2, so there was no jump, but later... hack..

else:
self.limited_steer = actuators.steer

# Steering Torque Scaling is to STEER_MAX, + 1024 for center
apply_steer = int(round((self.limited_steer * STEER_MAX) + 1024))

# This is redundant clipping code, kept in case it needs to be advanced
max_lim = 1024 + STEER_MAX
min_lim = 1024 - STEER_MAX
apply_steer = clip(apply_steer, min_lim, max_lim)

# Very basic Rate Limiting
# TODO: Revisit this
if (apply_steer - self.last_steer) > STEER_DELTA:
apply_steer = self.last_steer + STEER_DELTA
elif (self.last_steer - apply_steer) > STEER_DELTA:
apply_steer = self.last_steer - STEER_DELTA


# Inhibits *outside of* alerts
# Because the Turning Indicator Status is based on Lights and not Stalk, latching is
# needed for the disable to work.
if CS.left_blinker_on == 1 or CS.right_blinker_on == 1:
self.turning_inhibit = 180 # Disable for 1.8 Seconds after blinker turned off

if self.turning_inhibit > 0:
self.turning_inhibit = self.turning_inhibit - 1

if not enabled or self.turning_inhibit > 0:
apply_steer = 1024 # 1024 is midpoint (no steer)
self.last_steer = 1024 # Reset Last Steer
else:
self.lanes = 3 * 4 # bit 0 = Right Lane, bit 1 = Left Lane, Offset by 2 bits in byte.

self.last_steer = apply_steer

can_sends = []

# Index is 4 bits long, this is the counter
self.idx = self.idx + 1
if self.idx >= 16:
self.idx = 0

# Byte 4 is used for Index and HBA
# We generate the Index, but pass through HBA
lkas11_byte4 = self.idx * 16

# Split apply steer Word into 2 Bytes
apply_steer_a = apply_steer & 0xFF
apply_steer_b = (apply_steer >> 8) & 0xFF


# If Request to Steer is anything but 0 torque, turn on ActToi
if apply_steer != 1024:
apply_steer_b = apply_steer_b + 0x08


if enabled:
# When we send Torque signals that the camera does not expet, it faults.
# This masks the fault for 750ms after bringing stock back on.
# This does NOT mean that the factory system will be enabled, it will still be off.
# This was tested at 500ms, and 1 in 10 disables, a fault was still seen.
self.hide_lkas_fault = 75

# Generate the 7 bytes as needed for OP Control.
# Anything we don't generate, pass through from camera
lkas11_byte0 = int(self.lanes) + (CamS.lkas11_b0 & 0xC3)
lkas11_byte1 = CamS.lkas11_b1
lkas11_byte2 = apply_steer_a
lkas11_byte3 = apply_steer_b + (CamS.lkas11_b3 & 0xE0) # ToiFlt always comes on, don't pass it
lkas11_byte4 = lkas11_byte4 + (CamS.lkas11_b4 & 0x0F) # Always use our counter
lkas11_byte5 = CamS.lkas11_b5
lkas11_byte7 = CamS.lkas11_b7
else:
# Pass Through the 7 bytes so that Factory LKAS is in control
# We still use our counter, because otherwise duplicates and missed messages from the camera
# is possible due to the implementation method. As such, we recreate the checksum as well
# Byte 0 defined below due to Fault Masking
lkas11_byte1 = CamS.lkas11_b1
lkas11_byte2 = CamS.lkas11_b2
# Byte 3 defined below due to Fault Masking
lkas11_byte4 = lkas11_byte4 + (CamS.lkas11_b4 & 0x0F) # Always use our counter
lkas11_byte5 = CamS.lkas11_b5
lkas11_byte7 = CamS.lkas11_b7
# This is the Fault Masking needed in byte 0 and byte 3
if self.hide_lkas_fault > 0:
lkas11_byte0 = int(self.lanes) + (CamS.lkas11_b0 & 0xC3)
lkas11_byte3 = CamS.lkas11_b3 & 0xE7
self.hide_lkas_fault = self.hide_lkas_fault - 1
else:
lkas11_byte0 = CamS.lkas11_b0
lkas11_byte3 = CamS.lkas11_b3



# Create Checksum
# Sorento checksum is Byte 0 to 5
# Other models appear to be Byte 0 to Byte 5 as well as Byte 7
if CS.car_fingerprint == CAR.SORENTO:
# 6 Byte Checksum
checksum = (lkas11_byte0 + lkas11_byte1 + lkas11_byte2 + lkas11_byte3 + \
lkas11_byte4 + lkas11_byte5) % 256
else:
# 7 Byte Checksum
checksum = (lkas11_byte0 + lkas11_byte1 + lkas11_byte2 + lkas11_byte3 + \
lkas11_byte4 + lkas11_byte5 + lkas11_byte7) % 256



# Create LKAS11 Message at 100Hz
can_sends.append(create_lkas11(self.packer, lkas11_byte0, \
lkas11_byte1, lkas11_byte2, lkas11_byte3, lkas11_byte4, \
lkas11_byte5, checksum, lkas11_byte7))



# Create LKAS12 Message at 10Hz
if (frame % 10) == 0:
can_sends.append(create_lkas12b(self.packer, CamS.lkas12_b0, CamS.lkas12_b1, \
CamS.lkas12_b2, CamS.lkas12_b3, CamS.lkas12_b4, CamS.lkas12_b5))



# Limit Terminal Debugging to 5Hz
if (frame % 20) == 0:
print "controlsdDebug steer", actuators.steer, "strToq", CS.steer_torque_driver, "lim steer", self.limited_steer, "v_ego", \
CS.v_ego, "strAng", CS.angle_steers



# Send messages to canbus
sendcan.send(can_list_to_can_capnp(can_sends, msgtype='sendcan').to_bytes())
Loading