version: sunnypilot v2026.002.000 (staging) date: 2026-07-21T07:44:02 master commit: 2c334ede443d7391d27575af8c854a095ba702a8
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
from enum import StrEnum
|
|
|
|
from opendbc.car import Bus, structs
|
|
from opendbc.can.parser import CANParser
|
|
from opendbc.sunnypilot.car.honda.values_ext import HondaFlagsSP
|
|
|
|
|
|
class CarStateExt:
|
|
def __init__(self, CP, CP_SP):
|
|
self.CP = CP
|
|
self.CP_SP = CP_SP
|
|
|
|
def update(self, ret: structs.CarState, can_parsers: dict[StrEnum, CANParser]) -> None:
|
|
cp = can_parsers[Bus.pt]
|
|
cp_cam = can_parsers[Bus.cam]
|
|
|
|
if self.CP_SP.flags & HondaFlagsSP.NIDEC_HYBRID:
|
|
ret.accFaulted = bool(cp.vl["HYBRID_BRAKE_ERROR"]["BRAKE_ERROR_1"] or cp.vl["HYBRID_BRAKE_ERROR"]["BRAKE_ERROR_2"])
|
|
ret.stockAeb = bool(cp_cam.vl["BRAKE_COMMAND"]["AEB_REQ_1"] and cp_cam.vl["BRAKE_COMMAND"]["COMPUTER_BRAKE_HYBRID"] > 1e-5)
|
|
|
|
if self.CP_SP.flags & HondaFlagsSP.HYBRID_ALT_BRAKEHOLD:
|
|
ret.brakeHoldActive = cp.vl["BRAKE_HOLD_HYBRID_ALT"]["BRAKE_HOLD_ACTIVE"] == 1
|
|
|
|
if self.CP_SP.enableGasInterceptor:
|
|
# Same threshold as panda, equivalent to 1e-5 with previous DBC scaling
|
|
gas = (cp.vl["GAS_SENSOR"]["INTERCEPTOR_GAS"] + cp.vl["GAS_SENSOR"]["INTERCEPTOR_GAS2"]) // 2
|
|
ret.gasPressed = gas > 492
|