Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 0bec922

Browse files
authored
Merge pull request #11 from eFiniLan/2023-10-17
vehicle support as of 2023.10.17
2 parents e03b188 + a43e412 commit 0bec922

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1253
-789
lines changed

common/kalman/SConscript

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Import('envCython')
22

3-
envCython.Program('simple_kalman_impl.so', 'simple_kalman_impl.pyx')
3+
simple_kalman_python = envCython.Program('simple_kalman_impl.so', 'simple_kalman_impl.pyx')
4+
5+
Export('simple_kalman_python')

common/kalman/simple_kalman.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
# pylint: skip-file
21
from openpilot.common.kalman.simple_kalman_impl import KF1D as KF1D
32
assert KF1D
3+
import numpy as np
4+
5+
def get_kalman_gain(dt, A, C, Q, R, iterations=100):
6+
P = np.zeros_like(Q)
7+
for _ in range(iterations):
8+
P = A.dot(P).dot(A.T) + dt * Q
9+
S = C.dot(P).dot(C.T) + R
10+
K = P.dot(C.T).dot(np.linalg.inv(S))
11+
P = (np.eye(len(P)) - K.dot(C)).dot(P)
12+
return K

launch_chffrplus.sh

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ function two_init {
165165
echo "Installing spidev.cpython-38.so..."
166166
cp -f "$LIB_PATH/spidev.cpython-38.so" "$PY_LIB_DEST/"
167167
fi
168+
# StrEnum in values.py
169+
MODULE="strenum"
170+
if [ ! -d "$PY_LIB_DEST/$MODULE" ]; then
171+
echo "Installing $MODULE..."
172+
tar -zxvf "$LIB_PATH/$MODULE.tar.gz" -C "$PY_LIB_DEST/"
173+
fi
168174
mount -o remount,r /system
169175

170176
# Check for NEOS update

selfdrive/car/CARS_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Supported Cars
1212

13-
A supported vehicle is one that just works when you install a comma three. All supported cars provide a better experience than any stock system. Supported vehicles reference the US market unless otherwise specified.
13+
A supported vehicle is one that just works when you install a comma device. All supported cars provide a better experience than any stock system. Supported vehicles reference the US market unless otherwise specified.
1414

1515
# {{all_car_info | length}} Supported Cars
1616

selfdrive/car/__init__.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# functions common among cars
22
from collections import namedtuple
3-
from typing import Dict, Optional
3+
from typing import Dict, List, Optional
44

55
import capnp
66

@@ -24,20 +24,23 @@ def apply_hysteresis(val: float, val_steady: float, hyst_gap: float) -> float:
2424
return val_steady
2525

2626

27-
def create_button_event(cur_but: int, prev_but: int, buttons_dict: Dict[int, capnp.lib.capnp._EnumModule],
28-
unpressed: int = 0) -> capnp.lib.capnp._DynamicStructBuilder:
29-
if cur_but != unpressed:
30-
be = car.CarState.ButtonEvent(pressed=True)
31-
but = cur_but
32-
else:
33-
be = car.CarState.ButtonEvent(pressed=False)
34-
but = prev_but
35-
be.type = buttons_dict.get(but, ButtonType.unknown)
36-
return be
27+
def create_button_events(cur_btn: int, prev_btn: int, buttons_dict: Dict[int, capnp.lib.capnp._EnumModule],
28+
unpressed_btn: int = 0) -> List[capnp.lib.capnp._DynamicStructBuilder]:
29+
events: List[capnp.lib.capnp._DynamicStructBuilder] = []
30+
31+
if cur_btn == prev_btn:
32+
return events
33+
34+
# Add events for button presses, multiple when a button switches without going to unpressed
35+
for pressed, btn in ((False, prev_btn), (True, cur_btn)):
36+
if btn != unpressed_btn:
37+
events.append(car.CarState.ButtonEvent(pressed=pressed,
38+
type=buttons_dict.get(btn, ButtonType.unknown)))
39+
return events
3740

3841

3942
def gen_empty_fingerprint():
40-
return {i: {} for i in range(0, 8)}
43+
return {i: {} for i in range(8)}
4144

4245

4346
# these params were derived for the Civic and used to calculate params for other cars
@@ -232,4 +235,4 @@ def update(self, current_value, current_counter):
232235
self.previous_counter = current_counter
233236
self.previous_value = current_value
234237

235-
return self.rate
238+
return self.rate

selfdrive/car/body/interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import math
32
from cereal import car
43
from openpilot.common.realtime import DT_CTRL

selfdrive/car/body/radar_interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
from openpilot.selfdrive.car.interfaces import RadarInterfaceBase
32

43
class RadarInterface(RadarInterfaceBase):

selfdrive/car/body/values.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from strenum import StrEnum
12
from typing import Dict
23

34
from cereal import car
@@ -21,7 +22,7 @@ def __init__(self, CP):
2122
pass
2223

2324

24-
class CAR:
25+
class CAR(StrEnum):
2526
BODY = "COMMA BODY"
2627

2728

selfdrive/car/car_helpers.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
from typing import Callable, Dict, List, Optional, Tuple
34

45
from cereal import car
@@ -65,9 +66,8 @@ def load_interfaces(brand_names):
6566
def _get_interface_names() -> Dict[str, List[str]]:
6667
# returns a dict of brand name and its respective models
6768
brand_names = {}
68-
for brand_name, model_names in get_interface_attr("CAR").items():
69-
model_names = [getattr(model_names, c) for c in model_names.__dict__.keys() if not c.startswith("__")]
70-
brand_names[brand_name] = model_names
69+
for brand_name, brand_models in get_interface_attr("CAR").items():
70+
brand_names[brand_name] = [model.value for model in brand_models]
7171

7272
return brand_names
7373

@@ -125,16 +125,16 @@ def fingerprint(logcan, sendcan, num_pandas):
125125
ecu_rx_addrs = set()
126126
params = Params()
127127

128+
start_time = time.monotonic()
128129
if not skip_fw_query:
129130
# Vin query only reliably works through OBDII
130131
bus = 1
131132

132133
cached_params = params.get("CarParamsCache")
133134
if cached_params is not None:
134-
cached_params = car.CarParams.from_bytes(cached_params)
135-
# with car.CarParams.from_bytes(cached_params) as cached_params:
136-
if cached_params.carName == "mock":
137-
cached_params = None
135+
with car.CarParams.from_bytes(cached_params) as cached_params:
136+
if cached_params.carName == "mock":
137+
cached_params = None
138138

139139
if cached_params is not None and len(cached_params.carFw) > 0 and \
140140
cached_params.carVin is not VIN_UNKNOWN and not disable_fw_cache:
@@ -166,6 +166,8 @@ def fingerprint(logcan, sendcan, num_pandas):
166166
set_obd_multiplexing(params, False)
167167
params.put_bool("FirmwareQueryDone", True)
168168

169+
fw_query_time = time.monotonic() - start_time
170+
169171
# CAN fingerprint
170172
# drain CAN socket so we get the latest messages
171173
messaging.drain_sock_raw(logcan)
@@ -186,7 +188,7 @@ def fingerprint(logcan, sendcan, num_pandas):
186188

187189
cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint, source=source, fuzzy=not exact_match, cached=cached,
188190
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), vin_rx_addr=vin_rx_addr, fingerprints=finger,
189-
error=True)
191+
fw_query_time=fw_query_time, error=True)
190192
return car_fingerprint, finger, vin, car_fw, source, exact_match
191193

192194

selfdrive/car/chrysler/carcontroller.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from opendbc.can.packer import CANPacker
22
from openpilot.common.realtime import DT_CTRL
33
from openpilot.selfdrive.car import apply_meas_steer_torque_limits
4-
from openpilot.selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, create_cruise_buttons
4+
from openpilot.selfdrive.car.chrysler import chryslercan
55
from openpilot.selfdrive.car.chrysler.values import RAM_CARS, CarControllerParams, ChryslerFlags
66

77

@@ -31,17 +31,18 @@ def update(self, CC, CS, now_nanos):
3131
# ACC cancellation
3232
if CC.cruiseControl.cancel:
3333
self.last_button_frame = self.frame
34-
can_sends.append(create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, cancel=True))
34+
can_sends.append(chryslercan.create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, cancel=True))
3535

3636
# ACC resume from standstill
3737
elif CC.cruiseControl.resume:
3838
self.last_button_frame = self.frame
39-
can_sends.append(create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, resume=True))
39+
can_sends.append(chryslercan.create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, resume=True))
4040

4141
# HUD alerts
4242
if self.frame % 25 == 0:
4343
if CS.lkas_car_model != -1:
44-
can_sends.append(create_lkas_hud(self.packer, self.CP, lkas_active, CC.hudControl.visualAlert, self.hud_count, CS.lkas_car_model, CS.auto_high_beam))
44+
can_sends.append(chryslercan.create_lkas_hud(self.packer, self.CP, lkas_active, CC.hudControl.visualAlert,
45+
self.hud_count, CS.lkas_car_model, CS.auto_high_beam))
4546
self.hud_count += 1
4647

4748
# steering
@@ -72,7 +73,7 @@ def update(self, CC, CS, now_nanos):
7273
apply_steer = 0
7374
self.apply_steer_last = apply_steer
7475

75-
can_sends.append(create_lkas_command(self.packer, self.CP, int(apply_steer), lkas_control_bit))
76+
can_sends.append(chryslercan.create_lkas_command(self.packer, self.CP, int(apply_steer), lkas_control_bit))
7677

7778
self.frame += 1
7879

selfdrive/car/chrysler/values.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ruff: noqa: E501
22
from enum import IntFlag
3+
from strenum import StrEnum
34
from dataclasses import dataclass, field
45
from typing import Dict, List, Optional, Union
56

@@ -16,7 +17,7 @@ class ChryslerFlags(IntFlag):
1617
HIGHER_MIN_STEERING_SPEED = 1
1718

1819

19-
class CAR:
20+
class CAR(StrEnum):
2021
# Chrysler
2122
PACIFICA_2017_HYBRID = "CHRYSLER PACIFICA HYBRID 2017"
2223
PACIFICA_2018_HYBRID = "CHRYSLER PACIFICA HYBRID 2018"

selfdrive/car/disable_ecu.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
from openpilot.selfdrive.car.isotp_parallel_query import IsoTpParallelQuery
23
from openpilot.system.swaglog import cloudlog
34

selfdrive/car/docs_definitions.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CarHarness(EnumBase):
8585
bosch_a = BaseCarHarness("Honda Bosch A connector")
8686
bosch_b = BaseCarHarness("Honda Bosch B connector")
8787
toyota_a = BaseCarHarness("Toyota A connector")
88+
toyota_b = BaseCarHarness("Toyota B connector")
8889
subaru_a = BaseCarHarness("Subaru A connector")
8990
subaru_b = BaseCarHarness("Subaru B connector")
9091
subaru_c = BaseCarHarness("Subaru C connector")
@@ -110,6 +111,7 @@ class CarHarness(EnumBase):
110111
hyundai_o = BaseCarHarness("Hyundai O connector")
111112
hyundai_p = BaseCarHarness("Hyundai P connector")
112113
hyundai_q = BaseCarHarness("Hyundai Q connector")
114+
hyundai_r = BaseCarHarness("Hyundai R connector")
113115
custom = BaseCarHarness("Developer connector")
114116
obd_ii = BaseCarHarness("OBD-II connector", parts=[Cable.long_obdc_cable, Cable.long_obdc_cable], has_connector=False)
115117
gm = BaseCarHarness("GM connector")
@@ -121,9 +123,9 @@ class CarHarness(EnumBase):
121123

122124

123125
class Device(EnumBase):
124-
three = BasePart("comma three", parts=[Mount.mount, Cable.right_angle_obd_c_cable_1_5ft])
125-
# variant of comma three with angled mounts
126-
three_angled_mount = BasePart("comma three", parts=[Mount.angled_mount_8_degrees, Cable.right_angle_obd_c_cable_1_5ft])
126+
threex = BasePart("comma 3X", parts=[Mount.mount, Cable.right_angle_obd_c_cable_1_5ft])
127+
# variant of comma 3X with angled mounts
128+
threex_angled_mount = BasePart("comma 3X", parts=[Mount.angled_mount_8_degrees, Cable.right_angle_obd_c_cable_1_5ft])
127129
red_panda = BasePart("red panda")
128130

129131

@@ -147,7 +149,7 @@ class PartType(Enum):
147149
tool = Tool
148150

149151

150-
DEFAULT_CAR_PARTS: List[EnumBase] = [Device.three]
152+
DEFAULT_CAR_PARTS: List[EnumBase] = [Device.threex]
151153

152154

153155
@dataclass
@@ -158,7 +160,7 @@ def __call__(self):
158160
return copy.deepcopy(self)
159161

160162
@classmethod
161-
def common(cls, add: List[EnumBase] = None, remove: List[EnumBase] = None):
163+
def common(cls, add: Optional[List[EnumBase]] = None, remove: Optional[List[EnumBase]] = None):
162164
p = [part for part in (add or []) + DEFAULT_CAR_PARTS if part not in (remove or [])]
163165
return cls(p)
164166

@@ -174,8 +176,8 @@ def all_parts(self):
174176

175177
class CommonFootnote(Enum):
176178
EXP_LONG_AVAIL = CarFootnote(
177-
"Experimental openpilot longitudinal control is available behind a toggle; " +
178-
"the toggle is only available in non-release branches such as `devel` or `master-ci`. ",
179+
"openpilot Longitudinal Control (Alpha) is available behind a toggle; " +
180+
"the toggle is only available in non-release branches such as `devel` or `master-ci`.",
179181
Column.LONGITUDINAL, docs_only=True)
180182
EXP_LONG_DSU = CarFootnote(
181183
"By default, this car will use the stock Adaptive Cruise Control (ACC) for longitudinal control. " +

selfdrive/car/ford/carcontroller.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from openpilot.common.numpy_fast import clip
33
from opendbc.can.packer import CANPacker
44
from openpilot.selfdrive.car import apply_std_steer_angle_limits
5-
from openpilot.selfdrive.car.ford.fordcan import CanBus, create_acc_msg, create_acc_ui_msg, create_button_msg, \
6-
create_lat_ctl_msg, create_lat_ctl2_msg, create_lka_msg, create_lkas_ui_msg
5+
from openpilot.selfdrive.car.ford import fordcan
76
from openpilot.selfdrive.car.ford.values import CANFD_CAR, CarControllerParams
87

98
LongCtrlState = car.CarControl.Actuators.LongControlState
@@ -27,7 +26,7 @@ def __init__(self, dbc_name, CP, VM):
2726
self.CP = CP
2827
self.VM = VM
2928
self.packer = CANPacker(dbc_name)
30-
self.CAN = CanBus(CP)
29+
self.CAN = fordcan.CanBus(CP)
3130
self.frame = 0
3231

3332
self.apply_curvature_last = 0
@@ -47,15 +46,15 @@ def update(self, CC, CS, now_nanos):
4746

4847
### acc buttons ###
4948
if CC.cruiseControl.cancel:
50-
can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, cancel=True))
51-
can_sends.append(create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, cancel=True))
49+
can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, cancel=True))
50+
can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, cancel=True))
5251
elif CC.cruiseControl.resume and (self.frame % CarControllerParams.BUTTONS_STEP) == 0:
53-
can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, resume=True))
54-
can_sends.append(create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, resume=True))
52+
can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, resume=True))
53+
can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, resume=True))
5554
# if stock lane centering isn't off, send a button press to toggle it off
5655
# the stock system checks for steering pressed, and eventually disengages cruise control
5756
elif CS.acc_tja_status_stock_values["Tja_D_Stat"] != 0 and (self.frame % CarControllerParams.ACC_UI_STEP) == 0:
58-
can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, tja_toggle=True))
57+
can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, tja_toggle=True))
5958

6059
### lateral control ###
6160
# send steer msg at 20Hz
@@ -73,13 +72,13 @@ def update(self, CC, CS, now_nanos):
7372
# TODO: extended mode
7473
mode = 1 if CC.latActive else 0
7574
counter = (self.frame // CarControllerParams.STEER_STEP) % 0xF
76-
can_sends.append(create_lat_ctl2_msg(self.packer, self.CAN, mode, 0., 0., -apply_curvature, 0., counter))
75+
can_sends.append(fordcan.create_lat_ctl2_msg(self.packer, self.CAN, mode, 0., 0., -apply_curvature, 0., counter))
7776
else:
78-
can_sends.append(create_lat_ctl_msg(self.packer, self.CAN, CC.latActive, 0., 0., -apply_curvature, 0.))
77+
can_sends.append(fordcan.create_lat_ctl_msg(self.packer, self.CAN, CC.latActive, 0., 0., -apply_curvature, 0.))
7978

8079
# send lka msg at 33Hz
8180
if (self.frame % CarControllerParams.LKA_STEP) == 0:
82-
can_sends.append(create_lka_msg(self.packer, self.CAN))
81+
can_sends.append(fordcan.create_lka_msg(self.packer, self.CAN))
8382

8483
### longitudinal control ###
8584
# send acc msg at 50Hz
@@ -91,16 +90,16 @@ def update(self, CC, CS, now_nanos):
9190
gas = CarControllerParams.INACTIVE_GAS
9291

9392
stopping = CC.actuators.longControlState == LongCtrlState.stopping
94-
can_sends.append(create_acc_msg(self.packer, self.CAN, CC.longActive, gas, accel, stopping))
93+
can_sends.append(fordcan.create_acc_msg(self.packer, self.CAN, CC.longActive, gas, accel, stopping))
9594

9695
### ui ###
9796
send_ui = (self.main_on_last != main_on) or (self.lkas_enabled_last != CC.latActive) or (self.steer_alert_last != steer_alert)
9897
# send lkas ui msg at 1Hz or if ui state changes
9998
if (self.frame % CarControllerParams.LKAS_UI_STEP) == 0 or send_ui:
100-
can_sends.append(create_lkas_ui_msg(self.packer, self.CAN, main_on, CC.latActive, steer_alert, hud_control, CS.lkas_status_stock_values))
99+
can_sends.append(fordcan.create_lkas_ui_msg(self.packer, self.CAN, main_on, CC.latActive, steer_alert, hud_control, CS.lkas_status_stock_values))
101100
# send acc ui msg at 5Hz or if ui state changes
102101
if (self.frame % CarControllerParams.ACC_UI_STEP) == 0 or send_ui:
103-
can_sends.append(create_acc_ui_msg(self.packer, self.CAN, self.CP, main_on, CC.latActive,
102+
can_sends.append(fordcan.create_acc_ui_msg(self.packer, self.CAN, self.CP, main_on, CC.latActive,
104103
fcw_alert, CS.out.cruiseState.standstill, hud_control,
105104
CS.acc_tja_status_stock_values))
106105

selfdrive/car/ford/interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
from cereal import car
32
from panda import Panda
43
from openpilot.common.conversions import Conversions as CV

selfdrive/car/ford/radar_interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
from math import cos, sin
32
from cereal import car
43
from opendbc.can.parser import CANParser

selfdrive/car/ford/tests/test_ford.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import capnp
77

88
from cereal import car
9-
from selfdrive.car.ford.values import FW_QUERY_CONFIG, FW_VERSIONS
9+
from openpilot.selfdrive.car.ford.values import FW_QUERY_CONFIG, FW_VERSIONS
1010

1111
Ecu = car.CarParams.Ecu
1212

0 commit comments

Comments
 (0)