States
In this section of the documentation we explain the default vehicle state type provided by AutomotiveSimulator
as well as the data types used to represent a driving scene. Most of the underlying structures are defined in Records.jl
. The data structures provided in ADM.jl are concrete instances of parametric types defined in Records. It is possible in principle to define your custom state definition and use the interface defined in ADM.jl.
Entity state
Entities are represented by the Entity
data type. The Entity
data type has three fields: a state, a definition and an id.
AutomotiveSimulator.Entity
— TypeEntity{S,D,I}
Immutable data structure to represent entities (vehicle, pedestrian, ...). Entities are defined by a state, a definition, and an id. The state of an entity usually models changing values while the definition and the id should not change.
Constructor
Entity(state, definition, id)
Copy constructor that keeps the definition and id but changes the state (a new object is still created):
Entity(entity::Entity{S,D,I}, s::S)
Fields
state::S
def::D
id::I
The state of an entity usually describes physical quantity such as position and velocity.
Two state data structures are provided.
Scenes
Scenes are represented using the Scene
object. It is a datastructure to represent a collection of entities.
AutomotiveSimulator.Scene
— TypeScene{E}
Container to store a list of entities. The main difference from a regular array is that its size is defined at construction and is fixed. (push!
is O(1))
Constructors
Scene(arr::AbstractVector; capacity::Int=length(arr))
Scene(::Type{E}, capacity::Int=100) where {E}
Fields
To interact with Scene
object it is preferable to use functions rather than accessing the fields directly.
entities::Vector{E}
n::Int
current number of entities in the scene
Defining your own state type
You can define your own state type if the provided VehicleState
does not contain the right information. There are a of couple functions that need to be defined such that other functions in AutomotiveSimulator can work smoothly with your custom state type.
AutomotiveSimulator.posg
— Functionposg(state)
returns the coordinates of the state in the global (world) frame. The return type is expected to be a VecSE2.
AutomotiveSimulator.posf
— Functionposf(state)
returns the coordinates of the state in the Frenet frame. The return type is expected to be Frenet
.
AutomotiveSimulator.vel
— Functionvel(state)
returns the norm of the longitudinal velocity.
AutomotiveSimulator.velf
— Functionvelf(state)
returns the velocity of the state in the Frenet frame.
AutomotiveSimulator.velg
— Functionvelg(state)
returns the velocity of the state in the global (world) frame.
Example of a custom state type containing acceleration:
# you can use composition to define your custom state type based on existing ones
struct MyVehicleState
veh::VehicleState
acc::Float64
end
# define the functions from the interface
posg(s::MyVehicleState) = posg(s.veh) # those functions are implemented for the `VehicleState` type
posf(s::MyVehicleState) = posf(s.veh)
velg(s::MyVehicleState) = velg(s.veh)
velf(s::MyVehicleState) = velf(s.veh)
vel(s::MyVehicleState) = vel(s.veh)
Provided State Type and Convenient Functions
Here we list useful functions to interact with vehicle states and retrieve interesting information like the position of the front of the vehicle or the lane to which the vehicle belongs.
AutomotiveSimulator.VehicleState
— TypeVehicleState
A default type to represent an agent physical state (position, velocity). It contains the position in the global frame, Frenet frame and the longitudinal velocity
constructors
VehicleState(posG::VecSE2{Float64}, v::Float64)
VehicleState(posG::VecSE2{Float64}, roadway::Roadway, v::Float64)
VehicleState(posG::VecSE2{Float64}, lane::Lane, roadway::Roadway, v::Float64)
VehicleState(posF::Frenet, roadway::Roadway, v::Float64)
fields
posG::VecSE2{Float64}
global positionposF::Frenet
lane relative positionv::Float64
longitudinal velocity
AutomotiveSimulator.Vec.lerp
— MethodVec.lerp(a::VehicleState, b::VehicleState, t::Float64, roadway::Roadway)
Perform linear interpolation of the two vehicle states. Returns a VehicleState.
AutomotiveSimulator.move_along
— Methodmove_along(vehstate::VehicleState, roadway::Roadway, Δs::Float64;
ϕ₂::Float64=vehstate.posF.ϕ, t₂::Float64=vehstate.posF.t, v₂::Float64=vehstate.v)
returns a vehicle state after moving vehstate of a length Δs along its lane.
AutomotiveSimulator.get_front
— Functionget_front(veh::Entity{VehicleState, VehicleDef, I})
returns the position of the front of the vehicle
AutomotiveSimulator.get_rear
— Functionget_rear(veh::Entity{VehicleState, VehicleDef, I})
returns the position of the rear of the vehicle
AutomotiveSimulator.get_center
— Functionget_center(veh::Entity{VehicleState, D, I})
returns the position of the center of the vehicle
AutomotiveSimulator.get_footpoint
— Functionget_footpoint(veh::Entity{VehicleState, D, I})
returns the position of the footpoint of the vehicle
AutomotiveSimulator.get_lane
— Functionget_lane(roadway::Roadway, vehicle::Entity)
get_lane(roadway::Roadway, vehicle::VehicleState)
return the lane where vehicle
is in.
AutomotiveSimulator.leftlane
— Methodleftlane(roadway::Roadway, veh::Entity)
returns the lane to the left of the lane veh is currently in, returns nothing if it does not exists
AutomotiveSimulator.rightlane
— Methodrightlane(roadway::Roadway, veh::Entity)
returns the lane to the right of the lane veh is currently in, returns nothing if it does not exists
Base.convert
— MethodBase.convert(::Type{Entity{S, VehicleDef, I}}, veh::Entity{S, D, I}) where {S,D<:AbstractAgentDefinition,I}
Converts the definition of an entity