selfdrive.controls.lib package

Subpackages

Submodules

selfdrive.controls.lib.alertmanager module

class selfdrive.controls.lib.alertmanager.AlertEntry(alert: openpilot.selfdrive.controls.lib.events.Alert | None = None, start_frame: int = -1, end_frame: int = -1)[source]

Bases: object

active(frame: int) bool[source]
alert: Alert | None = None
end_frame: int = -1
start_frame: int = -1
class selfdrive.controls.lib.alertmanager.AlertManager[source]

Bases: object

add_many(frame: int, alerts: list[Alert]) None[source]
process_alerts(frame: int, clear_event_types: set) Alert | None[source]
selfdrive.controls.lib.alertmanager.set_offroad_alert(alert: str, show_alert: bool, extra_text: str = None) None[source]

selfdrive.controls.lib.desire_helper module

class selfdrive.controls.lib.desire_helper.DesireHelper[source]

Bases: object

update(carstate, lateral_active, lane_change_prob)[source]

selfdrive.controls.lib.drive_helpers module

class selfdrive.controls.lib.drive_helpers.VCruiseHelper(CP)[source]

Bases: object

initialize_v_cruise(CS, experimental_mode: bool) None[source]
update_button_timers(CS, enabled)[source]
update_v_cruise(CS, enabled, is_metric)[source]
property v_cruise_initialized
selfdrive.controls.lib.drive_helpers.apply_center_deadzone(error, deadzone)[source]
selfdrive.controls.lib.drive_helpers.apply_deadzone(error, deadzone)[source]
selfdrive.controls.lib.drive_helpers.clip_curvature(v_ego, prev_curvature, new_curvature)[source]
selfdrive.controls.lib.drive_helpers.get_friction(lateral_accel_error: float, lateral_accel_deadzone: float, friction_threshold: float, torque_params: <capnp.lib.capnp._StructModule object at 0x7f3309048510>, friction_compensation: bool) float[source]
selfdrive.controls.lib.drive_helpers.get_speed_error(modelV2: <capnp.lib.capnp._StructModule object at 0x7f33092e4ad0>, v_ego: float) float[source]
selfdrive.controls.lib.drive_helpers.rate_limit(new_value, last_value, dw_step, up_step)[source]

selfdrive.controls.lib.events module

class selfdrive.controls.lib.events.Alert(alert_text_1: str, alert_text_2: str, alert_status: <capnp.lib.capnp._EnumModule object at 0x7f33092d33d0>, alert_size: <capnp.lib.capnp._EnumModule object at 0x7f33092d3250>, priority: ~selfdrive.controls.lib.events.Priority, visual_alert: <capnp.lib.capnp._EnumModule object at 0x7f3309037250>, audible_alert: <capnp.lib.capnp._EnumModule object at 0x7f3309037450>, duration: float, alert_rate: float = 0.0, creation_delay: float = 0.0)[source]

Bases: object

class selfdrive.controls.lib.events.ET[source]

Bases: object

ENABLE = 'enable'
IMMEDIATE_DISABLE = 'immediateDisable'
NO_ENTRY = 'noEntry'
OVERRIDE_LATERAL = 'overrideLateral'
OVERRIDE_LONGITUDINAL = 'overrideLongitudinal'
PERMANENT = 'permanent'
PRE_ENABLE = 'preEnable'
SOFT_DISABLE = 'softDisable'
USER_DISABLE = 'userDisable'
WARNING = 'warning'
class selfdrive.controls.lib.events.EngagementAlert(audible_alert: <capnp.lib.capnp._EnumModule object at 0x7f3309037450>)[source]

Bases: Alert

class selfdrive.controls.lib.events.Events[source]

Bases: object

add(event_name: int, static: bool = False) None[source]
add_from_msg(events)[source]
clear() None[source]
contains(event_type: str) bool[source]
create_alerts(event_types: list[str], callback_args=None)[source]
property names: list[int]
to_msg()[source]
class selfdrive.controls.lib.events.ImmediateDisableAlert(alert_text_2: str)[source]

Bases: Alert

class selfdrive.controls.lib.events.NoEntryAlert(alert_text_2: str, alert_text_1: str = 'openpilot Unavailable', visual_alert: <capnp.lib.capnp._EnumModule object at 0x7f3309037250> = 0)[source]

Bases: Alert

class selfdrive.controls.lib.events.NormalPermanentAlert(alert_text_1: str, alert_text_2: str = '', duration: float = 0.2, priority: Priority = Priority.LOWER, creation_delay: float = 0.0)[source]

Bases: Alert

class selfdrive.controls.lib.events.Priority(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

HIGH = 4
HIGHEST = 5
LOW = 2
LOWER = 1
LOWEST = 0
MID = 3
class selfdrive.controls.lib.events.SoftDisableAlert(alert_text_2: str)[source]

Bases: Alert

class selfdrive.controls.lib.events.StartupAlert(alert_text_1: str, alert_text_2: str = 'Always keep hands on wheel and eyes on road', alert_status=0)[source]

Bases: Alert

class selfdrive.controls.lib.events.UserSoftDisableAlert(alert_text_2: str)[source]

Bases: SoftDisableAlert

selfdrive.controls.lib.events.below_engage_speed_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.below_steer_speed_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.calibration_incomplete_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.calibration_invalid_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.camera_malfunction_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.comm_issue_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.get_display_speed(speed_ms: float, metric: bool) str[source]
selfdrive.controls.lib.events.high_cpu_usage_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.joystick_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.low_memory_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.modeld_lagging_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.no_gps_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.out_of_space_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.overheat_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.posenet_invalid_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.process_not_running_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.soft_disable_alert(alert_text_2: str) Alert][source]
selfdrive.controls.lib.events.startup_master_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]
selfdrive.controls.lib.events.user_soft_disable_alert(alert_text_2: str) Alert][source]
selfdrive.controls.lib.events.wrong_car_mode_alert(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>, CS: <capnp.lib.capnp._StructModule object at 0x7f3309034f50>, sm: ~cereal.messaging.SubMaster, metric: bool, soft_disable_time: int) Alert[source]

selfdrive.controls.lib.latcontrol module

class selfdrive.controls.lib.latcontrol.LatControl(CP, CI)[source]

Bases: ABC

reset()[source]
abstract update(active, CS, VM, params, steer_limited, desired_curvature, llk)[source]

selfdrive.controls.lib.latcontrol_angle module

class selfdrive.controls.lib.latcontrol_angle.LatControlAngle(CP, CI)[source]

Bases: LatControl

update(active, CS, VM, params, steer_limited, desired_curvature, llk)[source]

selfdrive.controls.lib.latcontrol_pid module

class selfdrive.controls.lib.latcontrol_pid.LatControlPID(CP, CI)[source]

Bases: LatControl

reset()[source]
update(active, CS, VM, params, steer_limited, desired_curvature, llk)[source]

selfdrive.controls.lib.latcontrol_torque module

class selfdrive.controls.lib.latcontrol_torque.LatControlTorque(CP, CI)[source]

Bases: LatControl

update(active, CS, VM, params, steer_limited, desired_curvature, llk)[source]
update_live_torque_params(latAccelFactor, latAccelOffset, friction)[source]

selfdrive.controls.lib.longcontrol module

class selfdrive.controls.lib.longcontrol.LongControl(CP)[source]

Bases: object

reset(v_pid)[source]

Reset PID controller and change setpoint

update(active, CS, long_plan, accel_limits, t_since_plan)[source]

Update longitudinal control. This updates the state machine and runs a PID loop

selfdrive.controls.lib.longcontrol.long_control_state_trans(CP, active, long_control_state, v_ego, v_target, v_target_1sec, brake_pressed, cruise_standstill)[source]

selfdrive.controls.lib.longitudinal_planner module

class selfdrive.controls.lib.longitudinal_planner.LongitudinalPlanner(CP, init_v=0.0, init_a=0.0, dt=0.05)[source]

Bases: object

static parse_model(model_msg, model_error)[source]
publish(sm, pm)[source]
update(sm)[source]
selfdrive.controls.lib.longitudinal_planner.get_max_accel(v_ego)[source]
selfdrive.controls.lib.longitudinal_planner.limit_accel_in_turns(v_ego, angle_steers, a_target, CP)[source]

This function returns a limited long acceleration allowed, depending on the existing lateral acceleration this should avoid accelerating when losing the target in turns

selfdrive.controls.lib.pid module

class selfdrive.controls.lib.pid.PIDController(k_p, k_i, k_f=0.0, k_d=0.0, pos_limit=1e+308, neg_limit=-1e+308, rate=100)[source]

Bases: object

property error_integral
property k_d
property k_i
property k_p
reset()[source]
update(error, error_rate=0.0, speed=0.0, override=False, feedforward=0.0, freeze_integrator=False)[source]

selfdrive.controls.lib.vehicle_model module

Dynamic bicycle model from “The Science of Vehicle Dynamics (2014), M. Guiggiani”

The state is x = [v, r]^T with v lateral speed [m/s], and r rotational speed [rad/s]

The input u is the steering angle [rad], and roll [rad]

The system is defined by x_dot = A*x + B*u

A depends on longitudinal speed, u [m/s], and vehicle parameters CP

class selfdrive.controls.lib.vehicle_model.VehicleModel(CP: <capnp.lib.capnp._StructModule object at 0x7f3309037850>)[source]

Bases: object

calc_curvature(sa: float, u: float, roll: float) float[source]

Returns the curvature. Multiplied by the speed this will give the yaw rate.

Args:

sa: Steering wheel angle [rad] u: Speed [m/s] roll: Road Roll [rad]

Returns:

Curvature factor [1/m]

curvature_factor(u: float) float[source]

Returns the curvature factor. Multiplied by wheel angle (not steering wheel angle) this will give the curvature.

Args:

u: Speed [m/s]

Returns:

Curvature factor [1/m]

get_steer_from_curvature(curv: float, u: float, roll: float) float[source]

Calculates the required steering wheel angle for a given curvature

Args:

curv: Desired curvature [1/m] u: Speed [m/s] roll: Road Roll [rad]

Returns:

Steering wheel angle [rad]

get_steer_from_yaw_rate(yaw_rate: float, u: float, roll: float) float[source]

Calculates the required steering wheel angle for a given yaw_rate

Args:

yaw_rate: Desired yaw rate [rad/s] u: Speed [m/s] roll: Road Roll [rad]

Returns:

Steering wheel angle [rad]

roll_compensation(roll: float, u: float) float[source]

Calculates the roll-compensation to curvature

Args:

roll: Road Roll [rad] u: Speed [m/s]

Returns:

Roll compensation curvature [rad]

steady_state_sol(sa: float, u: float, roll: float) ndarray[source]

Returns the steady state solution.

If the speed is too low we can’t use the dynamic model (tire slip is undefined), we then have to use the kinematic model

Args:

sa: Steering wheel angle [rad] u: Speed [m/s] roll: Road Roll [rad]

Returns:

2x1 matrix with steady state solution (lateral speed, rotational speed)

update_params(stiffness_factor: float, steer_ratio: float) None[source]

Update the vehicle model with a new stiffness factor and steer ratio

yaw_rate(sa: float, u: float, roll: float) float[source]

Calculate yaw rate

Args:

sa: Steering wheel angle [rad] u: Speed [m/s] roll: Road Roll [rad]

Returns:

Yaw rate [rad/s]

selfdrive.controls.lib.vehicle_model.calc_slip_factor(VM: VehicleModel) float[source]

The slip factor is a measure of how the curvature changes with speed it’s positive for Oversteering vehicle, negative (usual case) otherwise.

selfdrive.controls.lib.vehicle_model.create_dyn_state_matrices(u: float, VM: VehicleModel) tuple[ndarray, ndarray][source]

Returns the A and B matrix for the dynamics system

Args:

u: Vehicle speed [m/s] VM: Vehicle model

Returns:

A tuple with the 2x2 A matrix, and 2x2 B matrix

Parameters in the vehicle model:

cF: Tire stiffness Front [N/rad] cR: Tire stiffness Front [N/rad] aF: Distance from CG to front wheels [m] aR: Distance from CG to rear wheels [m] m: Mass [kg] j: Rotational inertia [kg m^2] sR: Steering ratio [-] chi: Steer ratio rear [-]

selfdrive.controls.lib.vehicle_model.dyn_ss_sol(sa: float, u: float, roll: float, VM: VehicleModel) ndarray[source]

Calculate the steady state solution when x_dot = 0, Ax + Bu = 0 => x = -A^{-1} B u

Args:

sa: Steering angle [rad] u: Speed [m/s] roll: Road Roll [rad] VM: Vehicle model

Returns:

2x1 matrix with steady state solution

selfdrive.controls.lib.vehicle_model.kin_ss_sol(sa: float, u: float, VM: VehicleModel) ndarray[source]

Calculate the steady state solution at low speeds At low speeds the tire slip is undefined, so a kinematic model is used.

Args:

sa: Steering angle [rad] u: Speed [m/s] VM: Vehicle model

Returns:

2x1 matrix with steady state solution

Module contents