Skip to content

Commit d38b616

Browse files
committed
throw on MIMO for tf
1 parent b025c2a commit d38b616

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/SymbolicControlSystems.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ Return a string with C-code for filtering a signal `u` through `G`.
261261
- `cse`: Perform common subexpression elimination. This generally improvems the performance of the generated code.
262262
"""
263263
function ccode(G::TransferFunction; simplify = identity, cse = true)
264+
(G.nu == 1 && G.ny == 1) || throw(ArgumentError("C-code generation for transfer functions does not support multiple inputs or outputs, convert the transfer function to a statespace system using ss(G) and call ccode on that instead."))
264265
P = Sym(G)
265266
P.has(z) || error("Did not find `z` in symbolic expression")
266267
P.has(s) && error("Found `s` in symbolic expression, provide expression in `z`")
@@ -348,8 +349,8 @@ function ccode(sys::StateSpace{<:Discrete}; cse = true, function_name = "transfe
348349
end
349350
x1 = zeros(Sym, nx) # workaround for strange bug with undefinied referece appearing in Pluto only
350351
y = zeros(Sym, ny)
351-
@show x1 = mul!(x1, sys.A, x) + sys.B * u
352-
@show y = mul!(y, sys.C, x) + sys.D * u
352+
x1 = mul!(x1, sys.A, x) + sys.B * u
353+
y = mul!(y, sys.C, x) + sys.D * u
353354
# @show y = sp.collect.(y, x)
354355

355356
u_str = nu == 1 ? "double u" : "double *u"
@@ -367,6 +368,7 @@ void $(function_name)(double *y, $(u_str)$(var_str)) {
367368
subex, final = sp.cse([x1; y])
368369
x1 = final[][1:length(x1)]
369370
y = final[][length(x1)+1:end]
371+
code *= "\n // Common sub expressions. These are all called xi, but are unrelated to the state x\n"
370372
for se in subex
371373
code *= " double $(se[1]) = $(sp.ccode(se[2]));\n"
372374
end

0 commit comments

Comments
 (0)