SymbolicControlSystems.jl contains a number of functions for converting to and from sympy, but the support for Symbolics.jl is not that well developed. However, it does look like the following works
julia> using Symbolics
julia> @variables s;
julia> (s+1) / (s+2);
julia> using SymbolicControlSystems
julia> G = (s+1) / (s+2)
(1 + s) / (2 + s)
julia> tf(G)
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
1.0s + 1.0
----------
1.0s + 2.0
Continuous-time transfer function model
using Symbolics, ControlSystemsBase
@variables R a b c d Ī Ļ U J Q s
input = 2s + 4U*a*s^3 + Q*(J*s+s)/(4Ī*U*s + 2a)
function split_s(input)
inp = simplify(input, expand=true)
vcat([Num(Symbolics.coeff(inp, s^i)) for i in Symbolics.degree(inp, s):-1:1],
substitute(inp, s => 0))
end
function symbolic2tf(expr::Num)
numerator, denominator = Symbolics.arguments(Symbolics.value(simplify(expr)))
num = split_s(numerator)
den = split_s(denominator)
num, den
tf(num, den)
end
res = symbolic2tf(input)
@baggepinnen What do you think about this solution?
Thatās not sufficient, your function produces the wrong result for this PID controller
@variables s
1 + s + 1/s
julia> symbolic2tf(1 + s + 1/s)
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Num}}
1
--
1s
Continuous-time transfer function model