1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00

Added angle2

This commit is contained in:
MoBit 2021-12-16 13:50:38 +01:00
parent a922ab9ab5
commit 14302fbe4e
3 changed files with 27 additions and 8 deletions

16
src/Geometry.jl Normal file
View file

@ -0,0 +1,16 @@
module Geometry
export angle2
using StaticArrays: SVector
function angle2(a::SVector{2,Float64}, b::SVector{2,Float64})
θ_a = atan(a[2], a[1])
θ_b = atan(b[2], b[1])
θ = θ_b - θ_a
return rem2pi(θ, RoundNearest)
end
end # module

View file

@ -10,7 +10,7 @@ using LoopVectorization: @turbo
using Random: Random
using ProgressMeter: @showprogress
using ..ReCo: ReCo, Particle
using ..ReCo: ReCo, Particle, angle2
const INITIAL_REWARD = 0.0
@ -45,10 +45,10 @@ mutable struct EnvParams
function EnvParams(
min_distance::Float64,
max_distance::Float64;
n_v_actions::Int64=3,
n_v_actions::Int64=2,
n_ω_actions::Int64=3,
max_v::Float64=80.0,
max_ω::Float64=π / 1.5,
max_ω::Float64=π / 2,
n_distance_states::Int64=2,
n_direction_states::Int64=2,
)
@ -93,7 +93,7 @@ mutable struct EnvParams
)
end
direction_range = 0.0:(2 * π / n_direction_states):(2 * π)
direction_range = (-π):(2 * π / n_direction_states):π
direction_state_space = Vector{DirectionState}(undef, n_direction_states)
@ -347,7 +347,7 @@ function post_integration_hook(
min_distance is not infinite, because otherwise
env_direction_state would be nothing and this else block will not be called
=#
direction = acos((r⃗₁₂[1] * co + r⃗₁₂[2] * si) / min_distance)
direction = angle2(SVector(co, si), r⃗₁₂)
for direction_state in rl_params.env_params.direction_state_space
if direction in direction_state.interval
@ -422,7 +422,7 @@ function run_rl(;
end
# Episode
run_sim(
ReCo.run_sim(
dir; duration=episode_duration, seed=rand(1:typemax(Int64)), rl_params=rl_params
)

View file

@ -18,7 +18,12 @@ import Base: wait
include("PreVectors.jl")
using .PreVectors
include("Geometry.jl")
using .Geometry
include("Particle.jl")
include("data.jl")
include("setup.jl")
include("Shape.jl")
using .Shape
@ -26,8 +31,6 @@ using .Shape
include("RL.jl")
using .RL
include("data.jl")
include("setup.jl")
include("simulation.jl")
include("run.jl")