Mazda: move to platform config (#31647)

* mazda platform config

* update ref
old-commit-hash: e122f1d749
chrysler-long2
Justin Newberry 1 year ago committed by GitHub
parent 1df44de8db
commit 1567508bd4
  1. 6
      selfdrive/car/mazda/carcontroller.py
  2. 6
      selfdrive/car/mazda/carstate.py
  3. 17
      selfdrive/car/mazda/interface.py
  4. 10
      selfdrive/car/mazda/mazdacan.py
  5. 77
      selfdrive/car/mazda/values.py
  6. 2
      selfdrive/test/process_replay/ref_commit

@ -36,13 +36,13 @@ class CarController(CarControllerBase):
if self.frame % 10 == 0 and not (CS.out.brakePressed and self.brake_counter < 7): if self.frame % 10 == 0 and not (CS.out.brakePressed and self.brake_counter < 7):
# Cancel Stock ACC if it's enabled while OP is disengaged # Cancel Stock ACC if it's enabled while OP is disengaged
# Send at a rate of 10hz until we sync with stock ACC state # Send at a rate of 10hz until we sync with stock ACC state
can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP.carFingerprint, CS.crz_btns_counter, Buttons.CANCEL)) can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP, CS.crz_btns_counter, Buttons.CANCEL))
else: else:
self.brake_counter = 0 self.brake_counter = 0
if CC.cruiseControl.resume and self.frame % 5 == 0: if CC.cruiseControl.resume and self.frame % 5 == 0:
# Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds
# Send Resume button when planner wants car to move # Send Resume button when planner wants car to move
can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP.carFingerprint, CS.crz_btns_counter, Buttons.RESUME)) can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP, CS.crz_btns_counter, Buttons.RESUME))
self.apply_steer_last = apply_steer self.apply_steer_last = apply_steer
@ -55,7 +55,7 @@ class CarController(CarControllerBase):
can_sends.append(mazdacan.create_alert_command(self.packer, CS.cam_laneinfo, ldw, steer_required)) can_sends.append(mazdacan.create_alert_command(self.packer, CS.cam_laneinfo, ldw, steer_required))
# send steering command # send steering command
can_sends.append(mazdacan.create_steering_control(self.packer, self.CP.carFingerprint, can_sends.append(mazdacan.create_steering_control(self.packer, self.CP,
self.frame, apply_steer, CS.cam_lkas)) self.frame, apply_steer, CS.cam_lkas))
new_actuators = CC.actuators.copy() new_actuators = CC.actuators.copy()

@ -3,7 +3,7 @@ from openpilot.common.conversions import Conversions as CV
from opendbc.can.can_define import CANDefine from opendbc.can.can_define import CANDefine
from opendbc.can.parser import CANParser from opendbc.can.parser import CANParser
from openpilot.selfdrive.car.interfaces import CarStateBase from openpilot.selfdrive.car.interfaces import CarStateBase
from openpilot.selfdrive.car.mazda.values import DBC, LKAS_LIMITS, GEN1 from openpilot.selfdrive.car.mazda.values import DBC, LKAS_LIMITS, MazdaFlags
class CarState(CarStateBase): class CarState(CarStateBase):
def __init__(self, CP): def __init__(self, CP):
@ -116,7 +116,7 @@ class CarState(CarStateBase):
("WHEEL_SPEEDS", 100), ("WHEEL_SPEEDS", 100),
] ]
if CP.carFingerprint in GEN1: if CP.flags & MazdaFlags.GEN1:
messages += [ messages += [
("ENGINE_DATA", 100), ("ENGINE_DATA", 100),
("CRZ_CTRL", 50), ("CRZ_CTRL", 50),
@ -136,7 +136,7 @@ class CarState(CarStateBase):
def get_cam_can_parser(CP): def get_cam_can_parser(CP):
messages = [] messages = []
if CP.carFingerprint in GEN1: if CP.flags & MazdaFlags.GEN1:
messages += [ messages += [
# sig_address, frequency # sig_address, frequency
("CAM_LANEINFO", 2), ("CAM_LANEINFO", 2),

@ -24,23 +24,6 @@ class CarInterface(CarInterfaceBase):
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning) CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
if candidate in (CAR.CX5, CAR.CX5_2022):
ret.mass = 3655 * CV.LB_TO_KG
ret.wheelbase = 2.7
ret.steerRatio = 15.5
elif candidate in (CAR.CX9, CAR.CX9_2021):
ret.mass = 4217 * CV.LB_TO_KG
ret.wheelbase = 3.1
ret.steerRatio = 17.6
elif candidate == CAR.MAZDA3:
ret.mass = 2875 * CV.LB_TO_KG
ret.wheelbase = 2.7
ret.steerRatio = 14.0
elif candidate == CAR.MAZDA6:
ret.mass = 3443 * CV.LB_TO_KG
ret.wheelbase = 2.83
ret.steerRatio = 15.5
if candidate not in (CAR.CX5_2022, ): if candidate not in (CAR.CX5_2022, ):
ret.minSteerSpeed = LKAS_LIMITS.DISABLE_SPEED * CV.KPH_TO_MS ret.minSteerSpeed = LKAS_LIMITS.DISABLE_SPEED * CV.KPH_TO_MS

@ -1,7 +1,7 @@
from openpilot.selfdrive.car.mazda.values import GEN1, Buttons from openpilot.selfdrive.car.mazda.values import Buttons, MazdaFlags
def create_steering_control(packer, car_fingerprint, frame, apply_steer, lkas): def create_steering_control(packer, CP, frame, apply_steer, lkas):
tmp = apply_steer + 2048 tmp = apply_steer + 2048
@ -45,7 +45,7 @@ def create_steering_control(packer, car_fingerprint, frame, apply_steer, lkas):
csum = csum % 256 csum = csum % 256
values = {} values = {}
if car_fingerprint in GEN1: if CP.flags & MazdaFlags.GEN1:
values = { values = {
"LKAS_REQUEST": apply_steer, "LKAS_REQUEST": apply_steer,
"CTR": ctr, "CTR": ctr,
@ -88,12 +88,12 @@ def create_alert_command(packer, cam_msg: dict, ldw: bool, steer_required: bool)
return packer.make_can_msg("CAM_LANEINFO", 0, values) return packer.make_can_msg("CAM_LANEINFO", 0, values)
def create_button_cmd(packer, car_fingerprint, counter, button): def create_button_cmd(packer, CP, counter, button):
can = int(button == Buttons.CANCEL) can = int(button == Buttons.CANCEL)
res = int(button == Buttons.RESUME) res = int(button == Buttons.RESUME)
if car_fingerprint in GEN1: if CP.flags & MazdaFlags.GEN1:
values = { values = {
"CAN_OFF": can, "CAN_OFF": can,
"CAN_OFF_INV": (can + 1) % 2, "CAN_OFF_INV": (can + 1) % 2,

@ -1,8 +1,9 @@
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import StrEnum from enum import IntFlag
from cereal import car from cereal import car
from openpilot.selfdrive.car import dbc_dict from openpilot.common.conversions import Conversions as CV
from openpilot.selfdrive.car import CarSpecs, DbcDict, PlatformConfig, Platforms, dbc_dict
from openpilot.selfdrive.car.docs_definitions import CarHarness, CarInfo, CarParts from openpilot.selfdrive.car.docs_definitions import CarHarness, CarInfo, CarParts
from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries
@ -25,29 +26,54 @@ class CarControllerParams:
pass pass
class CAR(StrEnum):
CX5 = "MAZDA CX-5"
CX9 = "MAZDA CX-9"
MAZDA3 = "MAZDA 3"
MAZDA6 = "MAZDA 6"
CX9_2021 = "MAZDA CX-9 2021"
CX5_2022 = "MAZDA CX-5 2022"
@dataclass @dataclass
class MazdaCarInfo(CarInfo): class MazdaCarInfo(CarInfo):
package: str = "All" package: str = "All"
car_parts: CarParts = field(default_factory=CarParts.common([CarHarness.mazda])) car_parts: CarParts = field(default_factory=CarParts.common([CarHarness.mazda]))
CAR_INFO: dict[str, MazdaCarInfo | list[MazdaCarInfo]] = { class MazdaFlags(IntFlag):
CAR.CX5: MazdaCarInfo("Mazda CX-5 2017-21"), # Gen 1 hardware: same CAN messages and same camera
CAR.CX9: MazdaCarInfo("Mazda CX-9 2016-20"), GEN1 = 1
CAR.MAZDA3: MazdaCarInfo("Mazda 3 2017-18"),
CAR.MAZDA6: MazdaCarInfo("Mazda 6 2017-20"),
CAR.CX9_2021: MazdaCarInfo("Mazda CX-9 2021-23", video_link="https://youtu.be/dA3duO4a0O4"), @dataclass
CAR.CX5_2022: MazdaCarInfo("Mazda CX-5 2022-24"), class MazdaPlatformConfig(PlatformConfig):
} dbc_dict: DbcDict = field(default_factory=lambda: dbc_dict('mazda_2017', None))
flags: int = field(default=MazdaFlags.GEN1)
class CAR(Platforms):
CX5 = MazdaPlatformConfig(
"MAZDA CX-5",
MazdaCarInfo("Mazda CX-5 2017-21"),
specs=CarSpecs(mass=3655 * CV.LB_TO_KG, wheelbase=2.7, steerRatio=15.5)
)
CX9 = MazdaPlatformConfig(
"MAZDA CX-9",
MazdaCarInfo("Mazda CX-9 2016-20"),
specs=CarSpecs(mass=4217 * CV.LB_TO_KG, wheelbase=3.1, steerRatio=17.6)
)
MAZDA3 = MazdaPlatformConfig(
"MAZDA 3",
MazdaCarInfo("Mazda 3 2017-18"),
specs=CarSpecs(mass=2875 * CV.LB_TO_KG, wheelbase=2.7, steerRatio=14.0)
)
MAZDA6 = MazdaPlatformConfig(
"MAZDA 6",
MazdaCarInfo("Mazda 6 2017-20"),
specs=CarSpecs(mass=3443 * CV.LB_TO_KG, wheelbase=2.83, steerRatio=15.5)
)
CX9_2021 = MazdaPlatformConfig(
"MAZDA CX-9 2021",
MazdaCarInfo("Mazda CX-9 2021-23", video_link="https://youtu.be/dA3duO4a0O4"),
specs=CX9.specs
)
CX5_2022 = MazdaPlatformConfig(
"MAZDA CX-5 2022",
MazdaCarInfo("Mazda CX-5 2022-24"),
specs=CX5.specs,
)
class LKAS_LIMITS: class LKAS_LIMITS:
@ -76,14 +102,5 @@ FW_QUERY_CONFIG = FwQueryConfig(
) )
DBC = { CAR_INFO = CAR.create_carinfo_map()
CAR.CX5: dbc_dict('mazda_2017', None), DBC = CAR.create_dbc_map()
CAR.CX9: dbc_dict('mazda_2017', None),
CAR.MAZDA3: dbc_dict('mazda_2017', None),
CAR.MAZDA6: dbc_dict('mazda_2017', None),
CAR.CX9_2021: dbc_dict('mazda_2017', None),
CAR.CX5_2022: dbc_dict('mazda_2017', None),
}
# Gen 1 hardware: same CAN messages and same camera
GEN1 = {CAR.CX5, CAR.CX9, CAR.CX9_2021, CAR.MAZDA3, CAR.MAZDA6, CAR.CX5_2022}

@ -1 +1 @@
b9d29ac9402cfc04bf3e48867415efa70c144029 658699a6ba183bd97f161baa29cd4764b6bd2c30

Loading…
Cancel
Save