7
7
using ContactImplicitMPC
8
8
using LinearAlgebra
9
9
using StaticArrays
10
+ using Random
10
11
11
12
# ## Simulation
12
13
s = get_simulation (" hopper_2D" , " flat_2D_lc" , " flat" );
@@ -25,7 +26,7 @@ function run_policy(s::Simulation; H_sim::Int = 4000, verbose = verbose,
25
26
joinpath (module_dir (), " src/dynamics/hopper_2D/gaits/gait_in_place.jld2" ),
26
27
load_type = :joint_traj ))
27
28
28
- H = ref_traj. H
29
+ H = ref_traj. H
29
30
h = ref_traj. h
30
31
N_sample = 5
31
32
H_mpc = 10
@@ -52,13 +53,12 @@ function run_policy(s::Simulation; H_sim::Int = 4000, verbose = verbose,
52
53
mpc_opts = LinearizedMPCOptions (
53
54
),
54
55
ip_opts = InteriorPointOptions (
55
- max_iter = 100 ,
56
- verbose = false ,
57
- r_tol = 1.0e-4 ,
58
- κ_tol = 1.0e-4 ,
56
+ undercut = 5.0 ,
57
+ κ_tol = κ_mpc,
58
+ r_tol = 1.0e-8 ,
59
59
diff_sol = true ,
60
60
solver = :empty_solver ,
61
- ),
61
+ max_time = 1e5 ),
62
62
)
63
63
64
64
q1_ref = copy (ref_traj. q[2 ]) + offset
@@ -67,16 +67,16 @@ function run_policy(s::Simulation; H_sim::Int = 4000, verbose = verbose,
67
67
q0_sim = SVector {model.dim.q} (copy (q1_sim - (q1_ref - q0_ref) / N_sample))
68
68
@assert norm ((q1_sim - q0_sim) / h_sim - (q1_ref - q0_ref) / h) < 1.0e-8
69
69
70
- sim = ContactImplicitMPC . simulator (s, q0_sim, q1_sim, h_sim, H_sim,
70
+ sim = simulator (s, q0_sim, q1_sim, h_sim, H_sim,
71
71
p = p,
72
- ip_opts = ContactImplicitMPC . InteriorPointOptions (
73
- r_tol = 1.0e-8 ,
74
- κ_init = 1.0e-6 ,
75
- κ_tol = 2 .0e-6 ,
76
- diff_sol = true ),
77
- sim_opts = ContactImplicitMPC . SimulatorOptions (warmstart = true ))
78
-
79
- status = ContactImplicitMPC . simulate! (sim, verbose = false )
72
+ ip_opts = InteriorPointOptions (
73
+ γ_reg = 0.0 ,
74
+ undercut = Inf ,
75
+ r_tol = 1 .0e-8 ,
76
+ κ_tol = 1.0e-8 , ),
77
+ sim_opts = SimulatorOptions (warmstart = true ))
78
+
79
+ status = simulate! (sim, verbose = false )
80
80
return deepcopy (sim. traj)
81
81
end
82
82
@@ -97,10 +97,10 @@ function collect_runs(s::Simulation; n::Int = 1, H_sim::Int = 4000, verbose::Boo
97
97
end
98
98
99
99
# ## Visualize runs
100
- function visualize_runs! (vis:: Visualizer , model:: ContactModel , trajs:: AbstractVector ;
100
+ function visualize_runs! (vis:: ContactImplicitMPC. Visualizer , model:: ContactModel , trajs:: AbstractVector ;
101
101
sample= max (1 , Int (floor (trajs[1 ]. H / 100 ))), h= trajs[1 ]. h* sample, α= 1.0 ,
102
- anim:: MeshCat.Animation = MeshCat. Animation (Int (floor (1 / h))),
103
- name:: Symbol = model_name (model))
102
+ anim:: ContactImplicitMPC. MeshCat.Animation= ContactImplicitMPC . MeshCat. Animation (Int (floor (1 / h))),
103
+ name:: Symbol = ContactImplicitMPC . model_name (model))
104
104
105
105
for (i, traj) in enumerate (trajs)
106
106
name_i = Symbol (string (name) * string (i))
@@ -110,16 +110,15 @@ function visualize_runs!(vis::Visualizer, model::ContactModel, trajs::AbstractVe
110
110
end
111
111
112
112
# ## Experiment
113
- H_sim = 5000
114
- trajs = collect_runs (s, n = 100 , H_sim = H_sim, verbose = true )
115
- anim = visualize_runs! (vis, s. model, trajs, α= 0.1 , sample= 5 )
116
- rep_ref_traj = repeat_ref_traj (ref_traj, Int (ceil (H_sim/ N_sample/ H)));
113
+ H_sim = 1000
114
+ trajs = collect_runs (s, n = 100 , H_sim = H_sim, verbose = true );
117
115
118
116
# ## Visualizer
119
117
vis = ContactImplicitMPC. Visualizer ()
120
118
open (vis)
121
119
122
120
# ## Visualize
123
- anim = visualize_robot! (vis, model, rep_ref_traj, name= :ref , anim= anim, sample= 1 , α= 1.0 )
121
+ anim = visualize_runs! (vis, s. model, trajs, α= 0.1 , sample= 5 )
122
+
124
123
125
124
0 commit comments