Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/manual/nonlinmpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ savefig("plot1_NonLinMPC.svg"); nothing # hide
![plot1_NonLinMPC](plot1_NonLinMPC.svg)

The [`setname!`](@ref) function allows customized Y-axis labels. The available plotting
options are detailed in the documentation of the corresponding [`plot`](@ref ModelPredictiveControl.plot)
options are detailed in the documentation of the corresponding [`plot`](@ref ModelPredictiveControl.plot_recipe)
method.

## Nonlinear Model Predictive Controller
Expand Down
2 changes: 1 addition & 1 deletion docs/src/public/plot_sim.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ The `plot` methods are based on [`Plots.jl`](https://github.com/JuliaPlots/Plots
To install it run `using Pkg; Pkg.add("Plots")` in the Julia REPL.

```@docs
ModelPredictiveControl.plot
ModelPredictiveControl.plot_recipe
```
32 changes: 13 additions & 19 deletions src/plot_sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,13 @@ end
"Keep manipulated input `u` unchanged for state estimator simulation."
sim_getu!(::StateEstimator, u, _ , _ ) = u


# dummy plot methods to document recipes (both in ?-mode and web documentation)
plot(::Nothing, ::SimResult{<:Real, <:SimModel}) = nothing
plot(::Nothing, ::SimResult{<:Real, <:StateEstimator}) = nothing
plot(::Nothing, ::SimResult{<:Real, <:PredictiveController}) = nothing
function get_indices(arg::IntRangeOrVector, n)
if length(unique(arg)) ≠ length(arg) || maximum(arg) > n
error("Plot keyword argument arguments should contains valid and unique indices")
end
return arg
end
get_indices(arg::Bool, n) = arg ? (1:n) : Int64[]

@doc raw"""
plot(res::SimResult{<:Real, <:SimModel}; <keyword arguments>)
Expand All @@ -348,15 +350,7 @@ julia> using Plots; plot(res, plotu=false)
```
![plot_model](../assets/plot_model.svg)
"""
plot(::Nothing, ::SimResult{<:Real, <:SimModel})

function get_indices(arg::IntRangeOrVector, n)
if length(unique(arg)) ≠ length(arg) || maximum(arg) > n
error("Plot keyword argument arguments should contains valid and unique indices")
end
return arg
end
get_indices(arg::Bool, n) = arg ? (1:n) : Int64[]
plot_recipe(::Nothing, ::SimResult{<:Real, <:SimModel}) = nothing

@recipe function plot_recipe(
res::SimResult{<:Real, <:SimModel};
Expand Down Expand Up @@ -468,7 +462,7 @@ Plot the simulation results of a [`StateEstimator`](@ref).
if applicable
- `plotx̂max=true` or *`plotxhatmax`* : plot estimated state upper bounds ``\mathbf{x̂_{max}}``
if applicable
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:SimModel})`](@ref)
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:SimModel})`](@ref plot_recipe)

# Examples
```julia-repl
Expand All @@ -478,7 +472,7 @@ julia> using Plots; plot(res, plotu=false, plotŷ=true, plotxwithx̂=true)
```
![plot_estimator](../assets/plot_estimator.svg)
"""
plot(::Nothing, ::SimResult{<:Real, <:StateEstimator})
plot_recipe(::Nothing, ::SimResult{<:Real, <:StateEstimator}) = nothing

@recipe function plot_recipe(
res::SimResult{<:Real, <:StateEstimator};
Expand Down Expand Up @@ -726,8 +720,8 @@ Plot the simulation results of a [`PredictiveController`](@ref).
- `plotru=true` : plot manipulated input setpoints ``\mathbf{r_u}`` if applicable
- `plotumin=true` : plot manipulated input lower bounds ``\mathbf{u_{min}}`` if applicable
- `plotumax=true` : plot manipulated input upper bounds ``\mathbf{u_{max}}`` if applicable
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:SimModel})`](@ref)
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:StateEstimator})`](@ref)
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:SimModel})`](@ref plot_recipe)
- `<keyword arguments>` of [`plot(::SimResult{<:Real, <:StateEstimator})`](@ref plot_recipe)

# Examples
```julia-repl
Expand All @@ -739,7 +733,7 @@ julia> using Plots; plot(res, plotŷ=true, plotry=true, plotumax=true, plotx̂=
```
![plot_controller](../assets/plot_controller.svg)
"""
plot(::Nothing, ::SimResult{<:Real, <:PredictiveController})
plot_recipe(::Nothing, ::SimResult{<:Real, <:PredictiveController}) = nothing

@recipe function plot_recipe(
res::SimResult{<:Real, <:PredictiveController};
Expand Down
Loading