From d72a2531ca928beafa52f7d2ec3af740658e4d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 31 Oct 2024 14:31:19 +0100 Subject: [PATCH] Revert "Delete double pendulum" This reverts commit 6f36279a2685ca8d7cf565c39c8950b9a492bf1d. --- .../solvers/Double_Pendulum_Safety.jl | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docs/src/examples/solvers/Double_Pendulum_Safety.jl diff --git a/docs/src/examples/solvers/Double_Pendulum_Safety.jl b/docs/src/examples/solvers/Double_Pendulum_Safety.jl new file mode 100644 index 000000000..ed667e059 --- /dev/null +++ b/docs/src/examples/solvers/Double_Pendulum_Safety.jl @@ -0,0 +1,54 @@ +using Test #src +using StaticArrays, Plots + +# At this point, we import the useful Dionysos sub-modules. +using Dionysos +const DI = Dionysos +const UT = DI.Utils +const DO = DI.Domain +const ST = DI.System +const SY = DI.Symbolic +const OP = DI.Optim +const AB = OP.Abstraction + +include( + joinpath( + dirname(dirname(pathof(Dionysos))), + "problems/double_pendulum", + "safety_stable_equilibrium.jl", + ), +) + +# and we can instantiate the DC system with the provided system +concrete_problem = DoublePendulum.problem(; approx_mode = "growth") +concrete_system = concrete_problem.system + +x0 = SVector(0.0, 0.0, 0.0, 0.0) +hx = SVector(0.1, 0.1, 0.1, 0.1) +state_grid = DO.GridFree(x0, hx) + +u0 = SVector(0.0); +h = SVector(0.3); +input_grid = DO.GridFree(u0, h); + +using JuMP +optimizer = MOI.instantiate(AB.UniformGridAbstraction.Optimizer) +MOI.set(optimizer, MOI.RawOptimizerAttribute("concrete_problem"), concrete_problem) +MOI.set(optimizer, MOI.RawOptimizerAttribute("state_grid"), state_grid) +MOI.set(optimizer, MOI.RawOptimizerAttribute("input_grid"), input_grid) +MOI.optimize!(optimizer) + +abstract_controller = MOI.get(optimizer, MOI.RawOptimizerAttribute("abstract_controller")) +concrete_controller = MOI.get(optimizer, MOI.RawOptimizerAttribute("concrete_controller")) + +# ### Trajectory display +# We choose the number of steps `nsteps` for the sampled system, i.e. the total elapsed time: `nstep`*`tstep` +# as well as the true initial state `x0` which is contained in the initial state-space defined previously. +nstep = 100 +x0 = SVector(0.15, 0.0, 0.0, 0.0) # SVector(0.15,0.0) # +control_trajectory = + ST.get_closed_loop_trajectory(concrete_system.f, concrete_controller, x0, nstep) + +fig = plot(; aspect_ratio = :equal); +plot!(concrete_system.X); +plot!(control_trajectory; markersize = 1, arrows = false)