Skip to content

Commit 436e5fa

Browse files
committed
generate examples
1 parent d71bec7 commit 436e5fa

File tree

13 files changed

+43
-52
lines changed

13 files changed

+43
-52
lines changed

deps/build.jl

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,4 @@ using Pkg
77
exampledir = joinpath(@__DIR__, "..", "examples")
88
Pkg.activate(exampledir)
99
Pkg.add("Literate")
10-
include(joinpath(exampledir, "generate_notebooks.jl"))
11-
12-
################################################################################
13-
# Dynamics and simulation generation
14-
################################################################################
15-
# Add minimal set of packages
16-
Pkg.add(PackageSpec(name = "FileIO", version = "1.9"))
17-
Pkg.add(PackageSpec(name = "ForwardDiff", version = "0.10"))
18-
Pkg.add(PackageSpec(name = "IfElse", version = "0.1"))
19-
Pkg.add(PackageSpec(name = "JLD2", version = "0.4"))
20-
Pkg.add(PackageSpec(name = "Rotations", version = "1.0"))
21-
Pkg.add(PackageSpec(name = "StaticArrays", version = "1.2"))
22-
Pkg.add(PackageSpec(name = "Symbolics", version = "0.1.29"))
23-
Pkg.add(PackageSpec(name = "LinearAlgebra"))
24-
25-
# Load minimal set of packages and scripts
26-
loaderdir = joinpath(@__DIR__, "..", "src", "code_gen_loader.jl")
27-
include(loaderdir)
28-
29-
# Generate dynamics expressions
30-
dynamicsdir = joinpath(@__DIR__, "..", "src", "dynamics")
31-
include(joinpath(dynamicsdir, "generate_dynamics.jl"))
32-
33-
# # Generate simulation expressions
34-
simulationdir = joinpath(@__DIR__, "..", "src", "simulation")
35-
include(joinpath(simulationdir, "generate_simulation.jl"))
10+
include(joinpath(exampledir, "generate_notebooks.jl"))

examples/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
This directory contains examples of contact-implicit model-predictive control.
44
The `.jl` files in each subdirectory are meant to be processed using [Literate.jl](https://github.com/fredrikekre/Literate.jl).
5-
During the build process, the `.jl` files are converted to notebooks and we generate models and simulation environments for each of the examples. Please note that the build time may take 30-60 minutes, but only needs to be performed once during the initial installation.
5+
During the build process, the `.jl` files are converted to notebooks.
66

7-
You can generate Jupyter notebooks and run them locally by performing the following steps:
7+
The initial installation of the package includes a number of pre-generated examples: [flamingo](examples/flamingo/flat.jl), [pushbot](examples/pushbot/push_recovery.jl), [hopper](examples/hopper/flat.jl), and [quadruped](examples/quadruped/flat.jl). You can generate Jupyter notebooks and run them locally by performing the following steps:
88

99
1. [install ContactImplicitMPC.jl](https://github.com/thowell/ContactImplicitMPC.jl)
1010
2. [install IJulia](https://github.com/JuliaLang/IJulia.jl) (`add` it to the default project)
@@ -19,3 +19,9 @@ You can generate Jupyter notebooks and run them locally by performing the follow
1919
notebook(dir=joinpath(dirname(pathof(ContactImplicitMPC)), "..", "examples"))
2020
```
2121

22+
Additional examples can be run by first generating the models and simulations. Note that this may take 30-60 minutes.
23+
24+
5. in the Julia REPL, run
25+
```
26+
include(joinpath(dirname(pathof(ContactImplicitMPC)), "..", "examples/generate_examples.jl"))
27+
```

examples/generate_examples.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
################################################################################
2+
# Dynamics and simulation generation
3+
################################################################################
4+
# Generate dynamics
5+
dynamicsdir = joinpath(@__DIR__, "..", "src", "dynamics")
6+
include(joinpath(dynamicsdir, "generate_dynamics.jl"))
7+
8+
# Generate simulation
9+
simulationdir = joinpath(@__DIR__, "..", "src", "simulation")
10+
include(joinpath(simulationdir, "generate_simulation.jl"))
20.5 MB
Binary file not shown.
24.8 MB
Binary file not shown.
0 Bytes
Binary file not shown.
-32.4 KB
Binary file not shown.

src/simulation/generate_simulation.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ instantiate_dynamics!(sim.model, path_dyn)
2020
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
2121
save_expressions(expr_res, path_res, overwrite=true)
2222
isfile(path_jac) && rm(path_jac)
23-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
23+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
2424
instantiate_residual!(sim, path_res, path_jac)
2525

2626
################################################################################
@@ -45,7 +45,7 @@ instantiate_dynamics!(s.model, path_dyn)
4545
expr_res, rz_sp, rθ_sp = generate_residual_expressions(s.model, s.env)
4646
save_expressions(expr_res, path_res, overwrite=true)
4747
isfile(path_jac) && rm(path_jac)
48-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
48+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
4949
instantiate_residual!(s, path_res, path_jac)
5050

5151
################################################################################
@@ -70,7 +70,7 @@ instantiate_dynamics!(sim.model, path_dyn)
7070
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
7171
save_expressions(expr_res, path_res, overwrite=true)
7272
isfile(path_jac) && rm(path_jac)
73-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
73+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
7474
instantiate_residual!(sim, path_res, path_jac)
7575

7676
################################################################################
@@ -95,7 +95,7 @@ instantiate_dynamics!(sim.model, path_dyn)
9595
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
9696
save_expressions(expr_res, path_res, overwrite=true)
9797
isfile(path_jac) && rm(path_jac)
98-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
98+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
9999
instantiate_residual!(sim, path_res, path_jac)
100100

101101
################################################################################
@@ -120,7 +120,7 @@ instantiate_dynamics!(sim.model, path_dyn)
120120
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
121121
save_expressions(expr_res, path_res, overwrite=true)
122122
isfile(path_jac) && rm(path_jac)
123-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
123+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
124124
instantiate_residual!(sim, path_res, path_jac)
125125

126126
################################################################################
@@ -145,7 +145,7 @@ instantiate_dynamics!(sim.model, path_dyn)
145145
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
146146
save_expressions(expr_res, path_res, overwrite=true)
147147
isfile(path_jac) && rm(path_jac)
148-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
148+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
149149
instantiate_residual!(sim, path_res, path_jac)
150150

151151
################################################################################
@@ -170,7 +170,7 @@ instantiate_dynamics!(sim.model, path_dyn)
170170
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
171171
save_expressions(expr_res, path_res, overwrite=true)
172172
isfile(path_jac) && rm(path_jac)
173-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
173+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
174174
instantiate_residual!(sim, path_res, path_jac)
175175

176176
################################################################################
@@ -195,7 +195,7 @@ instantiate_dynamics!(sim.model, path_dyn)
195195
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
196196
save_expressions(expr_res, path_res, overwrite=true)
197197
isfile(path_jac) && rm(path_jac)
198-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
198+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
199199
instantiate_residual!(sim, path_res, path_jac)
200200

201201
################################################################################
@@ -222,7 +222,7 @@ instantiate_dynamics!(sim.model, path_dyn, derivs = true)
222222
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env, jacobians = :approx)
223223
save_expressions(expr_res, path_res, overwrite=true)
224224
isfile(path_jac) && rm(path_jac)
225-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
225+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
226226
instantiate_residual!(sim, path_res, path_jac, jacobians = :approx)
227227

228228
################################################################################
@@ -247,7 +247,7 @@ instantiate_dynamics!(sim.model, path_dyn)
247247
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
248248
save_expressions(expr_res, path_res, overwrite=true)
249249
isfile(path_jac) && rm(path_jac)
250-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
250+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
251251
instantiate_residual!(sim, path_res, path_jac)
252252

253253
################################################################################
@@ -272,7 +272,7 @@ instantiate_dynamics!(sim.model, path_dyn)
272272
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
273273
save_expressions(expr_res, path_res, overwrite=true)
274274
isfile(path_jac) && rm(path_jac)
275-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
275+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
276276
instantiate_residual!(sim, path_res, path_jac)
277277

278278
################################################################################
@@ -297,7 +297,7 @@ instantiate_dynamics!(sim.model, path_dyn)
297297
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
298298
save_expressions(expr_res, path_res, overwrite=true)
299299
isfile(path_jac) && rm(path_jac)
300-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
300+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
301301
instantiate_residual!(sim, path_res, path_jac)
302302

303303
################################################################################
@@ -322,7 +322,7 @@ instantiate_dynamics!(sim.model, path_dyn)
322322
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
323323
save_expressions(expr_res, path_res, overwrite=true)
324324
isfile(path_jac) && rm(path_jac)
325-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
325+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
326326
instantiate_residual!(sim, path_res, path_jac)
327327

328328
################################################################################
@@ -347,7 +347,7 @@ instantiate_dynamics!(sim.model, path_dyn)
347347
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
348348
save_expressions(expr_res, path_res, overwrite=true)
349349
isfile(path_jac) && rm(path_jac)
350-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
350+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
351351
instantiate_residual!(sim, path_res, path_jac)
352352

353353
################################################################################
@@ -372,7 +372,7 @@ instantiate_dynamics!(sim.model, path_dyn)
372372
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env, jacobians = :full)
373373
save_expressions(expr_res, path_res, overwrite=true)
374374
isfile(path_jac) && rm(path_jac)
375-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
375+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
376376
instantiate_residual!(sim, path_res, path_jac)
377377

378378
################################################################################
@@ -399,7 +399,7 @@ instantiate_dynamics!(sim.model, path_dyn, derivs = true)
399399
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env, jacobians = :approx)
400400
save_expressions(expr_res, path_res, overwrite=true)
401401
isfile(path_jac) && rm(path_jac)
402-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
402+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
403403
instantiate_residual!(sim, path_res, path_jac, jacobians = :approx)
404404

405405
################################################################################
@@ -424,7 +424,7 @@ instantiate_dynamics!(sim.model, path_dyn)
424424
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
425425
save_expressions(expr_res, path_res, overwrite=true)
426426
isfile(path_jac) && rm(path_jac)
427-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
427+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
428428
instantiate_residual!(sim, path_res, path_jac)
429429

430430
################################################################################
@@ -449,7 +449,7 @@ instantiate_dynamics!(sim.model, path_dyn)
449449
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
450450
save_expressions(expr_res, path_res, overwrite=true)
451451
isfile(path_jac) && rm(path_jac)
452-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
452+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
453453
instantiate_residual!(sim, path_res, path_jac)
454454

455455
################################################################################
@@ -474,7 +474,7 @@ instantiate_dynamics!(sim.model, path_dyn)
474474
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
475475
save_expressions(expr_res, path_res, overwrite=true)
476476
isfile(path_jac) && rm(path_jac)
477-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
477+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
478478
instantiate_residual!(sim, path_res, path_jac)
479479

480480
################################################################################
@@ -501,10 +501,10 @@ instantiate_dynamics!(sim.model, path_dyn, derivs=true)
501501
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env, jacobians = :approx)
502502
save_expressions(expr_res, path_res, overwrite=true)
503503
isfile(path_jac) && rm(path_jac)
504-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
504+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
505505
instantiate_residual!(sim, path_res, path_jac, jacobians = :approx)
506506

507-
# ################################################################################
507+
################################################################################
508508
# PushBot
509509
################################################################################
510510
dir_model = joinpath(module_dir(), "src/dynamics/pushbot")
@@ -526,7 +526,7 @@ instantiate_dynamics!(sim.model, path_dyn)
526526
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env)
527527
save_expressions(expr_res, path_res, overwrite=true)
528528
isfile(path_jac) && rm(path_jac)
529-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
529+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
530530
instantiate_residual!(sim, path_res, path_jac)
531531

532532
################################################################################
@@ -551,5 +551,5 @@ instantiate_dynamics!(sim.model, path_dyn)
551551
expr_res, rz_sp, rθ_sp = generate_residual_expressions(sim.model, sim.env, mapping = Gz_func)
552552
save_expressions(expr_res, path_res, overwrite=true)
553553
isfile(path_jac) && rm(path_jac)
554-
save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
554+
ContactImplicitMPC.JLD2.save(path_jac, "rz_sp", rz_sp, "rθ_sp", rθ_sp)
555555
instantiate_residual!(sim, path_res, path_jac)
-4.78 KB
Binary file not shown.
2.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)