Skip to content

Commit 9ab660a

Browse files
CAN parser dict
1 parent bbbc7f9 commit 9ab660a

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

opendbc/car/car.capnp

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ struct CarParams {
622622
chryslerCusw @30;
623623
psa @31;
624624
fcaGiorgio @32;
625+
rivian @33;
625626
}
626627

627628
enum SteerControlType {

opendbc/car/rivian/carcontroller.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import copy
22
from opendbc.can.packer import CANPacker
3-
from opendbc.car import apply_driver_steer_torque_limits
3+
from opendbc.car import Bus, apply_driver_steer_torque_limits
44
from opendbc.car.interfaces import CarControllerBase
55
from opendbc.car.rivian.riviancan import create_lka_steering, create_acm_status, create_longitudinal
66
from opendbc.car.rivian.values import CarControllerParams
77

88
class CarController(CarControllerBase):
9-
def __init__(self, dbc_name, CP):
9+
def __init__(self, dbc_names, CP):
10+
super().__init__(dbc_names, CP)
1011
self.CP = CP
11-
self.frame = 0
1212
self.apply_steer_last = 0
13-
self.packer = CANPacker(dbc_name)
13+
self.packer = CANPacker(dbc_names[Bus.pt])
1414

1515
def update(self, CC, CS, now_nanos):
1616
actuators = CC.actuators

opendbc/car/rivian/carstate.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
from opendbc.can.parser import CANParser
3-
from opendbc.car import structs
3+
from opendbc.car import Bus, structs
44
from opendbc.car.interfaces import CarStateBase
55
from opendbc.car.rivian.values import DBC, GEAR_MAP
66
from opendbc.car.common.conversions import Conversions as CV
@@ -13,7 +13,10 @@ def __init__(self, CP):
1313
# Needed by carcontroller
1414
self.acm_lka_hba_cmd = None
1515

16-
def update(self, cp, cp_cam, cp_adas, *_) -> structs.CarState:
16+
def update(self, can_parsers) -> structs.CarState:
17+
cp = can_parsers[Bus.pt]
18+
cp_cam = can_parsers[Bus.pt]
19+
cp_adas = can_parsers[Bus.pt]
1720
ret = structs.CarState()
1821

1922
# Vehicle speed
@@ -72,8 +75,8 @@ def update(self, cp, cp_cam, cp_adas, *_) -> structs.CarState:
7275
return ret
7376

7477
@staticmethod
75-
def get_can_parser(CP):
76-
messages = [
78+
def get_can_parsers(CP):
79+
pt_messages = [
7780
# sig_address, frequency
7881
("ESPiB1", 50),
7982
("VDM_PropStatus", 50),
@@ -84,24 +87,20 @@ def get_can_parser(CP):
8487
("VDM_AdasSts", 100)
8588
]
8689

87-
return CANParser(DBC[CP.carFingerprint]['pt'], messages, 0)
88-
89-
@staticmethod
90-
def get_cam_can_parser(CP):
91-
messages = [
90+
cam_messages = [
9291
("ACM_longitudinalRequest", 100),
9392
("ACM_AebRequest", 100),
9493
("ACM_Status", 100),
9594
("ACM_lkaHbaCmd", 100)
9695
]
9796

98-
return CANParser(DBC[CP.carFingerprint]['pt'], messages, 2)
99-
100-
@staticmethod
101-
def get_adas_can_parser(CP):
102-
messages = [
97+
adas_messages = [
10398
("IndicatorLights", 10),
10499
# ("ACM_tsrCmd", 10),
105100
]
106101

107-
return CANParser(DBC[CP.carFingerprint]['pt'], messages, 1)
102+
return {
103+
Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], pt_messages, 0),
104+
Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], cam_messages, 2),
105+
Bus.adas: CANParser(DBC[CP.carFingerprint][Bus.pt], adas_messages, 1)
106+
}

opendbc/car/rivian/interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
from panda import Panda
32
from opendbc.car import get_safety_config, structs
43
from opendbc.car.interfaces import CarInterfaceBase
54
from opendbc.car.rivian.values import CAR

opendbc/car/rivian/values.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import IntFlag
22
from opendbc.car.structs import CarParams
3-
from opendbc.car import structs
4-
from opendbc.car import CarSpecs, PlatformConfig, Platforms, dbc_dict
3+
from opendbc.car import Bus, structs
4+
from opendbc.car import CarSpecs, PlatformConfig, Platforms
55
from opendbc.car.docs_definitions import CarDocs
66
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries
77

@@ -12,7 +12,7 @@ class CAR(Platforms):
1212
RIVIAN_R1S = PlatformConfig(
1313
[CarDocs("Rivian R1S", "All")],
1414
CarSpecs(mass=3206., wheelbase=3.08, steerRatio=15.2),
15-
dbc_dict('rivian_can', None)
15+
{Bus.pt: 'rivian_can'}
1616
)
1717

1818

@@ -56,10 +56,6 @@ class CarControllerParams:
5656
ACCEL_MIN = -3.48 # m/s^2
5757
ACCEL_MAX = 2.0 # m/s^2
5858

59-
def __init__(self, CP):
60-
pass
61-
62-
6359
class RivianFlags(IntFlag):
6460
FLAG_RIVIAN_LONG_CONTROL = 1
6561

0 commit comments

Comments
 (0)