Skip to content

Commit

Permalink
Merge pull request #149 from control-toolbox/fixplotjoseph
Browse files Browse the repository at this point in the history
fix plot constant negative value
  • Loading branch information
ocots authored Jun 10, 2024
2 parents ae0c34a + f877346 commit 2d0a906
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ function __plot_time!(p::Union{Plots.Plot, Plots.Subplot}, sol::OptimalControlSo

if (ymin != Inf) && (ymax != -Inf) && (abs(ymax-ymin) abs(ymin)*tol)
ymiddle = (ymin+ymax)/2.0
ylims!(p, (0.9*ymiddle, 1.1*ymiddle))
if (abs(ymiddle) < 1e-12)
ylims!(p, (-0.1, 0.1))
else
ymiddle > 0 ? ylims!(p, (0.9*ymiddle, 1.1*ymiddle)) : ylims!(p, (1.1*ymiddle, 0.9*ymiddle))
end
end

return p
Expand Down
53 changes: 53 additions & 0 deletions test/test_plot_joseph.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# using OptimalControl

# @def ocp begin

# t ∈ [ 0, 1 ], time
# x ∈ R, state
# u ∈ R, control
# x(0) == 0
# -1 ≤ u(t) ≤ 1
# ẋ(t) == -x(t) + u(t)
# x(1) → min

# end

# sol = solve(ocp, grid_size=20, print_level=5)
# plt = plot(sol)

# a la main
using CTBase

n=1
m=1
t0=0
tf=1
x0=0
x = t -> -1+1e-8*rand()
p = t -> 0+1e-8*rand()
u = t -> 0
objective = 1
#
N=201
times = range(t0, tf, N)
#

sol = OptimalControlSolution()
sol.state_dimension = n
sol.control_dimension = m
sol.times = times
sol.time_name="t"
sol.state = x
sol.state_name = "x"
sol.state_components_names = [ "x" ]
sol.costate = p
sol.control = u
sol.control_name = "u"
sol.control_components_names = [ "u" ]
sol.objective = objective
sol.iterations = 0
sol.stopping = :dummy
sol.message = "ceci est un test"
sol.success = true

plt = plot(sol)

0 comments on commit 2d0a906

Please sign in to comment.