-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Subaru: Crosstrek Hybrid dashcam mode #25378
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ca66665
Subaru: Crosstrek Hybrid support
adeebshihadeh 89737b2
Merge remote-tracking branch 'origin/master' into subaru-hybrid
jnewb1 f9ed9ec
hybrid cars in dashcam only
jnewb1 0292191
revert that
jnewb1 901d9bf
just dashcam
jnewb1 fc8670f
tah should be abs
jnewb1 abccf1e
remove unused import
jnewb1 1abcb34
use the old dbc for now
jnewb1 9b8f02e
hybrid car exceptions in carstate
jnewb1 faf8c71
need dashstatus until we get a proper cruiseactivated bit
jnewb1 627f4ba
missing CP
jnewb1 fd70e06
merge conflicts
jnewb1 62812ef
lets be consistent about extend
jnewb1 2e147d5
cleanup
jnewb1 b523c41
Merge remote-tracking branch 'origin/master' into subaru-hybrid
jnewb1 cc833aa
fix and comments
jnewb1 bd632d6
preglobal fix
jnewb1 e246c9d
and the rest
jnewb1 3844571
and this
jnewb1 479f790
added hybrid to release
jnewb1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from opendbc.can.parser import CANParser | ||
from openpilot.selfdrive.car.subaru.values import DBC, CAR, GLOBAL_GEN2, PREGLOBAL_CARS, CanBus, SubaruFlags | ||
from openpilot.selfdrive.car import CanSignalRateCalculator | ||
from selfdrive.car.subaru.values import HYBRID_CARS | ||
|
||
|
||
class CarState(CarStateBase): | ||
|
@@ -19,7 +20,9 @@ def __init__(self, CP): | |
def update(self, cp, cp_cam, cp_body): | ||
ret = car.CarState.new_message() | ||
|
||
ret.gas = cp.vl["Throttle"]["Throttle_Pedal"] / 255. | ||
throttle_msg = cp.vl["Throttle"] if self.car_fingerprint not in HYBRID_CARS else cp_body.vl["Throttle_Hybrid"] | ||
ret.gas = throttle_msg["Throttle_Pedal"] / 255. | ||
|
||
ret.gasPressed = ret.gas > 1e-5 | ||
if self.car_fingerprint in PREGLOBAL_CARS: | ||
ret.brakePressed = cp.vl["Brake_Pedal"]["Brake_Pedal"] > 2 | ||
|
@@ -46,7 +49,8 @@ def update(self, cp, cp_cam, cp_body): | |
ret.leftBlindspot = (cp.vl["BSD_RCTA"]["L_ADJACENT"] == 1) or (cp.vl["BSD_RCTA"]["L_APPROACHING"] == 1) | ||
ret.rightBlindspot = (cp.vl["BSD_RCTA"]["R_ADJACENT"] == 1) or (cp.vl["BSD_RCTA"]["R_APPROACHING"] == 1) | ||
|
||
can_gear = int(cp.vl["Transmission"]["Gear"]) | ||
cp_transmission = cp_body if self.car_fingerprint in HYBRID_CARS else cp | ||
can_gear = int(cp_transmission.vl["Transmission"]["Gear"]) | ||
ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(can_gear, None)) | ||
|
||
ret.steeringAngleDeg = cp.vl["Steering_Torque"]["Steering_Angle"] | ||
|
@@ -62,8 +66,12 @@ def update(self, cp, cp_cam, cp_body): | |
ret.steeringPressed = abs(ret.steeringTorque) > steer_threshold | ||
|
||
cp_cruise = cp_body if self.car_fingerprint in GLOBAL_GEN2 else cp | ||
ret.cruiseState.enabled = cp_cruise.vl["CruiseControl"]["Cruise_Activated"] != 0 | ||
ret.cruiseState.available = cp_cruise.vl["CruiseControl"]["Cruise_On"] != 0 | ||
if self.car_fingerprint in HYBRID_CARS: | ||
ret.cruiseState.enabled = cp_cam.vl["ES_DashStatus"]['Cruise_Activated'] != 0 | ||
ret.cruiseState.available = cp_cam.vl["ES_DashStatus"]['Cruise_On'] != 0 | ||
else: | ||
ret.cruiseState.enabled = cp_cruise.vl["CruiseControl"]["Cruise_Activated"] != 0 | ||
ret.cruiseState.available = cp_cruise.vl["CruiseControl"]["Cruise_On"] != 0 | ||
ret.cruiseState.speed = cp_cam.vl["ES_DashStatus"]["Cruise_Set_Speed"] * CV.KPH_TO_MS | ||
|
||
if (self.car_fingerprint in PREGLOBAL_CARS and cp.vl["Dash_State2"]["UNITS"] == 1) or \ | ||
|
@@ -77,7 +85,7 @@ def update(self, cp, cp_cam, cp_body): | |
cp.vl["BodyInfo"]["DOOR_OPEN_FL"]]) | ||
ret.steerFaultPermanent = cp.vl["Steering_Torque"]["Steer_Error_1"] == 1 | ||
|
||
cp_es_distance = cp_body if self.car_fingerprint in GLOBAL_GEN2 else cp_cam | ||
cp_es_distance = cp_body if self.car_fingerprint in (GLOBAL_GEN2 | HYBRID_CARS) else cp_cam | ||
if self.car_fingerprint in PREGLOBAL_CARS: | ||
self.cruise_button = cp_cam.vl["ES_Distance"]["Cruise_Button"] | ||
self.ready = not cp_cam.vl["ES_DashStatus"]["Not_Ready_Startup"] | ||
|
@@ -87,63 +95,77 @@ def update(self, cp, cp_cam, cp_body): | |
ret.cruiseState.standstill = cp_cam.vl["ES_DashStatus"]["Cruise_State"] == 3 | ||
ret.stockFcw = (cp_cam.vl["ES_LKAS_State"]["LKAS_Alert"] == 1) or \ | ||
(cp_cam.vl["ES_LKAS_State"]["LKAS_Alert"] == 2) | ||
# 8 is known AEB, there are a few other values related to AEB we ignore | ||
ret.stockAeb = (cp_es_distance.vl["ES_Brake"]["AEB_Status"] == 8) and \ | ||
(cp_es_distance.vl["ES_Brake"]["Brake_Pressure"] != 0) | ||
|
||
self.es_lkas_state_msg = copy.copy(cp_cam.vl["ES_LKAS_State"]) | ||
cp_es_brake = cp_body if self.car_fingerprint in GLOBAL_GEN2 else cp_cam | ||
self.es_brake_msg = copy.copy(cp_es_brake.vl["ES_Brake"]) | ||
cp_es_status = cp_body if self.car_fingerprint in GLOBAL_GEN2 else cp_cam | ||
self.es_status_msg = copy.copy(cp_es_status.vl["ES_Status"]) | ||
self.cruise_control_msg = copy.copy(cp_cruise.vl["CruiseControl"]) | ||
self.brake_status_msg = copy.copy(cp_brakes.vl["Brake_Status"]) | ||
|
||
self.es_distance_msg = copy.copy(cp_es_distance.vl["ES_Distance"]) | ||
if self.car_fingerprint not in HYBRID_CARS: # Hybrid cars don't have es_distance, need a replacement | ||
# 8 is known AEB, there are a few other values related to AEB we ignore | ||
ret.stockAeb = (cp_es_distance.vl["ES_Brake"]["AEB_Status"] == 8) and \ | ||
(cp_es_distance.vl["ES_Brake"]["Brake_Pressure"] != 0) | ||
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. spacing |
||
self.es_distance_msg = copy.copy(cp_es_distance.vl["ES_Distance"]) | ||
|
||
self.es_status_msg = copy.copy(cp_es_status.vl["ES_Status"]) | ||
self.cruise_control_msg = copy.copy(cp_cruise.vl["CruiseControl"]) | ||
|
||
if self.car_fingerprint not in HYBRID_CARS: | ||
self.es_distance_msg = copy.copy(cp_es_distance.vl["ES_Distance"]) | ||
Comment on lines
+108
to
+114
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. seems like we can simplify this so we don't need to copy twice? |
||
self.es_dashstatus_msg = copy.copy(cp_cam.vl["ES_DashStatus"]) | ||
if self.CP.flags & SubaruFlags.SEND_INFOTAINMENT: | ||
self.es_infotainment_msg = copy.copy(cp_cam.vl["ES_Infotainment"]) | ||
|
||
return ret | ||
|
||
@staticmethod | ||
def get_common_global_body_messages(): | ||
def get_common_global_body_messages(CP): | ||
messages = [ | ||
("CruiseControl", 20), | ||
("Wheel_Speeds", 50), | ||
("Brake_Status", 50), | ||
] | ||
|
||
if CP.carFingerprint not in HYBRID_CARS: | ||
messages.append(("CruiseControl", 20)) | ||
|
||
return messages | ||
|
||
@staticmethod | ||
def get_common_global_es_messages(): | ||
def get_common_global_es_messages(CP): | ||
messages = [ | ||
("ES_Brake", 20), | ||
("ES_Distance", 20), | ||
("ES_Status", 20), | ||
("ES_Brake", 20), | ||
] | ||
|
||
if CP.carFingerprint not in HYBRID_CARS: | ||
messages += [ | ||
("ES_Distance", 20), | ||
("ES_Status", 20) | ||
] | ||
|
||
return messages | ||
|
||
@staticmethod | ||
def get_can_parser(CP): | ||
messages = [ | ||
# sig_address, frequency | ||
("Throttle", 100), | ||
("Dashlights", 10), | ||
("Brake_Pedal", 50), | ||
("Transmission", 100), | ||
("Steering_Torque", 50), | ||
("BodyInfo", 1), | ||
("Brake_Pedal", 50), | ||
] | ||
|
||
if CP.carFingerprint not in HYBRID_CARS: | ||
messages += [ | ||
("Throttle", 100), | ||
("Transmission", 100) | ||
] | ||
|
||
if CP.enableBsm: | ||
messages.append(("BSD_RCTA", 17)) | ||
|
||
if CP.carFingerprint not in PREGLOBAL_CARS: | ||
if CP.carFingerprint not in GLOBAL_GEN2: | ||
messages += CarState.get_common_global_body_messages() | ||
messages += CarState.get_common_global_body_messages(CP) | ||
|
||
messages += [ | ||
("Dashlights", 10), | ||
|
@@ -184,7 +206,7 @@ def get_cam_can_parser(CP): | |
] | ||
|
||
if CP.carFingerprint not in GLOBAL_GEN2: | ||
messages += CarState.get_common_global_es_messages() | ||
messages += CarState.get_common_global_es_messages(CP) | ||
|
||
if CP.flags & SubaruFlags.SEND_INFOTAINMENT: | ||
messages.append(("ES_Infotainment", 10)) | ||
|
@@ -193,9 +215,17 @@ def get_cam_can_parser(CP): | |
|
||
@staticmethod | ||
def get_body_can_parser(CP): | ||
messages = [] | ||
|
||
if CP.carFingerprint in GLOBAL_GEN2: | ||
messages = CarState.get_common_global_body_messages() | ||
messages += CarState.get_common_global_es_messages() | ||
return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus.alt) | ||
messages += CarState.get_common_global_body_messages(CP) | ||
messages += CarState.get_common_global_es_messages(CP) | ||
|
||
if CP.carFingerprint in HYBRID_CARS: | ||
messages += [ | ||
("Throttle_Hybrid", 40), | ||
("Transmission", 100) | ||
] | ||
|
||
return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus.alt) | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 already import from values above