Skip to content

Commit f9c8e96

Browse files
committed
example deps
1 parent 9a4b4a9 commit f9c8e96

24 files changed

+107
-109
lines changed

examples/flamingo/flat.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s = get_simulation("flamingo", "flat_2D_lc", "flat")
@@ -52,8 +52,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5252
mpc_opts = CIMPCOptions());
5353

5454
# ## Initial conditions
55-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
56-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
55+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
56+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
5757

5858
# ## Simulator
5959
sim = simulator(s, q0_sim, q1_sim, h_sim, H_sim,

examples/flamingo/piecewise.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("flamingo", "piecewise1_2D_lc", "piecewise", approx = true)
@@ -49,8 +49,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
4949
);
5050

5151
# ## Initial conditions
52-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
53-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
52+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
53+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
5454

5555
# ## Simulator
5656
sim = simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/flamingo/sine.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("flamingo", "sine3_2D_lc", "sinusoidal");
@@ -57,8 +57,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5757
);
5858

5959
# ## Initial conditions
60-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
61-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
60+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
61+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6262

6363
# ## Simulator
6464
sim = simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/flamingo/slope.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("flamingo", "slope_smooth_2D_lc", "slope");
@@ -57,8 +57,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5757
);
5858

5959
# ## Initial conditions
60-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
61-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
60+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
61+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6262

6363
# ## Simulator
6464
sim = simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/generate_notebooks.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ using Literate
22

33
function preprocess(str)
44
str = replace(str, "# PREAMBLE" => "")
5-
str = replace(str, "# PKG_SETUP" =>
6-
"""
7-
using Pkg, ContactImplicitMPC
8-
Pkg.activate(joinpath(dirname(pathof(ContactImplicitMPC)), ".."))
9-
""")
5+
str = replace(str, "# PKG_SETUP" => "")
106
return str
117
end
128

examples/hopper/3D_flat.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("hopper_3D", "flat_3D_lc", "flat");
@@ -81,8 +81,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
8181
);
8282

8383
# ## Initial conditions
84-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
85-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
84+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
85+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
8686

8787
# ## Simulator
8888
sim = simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/hopper/3D_sine.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("hopper_3D", "sine2_3D_lc", "sinusoidal");
@@ -81,8 +81,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
8181
);
8282

8383
# ## Initial conditions
84-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
85-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
84+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
85+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
8686

8787
# ## Simulator
8888
sim = simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/hopper/flat.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7+
using ContactImplicitMPC
78
using LinearAlgebra
8-
using StaticArrays
99

1010
# ## Simulation
1111
s = get_simulation("hopper_2D", "flat_2D_lc", "flat")
@@ -51,8 +51,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5151
mpc_opts = CIMPCOptions());
5252

5353
# ## Initial conditions
54-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
55-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
54+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
55+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
5656

5757
# ## Simulator
5858
sim = simulator(s, q0_sim, q1_sim, h_sim, H_sim,

examples/hopper/monte_carlo.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99
using Random
1010

1111
# ## Simulation
@@ -62,8 +62,8 @@ function run_policy(s::Simulation; H_sim::Int = 4000, verbose = verbose,
6262

6363
q1_ref = copy(ref_traj.q[2]) + offset
6464
q0_ref = copy(ref_traj.q[1]) + offset
65-
q1_sim = SVector{model.dim.q}(q1_ref)
66-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (q1_ref - q0_ref) / N_sample))
65+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(q1_ref)
66+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (q1_ref - q0_ref) / N_sample))
6767
@assert norm((q1_sim - q0_sim) / h_sim - (q1_ref - q0_ref) / h) < 1.0e-8
6868

6969
sim = simulator(s, q0_sim, q1_sim, h_sim, H_sim,
@@ -82,13 +82,13 @@ end
8282
# ## Collect runs
8383
function collect_runs(s::Simulation; n::Int = 1, H_sim::Int = 4000, verbose::Bool = false)
8484
trajs = []
85-
Random.seed!(100)
85+
ContactImplicitMPC.Random.seed!(100)
8686
offset_max = [+0.50, 0.30, +0.30, +0.00]
8787
offset_min = [-0.50, 0.00, -0.30, -0.30]
8888
offset_Δ = offset_max .- offset_min
8989
for i = 1:n
9090
verbose && println("sample = $i/$n")
91-
offset = offset_min .+ offset_Δ .* rand(s.model.dim.q)
91+
offset = offset_min .+ offset_Δ .* ContactImplicitMPC.rand(s.model.dim.q)
9292
traj = run_policy(s, H_sim = H_sim, offset = offset, verbose = verbose)
9393
push!(trajs, traj)
9494
end

examples/hopper/parkour.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# Define a special stride where x and z are updated.
1111
function get_stride(model, traj)
@@ -55,8 +55,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5555
mpc_opts = mpc_opts);
5656

5757
# ## Initial conditions (stairs)
58-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
59-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
58+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
59+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6060

6161
# ## Simulator (stairs)
6262
sim_stair = ContactImplicitMPC.simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,
@@ -110,8 +110,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
110110
);
111111

112112
# ## Set initial configurations to simulation result
113-
q0_sim = deepcopy(SVector{model.dim.q}(sim_stair.traj.q[end-1]))
114-
q1_sim = deepcopy(SVector{model.dim.q}(sim_stair.traj.q[end]))
113+
q0_sim = deepcopy(ContactImplicitMPC.SVector{model.dim.q}(sim_stair.traj.q[end-1]))
114+
q1_sim = deepcopy(ContactImplicitMPC.SVector{model.dim.q}(sim_stair.traj.q[end]))
115115

116116
# ## Simulator (flip)
117117
sim_flip = ContactImplicitMPC.simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/hopper/piecewise.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("hopper_2D", "piecewise1_2D_lc", "piecewise", approx = true);
@@ -55,8 +55,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5555
);
5656

5757
# ## Initial conditions
58-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
59-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
58+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
59+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6060

6161
# ## Simulator
6262
sim = ContactImplicitMPC.simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/hopper/sine.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s_sim = get_simulation("hopper_2D", "sine2_2D_lc", "sinusoidal");
@@ -55,8 +55,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5555
);
5656

5757
# ## Initial conditions
58-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
59-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
58+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
59+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6060

6161
# ## Simulator
6262
sim = ContactImplicitMPC.simulator(s_sim, q0_sim, q1_sim, h_sim, H_sim,

examples/miqp/miqp.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# PKG_SETUP
44

55
# ## Setup
6-
# set environment variables to location of Gurobi software and license
6+
7+
using ContactImplicitMPC# set environment variables to location of Gurobi software and license
78
ENV["GUROBI_HOME"] = "/gurobi912/linux64/"
89
ENV["GRB_LICENSE_FILE"] = "/gurobi912/gurobi.lic"
910

examples/pushbot/push_recovery.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s = get_simulation("pushbot", "flat_2D_lc", "flat");
@@ -32,8 +32,8 @@ for t = 1:H
3232
end
3333

3434
# ## Initial conditions
35-
q0 = @SVector [0.0 * π, 0.0]
36-
q1 = @SVector [0.0 * π, 0.0]
35+
q0 = @ContactImplicitMPC.SVector [0.0 * π, 0.0]
36+
q1 = @ContactImplicitMPC.SVector [0.0 * π, 0.0]
3737

3838
# ## Simulator
3939
sim = simulator(s, q0, q1, h, H,
@@ -90,8 +90,8 @@ impulses = [[-5.5; 0.0], [+5.5; 0.0], [+5.5; 0.0], [-1.5; 0.0], [-6.5; 0.0]]
9090
d = impulse_disturbances(impulses, idx);
9191

9292
# ## Initial Conditions
93-
q1_sim = SVector{model.dim.q}([0.0, 0.0])
94-
q0_sim = SVector{model.dim.q}([0.0, 0.0])
93+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}([0.0, 0.0])
94+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}([0.0, 0.0])
9595

9696
# ## Simulator
9797
sim = simulator(s, q0_sim, q1_sim, h_sim, H_sim,

examples/quadruped/flat.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
7+
using ContactImplicitMPC
8+
using LinearAlgebra
99

1010
# ## Simulation
1111
s = get_simulation("quadruped", "flat_2D_lc", "flat");
@@ -56,8 +56,8 @@ p = ci_mpc_policy(ref_traj, s, obj,
5656
);
5757

5858
# ## Initial conditions
59-
q1_sim = SVector{model.dim.q}(copy(ref_traj.q[2]))
60-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
59+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(ref_traj.q[2]))
60+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (copy(ref_traj.q[2]) - copy(ref_traj.q[1])) / N_sample));
6161

6262
# ## Simulator
6363
sim = simulator(s, q0_sim, q1_sim, h_sim, H_sim,

examples/quadruped/monte_carlo.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
# ## Setup
66

7-
using LinearAlgebra
8-
using StaticArrays
9-
using Random
7+
using ContactImplicitMPC
8+
using LinearAlgebra
109

1110
# ## Simulation
1211
s = get_simulation("quadruped", "flat_2D_lc", "flat")
@@ -61,8 +60,8 @@ function run_policy(s::Simulation; H_sim::Int = 2000, verbose = false,
6160

6261
q1_ref = copy(qinit)
6362
q0_ref = copy(qinit)
64-
q1_sim = SVector{model.dim.q}(q1_ref)
65-
q0_sim = SVector{model.dim.q}(copy(q1_sim - (q1_ref - q0_ref) / N_sample))
63+
q1_sim = ContactImplicitMPC.SVector{model.dim.q}(q1_ref)
64+
q0_sim = ContactImplicitMPC.SVector{model.dim.q}(copy(q1_sim - (q1_ref - q0_ref) / N_sample))
6665
@assert norm((q1_sim - q0_sim) / h_sim - (q1_ref - q0_ref) / h) < 1.0e-8
6766

6867
sim = ContactImplicitMPC.simulator(s, q0_sim, q1_sim, h_sim, H_sim,
@@ -82,13 +81,13 @@ end
8281
function collect_runs(s::Simulation; n::Int = 1, H_sim::Int = 2000, verbose::Bool = false)
8382
nq = s.model.dim.q
8483
trajs = []
85-
Random.seed!(100)
84+
ContactImplicitMPC.Random.seed!(100)
8685
conf_max = [0.05, 0.8, 0.8, 0.8, +0.2, 0.10]
8786
conf_min = [0.00, 0.6, 0.6, 0.6, -0.2, -0.30]
8887
conf_Δ = conf_max .- conf_min
8988
for i = 1:n
9089
verbose && println("sample = $i/$n")
91-
conf = conf_min .+ conf_Δ .* rand(length(conf_min))
90+
conf = conf_min .+ conf_Δ .* ContactImplicitMPC.rand(length(conf_min))
9291
conf[end] = max(conf[end], 0.0)
9392
qinit = initial_configuration(s.model, conf...)
9493
traj = run_policy(s, H_sim = H_sim, qinit = qinit, verbose = verbose)

0 commit comments

Comments
 (0)