selfdrive.car package

Subpackages

Submodules

selfdrive.car.car_helpers module

selfdrive.car.car_helpers.fingerprint(logcan, sendcan)[source]
selfdrive.car.car_helpers.get_car(logcan, sendcan)[source]
selfdrive.car.car_helpers.get_one_can(logcan)[source]
selfdrive.car.car_helpers.get_startup_event(car_recognized, controller_available, fw_seen)[source]
selfdrive.car.car_helpers.load_interfaces(brand_names)[source]

selfdrive.car.disable_ecu module

selfdrive.car.disable_ecu.disable_ecu(logcan, sendcan, bus=0, addr=2000, com_cont_req=b'(\x83\x01', timeout=0.1, retry=10, debug=False)[source]

Silence an ECU by disabling sending and receiving messages using UDS 0x28. The ECU will stay silent as long as openpilot keeps sending Tester Present.

This is used to disable the radar in some cars. Openpilot will emulate the radar. WARNING: THIS DISABLES AEB!

selfdrive.car.docs module

selfdrive.car.docs.generate_cars_md(all_car_info: List[CarInfo], template_fn: str, only_tier_cols: bool) str[source]
selfdrive.car.docs.get_all_car_info(only_tier_cols: bool = False) List[CarInfo][source]
selfdrive.car.docs.get_all_footnotes(only_tier_cols: bool = False) Dict[Enum, int][source]
selfdrive.car.docs.group_by_make(all_car_info: List[CarInfo]) Dict[str, List[CarInfo]][source]

selfdrive.car.docs_definitions module

class selfdrive.car.docs_definitions.CarFootnote(text, column, star)

Bases: tuple

column

Alias for field number 1

star

Alias for field number 2

text

Alias for field number 0

class selfdrive.car.docs_definitions.CarInfo(name: str, package: str, video_link: Union[str, NoneType] = None, footnotes: List[enum.Enum] = <factory>, min_steer_speed: Union[float, NoneType] = None, min_enable_speed: Union[float, NoneType] = None, harness: Union[enum.Enum, NoneType] = None)[source]

Bases: object

footnotes: List[Enum]
get_column(column: Column, star_icon: str, footnote_tag: str) str[source]
get_detail_sentence(CP)[source]
harness: Optional[Enum] = None
init(CP: <capnp.lib.capnp._StructModule object at 0x7efd62b23700>, all_footnotes: ~typing.Dict[~enum.Enum, int])[source]
min_enable_speed: Optional[float] = None
min_steer_speed: Optional[float] = None
name: str
package: str
class selfdrive.car.docs_definitions.Column(value)[source]

Bases: Enum

An enumeration.

FSR_LONGITUDINAL = 'Stop and Go'
FSR_STEERING = 'Steer to 0'
LONGITUDINAL = 'openpilot ACC'
MAKE = 'Make'
MODEL = 'Model'
PACKAGE = 'Supported Package'
STEERING_TORQUE = 'Steering Torque'
class selfdrive.car.docs_definitions.Harness(value)[source]

Bases: Enum

An enumeration.

bosch_a = 'Honda Bosch A'
bosch_b = 'Honda Bosch B'
custom = 'Developer'
fca = 'FCA'
hyundai_a = 'Hyundai A'
hyundai_b = 'Hyundai B'
hyundai_c = 'Hyundai C'
hyundai_d = 'Hyundai D'
hyundai_e = 'Hyundai E'
hyundai_f = 'Hyundai F'
hyundai_g = 'Hyundai G'
hyundai_h = 'Hyundai H'
hyundai_i = 'Hyundai I'
hyundai_j = 'Hyundai J'
hyundai_k = 'Hyundai K'
hyundai_l = 'Hyundai L'
hyundai_m = 'Hyundai M'
hyundai_n = 'Hyundai N'
hyundai_o = 'Hyundai O'
hyundai_p = 'Hyundai P'
j533 = 'J533'
mazda = 'Mazda'
nidec = 'Honda Nidec'
nissan_a = 'Nissan A'
nissan_b = 'Nissan B'
none = 'None'
obd_ii = 'OBD-II'
ram = 'Ram'
subaru = 'Subaru'
toyota = 'Toyota'
vw = 'VW'
class selfdrive.car.docs_definitions.Star(value)[source]

Bases: Enum

An enumeration.

EMPTY = 'empty'
FULL = 'full'
HALF = 'half'
class selfdrive.car.docs_definitions.Tier(value)[source]

Bases: Enum

An enumeration.

BRONZE = 2
GOLD = 0
SILVER = 1
selfdrive.car.docs_definitions.get_footnotes(footnotes: List[Enum], column: Column) List[Enum][source]
selfdrive.car.docs_definitions.get_year_list(years)[source]
selfdrive.car.docs_definitions.split_name(name: str) Tuple[str, str, str][source]

selfdrive.car.ecu_addrs module

selfdrive.car.ecu_addrs.get_all_ecu_addrs(logcan: SubSocket, sendcan: PubSocket, bus: int, timeout: float = 1, debug: bool = True) Set[Tuple[int, Optional[int], int]][source]
selfdrive.car.ecu_addrs.get_ecu_addrs(logcan: SubSocket, sendcan: PubSocket, queries: Set[Tuple[int, Optional[int], int]], responses: Set[Tuple[int, Optional[int], int]], timeout: float = 1, debug: bool = False) Set[Tuple[int, Optional[int], int]][source]
selfdrive.car.ecu_addrs.is_tester_present_response(msg: _DynamicStructReader, subaddr: Optional[int] = None) bool[source]
selfdrive.car.ecu_addrs.make_tester_present_msg(addr, bus, subaddr=None)[source]

selfdrive.car.fingerprints module

selfdrive.car.fingerprints.all_known_cars()[source]

Returns a list of all known car strings.

selfdrive.car.fingerprints.all_legacy_fingerprint_cars()[source]

Returns a list of all known car strings, FPv1 only.

selfdrive.car.fingerprints.eliminate_incompatible_cars(msg, candidate_cars)[source]

Removes cars that could not have sent msg.

Inputs:

msg: A cereal/log CanData message from the car. candidate_cars: A list of cars to consider.

Returns:

A list containing the subset of candidate_cars that could have sent msg.

selfdrive.car.fingerprints.is_valid_for_fingerprint(msg, car_fingerprint)[source]

selfdrive.car.fw_versions module

class selfdrive.car.fw_versions.Request(brand: str, request: List[bytes], response: List[bytes], whitelist_ecus: List[int] = <factory>, rx_offset: int = 8, bus: int = 1)[source]

Bases: object

brand: str
bus: int = 1
request: List[bytes]
response: List[bytes]
rx_offset: int = 8
whitelist_ecus: List[int]
selfdrive.car.fw_versions.build_fw_dict(fw_versions, filter_brand=None)[source]
selfdrive.car.fw_versions.chunks(l, n=128)[source]
selfdrive.car.fw_versions.get_brand_addrs()[source]
selfdrive.car.fw_versions.get_brand_ecu_matches(ecu_rx_addrs)[source]

Returns dictionary of brands and matches with ECUs in their FW versions

selfdrive.car.fw_versions.get_fw_versions(logcan, sendcan, query_brand=None, extra=None, timeout=0.1, debug=False, progress=False)[source]
selfdrive.car.fw_versions.get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs, timeout=0.1, debug=False, progress=False)[source]

Queries for FW versions ordering brands by likelihood, breaks when exact match is found

selfdrive.car.fw_versions.get_present_ecus(logcan, sendcan)[source]
selfdrive.car.fw_versions.match_fw_to_car(fw_versions, allow_fuzzy=True)[source]
selfdrive.car.fw_versions.match_fw_to_car_exact(fw_versions_dict)[source]

Do an exact FW match. Returns all cars that match the given FW versions for a list of “essential” ECUs. If an ECU is not considered essential the FW version can be missing to get a fingerprint, but if it’s present it needs to match the database.

selfdrive.car.fw_versions.match_fw_to_car_fuzzy(fw_versions_dict, log=True, exclude=None)[source]

Do a fuzzy FW match. This function will return a match, and the number of firmware version that were matched uniquely to that specific car. If multiple ECUs uniquely match to different cars the match is rejected.

selfdrive.car.fw_versions.p16(val)[source]

selfdrive.car.interfaces module

class selfdrive.car.interfaces.CarInterfaceBase(CP, CarController, CarState)[source]

Bases: ABC

abstract apply(c: <capnp.lib.capnp._StructModule object at 0x7efd62b23220>) List[bytes]][source]
static configure_torque_tune(candidate, tune, steering_angle_deadzone_deg=0.0, use_steering_angle=True)[source]
create_common_events(cs_out, extra_gears=None, pcm_enable=True, allow_enable=True)[source]
abstract static get_params(candidate, fingerprint={0: {}, 1: {}, 2: {}, 3: {}}, car_fw=None, disable_radar=False)[source]
static get_pid_accel_limits(CP, current_speed, cruise_speed)[source]
static get_std_params(candidate, fingerprint)[source]
static get_steer_feedforward_default(desired_angle, v_ego)[source]
get_steer_feedforward_function()[source]
static init(CP, logcan, sendcan)[source]
update(c: <capnp.lib.capnp._StructModule object at 0x7efd62b23220>, can_strings: ~typing.List[bytes]) <capnp.lib.capnp._StructModule object at 0x7efd62b11970>[source]
class selfdrive.car.interfaces.CarStateBase(CP)[source]

Bases: ABC

static get_adas_can_parser(CP)[source]
static get_body_can_parser(CP)[source]
static get_cam_can_parser(CP)[source]
static get_loopback_can_parser(CP)[source]
get_wheel_speeds(fl, fr, rl, rr, unit=0.2777777777777778)[source]
static parse_gear_shifter(gear: Optional[str]) <capnp.lib.capnp._EnumModule object at 0x7efd62b11d00>[source]
update_blinker_from_lamp(blinker_time: int, left_blinker_lamp: bool, right_blinker_lamp: bool)[source]

Update blinkers from lights. Enable output when light was seen within the last blinker_time iterations

update_blinker_from_stalk(blinker_time: int, left_blinker_stalk: bool, right_blinker_stalk: bool)[source]

Update blinkers from stalk position. When stalk is seen the blinker will be on for at least blinker_time, or until the stalk is turned off, whichever is longer. If the opposite stalk direction is seen the blinker is forced to the other side. On a rising edge of the stalk the timeout is reset.

update_speed_kf(v_ego_raw)[source]
class selfdrive.car.interfaces.RadarInterfaceBase(CP)[source]

Bases: ABC

update(can_strings)[source]
selfdrive.car.interfaces.get_interface_attr(attr: str, combine_brands: bool = False, ignore_none: bool = False) Dict[str, Any][source]
selfdrive.car.interfaces.get_torque_params(candidate)[source]

selfdrive.car.isotp_parallel_query module

class selfdrive.car.isotp_parallel_query.IsoTpParallelQuery(sendcan, logcan, bus, addrs, request, response, response_offset=8, functional_addr=False, debug=False, response_pending_timeout=10)[source]

Bases: object

get_data(timeout, total_timeout=60.0)[source]
rx()[source]

Drain can socket and sort messages into buffers based on address

selfdrive.car.vin module

selfdrive.car.vin.get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False)[source]
selfdrive.car.vin.is_valid_vin(vin: str)[source]

Module contents

class selfdrive.car.CivicParams[source]

Bases: object

CENTER_TO_FRONT = 1.08
CENTER_TO_REAR = 1.62
MASS = 1462.0
ROTATIONAL_INERTIA = 2500
TIRE_STIFFNESS_FRONT = 192150
TIRE_STIFFNESS_REAR = 202500
WHEELBASE = 2.7
selfdrive.car.apply_std_steer_torque_limits(apply_torque, apply_torque_last, driver_torque, LIMITS)[source]
selfdrive.car.apply_toyota_steer_torque_limits(apply_torque, apply_torque_last, motor_torque, LIMITS)[source]
selfdrive.car.crc8_pedal(data)[source]
selfdrive.car.create_button_enable_events(buttonEvents: _DynamicListBuilder, pcm_cruise: bool = False) List[int][source]
selfdrive.car.create_button_event(cur_but: int, prev_but: int, buttons_dict: Dict[int, _EnumModule], unpressed: int = 0) _DynamicStructBuilder[source]
selfdrive.car.create_gas_interceptor_command(packer, gas_amount, idx)[source]
selfdrive.car.dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None, body_dbc=None) Dict[str, str][source]
selfdrive.car.gen_empty_fingerprint()[source]
selfdrive.car.get_safety_config(safety_model, safety_param=None)[source]
selfdrive.car.make_can_msg(addr, dat, bus)[source]
selfdrive.car.scale_rot_inertia(mass, wheelbase)[source]
selfdrive.car.scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor=1.0)[source]