Commit 8912ea2a authored by Martin Karlsson's avatar Martin Karlsson
Browse files

update ETHheli to LabConnections

parent f85e48eb
Pipeline #526 failed with stage
in 1 minute and 3 seconds
......@@ -2,13 +2,14 @@
module LabProcesses
using ControlSystems
using ControlSystems, LabConnection.Computer
include("utilities.jl")
include("interface.jl")
include("interface_documentation.jl")
include("interface_implementations/ballandbeam.jl")
include("interface_implementations/eth_helicopter.jl")
include("reference_generators.jl")
include("controllers.jl")
......
......@@ -8,10 +8,15 @@
export ETHHelicopter, ETHHelicopterSimulator, AbstractETHHelicopter
struct ETHHelicopter <: PhysicalProcess
h::Float64
h::Float64
bias::Float64
stream::LabStream
measure1::AnalogInput10V
measure2::AnalogInput10V
control1::AnalogOutput10V
control2::AnalogOutput10V
end
ETHHelicopter() = ETHHelicopter(0.050, 0.)
ETHHelicopter() = ETHHelicopter(0.050, 0., ComediStream(), AnalogInput10V(0), AnalogInput10V(1), AnalogOutput10V(0), AnalogOutput10V(1))
struct ETHHelicopterSimulator <: SimulatedProcess
h::Float64
......@@ -32,22 +37,19 @@ bias(p::AbstractETHHelicopter) = p.bias
function control(p::ETHHelicopter, u)
ccall((:comedi_write, comedipath),Int32,(Int32,Int32,Int32,Int32), 0,1,0,num2io(u[1]))
ccall((:comedi_write, comedipath),Int32,(Int32,Int32,Int32,Int32), 0,1,1,num2io(u[2]))
send(p.control1,u[1])
send(p.control2,u[2])
end
measure(p::ETHHelicopter) = [io2num(ccall((:comedi_read, comedipath),Int32,(Int32,Int32,Int32), 0,0,i)) for i = 0:1] #i=0 for pitch, i=1 for yaw
measure(p::ETHHelicopter) = [read(p.measure1), read(p.measure2)] #i=0 for pitch, i=1 for yaw
control(p::ETHHelicopterSimulator, u) = error("Not yet implemented")
measure(p::ETHHelicopterSimulator) = error("Not yet implemented")
const comedipath = Pkg.dir("LabProcesses","c","comedi_bridge.so")
const conversion = 65535/20
io2num(x) = x/conversion -10 # Converts from io to float
num2io(x) = round(Int32,(x + 10)*conversion) # Converts from regular number to io
initialize(p::ETHHelicopter) = ccall((:comedi_start, comedipath),Int32,(Int32,), 0)
finalize(p::ETHHelicopter) = (control(p,0);ccall((:comedi_stop, comedipath),Int32,(Int32,), 0))
initialize(p::ETHHelicopter) = init_devices!(p.stream, p.measure1, p.measure2, p.control1, p.control2)
finalize(p::ETHHelicopter) = close(p.stream)
initialize(p::ETHHelicopterSimulator) = nothing
finalize(p::ETHHelicopterSimulator) = nothing
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