The control-toolbox REPL

We present in this tutorial the control-toolbox REPL which permits first an incremental definition of the optimal control problem, but also to solve it (with default options only) and plot the solution (with default options only).

To enter into the control-toolbox, press > key.

Standard usage

You can define the problem under the control-toolbox REPL and then, solve it and plot the solution in the Julia REPL. Use the command NAME to rename the optimal control problem: ct> NAME=ocp.

Nota bene

In the following gif, the plot is not displayed since only the terminal is recorded.

Control-toolbox REPL

Credits

This gif has been made with this version of Replay.jl. To make the gif we first need a script (named ct-repl.jl) containing:

using Replay

repl_script = """
using OptimalControl
t0 = 0
tf = 1
# press ">" to enter into control-toolbox repl
>t ∈ [t0, tf], time
# rename the ocp and the sol 
NAME=(ocp, sol)
SHOW
# more commands
HELP
# add ";" at the end of the line for no output
x ∈ R^2, state;
u ∈ R, control;
x(t0) == [ -1, 0 ];
x(tf) == [ 0, 0 ];
\\partial$(TAB)(x)(t) == [ x\\_2$(TAB)(t), u(t) ];
\\int$(TAB)( 0.5u(t)^2 ) \\to$(TAB) min;
SHOW
$BACKSPACE
using NLPModelsIpopt
>SOLVE
$BACKSPACE
# you can access the ocp and the sol in Julia repl
ocp
sol
using Plots
>PLOT
$BACKSPACE
"""

replay(
    repl_script, 
    stdout, 
    julia_project=@__DIR__, 
    use_ghostwriter=true, 
    cmd=`--color=yes`
)

Then, to register the terminal we have used asciinema and to save the record into a gif file, we have used agg. The shell script to obtain the gif is:

julia --project=@. -e 'using Pkg; Pkg.instantiate()'
asciinema rec result.cast \
    -i 2 \
    --cols=95 \
    --rows=30 \
    --overwrite \
    --command "julia --project=@. ./ct-repl.jl"
agg result.cast ct-repl.gif