selfdrive.controls.lib package

Subpackages

Submodules

selfdrive.controls.lib.alertmanager module

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

Bases: object

active(frame: int) bool[source]
alert: Optional[Alert] = 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) Optional[Alert][source]
selfdrive.controls.lib.alertmanager.set_offroad_alert(alert: str, show_alert: bool, extra_text: Optional[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.MPC_COST_LAT[source]

Bases: object

HEADING = 1.0
PATH = 1.0
STEER_RATE = 1.0
selfdrive.controls.lib.drive_helpers.apply_deadzone(error, deadzone)[source]
selfdrive.controls.lib.drive_helpers.get_lag_adjusted_curvature(CP, v_ego, psis, curvatures, curvature_rates)[source]
selfdrive.controls.lib.drive_helpers.initialize_v_cruise(v_ego, buttonEvents, v_cruise_last)[source]
selfdrive.controls.lib.drive_helpers.rate_limit(new_value, last_value, dw_step, up_step)[source]
selfdrive.controls.lib.drive_helpers.update_v_cruise(v_cruise_kph, v_ego, gas_pressed, buttonEvents, button_timers, enabled, metric)[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 0x7fad9f78eb50>, alert_size: <capnp.lib.capnp._EnumModule object at 0x7fad9f78ec10>, priority: ~selfdrive.controls.lib.events.Priority, visual_alert: <capnp.lib.capnp._EnumModule object at 0x7fad9f770490>, audible_alert: <capnp.lib.capnp._EnumModule object at 0x7fad9f770520>, 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 0x7fad9f770520>)[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]
any(event_type: str) bool[source]
clear() None[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 0x7fad9f770490> = 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)[source]

Bases: IntEnum

An enumeration.

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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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 0x7fad9f770400>, CS: <capnp.lib.capnp._StructModule object at 0x7fad9f75d670>, 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, last_actuators, steer_limited, desired_curvature, desired_curvature_rate, 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, last_actuators, steer_limited, desired_curvature, desired_curvature_rate, llk)[source]

selfdrive.controls.lib.latcontrol_indi module

class selfdrive.controls.lib.latcontrol_indi.LatControlINDI(CP, CI)[source]

Bases: LatControl

property G
property RC
property inner_loop_gain
property outer_loop_gain
reset()[source]
update(active, CS, VM, params, last_actuators, steer_limited, desired_curvature, desired_curvature_rate, 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, last_actuators, steer_limited, desired_curvature, desired_curvature_rate, 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, last_actuators, steer_limited, desired_curvature, desired_curvature_rate, llk)[source]
update_live_torque_params(latAccelFactor, latAccelOffset, friction)[source]

selfdrive.controls.lib.lateral_planner module

class selfdrive.controls.lib.lateral_planner.LateralPlanner(CP)[source]

Bases: object

publish(sm, pm)[source]
reset_mpc(x0=array([0., 0., 0., 0.]))[source]
update(sm)[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)[source]

Bases: object

parse_model(model_msg)[source]
publish(sm, pm)[source]
read_param()[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.radar_helpers module

class selfdrive.controls.lib.radar_helpers.Cluster[source]

Bases: object

property aLeadK
property aLeadTau
property aRel
add(t)[source]
property dPath
property dRel
get_RadarState(model_prob=0.0)[source]
get_RadarState_from_vision(lead_msg, v_ego)[source]
is_potential_fcw(model_prob)[source]
property measured
potential_low_speed_lead(v_ego)[source]
property vLat
property vLead
property vLeadK
property vRel
property yRel
class selfdrive.controls.lib.radar_helpers.Track(v_lead, kalman_params)[source]

Bases: object

get_key_for_cluster()[source]
reset_a_lead(aLeadK, aLeadTau)[source]
update(d_rel, y_rel, v_rel, v_lead, measured)[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 0x7fad9f770400>)[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