Skip to content
Permalink
Browse files

added some types, fixed params constructor

  • Loading branch information...
tejank10 committed Jun 12, 2019
1 parent 5302a67 commit 81a042fdc758a49f0a47cbc0e37e4426df01fb9b
Showing with 130 additions and 130 deletions.
  1. +7 −8 Manifest.toml
  2. +115 −0 src/fixed_params.jl
  3. +6 −6 src/map.jl
  4. +2 −116 src/simulator.jl
@@ -230,7 +230,7 @@ version = "0.4.0"
deps = ["InteractiveUtils", "MacroTools", "Test"]
git-tree-sha1 = "4d0c6647aa89b3678d03967ca11c8a5cdc83d2b5"
repo-rev = "master"
repo-url = "https://github.com/MikeInnes/IRTools.jl"
repo-url = "https://github.com/MikeInnes/IRTools.jl.git"
uuid = "7869d1d1-7146-5819-86e3-90919afe41df"
version = "0.2.1"

@@ -454,7 +454,7 @@ version = "0.3.1"

[[RayTracer]]
deps = ["Distributed", "Flux", "IRTools", "Images", "Zygote"]
git-tree-sha1 = "0445e91cf6314e21632d9a760c1e742a7739155f"
git-tree-sha1 = "e58ac058e9f502aeda2590f3108d0282b69c7647"
repo-rev = "master"
repo-url = "https://github.com/avik-pal/RayTracer.jl"
uuid = "60dacb86-48ff-11e9-0f01-03ab8794bbc9"
@@ -550,7 +550,7 @@ uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
version = "0.8.0"

[[SuiteSparse]]
deps = ["Libdl", "LinearAlgebra", "SparseArrays"]
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[[Test]]
@@ -570,10 +570,9 @@ uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
version = "0.5.0"

[[Tokenize]]
deps = ["Printf", "Test"]
git-tree-sha1 = "3e83f60b74911d3042d3550884ca2776386a02b8"
git-tree-sha1 = "0de343efc07da00cd449d5b04e959ebaeeb3305d"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.3"
version = "0.5.4"

[[Tracker]]
deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"]
@@ -626,8 +625,8 @@ version = "0.8.3"

[[Zygote]]
deps = ["DiffRules", "FillArrays", "ForwardDiff", "IRTools", "InteractiveUtils", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Random", "Requires", "SpecialFunctions", "Statistics"]
git-tree-sha1 = "961ce4a291d53bfaee6c25f02ec75bd59d126f61"
git-tree-sha1 = "1725b1335296ea8da7bcf4222777a7ef5f8d202e"
repo-rev = "master"
repo-url = "https://github.com/FluxML/Zygote.jl"
repo-url = "https://github.com/FluxML/Zygote.jl.git"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.3.1"
@@ -36,6 +36,121 @@ mutable struct FixedSimParams <: RayTracer.FixedParams
cam_offset::Vector
end

function FixedSimParams(map_name::String=DEFAULT_MAP_NAME,
max_steps::Int=DEFAULT_MAX_STEPS;
draw_curve::Bool=false,
draw_bbox::Bool=false,
domain_rand::Bool=true,
frame_rate::Int=DEFAULT_FRAMERATE,
frame_skip::Int=DEFAULT_FRAME_SKIP,
camera_width::Int=DEFAULT_CAMERA_WIDTH,
camera_height::Int=DEFAULT_CAMERA_HEIGHT,
robot_speed::Float32=DEFAULT_ROBOT_SPEED,
accept_start_angle_deg::Real=DEFAULT_ACCEPT_START_ANGLE_DEG,
full_transparency::Bool=false,
user_tile_start=nothing,
seed=nothing,
distortion::Bool=false,
randomize_maps_on_reset::Bool=false)
#=
:param map_name:
:param max_steps:
:param draw_curve:
:param draw_bbox:
:param domain_rand: If true, applies domain randomization
:param frame_rate:
:param frame_skip:
:param camera_width:
:param camera_height:
:param robot_speed:
:param accept_start_angle_deg:
:param full_transparency: # If true, then we publish all transparency information
:param user_tile_start: If None, sample randomly. Otherwise (i,j). Overrides map start tile
:param seed:
:param distortion: If true, distorts the image with fish-eye approximation
:param randomize_maps_on_reset: If true, randomizes the map on reset (Slows down training)
=#

# first initialize the RNG
rng = MersenneTwister(seed)

_map = Map(map_name, domain_rand)

randomizer = domain_rand ? Randomizer() : nothing
randomization_settings = nothing

delta_time = 1f0 / frame_rate

# Produce graphical output
graphics = true

# Two-tuple of wheel torques, each in the range [-1, 1]
action_space = Box(-1, 1, (2,), Float32)

# We observe an RGB image with pixels in [0, 255]
# Note: the pixels are in UInt8 format because this is more compact
# than Float32 if sent over the network or stored in a dataset
observation_space = Box(0, 255, (camera_height, camera_width, 3), UInt8)

reward_range = (-1000, 1000)

last_action = zeros(Float32, 2)
wheelVels = zeros(Float32, 2)

# Distortion params, if so, load the library, only if not bbox mode
distortion = distortion && !draw_bbox
camera_model = nothing
if !draw_bbox && distortion
if distortion
throw(error("Currently not supporting distortion!"))
#include("distortion.jl")
#camera_model = Distortion()
end
end

map_names = nothing
if randomize_maps_on_reset
map_names = readdir("src/maps")
map_names = map(mapfile->replace(mapfile, ".yaml"=>""), map_names)
end

# Used by the UndistortWrapper, always initialized to False
undistort = false

step_count = 0
timestamp = 0f0

# Robot's current speed
speed = 0f0

horizon_color = BLUE_SKY_COLOR
ground_color = GROUND_COLOR

# Distance between the robot's wheels
wheel_dist = WHEEL_DIST

# Distance bewteen camera and ground
cam_height = CAMERA_FLOOR_DIST

# Angle at which the camera is rotated
cam_angle = [CAMERA_ANGLE, 0, 0]

# Field of view angle of the camera
cam_fov_y = CAMERA_FOV_Y

# Camera offset for use in free camera mode
cam_offset = zeros(Float32, 3)

FixedSimParams(rng, _map, max_steps, draw_curve, draw_bbox, domain_rand,
randomizer, randomization_settings, graphics, frame_rate,
frame_skip, delta_time, camera_width, camera_height,
robot_speed, action_space, observation_space, reward_range,
accept_start_angle_deg, full_transparency, user_tile_start,
distortion, randomize_maps_on_reset, camera_model,
map_names, undistort, horizon_color, ground_color, wheel_dist, cam_height,
cam_angle, cam_fov_y, cam_offset)
end

function reset!(fsp::FixedSimParams)
# Step count since episode start
if fsp.randomize_maps_on_reset
@@ -262,17 +262,17 @@ function _get_curve(grid, i, j, width, height, road_tile_size)
end

struct Grid
road_tile_size
road_tile_size::Float32
grid_width::Int
grid_height::Int
_grid::Vector
obj_data::ObjectData
road_vlist
road_vlist::Matrix{Float32}
road_tlist
ground_vlist
drivable_tiles
mesh
start_tile
ground_vlist::Matrix{Float32}
drivable_tiles::Vector{Dict}
mesh::ObjectMesh
start_tile::Union{Nothing,Dict}
end


@@ -126,122 +126,8 @@ end

@diffops Simulator

function Simulator(
map_name::String=DEFAULT_MAP_NAME,
max_steps::Int=DEFAULT_MAX_STEPS;
draw_curve::Bool=false,
draw_bbox::Bool=false,
domain_rand::Bool=true,
frame_rate::Int=DEFAULT_FRAMERATE,
frame_skip::Int=DEFAULT_FRAME_SKIP,
camera_width::Int=DEFAULT_CAMERA_WIDTH,
camera_height::Int=DEFAULT_CAMERA_HEIGHT,
robot_speed::Float32=DEFAULT_ROBOT_SPEED,
accept_start_angle_deg::Real=DEFAULT_ACCEPT_START_ANGLE_DEG,
full_transparency::Bool=false,
user_tile_start=nothing,
seed=nothing,
distortion::Bool=false,
randomize_maps_on_reset::Bool=false
)
#=
:param map_name:
:param max_steps:
:param draw_curve:
:param draw_bbox:
:param domain_rand: If true, applies domain randomization
:param frame_rate:
:param frame_skip:
:param camera_width:
:param camera_height:
:param robot_speed:
:param accept_start_angle_deg:
:param full_transparency: # If true, then we publish all transparency information
:param user_tile_start: If None, sample randomly. Otherwise (i,j). Overrides map start tile
:param seed:
:param distortion: If true, distorts the image with fish-eye approximation
:param randomize_maps_on_reset: If true, randomizes the map on reset (Slows down training)
=#
# first initialize the RNG
rng = MersenneTwister(seed)

_map = Map(map_name, domain_rand)

randomizer = domain_rand ? Randomizer() : nothing
randomization_settings = nothing

delta_time = 1f0 / frame_rate

# Produce graphical output
graphics = true

# Two-tuple of wheel torques, each in the range [-1, 1]
action_space = Box(-1, 1, (2,), Float32)

# We observe an RGB image with pixels in [0, 255]
# Note: the pixels are in UInt8 format because this is more compact
# than Float32 if sent over the network or stored in a dataset
observation_space = Box(0, 255, (camera_height, camera_width, 3), UInt8)

reward_range = (-1000, 1000)

last_action = zeros(Float32, 2)
wheelVels = zeros(Float32, 2)

# Distortion params, if so, load the library, only if not bbox mode
distortion = distortion && !draw_bbox
camera_model = nothing
if !draw_bbox && distortion
if distortion
throw(error("Currently not supporting distortion!"))
#include("distortion.jl")
#camera_model = Distortion()
end
end

map_names = nothing
if randomize_maps_on_reset
map_names = readdir("src/maps")
map_names = map(mapfile->replace(mapfile, ".yaml"=>""), map_names)
end

# Used by the UndistortWrapper, always initialized to False
undistort = false

step_count = 0
timestamp = 0f0

# Robot's current speed
speed = 0f0

horizon_color = BLUE_SKY_COLOR
ground_color = GROUND_COLOR

# Distance between the robot's wheels
wheel_dist = WHEEL_DIST

# Distance bewteen camera and ground
cam_height = CAMERA_FLOOR_DIST

# Angle at which the camera is rotated
cam_angle = [CAMERA_ANGLE, 0, 0]

# Field of view angle of the camera
cam_fov_y = CAMERA_FOV_Y

# Camera offset for use in free camera mode
cam_offset = zeros(Float32, 3)

fp = FixedSimParams(rng, _map, max_steps, draw_curve, draw_bbox, domain_rand,
randomizer, randomization_settings, graphics, frame_rate,
frame_skip, delta_time, camera_width, camera_height,
robot_speed, action_space, observation_space, reward_range,
accept_start_angle_deg, full_transparency, user_tile_start,
distortion, randomize_maps_on_reset, camera_model,
map_names, undistort, horizon_color, ground_color, wheel_dist, cam_height,
cam_angle, cam_fov_y, cam_offset)

function Simulator(map_name::String=DEFAULT_MAP_NAME, max_steps::Int=DEFAULT_MAX_STEPS; kwargs...)
fp = FixedSimParams(map_name, max_steps; kwargs...)
cur_pos, cur_angle = reset!(fp)

# Robot's current speed

0 comments on commit 81a042f

Please sign in to comment.
You can’t perform that action at this time.