Skip to content

Commit 8ed3c52

Browse files
add documentation
1 parent 538b64b commit 8ed3c52

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/src/systems/ControlSystem.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ControlSystem
2+
3+
## System Constructors
4+
5+
```@docs
6+
ControlSystem
7+
```
8+
9+
## Composition and Accessor Functions
10+
11+
- `sys.eqs` or `equations(sys)`: The equations that define the system.
12+
- `sys.states` or `states(sys)`: The set of states in the system.
13+
- `sys.parameters` or `parameters(sys)`: The parameters of the system.
14+
- `sys.controls` or `controls(sys)`: The control variables of the system
15+
16+
## Transformations
17+
18+
```@docs
19+
runge_kutta_discretize
20+
```

src/systems/control/controlsystem.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ end
1818

1919
controls(sys::AbstractControlSystem) = isempty(sys.systems) ? sys.controls : [sys.controls;reduce(vcat,namespace_controls.(sys.systems))]
2020

21+
"""
22+
$(TYPEDEF)
23+
24+
A system describing an optimal control problem. This contains a loss function
25+
and ordinary differential equations with control variables that describe the
26+
dynamics.
27+
28+
# Fields
29+
$(FIELDS)
30+
31+
# Example
32+
33+
```
34+
using ModelingToolkit
35+
36+
@variables t x(t) v(t) u(t)
37+
@derivatives D'~t
38+
39+
loss = (4-x)^2 + 2v^2 + u^2
40+
eqs = [
41+
D(x) ~ v
42+
D(v) ~ u^3
43+
]
44+
45+
sys = ControlSystem(loss,eqs,t,[x,v],[u],[])
46+
```
47+
"""
2148
struct ControlSystem <: AbstractControlSystem
2249
"""The Loss function"""
2350
loss::Operation
@@ -86,6 +113,19 @@ function constructRadauIIA5(T::Type = Float64)
86113
return(DiffEqBase.ImplicitRKTableau(A,c,α,5))
87114
end
88115

116+
117+
"""
118+
```julia
119+
runge_kutta_discretize(sys::ControlSystem,dt,tspan;
120+
tab = ModelingToolkit.constructRadauIIA5())
121+
```
122+
123+
Transforms a nonlinear optimal control problem into a constrained
124+
`OptimizationProblem` according to a Runge-Kutta tableau that describes
125+
a collocation method. Requires a fixed `dt` over a given `timespan`.
126+
Defaults to using the 5th order RadauIIA tableau, and altnerative tableaus
127+
can be specified using the SciML tableau style.
128+
"""
89129
function runge_kutta_discretize(sys::ControlSystem,dt,tspan;
90130
tab = ModelingToolkit.constructRadauIIA5())
91131
n = length(tspan[1]:dt:tspan[2]) - 1

0 commit comments

Comments
 (0)