openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
7.9 KiB

import copy
from cereal import car
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
from common.conversions import Conversions as CV
from common.numpy_fast import mean
from opendbc.can.can_define import CANDefine
from opendbc.can.parser import CANParser
from selfdrive.car.interfaces import CarStateBase
from selfdrive.car.gm.values import DBC, AccState, CanBus, STEER_THRESHOLD
TransmissionType = car.CarParams.TransmissionType
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
NetworkLocation = car.CarParams.NetworkLocation
STANDSTILL_THRESHOLD = 10 * 0.0311 * CV.KPH_TO_MS
class CarState(CarStateBase):
def __init__(self, CP):
super().__init__(CP)
can_define = CANDefine(DBC[CP.carFingerprint]["pt"])
self.shifter_values = can_define.dv["ECMPRDNL2"]["PRNDL2"]
self.loopback_lka_steering_cmd_updated = False
self.camera_lka_steering_cmd_counter = 0
self.buttons_counter = 0
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
def update(self, pt_cp, cam_cp, loopback_cp):
5 years ago
ret = car.CarState.new_message()
self.prev_cruise_buttons = self.cruise_buttons
self.cruise_buttons = pt_cp.vl["ASCMSteeringButton"]["ACCButtons"]
self.buttons_counter = pt_cp.vl["ASCMSteeringButton"]["RollingCounter"]
self.pscm_status = copy.copy(pt_cp.vl["PSCMStatus"])
self.moving_backward = pt_cp.vl["EBCMWheelSpdRear"]["MovingBackward"] != 0
# Variables used for avoiding LKAS faults
self.loopback_lka_steering_cmd_updated = len(loopback_cp.vl_all["ASCMLKASteeringCmd"]["RollingCounter"]) > 0
if self.CP.networkLocation == NetworkLocation.fwdCamera:
self.camera_lka_steering_cmd_counter = cam_cp.vl["ASCMLKASteeringCmd"]["RollingCounter"]
ret.wheelSpeeds = self.get_wheel_speeds(
pt_cp.vl["EBCMWheelSpdFront"]["FLWheelSpd"],
pt_cp.vl["EBCMWheelSpdFront"]["FRWheelSpd"],
pt_cp.vl["EBCMWheelSpdRear"]["RLWheelSpd"],
pt_cp.vl["EBCMWheelSpdRear"]["RRWheelSpd"],
)
5 years ago
ret.vEgoRaw = mean([ret.wheelSpeeds.fl, ret.wheelSpeeds.fr, ret.wheelSpeeds.rl, ret.wheelSpeeds.rr])
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
# sample rear wheel speeds, standstill=True if ECM allows engagement with brake
ret.standstill = ret.wheelSpeeds.rl <= STANDSTILL_THRESHOLD and ret.wheelSpeeds.rr <= STANDSTILL_THRESHOLD
if pt_cp.vl["ECMPRDNL2"]["ManualMode"] == 1:
ret.gearShifter = self.parse_gear_shifter("T")
else:
ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(pt_cp.vl["ECMPRDNL2"]["PRNDL2"], None))
# Some Volt 2016-17 have loose brake pedal push rod retainers which causes the ECM to believe
# that the brake is being intermittently pressed without user interaction.
# To avoid a cruise fault we need to match the ECM's brake pressed signal and threshold
# https://static.nhtsa.gov/odi/tsbs/2017/MC-10137629-9999.pdf
ret.brake = pt_cp.vl["ECMAcceleratorPos"]["BrakePedalPos"]
ret.brakePressed = ret.brake >= 8
# Regen braking is braking
if self.CP.transmissionType == TransmissionType.direct:
ret.brakePressed = ret.brakePressed or pt_cp.vl["EBCMRegenPaddle"]["RegenPaddle"] != 0
ret.gas = pt_cp.vl["AcceleratorPedal2"]["AcceleratorPedal2"] / 254.
5 years ago
ret.gasPressed = ret.gas > 1e-5
ret.steeringAngleDeg = pt_cp.vl["PSCMSteeringAngle"]["SteeringWheelAngle"]
ret.steeringRateDeg = pt_cp.vl["PSCMSteeringAngle"]["SteeringWheelRate"]
ret.steeringTorque = pt_cp.vl["PSCMStatus"]["LKADriverAppldTrq"]
ret.steeringTorqueEps = pt_cp.vl["PSCMStatus"]["LKATorqueDelivered"]
5 years ago
ret.steeringPressed = abs(ret.steeringTorque) > STEER_THRESHOLD
# 0 inactive, 1 active, 2 temporarily limited, 3 failed
self.lkas_status = pt_cp.vl["PSCMStatus"]["LKATorqueDeliveredStatus"]
ret.steerFaultTemporary = self.lkas_status == 2
ret.steerFaultPermanent = self.lkas_status == 3
# 1 - open, 0 - closed
ret.doorOpen = (pt_cp.vl["BCMDoorBeltStatus"]["FrontLeftDoor"] == 1 or
pt_cp.vl["BCMDoorBeltStatus"]["FrontRightDoor"] == 1 or
pt_cp.vl["BCMDoorBeltStatus"]["RearLeftDoor"] == 1 or
pt_cp.vl["BCMDoorBeltStatus"]["RearRightDoor"] == 1)
# 1 - latched
ret.seatbeltUnlatched = pt_cp.vl["BCMDoorBeltStatus"]["LeftSeatBelt"] == 0
ret.leftBlinker = pt_cp.vl["BCMTurnSignals"]["TurnSignals"] == 1
ret.rightBlinker = pt_cp.vl["BCMTurnSignals"]["TurnSignals"] == 2
ret.parkingBrake = pt_cp.vl["VehicleIgnitionAlt"]["ParkBrake"] == 1
ret.cruiseState.available = pt_cp.vl["ECMEngineStatus"]["CruiseMainOn"] != 0
ret.espDisabled = pt_cp.vl["ESPStatus"]["TractionControlOn"] != 1
ret.accFaulted = pt_cp.vl["AcceleratorPedal2"]["CruiseState"] == AccState.FAULTED
ret.cruiseState.enabled = pt_cp.vl["AcceleratorPedal2"]["CruiseState"] != AccState.OFF
ret.cruiseState.standstill = pt_cp.vl["AcceleratorPedal2"]["CruiseState"] == AccState.STANDSTILL
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
if self.CP.networkLocation == NetworkLocation.fwdCamera:
ret.cruiseState.speed = cam_cp.vl["ASCMActiveCruiseControlStatus"]["ACCSpeedSetpoint"] * CV.KPH_TO_MS
ret.stockAeb = cam_cp.vl["AEBCmd"]["AEBCmdActive"] != 0
5 years ago
return ret
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
@staticmethod
def get_cam_can_parser(CP):
signals = []
checks = []
if CP.networkLocation == NetworkLocation.fwdCamera:
signals += [
("AEBCmdActive", "AEBCmd"),
("RollingCounter", "ASCMLKASteeringCmd"),
("ACCSpeedSetpoint", "ASCMActiveCruiseControlStatus"),
]
checks += [
("AEBCmd", 10),
("ASCMLKASteeringCmd", 10),
("ASCMActiveCruiseControlStatus", 25),
]
GM: Bolt EUV 2022-23 port (#24875) * Switch to ECMPRDNL2 for GM gear * Removing manumatic gear # * values.py almost complete * Silverado and Bolt EUV val and CP * GM controller updated * Cam hrns supp done (in theory) * cleanup for new cars * Remove extra constant * WS, etc cleanup * removing the unused * Fix kpBP typo * Updated docs * Skip's PIF tune * Dropped LKA CAN error patch * Add silverado sigmoid ff * CAN Err & LKA latch patch * Remove EPS fault fix (another PR) * Remove Silverado (another PR) * clean up some common params * Remove Escalade FP Remove Escalade FP * comment * Premier is just a trim Premier is just a trim Premier is just a trim * no footnote: new Bolt is like most other cars, older GM were outliers not at the camera * clean up clean up * bump panda * bump panda * bump panda * bump panda * bump panda * remove comments * try spamming buttons on bus 2 * bump panda * bumping opendbc w btn rc * not needed for this port This reverts commit 6af1f0ba799e075f877d7acc8ca0f117d97da361. * add button safety * Send next rc when spamming btns * forward other signals in message * missing DriveModeButton * fill cruiseState.speed * see if resume works without counter * try the whole message * send immediately and at 10Hz * no resume, back to just button signal * even holding random buttons it cancels * Use torque controller with base tune * stock long GM don't auto-resume yet * Testing GM zero min steer speed * Revert latcontrol * revert opendbc * latActive is basically lkas_enabled * Update Bolt torque params * comment * clean up * Add to releases * Add test route * Don't specify segment * bump panda * bump panda * no harness for Bolt just yet * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * We support all and 2023 * move safetyParam up to first cam check * Bump panda and update docs * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 4ffe9e68db8d752d9da45febccfe4c28a6e8a0f9
3 years ago
return CANParser(DBC[CP.carFingerprint]["pt"], signals, checks, CanBus.CAMERA)
@staticmethod
def get_can_parser(CP):
signals = [
# sig_name, sig_address
("BrakePedalPos", "ECMAcceleratorPos"),
("FrontLeftDoor", "BCMDoorBeltStatus"),
("FrontRightDoor", "BCMDoorBeltStatus"),
("RearLeftDoor", "BCMDoorBeltStatus"),
("RearRightDoor", "BCMDoorBeltStatus"),
("LeftSeatBelt", "BCMDoorBeltStatus"),
("RightSeatBelt", "BCMDoorBeltStatus"),
("TurnSignals", "BCMTurnSignals"),
("AcceleratorPedal2", "AcceleratorPedal2"),
("CruiseState", "AcceleratorPedal2"),
("ACCButtons", "ASCMSteeringButton"),
("RollingCounter", "ASCMSteeringButton"),
("SteeringWheelAngle", "PSCMSteeringAngle"),
("SteeringWheelRate", "PSCMSteeringAngle"),
("FLWheelSpd", "EBCMWheelSpdFront"),
("FRWheelSpd", "EBCMWheelSpdFront"),
("RLWheelSpd", "EBCMWheelSpdRear"),
("RRWheelSpd", "EBCMWheelSpdRear"),
("MovingBackward", "EBCMWheelSpdRear"),
("PRNDL2", "ECMPRDNL2"),
("ManualMode", "ECMPRDNL2"),
("LKADriverAppldTrq", "PSCMStatus"),
("LKATorqueDelivered", "PSCMStatus"),
("LKATorqueDeliveredStatus", "PSCMStatus"),
("HandsOffSWlDetectionStatus", "PSCMStatus"),
("HandsOffSWDetectionMode", "PSCMStatus"),
("LKATotalTorqueDelivered", "PSCMStatus"),
("PSCMStatusChecksum", "PSCMStatus"),
("RollingCounter", "PSCMStatus"),
("TractionControlOn", "ESPStatus"),
("ParkBrake", "VehicleIgnitionAlt"),
("CruiseMainOn", "ECMEngineStatus"),
]
checks = [
("BCMTurnSignals", 1),
("ECMPRDNL2", 10),
("PSCMStatus", 10),
("ESPStatus", 10),
("BCMDoorBeltStatus", 10),
("VehicleIgnitionAlt", 10),
("EBCMWheelSpdFront", 20),
("EBCMWheelSpdRear", 20),
("AcceleratorPedal2", 33),
("ASCMSteeringButton", 33),
("ECMEngineStatus", 100),
("PSCMSteeringAngle", 100),
("ECMAcceleratorPos", 80),
]
if CP.transmissionType == TransmissionType.direct:
signals.append(("RegenPaddle", "EBCMRegenPaddle"))
checks.append(("EBCMRegenPaddle", 50))
return CANParser(DBC[CP.carFingerprint]["pt"], signals, checks, CanBus.POWERTRAIN)
@staticmethod
def get_loopback_can_parser(CP):
signals = [
("RollingCounter", "ASCMLKASteeringCmd"),
]
checks = [
("ASCMLKASteeringCmd", 0),
]
return CANParser(DBC[CP.carFingerprint]["pt"], signals, checks, CanBus.LOOPBACK, enforce_checks=False)