-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from control-toolbox/303-present-ct-repl-in-t…
…he-documentation 303 present ct repl in the documentation
- Loading branch information
Showing
5 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# 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 define the problem please check the [abstract syntax tutorial](@ref tutorial-abstract). | ||
- For more details about solving an optimal control problem, we refer to the [solve tutorial](@ref tutorial-solve) and to plot a solution, check the [plot a solution tutorial](@ref tutorial-plot). | ||
|
||
To enter into the control-toolbox, press `>` key. | ||
|
||
!!! tip "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`. | ||
|
||
![Control-toolbox REPL](assets/ct-repl-95x30.gif) | ||
|
||
!!! note "Credits" | ||
|
||
This gif has been made with this version of [Replay.jl](https://github.com/ocots/Replay.jl). To make the gif we first need a script (named ct-repl.jl) containing: | ||
|
||
```julia | ||
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](https://github.com/asciinema/asciinema) | ||
and to save the record into a gif file, we have used | ||
[agg](https://github.com/asciinema/agg). | ||
The shell script to obtain the gif is: | ||
|
||
```bash | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters