Commit 48557a1a authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Update controller

parent be16098a
......@@ -11,6 +11,7 @@ export num_outputs,
include("utilities.jl")
include("controllers.jl")
# Interface specification ===================================================================
abstract type AbstractProcess end
......@@ -44,7 +45,7 @@ end
const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator}
num_outputs(p::BallAndBeamType) = 2
num_inputs(p::BallAndBeamType) = 1
outputrange(p::BallAndBeamType) = [(-10,10)]
outputrange(p::BallAndBeamType) = [(-10,10),(-1,1)] # Beam angle, Ball position
inputrange(p::BallAndBeamType) = [(-10,10)]
isstable(p::BallAndBeamType) = false
sampletime(p::BallAndBeamType) = p.h
......@@ -63,7 +64,7 @@ io2num(x) = x/conversion -10 # Converts from io to float
num2io(x) = round(Int32,x*100 + 2050) # Converts from regular number to io
initialize(p::BallAndBeam) = ccall((:comedi_start, comedipath),Int32,(Int32,), 0)
finalize(p::BallAndBeam) = ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0)
finalize(p::BallAndBeam) = (control(P,0);ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0))
initialize(p::BallAndBeamSimulator) = nothing
finalize(p::BallAndBeamSimulator) = nothing
......
export run_control_2DOF
"""
y,u,r = run_control(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t)))
Perform control experiemnt where the feedback and feedforward controllers are given by
`sysFB` and `sysFF`, both of type `StateSpace`. See [`fbdesign`](@ref) [`ffdesign`](@ref).
`sysFB` and `sysFF`, both of type `StateSpace`.
`reference` is a reference generating function that accepts a scalar `t` (time in seconds) and outputs a scalar `r`, default is `reference(t) = sign(sin(2π*t))`.
The outputs `y,u,r` are the beam angle, control signal and reference respectively.
"""
function run_control(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t)))
function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t)))
h = sampletime(P)
y = zeros(0:h:duration)
u = zeros(0:h:duration)
......@@ -36,7 +38,6 @@ function run_control(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, ref
control(P, u[i])
end
end
control(P, 0)
finalize(P)
y,u,r
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment