Skip to content

Commit

Permalink
Revert "Delete double pendulum"
Browse files Browse the repository at this point in the history
This reverts commit 6f36279.
  • Loading branch information
blegat committed Oct 31, 2024
1 parent 220547e commit d72a253
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/src/examples/solvers/Double_Pendulum_Safety.jl
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d72a253

Please sign in to comment.