Skip to content

Commit

Permalink
Merge 9623c37 into 43f2b0b
Browse files Browse the repository at this point in the history
  • Loading branch information
mossr committed May 23, 2021
2 parents 43f2b0b + 9623c37 commit 1d25ff2
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Expand Up @@ -4,8 +4,8 @@ repo = "https://github.com/sisl/AutoUrban.jl"
version = "0.2.4"

[deps]
AutoViz = "82aa6e0c-a491-5edf-8d4b-c16b98e4ea17"
AutomotiveDrivingModels = "99497e54-f3d6-53d3-a3a9-fa9315a7f1ba"
AutomotiveSimulator = "6aa42d20-6c96-11ea-1103-339224409280"
AutomotiveVisualization = "0faf7fd0-6c98-11ea-1740-03605baa3b07"
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/sisl/AutoUrban.jl.svg)](https://travis-ci.org/sisl/AutoUrban.jl)
[![Coverage Status](https://coveralls.io/repos/github/sisl/AutoUrban.jl/badge.svg?branch=master)](https://coveralls.io/github/sisl/AutoUrban.jl?branch=master)

A Julia package expanding the [AutomotiveDrivingModels.jl](https://github.com/sisl/AutomotiveDrivingModels.jl) with intersections, enabling auto-converting roadway in AutomotiveDrivingModels.jl into [OpenDrive format (.xodr)](http://www.opendrive.org/) used in [VIRES VirtualTestDrive](https://vires.com/vtd-vires-virtual-test-drive/). It also contains some driver models.
A Julia package expanding the [AutomotiveSimulator.jl](https://github.com/sisl/AutomotiveSimulator.jl) package with intersections, enabling auto-converting roadway in AutomotiveSimulator.jl into [OpenDrive format (.xodr)](http://www.opendrive.org/) used in [VIRES VirtualTestDrive](https://vires.com/vtd-vires-virtual-test-drive/). It also contains some driver models.

## Installation

Expand All @@ -19,8 +19,8 @@ Other way, by manually adding all the dependencies:
using Pkg
Pkg.add(PackageSpec(url="https://github.com/sisl/Vec.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/Records.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveDrivingModels.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/AutoViz.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveSimulator.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveVisualization.jl"))
Pkg.add(PackageSpec(url="https://github.com/sisl/AutoUrban.jl"))
```

Expand Down
8 changes: 4 additions & 4 deletions deps/build.jl
Expand Up @@ -6,10 +6,10 @@ end
if !in("Records", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/Records.jl.git"))
end
if !in("AutomotiveDrivingModels", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveDrivingModels.jl.git"))
if !in("AutomotiveSimulator", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveSimulator.jl.git"))
end
if !in("AutoViz", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/AutoViz.jl.git"))
if !in("AutomotiveVisualization", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveVisualization.jl.git"))
end

5 changes: 3 additions & 2 deletions src/AutoUrban.jl
Expand Up @@ -2,10 +2,11 @@ __precompile__()

module AutoUrban

using AutomotiveDrivingModels
using AutoViz
using AutomotiveSimulator
using AutomotiveVisualization
using EzXML
using Printf
import Records: QueueRecord, Frame
using LinearAlgebra
using Distributions
import Cairo
Expand Down
16 changes: 13 additions & 3 deletions src/actions.jl
Expand Up @@ -12,7 +12,7 @@ function Base.copyto!(v::Vector{Float64}, a::LatLonAccelDirection)
v[3] = convert(Float64,a.direction)
v
end
function AutomotiveDrivingModels.propagate(veh::Entity{VehicleState, D, Int}, action::LatLonAccelDirection, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
function AutomotiveSimulator.propagate(veh::Entity{VehicleState, D, Int}, action::LatLonAccelDirection, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
previousInd = veh.state.posF.roadind
a_lat = action.a_lat
a_lon = action.a_lon
Expand Down Expand Up @@ -69,6 +69,16 @@ function AutomotiveDrivingModels.propagate(veh::Entity{VehicleState, D, Int}, ac
end
end

"""
SceneRecord
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)
"""
const SceneRecord = QueueRecord{VehicleDef}
SceneRecord(capacity::Int, timestep::Float64, frame_capacity::Int=100) = QueueRecord(VehicleDef, capacity, timestep, frame_capacity)
Base.show(io::IO, rec::SceneRecord) = print(io, "SceneRecord(nscenes=", nframes(rec), ")")

function Base.get(::Type{LatLonAccelDirection}, rec::SceneRecord, roadway::Roadway, vehicle_index::Int, pastframe::Int=0)
accel_lat = get(ACCFT, rec, roadway, vehicle_index, pastframe)
accel_lon = get(ACCFS, rec, roadway, vehicle_index, pastframe)
Expand All @@ -95,7 +105,7 @@ function Base.copyto!(v::Vector{Float64}, a::AccelSteeringDirection)
v
end
#function propagate(veh::Entity{VehicleState, BicycleModel, Int}, action::AccelSteeringAngle, roadway::Roadway, Δt::Float64)
function AutomotiveDrivingModels.propagate(veh::Entity{VehicleState, D, Int}, action::AccelSteeringDirection, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
function AutomotiveSimulator.propagate(veh::Entity{VehicleState, D, Int}, action::AccelSteeringDirection, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
previousInd = veh.state.posF.roadind

L = veh.def.a + veh.def.b
Expand Down Expand Up @@ -169,7 +179,7 @@ function NextState()
return NextState(0.0,0.0,0.0,0.0,1)
end

function AutomotiveDrivingModels.propagate(veh::Entity{VehicleState, D, Int}, action::NextState, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
function AutomotiveSimulator.propagate(veh::Entity{VehicleState, D, Int}, action::NextState, roadway::Roadway, Δt::Float64) where {D<:Union{VehicleDef, BicycleModel}}
previousInd = veh.state.posF.roadind

posG = VecSE2(action.x, action.y, action.theta)
Expand Down
8 changes: 4 additions & 4 deletions src/drivermodels/IDMDriver.jl
@@ -1,4 +1,4 @@
import AutomotiveDrivingModels.observe!
import AutomotiveSimulator.observe!

mutable struct IDMDriver <: LaneFollowingDriver
a::Float64 # predicted acceleration
Expand Down Expand Up @@ -43,13 +43,13 @@ mutable struct IDMDriver <: LaneFollowingDriver
retval
end
end
get_name(::IDMDriver) = "IDM"

function set_desired_speed!(model::IDMDriver, v_des::Float64)
model.v_des = v_des
model
end

function AutomotiveDrivingModels.observe!(model::IDMDriver, scene::Frame{Entity{VehicleState, BicycleModel, Int}}, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::IDMDriver, scene::Frame{Entity{VehicleState, BicycleModel, Int}}, roadway::Roadway, egoid::Int)
vehicle_index = findfirst(scene, egoid)

fore = get_neighbor_fore_along_lane(scene, vehicle_index, roadway, VehicleTargetPointFront(), VehicleTargetPointRear(), VehicleTargetPointFront(),max_distance_fore=model.max_horizon)
Expand All @@ -68,7 +68,7 @@ function AutomotiveDrivingModels.observe!(model::IDMDriver, scene::Frame{Entity{
return model
end

function AutomotiveDrivingModels.observe!(model::IDMDriver, scene::Scene, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::IDMDriver, scene::Scene, roadway::Roadway, egoid::Int)
vehicle_index = findfirst(scene, egoid)

fore = get_neighbor_fore_along_lane(scene, vehicle_index, roadway, VehicleTargetPointFront(), VehicleTargetPointRear(), VehicleTargetPointFront(),max_distance_fore=model.max_horizon)
Expand Down
8 changes: 4 additions & 4 deletions src/drivermodels/MOBILDriver.jl
@@ -1,4 +1,4 @@
import AutomotiveDrivingModels.observe!
import AutomotiveSimulator.observe!

mutable struct MOBILDriver <: LaneChangeModel{LaneChangeChoice}

Expand Down Expand Up @@ -31,15 +31,15 @@ mutable struct MOBILDriver <: LaneChangeModel{LaneChangeChoice}
retval
end
end
get_name(::MOBILDriver) = "MOBILDriver"

function set_desired_speed!(model::MOBILDriver, v_des::Float64)
set_desired_speed!(model.mlon, v_des)
model
end
function AutomotiveDrivingModels.observe!(model::MOBILDriver, scene::Scene, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::MOBILDriver, scene::Scene, roadway::Roadway, egoid::Int)
observe_helper!(model,scene,roadway,egoid)
end
function AutomotiveDrivingModels.observe!(model::MOBILDriver, scene::Frame{Entity{VehicleState, BicycleModel, Int}}, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::MOBILDriver, scene::Frame{Entity{VehicleState, BicycleModel, Int}}, roadway::Roadway, egoid::Int)
observe_helper!(model,scene,roadway,egoid)
end

Expand Down
4 changes: 1 addition & 3 deletions src/drivermodels/acc_steer_drivers.jl
Expand Up @@ -10,9 +10,7 @@ function AccSteerDriver(acc::Float64, steer::Float64)
return AccSteerDriver(acc, steer, 1)
end

AutomotiveDrivingModels.get_name(model::AccSteerDriver) = "AccSteerDriver"

function AutomotiveDrivingModels.observe!(model::AccSteerDriver, scene::Scene, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::AccSteerDriver, scene::Scene, roadway::Roadway, egoid::Int)
model
end
Base.rand(model::AccSteerDriver) = AccelSteeringDirection(model.acc,model.steer,model.direction)
Expand Down
4 changes: 1 addition & 3 deletions src/drivermodels/multiPtsTurning_driver.jl
Expand Up @@ -22,8 +22,6 @@ mutable struct MultiPtsTurningDriver <: MultiPtsDriver
MultiPtsTurningDriver(Δt::Float64; siji::AccSteerDriver=AccSteerDriver(0.0,0.0),N::Int=20,Pts::Matrix{Float64}=zeros(2,20),steermax::Float64=pi/4,steerdotmax::Float64=20.0,accmax::Float64=10.0,commands::Array{Float64}=zeros(4),index::Int=0,subindex::Int=0,laneNum_desire::Int=1,acc_desire::Float64=0.0,v_desire::Float64=0.0,v_max::Float64=20.0,v_min::Float64=0.0,turning_direction::Int=1,color::Colorant=RGB(1, 0, 0))=new(Δt,siji,N,Pts,steermax,steerdotmax,accmax,commands,index,subindex,laneNum_desire,acc_desire,v_desire,v_max,v_min,turning_direction,color)
end

AutomotiveDrivingModels.get_name(model::MultiPtsTurningDriver) = "MultiPtsTurningDriver"

Base.rand(model::MultiPtsTurningDriver) = rand(model.siji)
Distributions.pdf(model::MultiPtsTurningDriver, a::Float64) = a == model.siji.acc ? Inf : 0.0
Distributions.logpdf(model::MultiPtsTurningDriver, a::Float64) = a == model.siji.acc ? Inf : -Inf
Expand All @@ -46,7 +44,7 @@ function set_pts!(model::MultiPtsTurningDriver,PtsIn::Matrix{Float64})
model
end

function AutomotiveDrivingModels.observe!(model::MultiPtsTurningDriver, scene::Union{Scene,Frame{Entity{VehicleState, BicycleModel, Int}}}, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(model::MultiPtsTurningDriver, scene::Union{Scene,Frame{Entity{VehicleState, BicycleModel, Int}}}, roadway::Roadway, egoid::Int)
ego_index = findfirst(scene, egoid)
get_acc_steer!(model,scene,roadway,ego_index)
model
Expand Down
9 changes: 4 additions & 5 deletions src/drivermodels/render_drivers.jl
@@ -1,5 +1,5 @@
import AutoViz.render
import AutoViz.render!
import AutomotiveVisualization.render
import AutomotiveVisualization.render!

function render_multipoint_drivers!(
rendermodel::RenderModel,
Expand Down Expand Up @@ -57,11 +57,10 @@ function render(ctx::Cairo.CairoContext, scene::Union{Scene,Frame{Entity{Vehicle
for (i,veh) in enumerate(scene)
if haskey(models,veh.id)
model = models[veh.id]
name = AutomotiveDrivingModels.get_name(model)
if name == "MultiPtsTurningDriver"
if model <: MultiPtsTurningDriver
render_multipoint_drivers!(rendermodel,model,veh.id,car_colors)
end
if name == "UrbanDriver"
if model <: UrbanDriver
render_urban_drivers!(rendermodel,model,veh.id,car_colors)
end
end
Expand Down
13 changes: 6 additions & 7 deletions src/drivermodels/urban_drivers.jl
Expand Up @@ -37,11 +37,10 @@ mutable struct UrbanDriver <: DriverModel{LatLonAccelDirection}
retval
end
end
AutomotiveDrivingModels.get_name(::UrbanDriver) = "UrbanDriver"

function set_desired_speed!(model::UrbanDriver, v_des::Float64)
AutomotiveDrivingModels.set_desired_speed!(model.mlon, v_des)
AutomotiveDrivingModels.set_desired_speed!(model.mlane, v_des)
AutomotiveSimulator.set_desired_speed!(model.mlon, v_des)
AutomotiveSimulator.set_desired_speed!(model.mlane, v_des)
model
end

Expand All @@ -55,12 +54,12 @@ function track_longitudinal!(driver::LaneFollowingDriver, scene::Union{Scene,Fra
return track_longitudinal!(driver, v_ego, v_oth, headway)
end

function AutomotiveDrivingModels.observe!(driver::UrbanDriver, scene2::Union{Scene,Frame{Entity{VehicleState, BicycleModel, Int}}}, roadway::Roadway, egoid::Int)
function AutomotiveSimulator.observe!(driver::UrbanDriver, scene2::Union{Scene,Frame{Entity{VehicleState, BicycleModel, Int}}}, roadway::Roadway, egoid::Int)
scene = Scene()
for veh in scene2
push!(scene,Vehicle(veh.state,veh.def.def,veh.id))
end
AutomotiveDrivingModels.update!(driver.rec, scene)
AutomotiveSimulator.update!(driver.rec, scene)
observe!(driver.mlane, scene, roadway, egoid)
lane_change_action = rand(driver.mlane)

Expand All @@ -82,8 +81,8 @@ function AutomotiveDrivingModels.observe!(driver::UrbanDriver, scene2::Union{Sce
end


AutomotiveDrivingModels.track_lateral!(driver.mlat, laneoffset, lateral_speed)
#AutomotiveDrivingModels.track_longitudinal!(driver.mlon, scene, roadway, vehicle_index, fore.ind)
AutomotiveSimulator.track_lateral!(driver.mlat, laneoffset, lateral_speed)
#AutomotiveSimulator.track_longitudinal!(driver.mlon, scene, roadway, vehicle_index, fore.ind)
roadind = scene[vehicle_index].state.posF.roadind
max_k,distance = get_max_curvature(roadind, roadway, 25.0,direction = driver.direction)
#println(max_k,distance)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
@@ -1,6 +1,6 @@
using Test

using AutomotiveDrivingModels
using AutomotiveSimulator
using EzXML
using AutoUrban

Expand Down

0 comments on commit 1d25ff2

Please sign in to comment.