JuliaControl / ControlSystems.jl

A Control Systems Toolbox for Julia
https://juliacontrol.github.io/ControlSystems.jl/stable/
Other
509 stars 85 forks source link

c2d not working with method input #873

Closed fibonatic closed 11 months ago

fibonatic commented 11 months ago

When I attempt to specify which discretization method I want to use, for example: Gd = c2d(G::TransferFunction{<:Continuous}, Ts, method=:zoh) I get the error: c2d_x0map(::AbstractStateSpace{<:Continuous}, ::Real) got unsupported keyword argument "method"

I am using Julia 1.9.3 and just installed ControlSystems.jl today. I also get the same error in Julia 1.8.5

baggepinnen commented 11 months ago

This appears to work for me

julia> G = tf(1.0, [1, 1])
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
   1.0
----------
1.0s + 1.0

Continuous-time transfer function model

julia> c2d(G, 0.1, :zoh)
TransferFunction{Discrete{Float64}, ControlSystemsBase.SisoRational{Float64}}
   0.09516258196404037
-------------------------
1.0z - 0.9048374180359594

Sample Time: 0.1 (seconds)
Discrete-time transfer function model

Are you trying to use method as a keyword argument? It's a regular positional argument.

baggepinnen commented 11 months ago

On a side note, are you the user handle fibonatic on the control discord? If so, we spoke about coherence functions this morning ;)

fibonatic commented 11 months ago

Yes, I am currently busy writing some test code, but it has been a while since I used Julia. And I was indeed using method=:zoh as input argument. Without the method= it is indeed working OK. Thanks!

baggepinnen commented 11 months ago

You might have been confused by the fact that the method argument hasa default value indicated by the signature in the docstring

    sysd = c2d(sys::AbstractStateSpace{<:Continuous}, Ts, method=:zoh; w_prewarp=0)
    Gd = c2d(G::TransferFunction{<:Continuous}, Ts, method=:zoh)

Note the difference between the two method signatures, the ; denotes the delimitation between positional arguments and keyword arguments.