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

Commit

Permalink
Merge pull request #15 from eFiniLan/20240129
Browse files Browse the repository at this point in the history
2024-01-29 commits
  • Loading branch information
eFiniLan authored Feb 4, 2024
2 parents bbade30 + 3a70a08 commit 608d7eb
Show file tree
Hide file tree
Showing 89 changed files with 8,730 additions and 7,912 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ I recommend using the openpilot [commatwo_master](https://github.com/commaai/ope

I have decided to make this side project open source for users who wish to:

* Port unsupported vehicles
* Evaluate end-to-end lateral and longitudinal control on previously unsupported vehicles
* Understand the limitations of legacy devices
* Port unsupported vehicles using cheaper devices.
* Evaluate end-to-end lateral and longitudinal control on previously unsupported vehicles.
* Understand the limitations of legacy devices.
* Experience pure openpilot (without the modifications of dragonpilot)
* Make their own EON/C2 fork without spending hundreds of hours reverting and testing code.

Expand All @@ -36,7 +36,7 @@ I encourage users to consider purchasing a [comma 3x](https://shop.comma.ai) for
## Limitations

* On-road tests are conducted exclusively in a 2021 Toyota C-HR; other models may not perform properly.
* CAN-FD and BODY features are not supported due to outdated libraries in EON/C2 firmware.
* ~~CAN-FD and BODY features are not supported due to outdated libraries in EON/C2 firmware.~~
* The driving AI model remains in version 0.8.16, as porting TinyGrad/PyOpenCL requires significant effort.
* The driver monitoring AI model remains in version 0.8.13.
* Navigation On Openpilot (NOO) is not supported, as it requires a newer driving model that is not currently available in legacypilot.
Expand All @@ -52,6 +52,15 @@ I encourage users to consider purchasing a [comma 3x](https://shop.comma.ai) for

* For research purposes, the INDI and LQR lateral controllers have been restored. Please use the `dp_lat_controller` parameter to override the default controller (0 = DEFAULT, 1 = INDI, 2 = LQR).
* If you are not a Comma Two device, you can use the `dp_no_fan_ctrl` parameter to disable fan-related detection and control.
* The BODY has been tested and is working; however, I personally haven't tried it, so I'm not sure what steps are needed to get it to work.


## Red Panda (a.k.a. CAN-FD support)
The EON + Red Panda configuration has been tested and worked on [my Toyota](https://youtu.be/KgrI2Ley_Nk) (CAN), so technically it should work on CAN-FD vehicles. However, there are a couple of considerations:
* C2 will not function without hardware modification. You cannot connect the Red Panda directly to the C2 USB port.
* If any changes are made to the Red Panda firmware, the firmware needs to be pre-compiled on a PC and then uploaded to `/data/openpilot/panda/board/obj/`.
* Please be aware that you may encounter **CANBUS disconnection errors**. If this occurs, simply **power cycle BOTH your device and Red Panda**.


=======================

Expand Down
6 changes: 6 additions & 0 deletions launch_chffrplus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ function two_init {
LIB_PATH="/data/openpilot/system/hardware/eon/libs"
PY_LIB_DEST="/system/comma/usr/lib/python3.8/site-packages"
mount -o remount,rw /system
# tomli
MODULE="tomli"
if [ ! -d "$PY_LIB_DEST/$MODULE" ]; then
echo "Installing $MODULE..."
tar -zxvf "$LIB_PATH/$MODULE.tar.gz" -C "$PY_LIB_DEST/"
fi
# libgfortran
if [ ! -f "/system/comma/usr/lib/libgfortran.so.5.0.0" ]; then
echo "Installing libgfortran..."
Expand Down
6 changes: 4 additions & 2 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,11 @@ void panda_state_thread(std::vector<Panda *> pandas, bool spoofing_started) {

void peripheral_control_thread(Panda *panda, bool no_fan_control) {
util::set_thread_name("boardd_peripheral_control");
// rick - a device with black panda = EON / LEON / clone 1.5
// rick - a device with black/red panda = EON / LEON / clone 1.5
if (!Params().getBool("dp_no_fan_ctrl")) {
no_fan_control = panda->hw_type == cereal::PandaState::PandaType::BLACK_PANDA;
no_fan_control = panda->hw_type == cereal::PandaState::PandaType::BLACK_PANDA ||
panda->hw_type == cereal::PandaState::PandaType::RED_PANDA ||
panda->hw_type == cereal::PandaState::PandaType::RED_PANDA_V2;
Params().putBool("dp_no_fan_ctrl", no_fan_control);
}

Expand Down
4 changes: 4 additions & 0 deletions selfdrive/boardd/panda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Panda::Panda(std::string serial, uint32_t bus_offset) : bus_offset(bus_offset) {
has_gps = hw_type == cereal::PandaState::PandaType::GREY_PANDA;
hw_type = cereal::PandaState::PandaType::BLACK_PANDA;
}
// rick - do it in defined(QCOM) only, otherwise has_gps is unused
if (hw_type == cereal::PandaState::PandaType::RED_PANDA || hw_type == cereal::PandaState::PandaType::RED_PANDA_V2) {
has_gps = false;
}
#endif

has_rtc = (hw_type == cereal::PandaState::PandaType::UNO) ||
Expand Down
19 changes: 19 additions & 0 deletions selfdrive/car/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Car port structure

### interface.py
Generic interface to send and receive messages from CAN (controlsd uses this to communicate with car)

### fingerprints.py
Fingerprints for matching to a specific car

### carcontroller.py
Builds CAN messages to send to car

##### carstate.py
Reads CAN from car and builds openpilot CarState message

##### values.py
Limits for actuation, general constants for cars, and supported car documentation

##### radar_interface.py
Interface for parsing radar points from the car
28 changes: 28 additions & 0 deletions selfdrive/car/body/fingerprints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ruff: noqa: E501
from cereal import car
from openpilot.selfdrive.car.body.values import CAR

Ecu = car.CarParams.Ecu

# debug ecu fw version is the git hash of the firmware


FINGERPRINTS = {
CAR.BODY: [{
513: 8, 516: 8, 514: 3, 515: 4
}],
}

FW_VERSIONS = {
CAR.BODY: {
(Ecu.engine, 0x720, None): [
b'0.0.01',
b'0.3.00a',
b'02/27/2022',
],
(Ecu.debug, 0x721, None): [
b'166bd860',
b'dc780f85',
],
},
}
21 changes: 1 addition & 20 deletions selfdrive/car/body/values.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from strenum import StrEnum
from enum import StrEnum
from typing import Dict

from cereal import car
Expand Down Expand Up @@ -30,11 +30,6 @@ class CAR(StrEnum):
CAR.BODY: CarInfo("comma body", package="All"),
}

FINGERPRINTS = {
CAR.BODY: [{
513: 8, 516: 8, 514: 3, 515: 4,
}],
}

FW_QUERY_CONFIG = FwQueryConfig(
requests=[
Expand All @@ -46,20 +41,6 @@ class CAR(StrEnum):
],
)

FW_VERSIONS = {
CAR.BODY: {
(Ecu.engine, 0x720, None): [
b'0.0.01',
b'02/27/2022',
b'0.3.00a',
],
# git hash of the firmware used
(Ecu.debug, 0x721, None): [
b'166bd860',
b'dc780f85',
],
},
}

DBC = {
CAR.BODY: dbc_dict('comma_body', None),
Expand Down
27 changes: 19 additions & 8 deletions selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ def fingerprint(logcan, sendcan, num_pandas):

start_time = time.monotonic()
if not skip_fw_query:
# Vin query only reliably works through OBDII
bus = 1

cached_params = params.get("CarParamsCache")
if cached_params is not None:
# with car.CarParams.from_bytes(cached_params) as cached_params:
Expand All @@ -140,20 +137,22 @@ def fingerprint(logcan, sendcan, num_pandas):
if cached_params is not None and len(cached_params.carFw) > 0 and \
cached_params.carVin is not VIN_UNKNOWN and not disable_fw_cache:
cloudlog.warning("Using cached CarParams")
vin, vin_rx_addr = cached_params.carVin, 0
vin_rx_addr, vin_rx_bus, vin = -1, -1, cached_params.carVin
car_fw = list(cached_params.carFw)
cached = True
else:
cloudlog.warning("Getting VIN & FW versions")
# enable OBD multiplexing for Vin query, also allows time for sendcan subscriber to connect
set_obd_multiplexing(params, True)
vin_rx_addr, vin = get_vin(logcan, sendcan, bus)
# Vin query only reliably works through OBDII
vin_rx_addr, vin_rx_bus, vin = get_vin(logcan, sendcan, (0, 1))
ecu_rx_addrs = get_present_ecus(logcan, sendcan, num_pandas=num_pandas)
car_fw = get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs, num_pandas=num_pandas)
cached = False

exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
else:
vin, vin_rx_addr = VIN_UNKNOWN, 0
vin_rx_addr, vin_rx_bus, vin = -1, -1, VIN_UNKNOWN
exact_fw_match, fw_candidates, car_fw = True, set(), []
cached = False

Expand Down Expand Up @@ -188,8 +187,8 @@ def fingerprint(logcan, sendcan, num_pandas):
source = car.CarParams.FingerprintSource.fixed

cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint, source=source, fuzzy=not exact_match, cached=cached,
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), vin_rx_addr=vin_rx_addr, fingerprints=finger,
fw_query_time=fw_query_time, error=True)
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), vin_rx_addr=vin_rx_addr, vin_rx_bus=vin_rx_bus,
fingerprints=finger, fw_query_time=fw_query_time, error=True)
return car_fingerprint, finger, vin, car_fw, source, exact_match


Expand All @@ -208,3 +207,15 @@ def get_car(logcan, sendcan, experimental_long_allowed, num_pandas=1):
CP.fuzzyFingerprint = not exact_match

return CarInterface(CP, CarController, CarState), CP

def write_car_param(fingerprint="mock"):
params = Params()
CarInterface, _, _ = interfaces[fingerprint]
CP = CarInterface.get_non_essential_params(fingerprint)
params.put("CarParams", CP.to_bytes())

def get_demo_car_params():
fingerprint="mock"
CarInterface, _, _ = interfaces[fingerprint]
CP = CarInterface.get_non_essential_params(fingerprint)
return CP
Loading

0 comments on commit 608d7eb

Please sign in to comment.