Skip to content

Commit

Permalink
add template f_(x_,u_) to allow for arbitrary input (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ueliwechsler committed Feb 3, 2020
1 parent 7774262 commit 641d4f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ function parse_system(exprs)
AT = abstract_system_type
# if the system has the structure x_ = A_*x_ + B_*u_ ,
# handle u_ as input variable
if @capture(stripped, (x_ = A_*x_ + B_*u_) | (x_ = A_*x_ + B_*u_ + c_) )
if @capture(stripped, (x_ = A_*x_ + B_*u_) |
(x_ = A_*x_ + B_*u_ + c_) |
(x_ = f_(x_, u_)) )
input_var = u
end

Expand Down Expand Up @@ -655,10 +657,10 @@ Similarly, a noise variable is specified with `noise: var` or `noise=var`.
**Exceptions.** The following exceptions and particular cases apply:
- If the right-hand side has the form `A*x + B*foo` or `A*x + B*foo + c`, the
equation is parsed as a controlled linear (affine) system with input `foo`.
Note that in this case, `input` variable does not correspond to the default
value of `u`, but `foo` is parsed as being the input.
- If the right-hand side has the form `A*x + B*foo`, `A*x + B*foo + c` or
`f(x, foo)`, the equation is parsed as a controlled linear (affine) or controlled
black-box system with input `foo`. Note that in this case, `input` variable does
not correspond to the default value of `u`, but `foo` is parsed as being the input.
- If the left-hand side contains a multiplicative term in the form `E*x⁺` or `E*x'`,
the equation is parsed as an algebraic system. In this case, the asterisk
Expand Down
3 changes: 3 additions & 0 deletions test/@system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ end
@test sys == ConstrainedBlackBoxContinuousSystem(f1, 2, X)
sys = @system(x' = f1(x, u), x X, u U, dims=(1, 2))
@test sys == ConstrainedBlackBoxControlContinuousSystem(f1, 1, 2, X, U)
# allow for arbitrary input with definition for rhs of the form f_(x_, u_)
sys = @system(x' = f1(x, u123), x X, u123 U, dims=(2, 3))
@test sys == ConstrainedBlackBoxControlContinuousSystem(f1, 2, 3, X, U)
end

# ==================
Expand Down

0 comments on commit 641d4f5

Please sign in to comment.