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
Legacy and Outback port #717
Changes from 7 commits
7cb21f5
81f5e64
d30b473
dea794c
0ac2a53
94d11a3
cbf3eb6
2a57df3
a7a53c9
8efea56
2996962
07707fc
4ebae40
f7ca42e
4dcb5c7
6792d55
6c36a86
8f24296
2e0b503
b8eeb69
4663c56
c4f453c
f2ddc55
6f20afd
2457931
886bc8b
cb8506f
b6d0362
91f267f
1e92f39
7dc136e
08e3870
c3f1a2a
04bc62d
54818ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from common.kalman.simple_kalman import KF1D | ||
from selfdrive.config import Conversions as CV | ||
from selfdrive.can.parser import CANParser | ||
from selfdrive.car.subaru.values import DBC, STEER_THRESHOLD | ||
from selfdrive.car.subaru.values import CAR, DBC, STEER_THRESHOLD | ||
|
||
def get_powertrain_can_parser(CP): | ||
# this function generates lists for signal, messages and initial values | ||
|
@@ -25,60 +25,71 @@ def get_powertrain_can_parser(CP): | |
("DOOR_OPEN_FL", "BodyInfo", 1), | ||
("DOOR_OPEN_RR", "BodyInfo", 1), | ||
("DOOR_OPEN_RL", "BodyInfo", 1), | ||
("Units", "Dash_State", 1), | ||
] | ||
|
||
checks = [ | ||
# sig_address, frequency | ||
("Dashlights", 10), | ||
("CruiseControl", 20), | ||
("Wheel_Speeds", 50), | ||
("Steering_Torque", 50), | ||
("BodyInfo", 10), | ||
] | ||
|
||
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) | ||
if CP.carFingerprint == CAR.IMPREZA: | ||
signals += [ | ||
("Units", "Dash_State", 1), | ||
] | ||
checks += [ | ||
("BodyInfo", 10), | ||
("CruiseControl", 20), | ||
] | ||
|
||
else: | ||
signals += [ | ||
("LKA_Lockout", "Steering_Torque", 0), | ||
] | ||
checks += [ | ||
("CruiseControl", 50), | ||
] | ||
|
||
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) | ||
|
||
def get_camera_can_parser(CP): | ||
signals = [ | ||
("Cruise_Set_Speed", "ES_DashStatus", 0), | ||
|
||
("Counter", "ES_Distance", 0), | ||
("Signal1", "ES_Distance", 0), | ||
("Signal2", "ES_Distance", 0), | ||
("Main", "ES_Distance", 0), | ||
("Signal3", "ES_Distance", 0), | ||
|
||
("Checksum", "ES_LKAS_State", 0), | ||
("Counter", "ES_LKAS_State", 0), | ||
("Keep_Hands_On_Wheel", "ES_LKAS_State", 0), | ||
("Empty_Box", "ES_LKAS_State", 0), | ||
("Signal1", "ES_LKAS_State", 0), | ||
("LKAS_ACTIVE", "ES_LKAS_State", 0), | ||
("Signal2", "ES_LKAS_State", 0), | ||
("Backward_Speed_Limit_Menu", "ES_LKAS_State", 0), | ||
("LKAS_ENABLE_3", "ES_LKAS_State", 0), | ||
("Signal3", "ES_LKAS_State", 0), | ||
("LKAS_ENABLE_2", "ES_LKAS_State", 0), | ||
("Signal4", "ES_LKAS_State", 0), | ||
("LKAS_Left_Line_Visible", "ES_LKAS_State", 0), | ||
("Signal6", "ES_LKAS_State", 0), | ||
("LKAS_Right_Line_Visible", "ES_LKAS_State", 0), | ||
("Signal7", "ES_LKAS_State", 0), | ||
("FCW_Cont_Beep", "ES_LKAS_State", 0), | ||
("FCW_Repeated_Beep", "ES_LKAS_State", 0), | ||
("Throttle_Management_Activated", "ES_LKAS_State", 0), | ||
("Traffic_light_Ahead", "ES_LKAS_State", 0), | ||
("Right_Depart", "ES_LKAS_State", 0), | ||
("Signal5", "ES_LKAS_State", 0), | ||
|
||
] | ||
|
||
checks = [ | ||
("ES_DashStatus", 10), | ||
] | ||
|
||
if CP.carFingerprint == CAR.IMPREZA: | ||
signals += [ | ||
("Counter", "ES_Distance", 0), | ||
("Signal1", "ES_Distance", 0), | ||
("Signal2", "ES_Distance", 0), | ||
("Main", "ES_Distance", 0), | ||
("Signal3", "ES_Distance", 0), | ||
|
||
("Checksum", "ES_LKAS_State", 0), | ||
("Counter", "ES_LKAS_State", 0), | ||
("Keep_Hands_On_Wheel", "ES_LKAS_State", 0), | ||
("Empty_Box", "ES_LKAS_State", 0), | ||
("Signal1", "ES_LKAS_State", 0), | ||
("LKAS_ACTIVE", "ES_LKAS_State", 0), | ||
("Signal2", "ES_LKAS_State", 0), | ||
("Backward_Speed_Limit_Menu", "ES_LKAS_State", 0), | ||
("LKAS_ENABLE_3", "ES_LKAS_State", 0), | ||
("Signal3", "ES_LKAS_State", 0), | ||
("LKAS_ENABLE_2", "ES_LKAS_State", 0), | ||
("Signal4", "ES_LKAS_State", 0), | ||
("FCW_Cont_Beep", "ES_LKAS_State", 0), | ||
("FCW_Repeated_Beep", "ES_LKAS_State", 0), | ||
("Throttle_Management_Activated", "ES_LKAS_State", 0), | ||
("Traffic_light_Ahead", "ES_LKAS_State", 0), | ||
("Right_Depart", "ES_LKAS_State", 0), | ||
("Signal5", "ES_LKAS_State", 0), | ||
] | ||
|
||
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2) | ||
|
||
|
||
|
@@ -118,12 +129,9 @@ def update(self, cp, cp_cam): | |
self.v_wheel_rr = cp.vl["Wheel_Speeds"]['RR'] * CV.KPH_TO_MS | ||
|
||
self.v_cruise_pcm = cp_cam.vl["ES_DashStatus"]['Cruise_Set_Speed'] | ||
# 1 = imperial, 6 = metric | ||
if cp.vl["Dash_State"]['Units'] == 1: | ||
self.v_cruise_pcm *= CV.MPH_TO_KPH | ||
|
||
v_wheel = (self.v_wheel_fl + self.v_wheel_fr + self.v_wheel_rl + self.v_wheel_rr) / 4. | ||
# Kalman filter, even though Hyundai raw wheel speed is heaviliy filtered by default | ||
# Kalman filter, even though Subaru raw wheel speed is heaviliy filtered by default | ||
if abs(v_wheel - self.v_ego) > 2.0: # Prevent large accelerations when car starts at non zero speed | ||
self.v_ego_kf.x = [[v_wheel], [0.0]] | ||
|
||
|
@@ -149,5 +157,14 @@ def update(self, cp, cp_cam): | |
cp.vl["BodyInfo"]['DOOR_OPEN_FR'], | ||
cp.vl["BodyInfo"]['DOOR_OPEN_FL']]) | ||
|
||
self.es_distance_msg = copy.copy(cp_cam.vl["ES_Distance"]) | ||
self.es_lkas_msg = copy.copy(cp_cam.vl["ES_LKAS_State"]) | ||
if self.car_fingerprint == CAR.IMPREZA: | ||
self.v_cruise_pcm = cp_cam.vl["ES_DashStatus"]["Cruise_Set_Speed"] * CV.MPH_TO_KPH | ||
self.steer_not_allowed = 0 | ||
self.es_distance_msg = copy.copy(cp_cam.vl["ES_Distance"]) | ||
self.es_lkas_msg = copy.copy(cp_cam.vl["ES_LKAS_State"]) | ||
# 1 = imperial, 6 = metric | ||
if cp.vl["Dash_State"]['Units'] == 1: | ||
self.v_cruise_pcm *= CV.MPH_TO_KPH | ||
else: | ||
self.v_cruise_pcm = cp_cam.vl["ES_DashStatus"]["Cruise_Set_Speed"] | ||
self.steer_not_allowed = cp.vl["Steering_Torque"]["LKA_Lockout"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the Impreza. All the cars shall have the same attributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which lines break the Impreza, 163-169? Should be the same. I'll look into it more later. The Outback and Legacy are on a very different platform There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change that else to outback and legacy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. steer_not_allowed is used in interface. so needs to be defined for all cars There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see now, I'll fix these all tonight. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the changes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,28 @@ def create_steering_control(packer, car_fingerprint, apply_steer, frame, steer_s | |
} | ||
values["Checksum"] = subaru_checksum(packer, values, 0x122) | ||
|
||
if car_fingerprint in (CAR.OUTBACK, CAR.LEGACY): | ||
|
||
if apply_steer != 0: | ||
chksm_steer = apply_steer * -1 | ||
chksm_engage = 1 | ||
else: | ||
chksm_steer = 0 | ||
chksm_engage = 0 | ||
|
||
#counts from 0 to 7 then back to 0 | ||
idx = (frame / steer_step) % 8 | ||
steer2 = (chksm_steer >> 8) & 0x1F | ||
steer1 = chksm_steer - (steer2 << 8) | ||
checksum = (idx + steer2 + steer1 + chksm_engage) % 256 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would define a generic "subaru_checksum_legacy" function. It must be computed in some generic way... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try, it's just the sum of all bytes mod 256. |
||
|
||
values = { | ||
"Counter": idx, | ||
"LKAS_Command": apply_steer, | ||
"LKAS_Active": 1 if apply_steer != 0 else 0, | ||
"Checksum": checksum | ||
} | ||
|
||
return packer.make_can_msg("ES_LKAS", 0, values) | ||
|
||
def create_steering_status(packer, car_fingerprint, apply_steer, frame, steer_step): | ||
|
@@ -55,3 +77,10 @@ def create_es_lkas(packer, es_lkas_msg, visual_alert, left_line, right_line): | |
values["Checksum"] = subaru_checksum(packer, values, 802) | ||
|
||
return packer.make_can_msg("ES_LKAS_State", 0, values) | ||
|
||
def create_door_control(packer): | ||
values = { | ||
"DOOR_OPEN_FR": 1, | ||
"_UNKNOWN": 5, | ||
} | ||
return packer.make_can_msg("BodyInfo", 2, values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably need to distinguish between Impreza and others and pass this param to panda safety.