From 6eee99e0b7974a495dfc5cc37af20c78b9ce8510 Mon Sep 17 00:00:00 2001
From: Fredrik Bagge Carlson <cont-frb@ulund.org>
Date: Sun, 20 Aug 2017 21:38:08 +0200
Subject: [PATCH] Update file structure

---
 src/LabProcesses.jl                          | 70 ++------------------
 src/interface.jl                             | 27 ++++++++
 src/interface_implementations/ballandbeam.jl | 39 +++++++++++
 3 files changed, 70 insertions(+), 66 deletions(-)
 create mode 100644 src/interface.jl
 create mode 100644 src/interface_implementations/ballandbeam.jl

diff --git a/src/LabProcesses.jl b/src/LabProcesses.jl
index d067c04..6cd40f1 100644
--- a/src/LabProcesses.jl
+++ b/src/LabProcesses.jl
@@ -1,73 +1,11 @@
 module LabProcesses
-export AbstractProcess, PhycicalProcess, SimulatedProcess, BallAndBeam, BallAndBeamSimulator, BallAndBeamType
-export  num_outputs,
-        num_inputs,
-        outputrange,
-        inputrange,
-        isstable,
-        sampletime,
-        control,
-        measure
 
+using ControlSystems
+
+include("interface.jl")
+include("interface_implementations/ballandbeam.jl")
 
 include("utilities.jl")
 include("controllers.jl")
 
-# Interface specification ===================================================================
-abstract type AbstractProcess end
-abstract type PhycicalProcess  <: AbstractProcess end
-abstract type SimulatedProcess <: AbstractProcess end
-
-num_outputs(p::AbstractProcess) = error("Function not implemented for $(typeof(p))")
-num_inputs(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
-outputrange(p::AbstractProcess) = error("Function not implemented for $(typeof(p))")
-inputrange(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
-isstable(p::AbstractProcess)    = error("Function not implemented for $(typeof(p))")
-sampletime(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))")
-
-initialize(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
-finalize(p::AbstractProcess)    = error("Function not implemented for $(typeof(p))")
-
-
-# Interface implementation Ball And Beam ====================================================
-
-struct BallAndBeam <: PhysicalProcess
-    h::Float64
-end
-BallAndBeam() = BallAndBeam(0.01)
-
-struct BallAndBeamSimulator <: SimulatedProcess
-    h::Float64
-end
-BallAndBeamSimulator() = BallAndBeamSimulator(0.01)
-
-const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator}
-num_outputs(p::BallAndBeamType) = 2
-num_inputs(p::BallAndBeamType)  = 1
-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
-
-control(p::BallAndBeam, u)  = ccall((:comedi_write, comedipath),Int32,
-                                        (Int32,Int32,Int32,Int32),0,1,1,num2io(u[1]))
-measure(p::BallAndBeam)     = io2num(ccall((:comedi_read,comedipath), Int32,
-                                        (Int32,Int32,Int32), 0,0,0))
-
-control(p::BallAndBeamSimulator, u)  = error("Not yet implemented")
-measure(p::BallAndBeamSimulator)     = error("Not yet implemented")
-
-const comedipath = "../c/comedi_bridge.so"
-const conversion = 65535/20
-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)    = (control(P,0);ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0))
-initialize(p::BallAndBeamSimulator)  = nothing
-finalize(p::BallAndBeamSimulator)    = nothing
-
 end # module
diff --git a/src/interface.jl b/src/interface.jl
new file mode 100644
index 0000000..aa90e30
--- /dev/null
+++ b/src/interface.jl
@@ -0,0 +1,27 @@
+export AbstractProcess, PhycicalProcess, SimulatedProcess
+export  num_outputs,
+        num_inputs,
+        outputrange,
+        inputrange,
+        isstable,
+        sampletime,
+        control,
+        measure
+
+# Interface specification ===================================================================
+abstract type AbstractProcess end
+abstract type PhycicalProcess  <: AbstractProcess end
+abstract type SimulatedProcess <: AbstractProcess end
+
+num_outputs(p::AbstractProcess) = error("Function not implemented for $(typeof(p))")
+num_inputs(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
+outputrange(p::AbstractProcess) = error("Function not implemented for $(typeof(p))")
+inputrange(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
+isstable(p::AbstractProcess)    = error("Function not implemented for $(typeof(p))")
+sampletime(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))")
+
+initialize(p::AbstractProcess)  = error("Function not implemented for $(typeof(p))")
+finalize(p::AbstractProcess)    = error("Function not implemented for $(typeof(p))")
diff --git a/src/interface_implementations/ballandbeam.jl b/src/interface_implementations/ballandbeam.jl
new file mode 100644
index 0000000..a88838a
--- /dev/null
+++ b/src/interface_implementations/ballandbeam.jl
@@ -0,0 +1,39 @@
+# Interface implementation Ball And Beam ====================================================
+
+export BallAndBeam, BallAndBeamSimulator, BallAndBeamType
+
+struct BallAndBeam <: PhysicalProcess
+    h::Float64
+end
+BallAndBeam() = BallAndBeam(0.01)
+
+struct BallAndBeamSimulator <: SimulatedProcess
+    h::Float64
+end
+BallAndBeamSimulator() = BallAndBeamSimulator(0.01)
+
+const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator}
+num_outputs(p::BallAndBeamType) = 2
+num_inputs(p::BallAndBeamType)  = 1
+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
+
+control(p::BallAndBeam, u)  = ccall((:comedi_write, comedipath),Int32,
+                                        (Int32,Int32,Int32,Int32),0,1,1,num2io(u[1]))
+measure(p::BallAndBeam)     = io2num(ccall((:comedi_read,comedipath), Int32,
+                                        (Int32,Int32,Int32), 0,0,0))
+
+control(p::BallAndBeamSimulator, u)  = error("Not yet implemented")
+measure(p::BallAndBeamSimulator)     = error("Not yet implemented")
+
+const comedipath = "../c/comedi_bridge.so"
+const conversion = 65535/20
+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)    = (control(P,0);ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0))
+initialize(p::BallAndBeamSimulator)  = nothing
+finalize(p::BallAndBeamSimulator)    = nothing
-- 
GitLab