@@ -31,7 +31,7 @@ mutable struct Environment{X,T,M,A,O,I}
31
31
dynamics_jacobian_state:: Matrix{T}
32
32
dynamics_jacobian_input:: Matrix{T}
33
33
input_previous:: Vector{T}
34
- control_map:: Matrix{T}
34
+ control_map:: Matrix{T}
35
35
num_states:: Int
36
36
num_inputs:: Int
37
37
num_observations:: Int
66
66
attitude_decompress: flag for pre- and post-concatenating Jacobians with attitude Jacobians
67
67
"""
68
68
function Base. step (env:: Environment , x, u;
69
- gradients= false ,
70
- attitude_decompress= false )
69
+ gradients = false ,
70
+ attitude_decompress = false )
71
71
72
72
mechanism = env. mechanism
73
- timestep= mechanism. timestep
73
+ timestep = mechanism. timestep
74
74
75
75
x0 = x
76
76
# u = clip(env.input_space, u) # control limits
77
77
env. input_previous .= u # for rendering in Gym
78
- u_scaled = env. control_map * u
78
+ u_scaled = env. control_map * u
79
79
80
80
z0 = env. representation == :minimal ? minimal_to_maximal (mechanism, x0) : x0
81
- z1 = step! (mechanism, z0, u_scaled; opts= env. opts_step)
81
+ z1 = step! (mechanism, z0, u_scaled; opts = env. opts_step)
82
82
env. state .= env. representation == :minimal ? maximal_to_minimal (mechanism, z1) : z1
83
83
84
84
# Compute cost
85
85
costs = cost (env, x, u)
86
86
87
- # Check termination
88
- done = is_done (env, x)
87
+ # Check termination
88
+ done = is_done (env, x)
89
89
90
90
# Gradients
91
91
if gradients
92
92
if env. representation == :minimal
93
- fx, fu = get_minimal_gradients! (env. mechanism, z0, u_scaled, opts= env. opts_grad)
93
+ fx, fu = get_minimal_gradients! (env. mechanism, z0, u_scaled, opts = env. opts_grad)
94
94
elseif env. representation == :maximal
95
- fx, fu = get_maximal_gradients! (env. mechanism, z0, u_scaled, opts= env. opts_grad)
95
+ fx, fu = get_maximal_gradients! (env. mechanism, z0, u_scaled, opts = env. opts_grad)
96
96
if attitude_decompress
97
97
A0 = attitude_jacobian (z0, length (env. mechanism. bodies))
98
98
A1 = attitude_jacobian (z1, length (env. mechanism. bodies))
@@ -109,11 +109,11 @@ function Base.step(env::Environment, x, u;
109
109
end
110
110
111
111
function Base. step (env:: Environment , u;
112
- gradients= false ,
113
- attitude_decompress= false )
114
- step (env, env. state, u;
115
- gradients= gradients,
116
- attitude_decompress= attitude_decompress)
112
+ gradients = false ,
113
+ attitude_decompress = false )
114
+ step (env, env. state, u;
115
+ gradients = gradients,
116
+ attitude_decompress = attitude_decompress)
117
117
end
118
118
119
119
"""
@@ -156,7 +156,7 @@ is_done(env::Environment, x) = false
156
156
x: state
157
157
"""
158
158
function Base. reset (env:: Environment{X} ;
159
- x= nothing ) where X
159
+ x = nothing ) where {X}
160
160
161
161
initialize! (env. mechanism, type2symbol (X))
162
162
if x != nothing
@@ -172,14 +172,14 @@ function Base.reset(env::Environment{X};
172
172
return get_observation (env)
173
173
end
174
174
175
- function MeshCat. render (env:: Environment ,
176
- mode= " human" )
175
+ function MeshCat. render (env:: Environment ,
176
+ mode = " human" )
177
177
z = env. representation == :minimal ? minimal_to_maximal (env. mechanism, env. state) : env. state
178
- set_robot (env. vis, env. mechanism, z, name= :robot )
178
+ set_robot (env. vis, env. mechanism, z, name = :robot )
179
179
return nothing
180
180
end
181
181
182
- function seed (env:: Environment , s= 0 )
182
+ function seed (env:: Environment , s = 0 )
183
183
env. rng[1 ] = MersenneTwister (s)
184
184
return nothing
185
185
end
@@ -214,26 +214,20 @@ mutable struct BoxSpace{T,N} <: Space{T,N}
214
214
dtype:: DataType # this is always T, it's needed to interface with Stable-Baselines
215
215
end
216
216
217
- function BoxSpace (n:: Int ; low:: AbstractVector{T} = - ones (n), high:: AbstractVector{T} = ones (n)) where T
217
+ function BoxSpace (n:: Int ; low:: AbstractVector{T} = - ones (n), high:: AbstractVector{T} = ones (n)) where {T}
218
218
return BoxSpace {T,n} (n, low, high, (n,), T)
219
219
end
220
220
221
221
function sample (s:: BoxSpace{T,N} ) where {T,N}
222
- return rand (T,N) .* (s. high .- s. low) .+ s. low
222
+ return rand (T, N) .* (s. high .- s. low) .+ s. low
223
223
end
224
224
225
225
function contains (s:: BoxSpace{T,N} , v:: AbstractVector{T} ) where {T,N}
226
226
all (v .>= s. low) && all (v .<= s. high)
227
227
end
228
228
229
- # For compat with RLBase
230
- Base. length (s:: BoxSpace ) = s. n
231
- Base. in (v:: AbstractVector{T} , s:: BoxSpace{T,N} ) where {T,N} = all (v .>= s. low) && all (v .<= s. high)
232
- Random. rand (rng:: Random.AbstractRNG , s:: BoxSpace{T,N} ) where {T,N} = return rand (rng, T,N) .* (s. high .- s. low) .+ s. low
233
-
234
229
function clip (s:: BoxSpace , u)
235
230
clamp .(u, s. low, s. high)
236
231
end
237
232
238
-
239
-
233
+ Random. rand (rng:: Random.AbstractRNG , s:: BoxSpace{T,N} ) where {T,N} = return rand (rng, T, N) .* (s. high .- s. low) .+ s. low
0 commit comments