Roadways
Data Types and Accessing Elements
The data structure to represent roadways can be decomposed as follows:
- Roadway The high level type containing all the information. It contains a list of
RoadSegment
.- RoadSegment: a vector of lanes
- Lane: A driving lane on a roadway. It identified by a
LaneTag
. A lane is defined by a curve which
- Lane: A driving lane on a roadway. It identified by a
- RoadSegment: a vector of lanes
represents a center line and a width. In addition it has attributed like speed limit. A lane can be connected to other lane in the roadway, the connection are specified in the exits and entrances fields.
Lower level types:
- Curves: A curve is a list of
CurvePt
- CurvePt: the lowest level type. It represents a point on a curve by its global position, position along the curve, curvature at this point and derivative of the curvature at this point. Other types like
CurveIndex
orCurveProjection
are used to identify a curve point along a curve.
AutomotiveDrivingModels.Roadway
— TypeRoadway
The main datastructure to represent road network, it consists of a list of RoadSegment
Fields
segments::Vector{RoadSegment}
AutomotiveDrivingModels.RoadSegment
— TypeRoadSegment{T}
a list of lanes forming a single road with a common direction
Fields
id::Int64
lanes::Vector{Lane{T}}
lanes are stored right to left
AutomotiveDrivingModels.move_along
— Functionmove_along(roadind::RoadIndex, road::Roadway, Δs::Float64)
Return the RoadIndex at ind's s position + Δs
move_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.
Roadway generation
AutomotiveDrivingModels.jl
provide high level functions to generate road networks by drawing straight road segment and circular curves. Two predefined road network can be generated easily: multi-lane straight roadway sections and a multi-lane stadium shaped roadway.
AutomotiveDrivingModels.gen_straight_curve
— Functiongen_straight_curve(A::VecE2{T}, B::VecE2{T}, nsamples::Integer) where T<:Real
Returns a Curve
corresponding to a straight line between A and B. nsamples
indicates the number of points to place between A and B, if set to two, the curve will only contains A and B.
AutomotiveDrivingModels.gen_straight_segment
— Functiongen_straight_segment(seg_id::Integer, nlanes::Integer, length::Float64=1000.0;
Generate a straight RoadSegment
with nlanes
number of lanes of length length
.
AutomotiveDrivingModels.gen_bezier_curve
— Functiongen_bezier_curve(A::VecSE2{T}, B::VecSE2{T}, rA::T, rB::T, nsamples::Int) where T <: Real
Generate a Bezier curve going from A to B with radii specified by rA and rB. It uses cubic interpolation. nsamples
specifies the number of point along the curve between A and B. The more points, the more accurate the approximation is. This is useful to generate arcs.
AutomotiveDrivingModels.gen_straight_roadway
— Functiongen_straight_roadway(nlanes::Int, length::Float64)
Generate a roadway with a single straight segment whose rightmost lane center starts at starts at (0,0), and proceeds in the positive x direction.
AutomotiveDrivingModels.gen_stadium_roadway
— Functiongen_stadium_roadway(nlanes::Int; length::Float64=100.0; width::Float64=10.0; radius::Float64=25.0)
Generate a roadway that is a rectangular racetrack with rounded corners. length = length of the x-dim straight section for the innermost (leftmost) lane [m] width = length of the y-dim straight section for the innermost (leftmost) lane [m] radius = turn radius [m]
______________________
/ \
| |
| |
\______________________/
Lane
The Lane
data structure represent a driving lane in the roadway. The default lane width is 3m. It contains all the low level geometry information.
AutomotiveDrivingModels.Lane
— TypeLane
A driving lane on a roadway. It identified by a LaneTag
. A lane is defined by a curve which represents a center line and a width. In addition it has attributed like speed limit. A lane can be connected to other lane in the roadway, the connection are specified in the exits and entrances fields.
Fields
tag::LaneTag
curve::Curve
width::Float64
[m]speed_limit::SpeedLimit
boundary_left::LaneBoundary
boundary_right::LaneBoundary
exits::Vector{LaneConnection} # list of exits; put the primary exit (at end of lane) first
entrances::Vector{LaneConnection} # list of entrances; put the primary entrance (at start of lane) first
AutomotiveDrivingModels.LaneTag
— TypeLaneTag
An identifier for a lane. The lane object can be retrieved by indexing the roadway by the lane tag:
tag = LaneTag(1, 2) # second lane segment 1
lane = roadway[tag] # returns a Lane object
Fields
segment::Int64
segment idlane::Int64
index in segment.lanes of this lane
AutomotiveDrivingModels.lanes
— Functionlanes(roadway::Roadway{T}) where T
return a list of all the lanes present in roadway.
AutomotiveDrivingModels.lanetags
— Functionlanetags(roadway::Roadway)
return a list of all the lane tags present in roadway.
AutomotiveDrivingModels.SpeedLimit
— TypeSpeedLimit
Datastructure to represent a speed limit
Fields
lo::Float64
[m/s] lower speed limithi::Float64
[m/s] higher speed limit
AutomotiveDrivingModels.LaneBoundary
— TypeLaneBoundary
Data structure to represent lanes boundaries such as double yellow lines.
Fields
- `style::Symbol` ∈ :solid, :broken, :double
- `color::Symbol` ∈ :yellow, white
AutomotiveDrivingModels.LaneConnection
— TypeLaneConnection{I <: Integer, T <: Real}
Data structure to specify the connection of a lane. It connects mylane
to the point target
. target
would typically be the starting point of a new lane.
downstream::Bool
mylane::CurveIndex{I,T}
target::RoadIndex{I,T}
AutomotiveDrivingModels.is_in_exits
— Functionis_in_exits(lane::Lane, target::LaneTag)
returns true if target
is in the exit lanes of lane
.
AutomotiveDrivingModels.is_in_entrances
— Functionis_in_entrances(lane::Lane, target::LaneTag)
returns true if target
is in the entrances lanes of lane
.
AutomotiveDrivingModels.connect!
— Functionconnect!(source::Lane, dest::Lane)
connect two lanes to each other. Useful for roadway construction.
AutomotiveDrivingModels.is_between_segments_hi
— Functionis_between_segments_hi(ind::CurveIndex, curve::Curve)
AutomotiveDrivingModels.is_between_segments
— Functionis_between_segments(ind::CurveIndex, curve::Curve)
AutomotiveDrivingModels.has_segment
— Functionhas_segment(roadway::Roadway, segid::Int)
returns true if segid
is in roadway
.
AutomotiveDrivingModels.has_lanetag
— Functionhas_lanetag(roadway::Roadway, tag::LaneTag)
returns true if roadway
contains a lane identified by tag
AutomotiveDrivingModels.next_lane
— Functionnext_lane(lane::Lane, roadway::Roadway)
returns the lane connected to the end lane
. If lane
has several exits, it returns the first one
AutomotiveDrivingModels.prev_lane
— Functionprev_lane(lane::Lane, roadway::Roadway)
returns the lane connected to the beginning lane
. If lane
has several entrances, it returns the first one
AutomotiveDrivingModels.has_next
— Functionhas_next(lane::Lane)
returns true if the end of the lane is connected to another lane (i.e. if it has an exit lane)
AutomotiveDrivingModels.has_prev
— Functionhas_prev(lane::Lane)
returns true if another lane is connected to the beginning of that lane. (i.e. if it has an entrance lane)
AutomotiveDrivingModels.next_lane_point
— Functionnext_lane_point(lane::Lane, roadway::Roadway)
returns the point of connection between lane
and its first exit
AutomotiveDrivingModels.prev_lane_point
— Functionprev_lane_point(lane::Lane, roadway::Roadway)
returns the point of connection between lane
and its first entrance
AutomotiveDrivingModels.n_lanes_left
— Methodn_lanes_left(roadway::Roadway, lane::Lane)
returns the number of lanes to the left of lane
AutomotiveDrivingModels.n_lanes_right
— Methodn_lanes_right(roadway::Roadway, lane::Lane)
returns the number of lanes to the right of lane
AutomotiveDrivingModels.leftlane
— Methodleftlane(roadway::Roadway, lane::Lane)
returns the lane to the left of lane if it exists, returns nothing otherwise
AutomotiveDrivingModels.rightlane
— Methodrightlane(roadway::Roadway, lane::Lane)
returns the lane to the right of lane if it exists, returns nothing otherwise
Frenet frame
The Frenet frame is a lane relative frame to represent a position on the road network.
AutomotiveDrivingModels.Frenet
— TypeFrenet
Represents a vehicle position and heading in a lane relative frame.
Constructors
Frenet(roadind::RoadIndex, roadway::Roadway; t::Float64=0.0, ϕ::Float64=0.0)
Frenet(roadproj::RoadProjection, roadway::Roadway)
Frenet(lane::Lane, s::Float64, t::Float64=0.0, ϕ::Float64=0.0)
Frenet(posG::VecSE2, roadway::Roadway)
Frenet(posG::VecSE2, lane::Lane, roadway::Roadway)
Fields
roadind
: road indexs
: distance along lanet
: lane offset, positive is to left. zero point is the centerline of the lane.ϕ
: lane relative heading
Accessing objects and projections
The main roadway
object can be indexed by different object to access different elements such as lane or curve points:
LaneTag
: indexing roadway by a lane tag will return the lane associated to the lane tagRoadIndex
: indexing roadway by a road index will return the curve point associated to this index
AutomotiveDrivingModels.RoadIndex
— TypeRoadIndex{I <: Integer, T <: Real}
A data structure to index points in a roadway. Calling roadway[roadind]
will return the point associated to the road index.
Fields
ind::CurveIndex{I,T}
the index of the point in the curvetag::LaneTag
the lane tag of the point
AutomotiveDrivingModels.CurveIndex
— TypeCurveIndex{I <: Integer, T <: Real}
Given a Curve
object curve
one can call curve[ind]
where ind
is a CurveIndex
. The field t
can be used to interpolate between two points in the curve.
Fields
i
::I` index in the curve , ∈ [1:length(curve)-1]t::T
∈ [0,1] for linear interpolation
AutomotiveDrivingModels.RoadProjection
— TypeRoadProjection{I <: Integer, T <: Real}
represents the projection of a point on the roadway
Fields
curveproj::CurveProjection{I, T}
tag::LaneTag
AutomotiveDrivingModels.Vec.proj
— Methodproj(posG::VecSE2{T}, lane::Lane, roadway::Roadway; move_along_curves::Bool=true) where T <: Real
Return the RoadProjection for projecting posG onto the lane. This will automatically project to the next or prev curve as appropriate. if move_along_curves
is false, will only project to lane.curve
AutomotiveDrivingModels.Vec.proj
— Methodproj(posG::VecSE2{T}, seg::RoadSegment, roadway::Roadway) where T <: Real
Return the RoadProjection for projecting posG onto the segment. Tries all of the lanes and gets the closest one
AutomotiveDrivingModels.Vec.proj
— Methodproj(posG::VecSE2{T}, seg::RoadSegment, roadway::Roadway) where T <: Real
Return the RoadProjection for projecting posG onto the roadway. Tries all of the lanes and gets the closest one
Base.getindex
— Methodlane[ind::CurveIndex, roadway::Roadway]
Accessor for lanes based on a CurveIndex. Note that we extend the definition of a CurveIndex, previously ind.i ∈ [1, length(curve)-1], to:
ind.i ∈ [0, length(curve)]
where 1 ≤ ind.i ≤ length(curve)-1 is as before, but if the index is on the section between two lanes, we use:
ind.i = length(curve), ind.t ∈ [0,1] for the region between curve[end] → next
ind.i = 0, ind.t ∈ [0,1] for the region between prev → curve[1]
Base.getindex
— MethodBase.getindex(roadway::Roadway, segid::Int)
returns the segment associated with id segid
Base.getindex
— MethodBase.getindex(roadway::Roadway, tag::LaneTag)
returns the lane identified by the tag LaneTag
Low level
AutomotiveDrivingModels.Curve
— TypeCurve{T}
is a vector of curve points
AutomotiveDrivingModels.CurvePt
— TypeCurvePt{T}
describes a point on a curve, associated with a curvature and the derivative of the curvature
pos::VecSE2{T}
# global position and orientations::T
# distance along the curvek::T
# curvaturekd::T
# derivative of curvature
AutomotiveDrivingModels.CurveProjection
— TypeCurveProjection{I <: Integer, T <: Real}
The result of a point projected to a Curve
Fields
ind::CurveIndex{I, T}
t::T
lane offsetϕ::T
lane-relative heading [rad]
AutomotiveDrivingModels.is_at_curve_end
— Functionis_at_curve_end(ind::CurveIndex, curve::Curve)
returns true if the curve index is at the end of the curve
AutomotiveDrivingModels.get_lerp_time
— Functionget_lerp_time(A::VecE2, B::VecE2, Q::VecE2)
Get lerp time t∈[0,1] such that lerp(A, B) is as close as possible to Q
AutomotiveDrivingModels.index_closest_to_point
— Functionindex_closest_to_point(curve::Curve, target::AbstractVec)
returns the curve index closest to the point described by target
. target
must be [x, y].
AutomotiveDrivingModels.get_curve_index
— Functionget_curve_index(curve::Curve{T}, s::T) where T <: Real
Return the CurveIndex for the closest s-location on the curve
get_curve_index(ind::CurveIndex, curve::Curve, Δs::T) where T <: Real
Return the CurveIndex at ind's s position + Δs
AutomotiveDrivingModels.Vec.lerp
— Methodcubic bezier lerp
AutomotiveDrivingModels.Vec.lerp
— Methodquadratic bezier lerp
1D roadway
AutomotiveDrivingModels.StraightRoadway
— TypeStraightRoadway
A simple type representing a one lane, one dimensional straight roadway
Fields
length::Float64
AutomotiveDrivingModels.mod_position_to_roadway
— Functionmod_position_to_roadway(s::Float64, roadway::StraightRoadway)
performs a modulo of the position s
with the length of roadway
AutomotiveDrivingModels.get_headway
— Functionget_headway(s_rear::Float64, s_fore::Float64, roadway::StraightRoadway)
returns a positive distance between srear and sfore.
Read and Write roadways
Base.read
— MethodBase.read(io::IO, ::MIME"text/plain", ::Type{Roadway})
extract roadway information from a text file and returns a roadway object.
Base.write
— MethodBase.write(io::IO, ::MIME"text/plain", roadway::Roadway)
write all the roadway information to a text file