States
In this section of the documentation we explain the default vehicle state type provided by AutomotiveDrivingModels
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 provided by Records.jl
(https://github.com/sisl/Records.jl/blob/master/src/entities.jl). The Entity
data type has three fields: a state, a definition and an id.
The state of an entity usually describes physical quantity such as position and velocity.
Two state data structures are provided.
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 AutomotiveDrivingModels can work smoothly with your custom state type.
AutomotiveDrivingModels.posg
— Functionposg(state)
returns the coordinates of the state in the global (world) frame. The return type is expected to be a VecSE2.
AutomotiveDrivingModels.posf
— Functionposf(state)
returns the coordinates of the state in the Frenet frame. The return type is expected to be Frenet
.
AutomotiveDrivingModels.vel
— Functionvel(state)
returns the norm of the longitudinal velocity.
AutomotiveDrivingModels.velf
— Functionvelf(state)
returns the velocity of the state in the Frenet frame.
AutomotiveDrivingModels.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)
1D states and vehicles
AutomotiveDrivingModels.State1D
— TypeState1D
A data type to represent one dimensional states
Fields
- `s::Float64` position
- `v::Float64` speed [m/s]
AutomotiveDrivingModels.Vehicle1D
— TypeVehicle1D
A specific instance of the Entity type defined in Records.jl to represent vehicles in 1d environments.
2D states and vehicles
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.
AutomotiveDrivingModels.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
AutomotiveDrivingModels.Vec.lerp
— MethodVec.lerp(a::VehicleState, b::VehicleState, t::Float64, roadway::Roadway)
Perform linear interpolation of the two vehicle states. Returns a VehicleState.
AutomotiveDrivingModels.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.
AutomotiveDrivingModels.Vehicle
— TypeVehicle
A specific instance of the Entity type defined in Records to represent Vehicles with state VehicleState
, definition VehicleDef
and id Int64
AutomotiveDrivingModels.get_front
— Functionget_front(veh::Entity{VehicleState, VehicleDef, I})
returns the position of the front of the vehicle
AutomotiveDrivingModels.get_rear
— Functionget_rear(veh::Entity{VehicleState, VehicleDef, I})
returns the position of the rear of the vehicle
AutomotiveDrivingModels.get_center
— Functionget_center(veh::Entity{VehicleState, D, I})
returns the position of the center of the vehicle
AutomotiveDrivingModels.get_footpoint
— Functionget_footpoint(veh::Entity{VehicleState, D, I})
returns the position of the footpoint of the vehicle
AutomotiveDrivingModels.get_lane
— Functionget_lane(roadway::Roadway, vehicle::Entity)
get_lane(roadway::Roadway, vehicle::VehicleState)
return the lane where vehicle
is in.
AutomotiveDrivingModels.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
AutomotiveDrivingModels.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{Vehicle}, veh::Entity{VehicleState, D, Int64}) where D<:AbstractAgentDefinition
Converts an entity in Vehicle (it is converting the agent definition only)
Scenes
A Scene represents a collection of vehicles at a given time.
AutomotiveDrivingModels.Scene
— TypeScene
A Scene is a specific instance of the Frame type defined in Records. It represents a collection of vehicles at a given time.
Constructors
- `Scene(n::Int=100)`
- `Scene(arr::Vector{Vehicle})`
AutomotiveDrivingModels.SceneRecord
— TypeSceneRecord
A SceneRecord is a specific instance of the QueueRecord type defined in Records.jl. It represents a collection of Scenes.
constructor
SceneRecord(capacity::Int, timestep::Float64, frame_capacity::Int=100)
AutomotiveDrivingModels.Trajdata
— TypeTrajdata
Trajdata is a specific instance of ListRecord defined in Records.jl. It is a collection of Scenes