Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brand Port: GWM Haval h6 2024 #1086

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6e69f52
add haval opendbc from celobusana
Jun 29, 2024
f4bec7d
add toyota BODY msgs
Jun 29, 2024
9be853c
Haval is already in 3rd generationgit add gwm_haval_h6_mk3.dbc
AlexandreSato Jul 6, 2024
dbc1254
remove the old one
AlexandreSato Jul 6, 2024
bd36c03
add brake from corolla to made tests
Jul 6, 2024
ce00a69
Merge branch 'master' into port_gwm_haval_h6
AlexandreSato Aug 17, 2024
13bafd5
merge branch "master" into port_gwm_haval_h6
AlexandreSato Aug 17, 2024
5433e24
move GWM to opendbc
AlexandreSato Aug 18, 2024
a080b0e
handle opendbc properly
AlexandreSato Aug 18, 2024
dfd52d1
typo
AlexandreSato Aug 18, 2024
15f1db5
i forgot this
AlexandreSato Aug 18, 2024
35f7a90
more fix
AlexandreSato Aug 18, 2024
8e0ac8f
more fix
AlexandreSato Aug 18, 2024
64eea00
even more fixes
AlexandreSato Aug 18, 2024
85b8f5a
switch from corolla to haval
AlexandreSato Aug 18, 2024
e45d799
i don't know why this happened
AlexandreSato Aug 18, 2024
5b31dda
steer direction and IMU
AlexandreSato Aug 26, 2024
c1b5938
try get the direction of the steer angle
AlexandreSato Aug 26, 2024
07f3bdc
Merge branch 'commaai:master' into port_gwm_haval_h6
AlexandreSato Aug 26, 2024
25311c1
Merge branch 'commaai:master' into port_gwm_haval_h6
AlexandreSato Sep 2, 2024
ee6265e
update routes.py
AlexandreSato Sep 2, 2024
e5ec75b
work
AlexandreSato Sep 2, 2024
5e3640e
add door open
AlexandreSato Sep 2, 2024
0745940
detect seat belt unlatched
AlexandreSato Sep 2, 2024
f23da35
add gas
AlexandreSato Sep 2, 2024
2bfae5b
add gears
AlexandreSato Sep 2, 2024
f01c22a
try this
AlexandreSato Sep 2, 2024
2544480
add steer torque and steerPressed
AlexandreSato Sep 2, 2024
2b5ed66
adjust signals
AlexandreSato Sep 2, 2024
4a31fd3
adjust steerPressed threshold
AlexandreSato Sep 2, 2024
aa4014a
add buttons
AlexandreSato Sep 2, 2024
778cb90
dirt hack just to test activation by buttons
Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opendbc/car/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from opendbc.car.chrysler.values import CAR as CHRYSLER
from opendbc.car.ford.values import CAR as FORD
from opendbc.car.gm.values import CAR as GM
from opendbc.car.gwm.values import CAR as GWM
from opendbc.car.honda.values import CAR as HONDA
from opendbc.car.hyundai.values import CAR as HYUNDAI
from opendbc.car.mazda.values import CAR as MAZDA
Expand Down Expand Up @@ -340,5 +341,6 @@ def all_legacy_fingerprint_cars():
"SKODA_SCALA_MK1": VW.SKODA_KAMIQ_MK1,
"SKODA SUPERB 3RD GEN": VW.SKODA_SUPERB_MK3,

"GWM HAVAL H6 PHEV 3RD GEN": GWM.GWM_HAVAL_H6_PHEV_3RD_GEN,
"mock": MOCK.MOCK,
}
Empty file added opendbc/car/gwm/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions opendbc/car/gwm/carcontroller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.gwm.values import CarControllerParams

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP):
self.CP = CP
self.CCP = CarControllerParams(self.CP)

self.frame = 0

def update(self, CC, CS, now_nanos):
actuators = CC.actuators
new_actuators = actuators
can_sends = []

# **** Steering Controls ******************************************* #
# TODO

# **** Acceleration Controls *************************************** #
# TODO

# **** HUD Controls ************************************************ #
# TODO

# **** Stock ACC Button Controls *********************************** #
# TODO

self.frame += 1
return new_actuators, can_sends
108 changes: 108 additions & 0 deletions opendbc/car/gwm/carstate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import numpy as np
from opendbc.car import structs
from opendbc.car.interfaces import CarStateBase
from opendbc.can.parser import CANParser
from opendbc.car.gwm.values import DBC, CANBUS, CarControllerParams


GearShifter = structs.CarState.GearShifter


class CarState(CarStateBase):
def __init__(self, CP):
super().__init__(CP)
self.frame = 0
self.CCP = CarControllerParams(CP)
self.button_states = {button.event_type: False for button in self.CCP.BUTTONS}

def create_button_events(self, cp, buttons):
button_events = []
for button in buttons:
state = cp.vl[button.can_addr][button.can_msg] in button.values
if self.button_states[button.event_type] != state:
event = structs.CarState.ButtonEvent()
event.type = button.event_type
event.pressed = state
button_events.append(event)
self.button_states[button.event_type] = state
return button_events

def update(self, cp, cam_cp, _, __, loopback_cp) -> structs.CarState:
ret = structs.CarState()

ret.wheelSpeeds = self.get_wheel_speeds(
cp.vl["WHEEL_SPEEDS"]["FRONT_LEFT_WHEEL_SPEED"],
cp.vl["WHEEL_SPEEDS"]["FRONT_RIGHT_WHEEL_SPEED"],
cp.vl["WHEEL_SPEEDS"]["REAR_LEFT_WHEEL_SPEED"],
cp.vl["WHEEL_SPEEDS"]["REAR_RIGHT_WHEEL_SPEED"],
)
ret.vEgoRaw = float(np.mean([ret.wheelSpeeds.fl, ret.wheelSpeeds.fr, ret.wheelSpeeds.rl, ret.wheelSpeeds.rr]))
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
ret.standstill = abs(ret.vEgoRaw) < 1e-3

ret.steeringAngleDeg = cp.vl["STEER_AND_AP_STALK"]["STEERING_ANGLE"] * (-1 if cp.vl["STEER_AND_AP_STALK"]["STEERING_DIRECTION"] else 1)
ret.steeringRateDeg = 0 # TODO
ret.steeringTorque = cp.vl["STEER_AND_AP_STALK"]["STEERING_TORQUE"] * (-1 if cp.vl["STEER_AND_AP_STALK"]["STEERING_DIRECTION"] else 1) * 73
ret.steeringPressed = abs(ret.steeringTorque) > 10
# ret.yawRate = NOT ABSOLUTE NECESSARY
# ret.steerFaultTemporary, ret.steerFaultPermanent = CRITICAL SAFETY TODO, CRITICAL SAFETY TODO

ret.gas = cp.vl["CAR_OVERALL_SIGNALS2"]["GAS_POSITION"]
ret.gasPressed = ret.gas > 0
ret.brake = cp.vl["BRAKE"]["BRAKE_PRESSURE"]
ret.brakePressed = cp.vl["BRAKE"]["BRAKE_PRESSURE"] > 0
ret.parkingBrake = cp.vl["CAR_OVERALL_SIGNALS"]["DRIVE_MODE"] == 0

# begin toyota brakePressed TODO clean-after-port
# ret.brakePressed = cp.vl["COROLLA_BRAKE_MODULE"]["BRAKE_PRESSED"] != 0
# end TODO clean-after-port

ret.gearShifter = GearShifter.drive if int(cp.vl["CAR_OVERALL_SIGNALS"]["DRIVE_MODE"]) == 1 else \
GearShifter.neutral if int(cp.vl["CAR_OVERALL_SIGNALS"]["DRIVE_MODE"]) == 2 else \
GearShifter.reverse if int(cp.vl["CAR_OVERALL_SIGNALS"]["DRIVE_MODE"]) == 3 else \
GearShifter.park

ret.doorOpen = any([cp.vl["DOOR_DRIVER"]["DOOR_REAR_RIGHT_OPEN"],
cp.vl["DOOR_DRIVER"]["DOOR_FRONT_RIGHT_OPEN"],
cp.vl["DOOR_DRIVER"]["DOOR_REAR_LEFT_OPEN"],
cp.vl["DOOR_DRIVER"]["DOOR_DRIVER_OPEN"]])
ret.seatbeltUnlatched = cp.vl["SEATBELT"]["SEAT_BELT_DRIVER_STATE"] != 1

ret.cruiseState.available = True #CRITICAL SAFETY TODO
# ret.cruiseState.enabled = TODO
# ret.cruiseState.speed = TODO

ret.leftBlinker, ret.rightBlinker = self.update_blinker_from_lamp(50, cp.vl["LIGHTS"]["LEFT_TURN_SIGNAL"],
cp.vl["LIGHTS"]["RIGHT_TURN_SIGNAL"])
ret.buttonEvents = self.create_button_events(cp, self.CCP.BUTTONS)
# ret.espDisabled = TODO

self.frame += 1
return ret


@staticmethod
def get_can_parser(CP):
messages = [
# COROLLA:
# ("COROLLA_BRAKE_MODULE", 40),

# HAVAL:
("BRAKE", 50),
("CAR_OVERALL_SIGNALS", 50),
("CAR_OVERALL_SIGNALS2", 100),
("DOOR_DRIVER", 20),
("LIGHTS", 20),
("SEATBELT", 2),
("STEER_AND_AP_STALK", 100),
("WHEEL_SPEEDS", 50),
]

return CANParser(DBC[CP.carFingerprint]["pt"], messages, CANBUS.pt)


@staticmethod
def get_cam_can_parser(CP):
messages = []

return CANParser(DBC[CP.carFingerprint]["pt"], messages, CANBUS.cam)
12 changes: 12 additions & 0 deletions opendbc/car/gwm/fingerprints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from opendbc.car.structs import CarParams
from opendbc.car.gwm.values import CAR

Ecu = CarParams.Ecu

FW_VERSIONS = {
CAR.GWM_HAVAL_H6_PHEV_3RD_GEN: {
(Ecu.engine, 0x7e0, None): [
b'PLACEHOLDER',
],
},
}
1 change: 1 addition & 0 deletions opendbc/car/gwm/gwmcan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pass
26 changes: 26 additions & 0 deletions opendbc/car/gwm/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from opendbc.car import get_safety_config, structs
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.gwm.values import CAR

class CarInterface(CarInterfaceBase):
@staticmethod
def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams:
ret.carName = "gwm"
ret.radarUnavailable = True

# Set global parameters

ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.allOutput,1)]

# Global lateral tuning defaults, can be overriden per-vehicle

ret.steerLimitTimer = 0.4
ret.steerActuatorDelay = 0.2
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)

# Global longitudinal tuning defaults, can be overridden per-vehicle

# ret.pcmCruise = not ret.openpilotLongitudinalControl
ret.pcmCruise = False # TODO clean-after-port MOCK engagement

return ret
4 changes: 4 additions & 0 deletions opendbc/car/gwm/radar_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from opendbc.car.interfaces import RadarInterfaceBase

class RadarInterface(RadarInterfaceBase):
pass
67 changes: 67 additions & 0 deletions opendbc/car/gwm/values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from collections import namedtuple
from dataclasses import dataclass, field

from opendbc.car import dbc_dict, CarSpecs, DbcDict, PlatformConfig, Platforms, structs
from opendbc.car.docs_definitions import CarHarness, CarDocs, CarParts
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries

Button = namedtuple('Button', ['event_type', 'can_addr', 'can_msg', 'values'])

class CarControllerParams:
def __init__(self, CP):
self.BUTTONS = [
Button(structs.CarState.ButtonEvent.Type.setCruise, "STEER_AND_AP_STALK", "AP_ENABLE_COMMAND", [1]),
# Button(structs.CarState.ButtonEvent.Type.resumeCruise, "STEER_AND_AP_STALK", "AP_ENABLE_COMMAND", [1]),
Button(structs.CarState.ButtonEvent.Type.accelCruise, "STEER_AND_AP_STALK", "AP_INCREASE_SPEED_COMMAND", [1]),
Button(structs.CarState.ButtonEvent.Type.decelCruise, "STEER_AND_AP_STALK", "AP_DECREASE_SPEED_COMMAND", [1]),
Button(structs.CarState.ButtonEvent.Type.cancel, "STEER_AND_AP_STALK", "AP_CANCEL_COMMAND", [1]),
Button(structs.CarState.ButtonEvent.Type.gapAdjustCruise, "STEER_AND_AP_STALK", "AP_INCREASE_DISTANCE_COMMAND", [1]),
]


class CANBUS:
pt = 0
cam = 2


@dataclass
class GwmPlatformConfig(PlatformConfig):
dbc_dict: DbcDict = field(default_factory=lambda: dbc_dict('gwm_haval_h6_mk3_generated', None))


@dataclass(frozen=True, kw_only=True)
class GwmCarSpecs(CarSpecs):
centerToFrontRatio: float = 0.45
steerRatio: float = 15.6


@dataclass
class GwmCarDocs(CarDocs):
package: str = "Adaptive Cruise Control (ACC) & Lane Assist"
car_parts: CarParts = field(default_factory=CarParts.common([CarHarness.custom]))


class CAR(Platforms):
config: GwmPlatformConfig

GWM_HAVAL_H6_PHEV_3RD_GEN = GwmPlatformConfig(
[
GwmCarDocs("GWM Haval H6 hybrid plug-in 2020-24"),
],
GwmCarSpecs(mass=2050, wheelbase=2.74),
)


FW_QUERY_CONFIG = FwQueryConfig(
requests=[
# TODO:
Request(
[StdQueries.MANUFACTURER_SOFTWARE_VERSION_REQUEST],
[StdQueries.MANUFACTURER_SOFTWARE_VERSION_RESPONSE],
bus=0,
),
],
)


DBC = CAR.create_dbc_map()
3 changes: 3 additions & 0 deletions opendbc/car/tests/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import NamedTuple

from opendbc.car.chrysler.values import CAR as CHRYSLER
from opendbc.car.gwm.values import CAR as GWM
from opendbc.car.gm.values import CAR as GM
from opendbc.car.ford.values import CAR as FORD
from opendbc.car.honda.values import CAR as HONDA
Expand Down Expand Up @@ -58,6 +59,8 @@ class CarTestRoute(NamedTuple):
CarTestRoute("37998aa0fade36ab/00000000--48f927c4f5", FORD.FORD_RANGER_MK2),
#TestRoute("f1b4c567731f4a1b|2018-04-30--10-15-35", FORD.FUSION),

CarTestRoute("5046371b6e9f0f3e/0000006f--fed43edbf9", GWM.GWM_HAVAL_H6_PHEV_3RD_GEN),

CarTestRoute("7cc2a8365b4dd8a9|2018-12-02--12-10-44", GM.GMC_ACADIA),
CarTestRoute("aa20e335f61ba898|2019-02-05--16-59-04", GM.BUICK_REGAL),
CarTestRoute("75a6bcb9b8b40373|2023-03-11--22-47-33", GM.BUICK_LACROSSE),
Expand Down
1 change: 1 addition & 0 deletions opendbc/car/torque_data/override.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
"HYUNDAI_CUSTIN_1ST_GEN" = [2.5, 2.5, 0.1]
"LEXUS_GS_F" = [2.5, 2.5, 0.08]
"HYUNDAI_STARIA_4TH_GEN" = [1.8, 2.0, 0.15]
"GWM_HAVAL_H6_PHEV_3RD_GEN" = [1.5, 1.5, 0.1]

# Dashcam or fallback configured as ideal car
"MOCK" = [10.0, 10, 0.0]
Expand Down
3 changes: 2 additions & 1 deletion opendbc/car/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from opendbc.car.chrysler.values import CAR as CHRYSLER
from opendbc.car.ford.values import CAR as FORD
from opendbc.car.gm.values import CAR as GM
from opendbc.car.gwm.values import CAR as GWM
from opendbc.car.honda.values import CAR as HONDA
from opendbc.car.hyundai.values import CAR as HYUNDAI
from opendbc.car.mazda.values import CAR as MAZDA
Expand All @@ -12,7 +13,7 @@
from opendbc.car.toyota.values import CAR as TOYOTA
from opendbc.car.volkswagen.values import CAR as VOLKSWAGEN

Platform = BODY | CHRYSLER | FORD | GM | HONDA | HYUNDAI | MAZDA | MOCK | NISSAN | SUBARU | TOYOTA | VOLKSWAGEN
Platform = BODY | CHRYSLER | FORD | GM | GWM | HONDA | HYUNDAI | MAZDA | MOCK | NISSAN | SUBARU | TOYOTA | VOLKSWAGEN
BRANDS = get_args(Platform)

PLATFORMS: dict[str, Platform] = {str(platform): platform for brand in BRANDS for platform in brand}
Loading
Loading