Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global trajectory parameters #41

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/struct_named_trajectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mutable struct NamedTrajectory{R <: Real}
final::NamedTuple{fnames, <:Tuple{Vararg{AbstractVector{R}}}} where fnames
goal::NamedTuple{gnames, <:Tuple{Vararg{AbstractVector{R}}}} where gnames
components::NamedTuple{cnames, <:Tuple{Vararg{AbstractVector{Int}}}} where cnames
params::NamedTuple{pnames, <:Tuple{Vararg{AbstractVector{R}}}} where pnames
names::Tuple{Vararg{Symbol}}
state_names::Tuple{Vararg{Symbol}}
control_names::Tuple{Vararg{Symbol}}
Expand All @@ -35,6 +36,7 @@ function NamedTrajectory(
initial=(;),
final=(;),
goal=(;),
params=(;),
) where R <: Real
controls = controls isa Symbol ? (controls,) : controls

Expand Down Expand Up @@ -153,6 +155,7 @@ function NamedTrajectory(
final,
goal,
comps,
params,
names,
state_names,
controls
Expand Down Expand Up @@ -187,6 +190,7 @@ function NamedTrajectory(
initial=(;),
final=(;),
goal=(;),
params=(;),
) where R <: Real
controls = (controls isa Symbol) ? (controls,) : controls

Expand Down Expand Up @@ -257,6 +261,7 @@ function NamedTrajectory(
final,
goal,
components,
params,
names,
state_names,
controls
Expand Down Expand Up @@ -287,6 +292,7 @@ function NamedTrajectory(
Z.final,
Z.goal,
Z.components,
z.params,
ErikQQY marked this conversation as resolved.
Show resolved Hide resolved
Z.names,
Z.state_names,
Z.control_names
Expand Down Expand Up @@ -317,6 +323,7 @@ function NamedTrajectory(
traj.final,
traj.goal,
traj.components,
traj.params,
traj.names,
traj.state_names,
traj.control_names
Expand Down Expand Up @@ -352,6 +359,7 @@ function NamedTrajectory(
initial = NamedTuple([(k => traj.initial[k]) for k ∈ keys(comps) if k ∈ keys(traj.initial)])
final = NamedTuple([(k => traj.final[k]) for k ∈ keys(comps) if k ∈ keys(traj.final)])
goal = NamedTuple([(k => traj.goal[k]) for k ∈ keys(comps) if k ∈ keys(traj.goal)])
params = NamedTuple([(k => traj.params[k]) for k ∈ keys(comps) if k ∈ keys(traj.params)])

return NamedTrajectory(
comps;
Expand All @@ -361,6 +369,7 @@ function NamedTrajectory(
initial=initial,
final=final,
goal=goal,
params
)

end
Expand Down
28 changes: 28 additions & 0 deletions test/test_constructor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
test: struct_named_trajectory.jl
"""

@testset "testing constructor" begin
# define number of timesteps and timestep
T = 10
dt = 0.1

components = (
x = rand(3, T),
u = rand(2, T),
Δt = fill(dt, 1, T),
)

timestep = 0.1
control = :u

# some global params as a NamedTuple
params = (
α = rand(1),
β = rand(1)
)

traj = NamedTrajectory(components; timestep=timestep, controls=control, params=params)

@test traj.params == params
end
Loading