-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjuliac_pid.jl
50 lines (37 loc) · 1.25 KB
/
juliac_pid.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module JuliacPID
import DiscretePIDs
import DiscretePIDs: DiscretePID
import Base.@ccallable
const T = Float64 # The numeric type used by the controller
# Set the initial PID parameters here
const pid = DiscretePIDs.DiscretePID(; K = T(1), Ti = 1, Td = false, Ts = 1)
@ccallable function calculate_control!(r::T, y::T, uff::T)::T
DiscretePIDs.calculate_control!(pid, r, y, uff)::T
end
@ccallable function set_K!(K::T, r::T, y::T)::Cvoid
DiscretePIDs.set_K!(pid, K, r, y)
nothing
end
@ccallable function set_Ti!(Ti::T)::Cvoid
DiscretePIDs.set_Ti!(pid, Ti)
nothing
end
@ccallable function set_Td!(Td::T)::Cvoid
DiscretePIDs.set_Td!(pid, Td)
nothing
end
@ccallable function reset_state!()::Cvoid
DiscretePIDs.reset_state!(pid)
nothing
end
# @ccallable function main()::Cint
# println(Core.stdout, "I'm alive and well")
# u = calculate_control!(0.0, 0.0, 0.0)
# println(Core.stdout, u)
# Cint(0)
# end
end
# compile using something like this, modified to suit your local paths
# cd(@__DIR__)
# run(`/home/fredrikb/repos/julia/julia --project --experimental /home/fredrikb/repos/julia/contrib/juliac.jl --output-lib juliac_pid --trim=unsafe-warn --experimental --compile-ccallable juliac_pid.jl`)
# run(`ls -ltrh`)