Skip to content

Commit

Permalink
Merge remote-tracking branch 'commaai/openpilot/master' into ui-home
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Aug 1, 2024
2 parents 6159e7a + 7de618a commit e4bd772
Show file tree
Hide file tree
Showing 66 changed files with 999 additions and 819 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/badges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
env:
BASE_IMAGE: openpilot-base
DOCKER_REGISTRY: ghcr.io/commaai
RUN: docker run --shm-size 1G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $DOCKER_REGISTRY/$BASE_IMAGE:latest /bin/bash -c
RUN: docker run --shm-size 2G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $DOCKER_REGISTRY/$BASE_IMAGE:latest /bin/bash -c

jobs:
badges:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/selfdrive_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
DOCKER_LOGIN: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
BUILD: selfdrive/test/docker_build.sh base

RUN: docker run --shm-size 1G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e CI=1 -e PRE_COMMIT_HOME=/tmp/pre-commit -e PYTHONWARNINGS=error -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/pre-commit:/tmp/pre-commit -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c
RUN: docker run --shm-size 2G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e CI=1 -e PRE_COMMIT_HOME=/tmp/pre-commit -e PYTHONWARNINGS=error -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/pre-commit:/tmp/pre-commit -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c

PYTEST: pytest --continue-on-collection-errors --cov --cov-report=xml --cov-append --durations=0 --durations-min=5 --hypothesis-seed 0 -n logical

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:

BUILD: selfdrive/test/docker_build.sh base

RUN: docker run --shm-size 1G -v $GITHUB_WORKSPACE:/tmp/openpilot -w /tmp/openpilot -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c
RUN: docker run --shm-size 2G -v $GITHUB_WORKSPACE:/tmp/openpilot -w /tmp/openpilot -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c


jobs:
Expand Down
3 changes: 0 additions & 3 deletions .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ ignore_imports =
openpilot.selfdrive.car.ecu_addrs -> openpilot.common.swaglog
openpilot.selfdrive.car.car_helpers -> openpilot.common.swaglog
openpilot.selfdrive.car.car_helpers -> openpilot.system.version
openpilot.selfdrive.car.ford.carcontroller -> openpilot.selfdrive.controls.lib.drive_helpers
openpilot.selfdrive.car.gm.interface -> openpilot.selfdrive.controls.lib.drive_helpers
openpilot.selfdrive.car.honda.carcontroller -> openpilot.selfdrive.controls.lib.drive_helpers
openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.drive_helpers
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_angle
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.longcontrol
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
</p>

<h3>
<a href="https://docs.comma.ai">Read the docs</a>
<a href="https://docs.comma.ai">Docs</a>
<span> · </span>
<a href="https://docs.comma.ai/contributing/roadmap/">Roadmap</a>
<span> · </span>
<a href="https://github.com/commaai/openpilot/blob/master/docs/CONTRIBUTING.md">Contribute</a>
<span> · </span>
Expand All @@ -18,7 +20,7 @@
<a href="https://comma.ai/shop">Try it on a comma 3X</a>
</h3>

Quick start: `curl -fsSL openpilot.comma.ai | bash`
Quick start: `bash <(curl -fsSL openpilot.comma.ai)`

![openpilot tests](https://github.com/commaai/openpilot/actions/workflows/selfdrive_tests.yaml/badge.svg)
[![codecov](https://codecov.io/gh/commaai/openpilot/branch/master/graph/badge.svg)](https://codecov.io/gh/commaai/openpilot)
Expand Down
5 changes: 3 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ env = Environment(
COMPILATIONDB_USE_ABSPATH=True,
REDNOSE_ROOT="#",
tools=["default", "cython", "compilation_db", "rednose_filter"],
toolpath=["#rednose_repo/site_scons/site_tools"],
toolpath=["#site_scons/site_tools", "#rednose_repo/site_scons/site_tools"],
)

if arch == "Darwin":
Expand Down Expand Up @@ -268,7 +268,8 @@ if arch == "Darwin":
else:
envCython["LINKFLAGS"] = ["-pthread", "-shared"]

Export('envCython')
np_version = SCons.Script.Value(np.__version__)
Export('envCython', 'np_version')

# Qt build environment
qt_env = env.Clone()
Expand Down
2 changes: 1 addition & 1 deletion cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ enum LaneChangeDirection {

struct CanData {
address @0 :UInt32;
busTime @1 :UInt16;
dat @2 :Data;
src @3 :UInt8;
busTimeDEPRECATED @1 :UInt16;
}

struct DeviceState @0xa4d8b5af2aa492eb {
Expand Down
20 changes: 12 additions & 8 deletions docs/README → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
This is the source for [docs.comma.ai](https://docs.comma.ai).
The site is updated on pushes to master by this [workflow](../.github/workflows/docs.yaml).

## development
```
# install the docs dependencies
## Development
NOTE: Those commands must be run in the root directory of openpilot, **not /docs**

**1. Install the docs dependencies**
``` bash
pip install .[docs]
```

cd docs/
**2. Build the new site**
``` bash
mkdocs build
```

# for a development server
**3. Run the new site locally**
``` bash
mkdocs serve

# build the site
mkdocs build
```

References:
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ site_name: openpilot docs
repo_url: https://github.com/commaai/openpilot/
site_url: https://docs.comma.ai

exclude_docs: README.md

strict: true
docs_dir: docs
site_dir: docs_site/
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"pycapnp",
"Cython",
"setuptools",
"numpy < 2.0.0", # control does not support numpy 2
"numpy",

# body / webrtcd
"aiohttp",
Expand Down Expand Up @@ -111,7 +111,6 @@ dev = [
"tabulate",
"types-requests",
"types-tabulate",
"hexdump",

# this is only pinned since 5.15.11 is broken
"pyqt5 ==5.15.2; platform_machine == 'x86_64'", # no aarch64 wheels for macOS/linux
Expand Down
34 changes: 33 additions & 1 deletion selfdrive/car/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import capnp

from cereal import car
from panda.python.uds import SERVICE_TYPE
from openpilot.common.numpy_fast import clip, interp
from openpilot.common.utils import Freezable
from openpilot.selfdrive.car.docs_definitions import CarDocs
Expand Down Expand Up @@ -166,8 +167,39 @@ def common_fault_avoidance(fault_condition: bool, request: bool, above_limit_fra
return above_limit_frames, request


def apply_center_deadzone(error, deadzone):
if (error > - deadzone) and (error < deadzone):
error = 0.
return error


def rate_limit(new_value, last_value, dw_step, up_step):
return clip(new_value, last_value + dw_step, last_value + up_step)


def get_friction(lateral_accel_error: float, lateral_accel_deadzone: float, friction_threshold: float,
torque_params: car.CarParams.LateralTorqueTuning, friction_compensation: bool) -> float:
friction_interp = interp(
apply_center_deadzone(lateral_accel_error, lateral_accel_deadzone),
[-friction_threshold, friction_threshold],
[-torque_params.friction, torque_params.friction]
)
friction = float(friction_interp) if friction_compensation else 0.0
return friction


def make_can_msg(addr, dat, bus):
return [addr, 0, dat, bus]
return [addr, dat, bus]


def make_tester_present_msg(addr, bus, subaddr=None, suppress_response=False):
dat = [0x02, SERVICE_TYPE.TESTER_PRESENT]
if subaddr is not None:
dat.insert(0, subaddr)
dat.append(0x80 if suppress_response else 0x0) # sub-function

dat.extend([0x0] * (8 - len(dat)))
return make_can_msg(addr, bytes(dat), bus)


def get_safety_config(safety_model, safety_param = None):
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/body/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
self.frame = 0
super().__init__(dbc_name, CP, VM)
self.packer = CANPacker(dbc_name)

# PIDs
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/car/chrysler/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
self.CP = CP
super().__init__(dbc_name, CP, VM)
self.apply_steer_last = 0
self.frame = 0

self.hud_count = 0
self.last_lkas_falling_edge = 0
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/chrysler/radar_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def _address_to_track(address):
class RadarInterface(RadarInterfaceBase):
def __init__(self, CP):
super().__init__(CP)
self.CP = CP
self.rcp = _create_radar_can_parser(CP.carFingerprint)
self.updated_messages = set()
self.trigger_msg = LAST_MSG
Expand Down
13 changes: 2 additions & 11 deletions selfdrive/car/ecu_addrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@

import cereal.messaging as messaging
from panda.python.uds import SERVICE_TYPE
from openpilot.selfdrive.car import make_can_msg
from openpilot.selfdrive.car import make_tester_present_msg
from openpilot.selfdrive.car.fw_query_definitions import EcuAddrBusType
from openpilot.selfdrive.pandad import can_list_to_can_capnp
from openpilot.common.swaglog import cloudlog


def _make_tester_present_msg(addr, bus, subaddr=None):
dat = [0x02, SERVICE_TYPE.TESTER_PRESENT, 0x0]
if subaddr is not None:
dat.insert(0, subaddr)

dat.extend([0x0] * (8 - len(dat)))
return make_can_msg(addr, bytes(dat), bus)


def _is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader, subaddr: int = None) -> bool:
# ISO-TP messages are always padded to 8 bytes
# tester present response is always a single frame
Expand All @@ -44,7 +35,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, que
responses: set[EcuAddrBusType], timeout: float = 1, debug: bool = False) -> set[EcuAddrBusType]:
ecu_responses: set[EcuAddrBusType] = set() # set((addr, subaddr, bus),)
try:
msgs = [_make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries]
msgs = [make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries]

messaging.drain_sock_raw(logcan)
sendcan.send(can_list_to_can_capnp(msgs, msgtype='sendcan'))
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/car/ford/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from openpilot.selfdrive.car.ford import fordcan
from openpilot.selfdrive.car.ford.values import CarControllerParams, FordFlags
from openpilot.selfdrive.car.interfaces import CarControllerBase
from openpilot.selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX

LongCtrlState = car.CarControl.Actuators.LongControlState
VisualAlert = car.CarControl.HUDControl.VisualAlert
V_CRUISE_MAX = 145


def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_curvature, v_ego_raw):
Expand All @@ -25,11 +25,10 @@ def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_c

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
self.CP = CP
super().__init__(dbc_name, CP, VM)
self.VM = VM
self.packer = CANPacker(dbc_name)
self.CAN = fordcan.CanBus(CP)
self.frame = 0

self.apply_curvature_last = 0
self.main_on_last = False
Expand Down Expand Up @@ -92,6 +91,7 @@ def update(self, CC, CS, now_nanos):
if not CC.longActive or gas < CarControllerParams.MIN_GAS:
gas = CarControllerParams.INACTIVE_GAS
stopping = CC.actuators.longControlState == LongCtrlState.stopping
# TODO: look into using the actuators packet to send the desired speed
can_sends.append(fordcan.create_acc_msg(self.packer, self.CAN, CC.longActive, gas, accel, stopping, v_ego_kph=V_CRUISE_MAX))

### ui ###
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/ford/fordcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_lat_ctl2_msg(packer, CAN: CanBus, mode: int, path_offset: float, path
}

# calculate checksum
dat = packer.make_can_msg("LateralMotionControl2", 0, values)[2]
dat = packer.make_can_msg("LateralMotionControl2", 0, values)[1]
values["LatCtlPath_No_Cs"] = calculate_lat_ctl2_checksum(mode, counter, dat)

return packer.make_can_msg("LateralMotionControl2", CAN.main, values)
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
self.CP = CP
super().__init__(dbc_name, CP, VM)
self.start_time = 0.
self.apply_steer_last = 0
self.apply_gas = 0
self.apply_brake = 0
self.frame = 0
self.last_steer_frame = 0
self.last_button_frame = 0
self.cancel_counter = 0
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/gm/gmcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_gas_regen_command(packer, bus, throttle, idx, enabled, at_full_stop):
"GasRegenAlwaysOne3": 1,
}

dat = packer.make_can_msg("ASCMGasRegenCmd", bus, values)[2]
dat = packer.make_can_msg("ASCMGasRegenCmd", bus, values)[1]
values["GasRegenChecksum"] = (((0xff - dat[1]) & 0xff) << 16) | \
(((0xff - dat[2]) & 0xff) << 8) | \
((0x100 - dat[3] - idx) & 0xff)
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

from openpilot.common.basedir import BASEDIR
from openpilot.common.conversions import Conversions as CV
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car import create_button_events, get_safety_config, get_friction
from openpilot.selfdrive.car.gm.radar_interface import RADAR_HEADER_MSG
from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus
from openpilot.selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel
from openpilot.selfdrive.controls.lib.drive_helpers import get_friction

ButtonType = car.CarState.ButtonEvent.Type
EventName = car.CarEvent.EventName
Expand Down
8 changes: 3 additions & 5 deletions selfdrive/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from cereal import car
from openpilot.common.numpy_fast import clip, interp
from opendbc.can.packer import CANPacker
from openpilot.selfdrive.car import DT_CTRL
from openpilot.selfdrive.car import DT_CTRL, rate_limit, make_tester_present_msg
from openpilot.selfdrive.car.honda import hondacan
from openpilot.selfdrive.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams
from openpilot.selfdrive.car.interfaces import CarControllerBase
from openpilot.selfdrive.controls.lib.drive_helpers import rate_limit

VisualAlert = car.CarControl.HUDControl.VisualAlert
LongCtrlState = car.CarControl.Actuators.LongControlState
Expand Down Expand Up @@ -106,11 +105,10 @@ def rate_limit_steer(new_steer, last_steer):

class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
self.CP = CP
super().__init__(dbc_name, CP, VM)
self.packer = CANPacker(dbc_name)
self.params = CarControllerParams(CP)
self.CAN = hondacan.CanBus(CP)
self.frame = 0

self.braking = False
self.brake_steady = 0.
Expand Down Expand Up @@ -165,7 +163,7 @@ def update(self, CC, CS, now_nanos):
# tester present - w/ no response (keeps radar disabled)
if self.CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and self.CP.openpilotLongitudinalControl:
if self.frame % 10 == 0:
can_sends.append((0x18DAB0F1, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", 1))
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))

# Send steering command.
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_steer, CC.latActive, self.CP.carFingerprint,
Expand Down
Loading

0 comments on commit e4bd772

Please sign in to comment.