|
|
|
@ -4,12 +4,12 @@ from common.conversions import Conversions as CV |
|
|
|
|
from selfdrive.car.interfaces import CarStateBase |
|
|
|
|
from opendbc.can.parser import CANParser |
|
|
|
|
from opendbc.can.can_define import CANDefine |
|
|
|
|
from selfdrive.car.volkswagen.values import PQ_CARS, DBC_FILES, CANBUS, NetworkLocation, TransmissionType, GearShifter, BUTTON_STATES, CarControllerParams |
|
|
|
|
|
|
|
|
|
from selfdrive.car.volkswagen.values import DBC_FILES, CANBUS, NetworkLocation, TransmissionType, GearShifter, \ |
|
|
|
|
CarControllerParams, PQ_CARS, PQ_BUTTONS, MQB_BUTTONS |
|
|
|
|
class CarState(CarStateBase): |
|
|
|
|
def __init__(self, CP): |
|
|
|
|
super().__init__(CP) |
|
|
|
|
self.buttonStates = BUTTON_STATES.copy() |
|
|
|
|
self.button_states = {button.event_type: False for button in MQB_BUTTONS} |
|
|
|
|
|
|
|
|
|
if CP.carFingerprint in PQ_CARS: |
|
|
|
|
can_define = CANDefine(DBC_FILES.pq) |
|
|
|
@ -124,26 +124,20 @@ class CarState(CarStateBase): |
|
|
|
|
if ret.cruiseState.speed > 90: |
|
|
|
|
ret.cruiseState.speed = 0 |
|
|
|
|
|
|
|
|
|
# Update control button states for turn signals and ACC controls. |
|
|
|
|
self.buttonStates["accelCruise"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Tip_Hoch"]) |
|
|
|
|
self.buttonStates["decelCruise"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Tip_Runter"]) |
|
|
|
|
self.buttonStates["cancel"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Abbrechen"]) |
|
|
|
|
self.buttonStates["setCruise"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Tip_Setzen"]) |
|
|
|
|
self.buttonStates["resumeCruise"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Tip_Wiederaufnahme"]) |
|
|
|
|
self.buttonStates["gapAdjustCruise"] = bool(pt_cp.vl["GRA_ACC_01"]["GRA_Verstellung_Zeitluecke"]) |
|
|
|
|
# Update button states for turn signals and ACC controls, capture all ACC button state/config for passthrough |
|
|
|
|
ret.leftBlinker = bool(pt_cp.vl["Blinkmodi_02"]["Comfort_Signal_Left"]) |
|
|
|
|
ret.rightBlinker = bool(pt_cp.vl["Blinkmodi_02"]["Comfort_Signal_Right"]) |
|
|
|
|
|
|
|
|
|
# Read ACC hardware button type configuration info that has to pass thru |
|
|
|
|
# to the radar. Ends up being different for steering wheel buttons vs |
|
|
|
|
# third stalk type controls. |
|
|
|
|
self.graHauptschalter = pt_cp.vl["GRA_ACC_01"]["GRA_Hauptschalter"] |
|
|
|
|
self.graTypHauptschalter = pt_cp.vl["GRA_ACC_01"]["GRA_Typ_Hauptschalter"] |
|
|
|
|
self.graButtonTypeInfo = pt_cp.vl["GRA_ACC_01"]["GRA_ButtonTypeInfo"] |
|
|
|
|
self.graTipStufe2 = pt_cp.vl["GRA_ACC_01"]["GRA_Tip_Stufe_2"] |
|
|
|
|
# Pick up the GRA_ACC_01 CAN message counter so we can sync to it for |
|
|
|
|
# later cruise-control button spamming. |
|
|
|
|
self.graMsgBusCounter = pt_cp.vl["GRA_ACC_01"]["COUNTER"] |
|
|
|
|
self.gra_stock_values = pt_cp.vl["GRA_ACC_01"] |
|
|
|
|
buttonEvents = [] |
|
|
|
|
for button in MQB_BUTTONS: |
|
|
|
|
state = (pt_cp.vl[button.can_addr][button.can_msg] in button.values) |
|
|
|
|
if self.button_states[button.event_type] != state: |
|
|
|
|
event = car.CarState.ButtonEvent.new_message() |
|
|
|
|
event.type = button.event_type |
|
|
|
|
event.pressed = state |
|
|
|
|
buttonEvents.append(event) |
|
|
|
|
self.button_states[button.event_type] = state |
|
|
|
|
ret.buttonEvents = buttonEvents |
|
|
|
|
|
|
|
|
|
# Additional safety checks performed in CarInterface. |
|
|
|
|
ret.espDisabled = pt_cp.vl["ESP_21"]["ESP_Tastung_passiv"] != 0 |
|
|
|
@ -253,28 +247,20 @@ class CarState(CarStateBase): |
|
|
|
|
if ret.cruiseState.speed > 70: # 255 kph in m/s == no current setpoint |
|
|
|
|
ret.cruiseState.speed = 0 |
|
|
|
|
|
|
|
|
|
# Update control button states for turn signals and ACC controls. |
|
|
|
|
self.buttonStates["accelCruise"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Up_kurz"]) or bool(pt_cp.vl["GRA_Neu"]["GRA_Up_lang"]) |
|
|
|
|
self.buttonStates["decelCruise"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Down_kurz"]) or bool(pt_cp.vl["GRA_Neu"]["GRA_Down_lang"]) |
|
|
|
|
self.buttonStates["cancel"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Abbrechen"]) |
|
|
|
|
self.buttonStates["setCruise"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Neu_Setzen"]) |
|
|
|
|
self.buttonStates["resumeCruise"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Recall"]) |
|
|
|
|
self.buttonStates["gapAdjustCruise"] = bool(pt_cp.vl["GRA_Neu"]["GRA_Zeitluecke"]) |
|
|
|
|
# Update button states for turn signals and ACC controls, capture all ACC button state/config for passthrough |
|
|
|
|
ret.leftBlinker = bool(pt_cp.vl["Gate_Komf_1"]["GK1_Blinker_li"]) |
|
|
|
|
ret.rightBlinker = bool(pt_cp.vl["Gate_Komf_1"]["GK1_Blinker_re"]) |
|
|
|
|
|
|
|
|
|
# Read ACC hardware button type configuration info that has to pass thru |
|
|
|
|
# to the radar. Ends up being different for steering wheel buttons vs |
|
|
|
|
# third stalk type controls. |
|
|
|
|
self.graHauptschalter = pt_cp.vl["GRA_Neu"]["GRA_Hauptschalt"] |
|
|
|
|
self.graSenderCoding = pt_cp.vl["GRA_Neu"]["GRA_Sender"] |
|
|
|
|
self.graTypHauptschalter = False |
|
|
|
|
self.graButtonTypeInfo = False |
|
|
|
|
self.graTipStufe2 = False |
|
|
|
|
|
|
|
|
|
# Pick up the GRA_ACC_01 CAN message counter so we can sync to it for |
|
|
|
|
# later cruise-control button spamming. |
|
|
|
|
self.graMsgBusCounter = pt_cp.vl["GRA_Neu"]["COUNTER"] |
|
|
|
|
self.gra_stock_values = pt_cp.vl["GRA_Neu"] |
|
|
|
|
buttonEvents = [] |
|
|
|
|
for button in PQ_BUTTONS: |
|
|
|
|
state = (pt_cp.vl[button.can_addr][button.can_msg] in button.values) |
|
|
|
|
if self.button_states[button.event_type] != state: |
|
|
|
|
event = car.CarState.ButtonEvent.new_message() |
|
|
|
|
event.type = button.event_type |
|
|
|
|
event.pressed = state |
|
|
|
|
buttonEvents.append(event) |
|
|
|
|
self.button_states[button.event_type] = state |
|
|
|
|
ret.buttonEvents = buttonEvents |
|
|
|
|
|
|
|
|
|
# Additional safety checks performed in CarInterface. |
|
|
|
|
ret.espDisabled = bool(pt_cp.vl["Bremse_1"]["ESP_Passiv_getastet"]) |
|
|
|
@ -325,6 +311,7 @@ class CarState(CarStateBase): |
|
|
|
|
("GRA_Tip_Wiederaufnahme", "GRA_ACC_01"), # ACC button, resume |
|
|
|
|
("GRA_Verstellung_Zeitluecke", "GRA_ACC_01"), # ACC button, time gap adj |
|
|
|
|
("GRA_Typ_Hauptschalter", "GRA_ACC_01"), # ACC main button type |
|
|
|
|
("GRA_Codierung", "GRA_ACC_01"), # ACC button configuration/coding |
|
|
|
|
("GRA_Tip_Stufe_2", "GRA_ACC_01"), # unknown related to stalk type |
|
|
|
|
("GRA_ButtonTypeInfo", "GRA_ACC_01"), # unknown related to stalk type |
|
|
|
|
("COUNTER", "GRA_ACC_01"), # GRA_ACC_01 CAN message counter |
|
|
|
@ -435,6 +422,8 @@ class CarState(CarStateBase): |
|
|
|
|
("GK1_Blinker_re", "Gate_Komf_1"), # Right turn signal on |
|
|
|
|
("Bremsinfo", "Kombi_1"), # Manual handbrake applied |
|
|
|
|
("GRA_Hauptschalt", "GRA_Neu"), # ACC button, on/off |
|
|
|
|
("GRA_Typ_Hauptschalt", "GRA_Neu"), # ACC button, momentary vs latching |
|
|
|
|
("GRA_Kodierinfo", "GRA_Neu"), # ACC button, configuration |
|
|
|
|
("GRA_Abbrechen", "GRA_Neu"), # ACC button, cancel |
|
|
|
|
("GRA_Neu_Setzen", "GRA_Neu"), # ACC button, set |
|
|
|
|
("GRA_Up_lang", "GRA_Neu"), # ACC button, increase or accel, long press |
|
|
|
@ -444,7 +433,7 @@ class CarState(CarStateBase): |
|
|
|
|
("GRA_Recall", "GRA_Neu"), # ACC button, resume |
|
|
|
|
("GRA_Zeitluecke", "GRA_Neu"), # ACC button, time gap adj |
|
|
|
|
("COUNTER", "GRA_Neu"), # ACC button, message counter |
|
|
|
|
("GRA_Sender", "GRA_Neu"), # GRA Sender Coding |
|
|
|
|
("GRA_Sender", "GRA_Neu"), # ACC button, CAN message originator |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
checks = [ |
|
|
|
|