From 1b5a03c899e2c80e55e59be0312ea7141dd6c3f5 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson <cont-frb@ulund.org> Date: Mon, 21 Aug 2017 20:08:24 +0200 Subject: [PATCH] Add a bias term to interface spec. --- src/LabProcesses.jl | 2 +- src/controllers.jl | 1 + src/interface.jl | 1 + src/interface_documentation.jl | 8 ++++++++ src/interface_implementations/ballandbeam.jl | 3 +++ src/interface_implementations/eth_helicopter.jl | 4 ++++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/LabProcesses.jl b/src/LabProcesses.jl index 83713b7..e7cc583 100644 --- a/src/LabProcesses.jl +++ b/src/LabProcesses.jl @@ -1,4 +1,4 @@ -#__precompile__() +__precompile__() module LabProcesses diff --git a/src/controllers.jl b/src/controllers.jl index 1bdb043..8b91d74 100644 --- a/src/controllers.jl +++ b/src/controllers.jl @@ -24,6 +24,7 @@ function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10 rf = sysFF == nothing ? r[i] : sysfilter!(stateFF, sysFF, r[i]) e = rf-y[i] ui = sysfilter!(stateFB, sysFB, e)[1] + ui + bias(P) end initialize(P) diff --git a/src/interface.jl b/src/interface.jl index 065dbd6..db99995 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -24,6 +24,7 @@ inputrange(p::AbstractProcess) = error("Function not implemented for $(typeof(p isstable(p::AbstractProcess) = error("Function not implemented for $(typeof(p))") isasstable(p::AbstractProcess) = error("Function not implemented for $(typeof(p))") sampletime(p::AbstractProcess) = error("Function not implemented for $(typeof(p))") +bias(p::AbstractProcess) = error("Function not implemented for $(typeof(p))") control(p::AbstractProcess, u) = error("Function not implemented for $(typeof(p))") measure(p::AbstractProcess) = error("Function not implemented for $(typeof(p))") diff --git a/src/interface_documentation.jl b/src/interface_documentation.jl index 59e6de5..d9fec07 100644 --- a/src/interface_documentation.jl +++ b/src/interface_documentation.jl @@ -62,6 +62,14 @@ Return the sample time of the process in seconds. """ sampletime +""" + b = bias(P::AbstractProcess) +Return an input bias for the process. This could be, i.e., the constant input uâ‚€ around which +a nonlinear system is linearized, or whatever other bias might exist on the input. +`length(b) = num_inputs(P)` +""" +bias + """ control(P::AbstractProcess, u) Send a control signal to the process. `u` must have dimension equal to `num_inputs(P)` diff --git a/src/interface_implementations/ballandbeam.jl b/src/interface_implementations/ballandbeam.jl index e4a8a63..fe1ed04 100644 --- a/src/interface_implementations/ballandbeam.jl +++ b/src/interface_implementations/ballandbeam.jl @@ -22,6 +22,9 @@ inputrange(p::BallAndBeamType) = [(-10,10)] isstable(p::BallAndBeamType) = false isasstable(p::BallAndBeamType) = false sampletime(p::BallAndBeamType) = p.h +bias(p::BallAndBeam) = p.bias +bias(p::BallAndBeamSimulator) = 0 + control(p::BallAndBeam, u) = ccall((:comedi_write, comedipath),Int32, (Int32,Int32,Int32,Int32),0,1,1,num2io(u[1]+p.bias)) diff --git a/src/interface_implementations/eth_helicopter.jl b/src/interface_implementations/eth_helicopter.jl index 1011c99..a541578 100644 --- a/src/interface_implementations/eth_helicopter.jl +++ b/src/interface_implementations/eth_helicopter.jl @@ -4,11 +4,13 @@ export ETHHelicopter, ETHHelicopterSimulator, ETHHelicopterType struct ETHHelicopter <: PhysicalProcess h::Float64 + bias::Float64 end ETHHelicopter() = ETHHelicopter(0.050) struct ETHHelicopterSimulator <: SimulatedProcess h::Float64 + bias::Float64 state::Vector{Float64} end ETHHelicopterSimulator() = ETHHelicopterSimulator(0.01, zeros(4)) @@ -21,6 +23,8 @@ inputrange(p::ETHHelicopterType) = [(-10,10)] isstable(p::ETHHelicopterType) = false isasstable(p::ETHHelicopterType) = false sampletime(p::ETHHelicopterType) = p.h +bias(p::ETHHelicopterType) = p.bias + function control(p::ETHHelicopter, u) ccall((:comedi_write, comedipath),Int32,(Int32,Int32,Int32,Int32), 0,1,0,num2io(u[1])) -- GitLab