|
|
|
import copy
|
|
|
|
from opendbc.can.can_define import CANDefine
|
|
|
|
from opendbc.can.parser import CANParser
|
selfdrive/car: ban cereal and capnp (#33208)
* ban cereal and msgq
* common too
* do toyota/values.py
* do all fingerprints
* example without builder
* this still works, but no type checking anymore
* stash
* wtf, how does this work
* okay actually not bad
* safe
* epic!
* stash data_structures.py
* some clean up
* hell yeah
* clean up old file
* add to delete
* delete
This reverts commit 90239b7797ace31ee647a2fdbd67e0c3faa98dcf.
* switch more CarParams stuff over
remove unused
* fix car tests by removing cereal! mypy forgets about dataclass if we wrap it :(
* fix this too
* fix this too
* remove more cereal and add some good hyundai tests
* bunch more typing
* override default with 20hz radar
* temp capnp converter helper
* more lateralTuning
* small union replicator is better than what i was trying, and fixes mypy dynamic typing issues
* can keep all this the same now!
* type ret: CarParams, add more missing structs, revert lateralTuning changes (smaller diff!)
* revert more
* get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :(
would have been `CarParams.NetworkLocation()`
* Revert "get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :("
This reverts commit bb28b228becba932052d2fc5a4389784027435b1.
* remove cereal from car_helpers (TODO: caching)
* remove a bunch of temp lines
* use dataclass_transform!
* remove some car.CarParams from the interfaces
* remove rest of car.CarParams from the interfaces
* same which() API
* sort
* from cereal/cache from fingerprinting!
* more typing
* dataclass to capnp helper for CarParams, cached it since it's kinda slow
* (partial) fix process replay fingerprintig for new API
* latcontrollers take capnp
* forgot this
* fix test_models
* fix unit tests
* not here
* VehicleModel and controller still takes capnp CP since they get it from Params()
* fix modeld test
* more fix
* need to namespace to structs, since CarState is both class and struct
* this was never in the base class?!
* clean that up again
* fix import error
fix import error
* cmts and more structs
* remove some more cereal from toyota + convert CarState to capnp
* bruh this was wrong
* replace more cereal
* EventName is one of the last things...
* replace a bunch more cereal.car
* missing imports
* more
* can fix this typing now
* proper toyota+others CS typing!
* mypy can detect return type of CS.update() now
* fix redeclaration of cruise_buttons type
* mypy is only complaining about events now
* temp fix
* add carControl struct
* replace CarControl
i hope there's no circular imports in hyundai's CC
* fine now
* lol this was wrong too
* fix crash
* include my failed attempts at recursively converting to dataclass (doesn't implicitly convert types/recursively :( )
but attrs does, maybe will switch in the future
* clean up
* try out attr.s for its converter (doesn't work recursively yet, but interesting!)
* Revert "try out attr.s for its converter (doesn't work recursively yet, but interesting!)"
This reverts commit ff2434f7bbd45a4d4bfb21f7d6712d1f1c3bcde9.
* test processes doesn't fail anymore (on toyota)!
* fix honda crash
* stash
* Revert "stash"
This reverts commit c1762af4e776790e4ad1322ad4ce0610157346e0.
* remove a bunch more cereal!
* LET'S GOOO
* fix these tests
* and these
* and that
* stash, something is wrong with hyundai enable
* Revert "stash, something is wrong with hyundai enable"
This reverts commit 39cf327def258e2959fe23cd7a550a858f6d8f03.
* forgot these
* remove cereal from fw_versions
* Revert "remove cereal from fw_versions"
This reverts commit 232b37cd409b55d04b1afc90d4a80c49e710eb56.
* remove rest of the cereal exceptions!
* fix that
* add typing to radard since I didn't realize RI.update() switched from cereal to structs
* and here too!
* add TODO for slots
* needed CS to be capnp, fix comparisons, and type hint car_specific so it's easier to catch type issues (capnp isn't detected by mypy :( )
* remove the struct converter
* save ~4-5% CPU at 100hz, we don't modify after so no need to deepcopy
btw pickle.loads(pickle.dumps()) is faster by ~1% CPU
* deepcopy -> copy: we can technically make a reference, but copy is almost free and less error-prone
saves ~1% CPU
* add non-copying asdict function
* should save ~3% CPU (still 4% above baseline)
* fix that, no dict support
* ~27% decrease in time for 20k iterations on 3X (3.37857 -> 2.4821s)
* give a better name
* fix
* dont support none, capitalize
* sheesh, this called type() on every field
* remove CS.events, clean up
* bump card %
* this was a bug on master!
* add a which enum
* default to pid
* revert
* update refs
* not needed, but consistent
* just Ecu
* don't need to do this in this pr
* clean up
* no cast
* consistent typing
* rm
* fix
* can do this if we're desperate for the last few %
* Revert "can do this if we're desperate for the last few %"
This reverts commit 18e11ac7883a0a56583750b1cc5a2b13011e7299.
* type this
* don't need to convert carControl
* i guess don't support set either
* fix CP type hint
* simplify that
1 year ago
|
|
|
from openpilot.selfdrive.car import create_button_events, structs
|
|
|
|
from openpilot.selfdrive.car.common.conversions import Conversions as CV
|
|
|
|
from openpilot.selfdrive.car.common.numpy_fast import mean
|
|
|
|
from openpilot.selfdrive.car.interfaces import CarStateBase
|
|
|
|
from openpilot.selfdrive.car.gm.values import DBC, AccState, CanBus, CruiseButtons, STEER_THRESHOLD
|
|
|
|
|
selfdrive/car: ban cereal and capnp (#33208)
* ban cereal and msgq
* common too
* do toyota/values.py
* do all fingerprints
* example without builder
* this still works, but no type checking anymore
* stash
* wtf, how does this work
* okay actually not bad
* safe
* epic!
* stash data_structures.py
* some clean up
* hell yeah
* clean up old file
* add to delete
* delete
This reverts commit 90239b7797ace31ee647a2fdbd67e0c3faa98dcf.
* switch more CarParams stuff over
remove unused
* fix car tests by removing cereal! mypy forgets about dataclass if we wrap it :(
* fix this too
* fix this too
* remove more cereal and add some good hyundai tests
* bunch more typing
* override default with 20hz radar
* temp capnp converter helper
* more lateralTuning
* small union replicator is better than what i was trying, and fixes mypy dynamic typing issues
* can keep all this the same now!
* type ret: CarParams, add more missing structs, revert lateralTuning changes (smaller diff!)
* revert more
* get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :(
would have been `CarParams.NetworkLocation()`
* Revert "get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :("
This reverts commit bb28b228becba932052d2fc5a4389784027435b1.
* remove cereal from car_helpers (TODO: caching)
* remove a bunch of temp lines
* use dataclass_transform!
* remove some car.CarParams from the interfaces
* remove rest of car.CarParams from the interfaces
* same which() API
* sort
* from cereal/cache from fingerprinting!
* more typing
* dataclass to capnp helper for CarParams, cached it since it's kinda slow
* (partial) fix process replay fingerprintig for new API
* latcontrollers take capnp
* forgot this
* fix test_models
* fix unit tests
* not here
* VehicleModel and controller still takes capnp CP since they get it from Params()
* fix modeld test
* more fix
* need to namespace to structs, since CarState is both class and struct
* this was never in the base class?!
* clean that up again
* fix import error
fix import error
* cmts and more structs
* remove some more cereal from toyota + convert CarState to capnp
* bruh this was wrong
* replace more cereal
* EventName is one of the last things...
* replace a bunch more cereal.car
* missing imports
* more
* can fix this typing now
* proper toyota+others CS typing!
* mypy can detect return type of CS.update() now
* fix redeclaration of cruise_buttons type
* mypy is only complaining about events now
* temp fix
* add carControl struct
* replace CarControl
i hope there's no circular imports in hyundai's CC
* fine now
* lol this was wrong too
* fix crash
* include my failed attempts at recursively converting to dataclass (doesn't implicitly convert types/recursively :( )
but attrs does, maybe will switch in the future
* clean up
* try out attr.s for its converter (doesn't work recursively yet, but interesting!)
* Revert "try out attr.s for its converter (doesn't work recursively yet, but interesting!)"
This reverts commit ff2434f7bbd45a4d4bfb21f7d6712d1f1c3bcde9.
* test processes doesn't fail anymore (on toyota)!
* fix honda crash
* stash
* Revert "stash"
This reverts commit c1762af4e776790e4ad1322ad4ce0610157346e0.
* remove a bunch more cereal!
* LET'S GOOO
* fix these tests
* and these
* and that
* stash, something is wrong with hyundai enable
* Revert "stash, something is wrong with hyundai enable"
This reverts commit 39cf327def258e2959fe23cd7a550a858f6d8f03.
* forgot these
* remove cereal from fw_versions
* Revert "remove cereal from fw_versions"
This reverts commit 232b37cd409b55d04b1afc90d4a80c49e710eb56.
* remove rest of the cereal exceptions!
* fix that
* add typing to radard since I didn't realize RI.update() switched from cereal to structs
* and here too!
* add TODO for slots
* needed CS to be capnp, fix comparisons, and type hint car_specific so it's easier to catch type issues (capnp isn't detected by mypy :( )
* remove the struct converter
* save ~4-5% CPU at 100hz, we don't modify after so no need to deepcopy
btw pickle.loads(pickle.dumps()) is faster by ~1% CPU
* deepcopy -> copy: we can technically make a reference, but copy is almost free and less error-prone
saves ~1% CPU
* add non-copying asdict function
* should save ~3% CPU (still 4% above baseline)
* fix that, no dict support
* ~27% decrease in time for 20k iterations on 3X (3.37857 -> 2.4821s)
* give a better name
* fix
* dont support none, capitalize
* sheesh, this called type() on every field
* remove CS.events, clean up
* bump card %
* this was a bug on master!
* add a which enum
* default to pid
* revert
* update refs
* not needed, but consistent
* just Ecu
* don't need to do this in this pr
* clean up
* no cast
* consistent typing
* rm
* fix
* can do this if we're desperate for the last few %
* Revert "can do this if we're desperate for the last few %"
This reverts commit 18e11ac7883a0a56583750b1cc5a2b13011e7299.
* type this
* don't need to convert carControl
* i guess don't support set either
* fix CP type hint
* simplify that
1 year ago
|
|
|
ButtonType = structs.CarState.ButtonEvent.Type
|
|
|
|
TransmissionType = structs.CarParams.TransmissionType
|
|
|
|
NetworkLocation = structs.CarParams.NetworkLocation
|
|
|
|
|
|
|
|
STANDSTILL_THRESHOLD = 10 * 0.0311 * CV.KPH_TO_MS
|
|
|
|
|
|
|
|
BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise,
|
|
|
|
CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel}
|
|
|
|
|
|
|
|
|
|
|
|
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.cluster_speed_hyst_gap = CV.KPH_TO_MS / 2.
|
|
|
|
self.cluster_min_speed = CV.KPH_TO_MS / 2.
|
|
|
|
|
|
|
|
self.loopback_lka_steering_cmd_updated = False
|
|
|
|
self.loopback_lka_steering_cmd_ts_nanos = 0
|
|
|
|
self.pt_lka_steering_cmd_counter = 0
|
|
|
|
self.cam_lka_steering_cmd_counter = 0
|
|
|
|
self.buttons_counter = 0
|
|
|
|
|
|
|
|
self.distance_button = 0
|
|
|
|
|
selfdrive/car: ban cereal and capnp (#33208)
* ban cereal and msgq
* common too
* do toyota/values.py
* do all fingerprints
* example without builder
* this still works, but no type checking anymore
* stash
* wtf, how does this work
* okay actually not bad
* safe
* epic!
* stash data_structures.py
* some clean up
* hell yeah
* clean up old file
* add to delete
* delete
This reverts commit 90239b7797ace31ee647a2fdbd67e0c3faa98dcf.
* switch more CarParams stuff over
remove unused
* fix car tests by removing cereal! mypy forgets about dataclass if we wrap it :(
* fix this too
* fix this too
* remove more cereal and add some good hyundai tests
* bunch more typing
* override default with 20hz radar
* temp capnp converter helper
* more lateralTuning
* small union replicator is better than what i was trying, and fixes mypy dynamic typing issues
* can keep all this the same now!
* type ret: CarParams, add more missing structs, revert lateralTuning changes (smaller diff!)
* revert more
* get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :(
would have been `CarParams.NetworkLocation()`
* Revert "get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :("
This reverts commit bb28b228becba932052d2fc5a4389784027435b1.
* remove cereal from car_helpers (TODO: caching)
* remove a bunch of temp lines
* use dataclass_transform!
* remove some car.CarParams from the interfaces
* remove rest of car.CarParams from the interfaces
* same which() API
* sort
* from cereal/cache from fingerprinting!
* more typing
* dataclass to capnp helper for CarParams, cached it since it's kinda slow
* (partial) fix process replay fingerprintig for new API
* latcontrollers take capnp
* forgot this
* fix test_models
* fix unit tests
* not here
* VehicleModel and controller still takes capnp CP since they get it from Params()
* fix modeld test
* more fix
* need to namespace to structs, since CarState is both class and struct
* this was never in the base class?!
* clean that up again
* fix import error
fix import error
* cmts and more structs
* remove some more cereal from toyota + convert CarState to capnp
* bruh this was wrong
* replace more cereal
* EventName is one of the last things...
* replace a bunch more cereal.car
* missing imports
* more
* can fix this typing now
* proper toyota+others CS typing!
* mypy can detect return type of CS.update() now
* fix redeclaration of cruise_buttons type
* mypy is only complaining about events now
* temp fix
* add carControl struct
* replace CarControl
i hope there's no circular imports in hyundai's CC
* fine now
* lol this was wrong too
* fix crash
* include my failed attempts at recursively converting to dataclass (doesn't implicitly convert types/recursively :( )
but attrs does, maybe will switch in the future
* clean up
* try out attr.s for its converter (doesn't work recursively yet, but interesting!)
* Revert "try out attr.s for its converter (doesn't work recursively yet, but interesting!)"
This reverts commit ff2434f7bbd45a4d4bfb21f7d6712d1f1c3bcde9.
* test processes doesn't fail anymore (on toyota)!
* fix honda crash
* stash
* Revert "stash"
This reverts commit c1762af4e776790e4ad1322ad4ce0610157346e0.
* remove a bunch more cereal!
* LET'S GOOO
* fix these tests
* and these
* and that
* stash, something is wrong with hyundai enable
* Revert "stash, something is wrong with hyundai enable"
This reverts commit 39cf327def258e2959fe23cd7a550a858f6d8f03.
* forgot these
* remove cereal from fw_versions
* Revert "remove cereal from fw_versions"
This reverts commit 232b37cd409b55d04b1afc90d4a80c49e710eb56.
* remove rest of the cereal exceptions!
* fix that
* add typing to radard since I didn't realize RI.update() switched from cereal to structs
* and here too!
* add TODO for slots
* needed CS to be capnp, fix comparisons, and type hint car_specific so it's easier to catch type issues (capnp isn't detected by mypy :( )
* remove the struct converter
* save ~4-5% CPU at 100hz, we don't modify after so no need to deepcopy
btw pickle.loads(pickle.dumps()) is faster by ~1% CPU
* deepcopy -> copy: we can technically make a reference, but copy is almost free and less error-prone
saves ~1% CPU
* add non-copying asdict function
* should save ~3% CPU (still 4% above baseline)
* fix that, no dict support
* ~27% decrease in time for 20k iterations on 3X (3.37857 -> 2.4821s)
* give a better name
* fix
* dont support none, capitalize
* sheesh, this called type() on every field
* remove CS.events, clean up
* bump card %
* this was a bug on master!
* add a which enum
* default to pid
* revert
* update refs
* not needed, but consistent
* just Ecu
* don't need to do this in this pr
* clean up
* no cast
* consistent typing
* rm
* fix
* can do this if we're desperate for the last few %
* Revert "can do this if we're desperate for the last few %"
This reverts commit 18e11ac7883a0a56583750b1cc5a2b13011e7299.
* type this
* don't need to convert carControl
* i guess don't support set either
* fix CP type hint
* simplify that
1 year ago
|
|
|
def update(self, pt_cp, cam_cp, _, __, loopback_cp) -> structs.CarState:
|
|
|
|
ret = structs.CarState()
|
|
|
|
|
|
|
|
prev_cruise_buttons = self.cruise_buttons
|
|
|
|
prev_distance_button = self.distance_button
|
|
|
|
self.cruise_buttons = pt_cp.vl["ASCMSteeringButton"]["ACCButtons"]
|
|
|
|
self.distance_button = pt_cp.vl["ASCMSteeringButton"]["DistanceButton"]
|
|
|
|
self.buttons_counter = pt_cp.vl["ASCMSteeringButton"]["RollingCounter"]
|
|
|
|
self.pscm_status = copy.copy(pt_cp.vl["PSCMStatus"])
|
|
|
|
# This is to avoid a fault where you engage while still moving backwards after shifting to D.
|
|
|
|
# An Equinox has been seen with an unsupported status (3), so only check if either wheel is in reverse (2)
|
|
|
|
self.moving_backward = (pt_cp.vl["EBCMWheelSpdRear"]["RLWheelDir"] == 2) or (pt_cp.vl["EBCMWheelSpdRear"]["RRWheelDir"] == 2)
|
|
|
|
|
|
|
|
# Variables used for avoiding LKAS faults
|
|
|
|
self.loopback_lka_steering_cmd_updated = len(loopback_cp.vl_all["ASCMLKASteeringCmd"]["RollingCounter"]) > 0
|
|
|
|
if self.loopback_lka_steering_cmd_updated:
|
|
|
|
self.loopback_lka_steering_cmd_ts_nanos = loopback_cp.ts_nanos["ASCMLKASteeringCmd"]["RollingCounter"]
|
|
|
|
if self.CP.networkLocation == NetworkLocation.fwdCamera:
|
|
|
|
self.pt_lka_steering_cmd_counter = pt_cp.vl["ASCMLKASteeringCmd"]["RollingCounter"]
|
|
|
|
self.cam_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"],
|
|
|
|
)
|
|
|
|
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))
|
|
|
|
|
|
|
|
ret.brake = pt_cp.vl["ECMAcceleratorPos"]["BrakePedalPos"]
|
|
|
|
if self.CP.networkLocation == NetworkLocation.fwdCamera:
|
|
|
|
ret.brakePressed = pt_cp.vl["ECMEngineStatus"]["BrakePressed"] != 0
|
|
|
|
else:
|
|
|
|
# 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 use a conservative brake position threshold
|
|
|
|
# https://static.nhtsa.gov/odi/tsbs/2017/MC-10137629-9999.pdf
|
|
|
|
ret.brakePressed = ret.brake >= 8
|
|
|
|
|
|
|
|
# Regen braking is braking
|
|
|
|
if self.CP.transmissionType == TransmissionType.direct:
|
|
|
|
ret.regenBraking = pt_cp.vl["EBCMRegenPaddle"]["RegenPaddle"] != 0
|
|
|
|
|
|
|
|
ret.gas = pt_cp.vl["AcceleratorPedal2"]["AcceleratorPedal2"] / 254.
|
|
|
|
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"]
|
|
|
|
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["BCMGeneralPlatformStatus"]["ParkBrakeSwActive"] == 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 or
|
|
|
|
pt_cp.vl["EBCMFrictionBrakeStatus"]["FrictionBrakeUnavailable"] == 1)
|
|
|
|
|
|
|
|
ret.cruiseState.enabled = pt_cp.vl["AcceleratorPedal2"]["CruiseState"] != AccState.OFF
|
|
|
|
ret.cruiseState.standstill = pt_cp.vl["AcceleratorPedal2"]["CruiseState"] == AccState.STANDSTILL
|
|
|
|
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
|
|
|
|
# openpilot controls nonAdaptive when not pcmCruise
|
|
|
|
if self.CP.pcmCruise:
|
|
|
|
ret.cruiseState.nonAdaptive = cam_cp.vl["ASCMActiveCruiseControlStatus"]["ACCCruiseState"] not in (2, 3)
|
|
|
|
|
|
|
|
if self.CP.enableBsm:
|
|
|
|
ret.leftBlindspot = pt_cp.vl["BCMBlindSpotMonitor"]["LeftBSM"] == 1
|
|
|
|
ret.rightBlindspot = pt_cp.vl["BCMBlindSpotMonitor"]["RightBSM"] == 1
|
|
|
|
|
|
|
|
# Don't add event if transitioning from INIT, unless it's to an actual button
|
|
|
|
if self.cruise_buttons != CruiseButtons.UNPRESS or prev_cruise_buttons != CruiseButtons.INIT:
|
|
|
|
ret.buttonEvents = [
|
|
|
|
*create_button_events(self.cruise_buttons, prev_cruise_buttons, BUTTONS_DICT,
|
|
|
|
unpressed_btn=CruiseButtons.UNPRESS),
|
|
|
|
*create_button_events(self.distance_button, prev_distance_button,
|
|
|
|
{1: ButtonType.gapAdjustCruise})
|
|
|
|
]
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_cam_can_parser(CP):
|
|
|
|
messages = []
|
|
|
|
if CP.networkLocation == NetworkLocation.fwdCamera:
|
|
|
|
messages += [
|
|
|
|
("AEBCmd", 10),
|
|
|
|
("ASCMLKASteeringCmd", 10),
|
|
|
|
("ASCMActiveCruiseControlStatus", 25),
|
|
|
|
]
|
|
|
|
|
|
|
|
return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus.CAMERA)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_can_parser(CP):
|
|
|
|
messages = [
|
|
|
|
("BCMTurnSignals", 1),
|
|
|
|
("ECMPRDNL2", 10),
|
|
|
|
("PSCMStatus", 10),
|
|
|
|
("ESPStatus", 10),
|
|
|
|
("BCMDoorBeltStatus", 10),
|
|
|
|
("BCMGeneralPlatformStatus", 10),
|
|
|
|
("EBCMWheelSpdFront", 20),
|
|
|
|
("EBCMWheelSpdRear", 20),
|
|
|
|
("EBCMFrictionBrakeStatus", 20),
|
|
|
|
("AcceleratorPedal2", 33),
|
|
|
|
("ASCMSteeringButton", 33),
|
|
|
|
("ECMEngineStatus", 100),
|
|
|
|
("PSCMSteeringAngle", 100),
|
|
|
|
("ECMAcceleratorPos", 80),
|
|
|
|
]
|
|
|
|
|
|
|
|
if CP.enableBsm:
|
|
|
|
messages.append(("BCMBlindSpotMonitor", 10))
|
|
|
|
|
|
|
|
# Used to read back last counter sent to PT by camera
|
|
|
|
if CP.networkLocation == NetworkLocation.fwdCamera:
|
|
|
|
messages += [
|
|
|
|
("ASCMLKASteeringCmd", 0),
|
|
|
|
]
|
|
|
|
|
|
|
|
if CP.transmissionType == TransmissionType.direct:
|
|
|
|
messages.append(("EBCMRegenPaddle", 50))
|
|
|
|
|
|
|
|
return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus.POWERTRAIN)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_loopback_can_parser(CP):
|
|
|
|
messages = [
|
|
|
|
("ASCMLKASteeringCmd", 0),
|
|
|
|
]
|
|
|
|
|
|
|
|
return CANParser(DBC[CP.carFingerprint]["pt"], messages, CanBus.LOOPBACK)
|