diff --git a/README.md b/README.md index 58ac930da09767067b07ea7ae3bcb062e889e033..1c9641ccd156e7319ce1ed08c32d25f32cb7aea8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ # LabProcesses -[](https://travis-ci.org/baggepinnen/LabProcesses.jl) - -[](https://coveralls.io/github/baggepinnen/LabProcesses.jl?branch=master) - -[](http://codecov.io/github/baggepinnen/LabProcesses.jl?branch=master) +Under development /Bagge diff --git a/c/Makefile b/c/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2983d113d7fac4c5b0ebea540ebf3948ca263af9 --- /dev/null +++ b/c/Makefile @@ -0,0 +1,15 @@ +CC=gcc + +CFLAGS=-c -Wall -fPIC + +SOURCES=comedi_bridge.c +OBJECTS=$(SOURCES:.c=.o) + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +lib: $(OBJECTS) + $(CC) -shared -fPIC -lcomedi -lm -o comedi_bridge.so $(OBJECTS) + +clean: + rm *.o *.so diff --git a/c/comedi_bridge.c b/c/comedi_bridge.c new file mode 100644 index 0000000000000000000000000000000000000000..c03c2f525797fcef7c86618aa6e3e14d2e6d7fcc --- /dev/null +++ b/c/comedi_bridge.c @@ -0,0 +1,38 @@ +#include <stdio.h> /* for printf() */ +#include <comedilib.h> + +int range = 0; +int aref = AREF_GROUND; +comedi_t *it; + +int comedi_write(int comediNbr, int subdev, int chan, int writeValue) { + static int retval; + retval = comedi_data_write(it, subdev, chan, range, aref, writeValue); + return retval; +} + +int comedi_read(int comediNbr, int subdev, int chan) { + lsampl_t data; + comedi_data_read(it, subdev, chan, range, aref, &data); + return data; +} + +int comedi_start(int comediNbr) { + it = comedi_open("/dev/comedi0"); + if(it == NULL) + { + comedi_perror("comedi_open_error"); + return -1; + } + return 0; +} + +void comedi_stop(int comediNbr) { + // Ad-hoc. Should be updated: + comedi_data_write(it, 1, 0, range, aref, 32767); + comedi_data_write(it, 1, 1, range, aref, 32767); + comedi_close(it); +} + + + diff --git a/c/comedi_bridge.o b/c/comedi_bridge.o new file mode 100644 index 0000000000000000000000000000000000000000..d35413629f28007e9b35f9d6f1179b0624e5eff1 Binary files /dev/null and b/c/comedi_bridge.o differ diff --git a/c/comedi_bridge.so b/c/comedi_bridge.so new file mode 100644 index 0000000000000000000000000000000000000000..8cce1524f394bbcf45466c8fe974f9e0c4b76ae1 Binary files /dev/null and b/c/comedi_bridge.so differ diff --git a/src/LabProcesses.jl b/src/LabProcesses.jl index 0ede1342c143a9d6601877acea4ffe5c5446dbdf..1c963b0fa1b205b7bd778c361ef7b6b97732bab8 100644 --- a/src/LabProcesses.jl +++ b/src/LabProcesses.jl @@ -1,5 +1,51 @@ module LabProcesses -# package code goes here +# Interface specification =================================================================== +abstract type AbstractProcess end +abstract type PhycicalProcess <: AbstractProcess end +abstract type SimulatedProcess <: AbstractProcess end + +num_outputs(p::AbstractProcess) = p.ny +num_inputs(p::AbstractProcess) = p.nu +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))") + + +# Interface implementation Ball And Beam ==================================================== + +struct BallAndBeam <: PhysicalProcess + h::Float64 +end + +struct BallAndBeamSimulator <: SimulatedProcess + h::Float64 +end + +const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator} +num_outputs(p::BallAndBeamType) = 2 +num_inputs(p::BallAndBeamType) = 1 +outputrange(p::BallAndBeamType) = [(-10,10)] +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)) + +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 + +control(p::BallAndBeamSimulator, u) = error("Not yet implemented") +measure(p::BallAndBeamSimulator) = error("Not yet implemented") + end # module