Behaviors
These stands one level above the actions
. They provide a higher level decision that the actions
then implement in order to propagate the simulation forward.
A behavior model can be interpreted as a control law. Given the current scene, representing all the vehicles present in the environment, a behavior model returns an action to execute.
Interface
We provide an interface to interact with behavior model or implement your own. To implement your own driver model you can create a type that inherits from the abstract type DriverModel
. Then you can implement the following methods:
AutomotiveSimulator.DriverModel
— TypeDriverModel{DriveAction}
A DriverModel represents a specific driving behavior. It specifies the action taken by the agent at a given scene. The ation will be of type DriveAction
. It can be interpreted as a distribution, the likelihood of taking a certain action in a given scene. The DriverModel type is an abstract type! Custom driver models should inherit from it.
AutomotiveSimulator.action_type
— Methodaction_type(::DriverModel{A}) where {A}
returns the type of the actions that are sampled from the model
AutomotiveSimulator.set_desired_speed!
— Functionset_desired_speed!(model::DriverModel, v_des::Float64)
Sets a desired speed. This method is relevant for models like IDM where the vehicle tracks a nominal speed.
reset_hidden_state!(model::DriverModel)
Resets the hidden states of the model.
reset_hidden_states!(models::Dict{I,M}) where {M<:DriverModel}
reset hidden states of all driver models in models
AutomotiveSimulator.observe!
— Functionobserve!(model::DriverModel, scene, roadway, egoid)
Observes the scene and updates the model states accordingly.
Base.rand
— Methodrand(model::DriverModel)
rand(rng::AbstractRNG, model::DriverModel)
Samples an action from the model.
observe!
and rand
are usually the most important methods to implement. observe!
sets the model state in a given situation and rand
allows to sample an action from the model.
Available Behaviors
AutomotiveSimulator.IntelligentDriverModel
— TypeIntelligentDriverModel <: LaneFollowingDriver
The Intelligent Driver Model. A rule based driving model that is governed by parameter settings. The output is an longitudinal acceleration.
Here, we have extended IDM to the errorable IDM. If a standard deviation parameter is specified, then the output is a longitudinal acceleration sampled from a normal distribution around the non-errorable IDM output.
Fields
a::Float64 = NaN
the predicted acceleration i.e. the output of the modelσ::Float64 = NaN
allows errorable IDM, optional stdev on top of the model, set to zero or NaN for deterministic behaviork_spd::Float64 = 1.0
proportional constant for speed tracking when in freeflow [s⁻¹]δ::Float64 = 4.0
acceleration exponentT::Float64 = 1.5
desired time headway [s]v_des::Float64 = 29.0
desired speed [m/s]s_min::Float64 = 5.0
minimum acceptable gap [m]a_max::Float64 = 3.0
maximum acceleration ability [m/s²]d_cmf::Float64 = 2.0
comfortable deceleration m/s²d_max::Float64 = 9.0
maximum deceleration m/s²
AutomotiveSimulator.Tim2DDriver
— TypeTim2DDriver
Driver that combines longitudinal driver and lateral driver into one model.
Constructors
Tim2DDriver(;kwargs...)
The keywords argument are the fields described below.
Fields
mlon::LaneFollowingDriver = IntelligentDriverModel()
Longitudinal driving modelmlat::LateralDriverModel = ProportionalLaneTracker()
Lateral driving modelmlane::LaneChangeModel =TimLaneChanger
Lane change model
AutomotiveSimulator.PrincetonDriver
— TypePrincetonDriver <: LaneFollowingDriver
A lane following driver model that controls longitudinal speed by following a front car.
Fields
a::Float64
σ::Float64 = NaN
optional stdev on top of the model, set to zero or NaN for deterministic behaviork::Float64 = 1.0
proportional constant for speed tracking [s⁻¹]v_des::Float64 = 29.0
desired speed [m/s]
AutomotiveSimulator.SidewalkPedestrianModel
— TypeSidewalkPedestrianModel
Walks along the sidewalk until approaching the crosswalk. Waits for the cars to pass, then crosses.
Fields
timestep::Float64
phase::Int = APPROACHING
ttc_threshold::Float64 = clamp(rand(Normal(4.0, 2.5)), 1.0, Inf)
crosswalk::Lane = Lane()
sw_origin::Lane = Lane()
sw_dest::Lane = Lane()
a::PedestrianLatLonAccel = PedestrianLatLonAccel(0.0, 0.0, sw_origin)
makes you turn, left/rightσ::Float64 = NaN
optional stdev on top of the model, set to zero or NaN for deterministicv_des_approach::Float64 = clamp(rand(Normal(1.28, 0.18)), 0.0, Inf)
Based on Feliciani et al. resultsv_des_appraise::Float64 = clamp(rand(Normal(0.94, 0.21)), 0.0, Inf)
v_des_cross::Float64 = clamp(rand(Normal(1.35, 0.18)), 0.0, Inf)
ped_accel::Float64 = 0.30
ped_decel::Float64 = -0.50
AutomotiveSimulator.StaticDriver
— TypeStaticDriver{A,P<:ContinuousMultivariateDistribution} <: DriverModel{A}
A driver model where actions are always sampled by the same distribution specified by the field distribution
.
Fields
distribution::P
Lane change helper functions
These are not standalone driver models but are used by the driver models to do lane changing and lateral control.
AutomotiveSimulator.MOBIL
— TypeMOBIL
See Treiber & Kesting, 'Modeling Lane-Changing Decisions with MOBIL'
Constructor
MOBIL(;kwargs...)
The keyword arguments are the fields highlighted below.
Fields
dir::Int = DIR_MIDDLE
mlon::LaneFollowingDriver=IntelligentDriverModel()
safe_decel::Float64=2.0
politeness::Float64=0.35
advantage_threshold::Float64=0.1
AutomotiveSimulator.TimLaneChanger
— TypeTimLaneChanger
A simple lane change behavior that changes lanes whenever the lead car is going slower than our desired speed. Lane changes are made when there is an available lane, fore/rear gaps exceed our thresholds, we are faster than a rear vehicle in the target lane, and any lead vehicle in the target lane is faster than we can currently go.
Has not been published anywhere, so first use in a paper would have to describe this. See MOBIL if you want a lane changer you can cite.
Constructors
TimLaneChanger(v_des::Float64=29.0, threshold_fore::Float64 = 50.0,threshold_lane_change_gap_fore::Float64 = 10.0, threshold_lane_change_gap_rear::Float64 = 10.0,dir::Int=DIR_MIDDLE)
Fields
dir::Int = DIR_MIDDLE
the desired lane to go to eg: left,middle (i.e. stay in same lane) or rightv_des::Float64 = 29.0
desired velocitythreshold_fore::Float64 = 50.0
Distance from lead vehiclethreshold_lane_change_gap_fore::Float64 = 10.0
Space in frontthreshold_lane_change_gap_rear::Float64 = 10.0
Space rear
AutomotiveSimulator.ProportionalLaneTracker
— TypeProportionalLaneTracker
A controller that executes the lane change decision made by the lane change models
Constructors
ProportionalLaneTracker(;σ::Float64 = NaN,kp::Float64 = 3.0,kd::Float64 = 2.0)
Fields
a::Float64 = NaN
predicted accelerationσ::Float64 = NaN
optional stdev on top of the model, set to zero or NaN for deterministic behaviorkp::Float64 = 3.0
proportional constant for lane trackingkd::Float64 = 2.0
derivative constant for lane tracking
Longitudinal helper functions
These are not standalone driver models but are used to do longitudinal control by the driver models.
AutomotiveSimulator.ProportionalSpeedTracker
— TypeProportionalSpeedTracker <: LaneFollowingDriver
Longitudinal proportional speed control.
Fields
a::Float64 = NaN
predicted accelerationσ::Float64 = NaN
optional stdev on top of the model, set to zero or NaN for deterministic behaviork::Float64 = 1.0
proportional constant for speed tracking [s⁻¹]v_des::Float64 = 29.0
desired speed [m/s]