selfdrive.controls.lib package
Subpackages
- selfdrive.controls.lib.lateral_mpc_lib package
- selfdrive.controls.lib.longitudinal_mpc_lib package
- selfdrive.controls.lib.tests package
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
- alert: Alert | None = None
- end_frame: int = -1
- start_frame: int = -1
selfdrive.controls.lib.desire_helper module
selfdrive.controls.lib.drive_helpers module
- class selfdrive.controls.lib.drive_helpers.VCruiseHelper(CP)[source]
Bases:
object
- property v_cruise_initialized
- 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.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.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.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.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.latcontrol module
selfdrive.controls.lib.latcontrol_angle module
selfdrive.controls.lib.latcontrol_pid module
selfdrive.controls.lib.latcontrol_torque module
selfdrive.controls.lib.longcontrol module
selfdrive.controls.lib.longitudinal_planner module
selfdrive.controls.lib.pid module
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)
- 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