diff --git a/src/Geometry.jl b/src/Geometry.jl new file mode 100644 index 0000000..9b22ba4 --- /dev/null +++ b/src/Geometry.jl @@ -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 \ No newline at end of file diff --git a/src/RL.jl b/src/RL.jl index 8fca548..f5a0e8a 100644 --- a/src/RL.jl +++ b/src/RL.jl @@ -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 ) diff --git a/src/ReCo.jl b/src/ReCo.jl index 8d921b0..386a0cd 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -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")