Commit 017bbe7d authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Draft interface and BallAndBeam implementation

parent 8f3aa8a5
# LabProcesses
[![Build Status](https://travis-ci.org/baggepinnen/LabProcesses.jl.svg?branch=master)](https://travis-ci.org/baggepinnen/LabProcesses.jl)
[![Coverage Status](https://coveralls.io/repos/baggepinnen/LabProcesses.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/baggepinnen/LabProcesses.jl?branch=master)
[![codecov.io](http://codecov.io/github/baggepinnen/LabProcesses.jl/coverage.svg?branch=master)](http://codecov.io/github/baggepinnen/LabProcesses.jl?branch=master)
Under development /Bagge
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
#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);
}
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
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