Currently I’m trying to plot real-time measured values (force values from a robot controller). By real-time I mean, at a 125Hz frequency as the values arrive. I’m working with Makie and concluded to this code based on this issue.
I will just comment the above code:
I got the values over TCP as a string in a format of "[1.1, 2.2, 3.3, 4.4, 5.5, 6.6]\n"
.
Then I update a string Node
to process it with readdlm()
. Right after processing I push the new values into a “fix size” array. This function is used to make the “fix size behaviour”:
function pushTo!(A, newX, maxSize)
if size(A, 1) < maxSize
push!(A, newX)
else
popfirst!(A)
push!(A, newX)
end
end
After updating the arrays I use the lastUpdate
node to update the plot. I throttle it down:
if (current_time-lastUpdate[])/1000000 > UPDATE_LAT
lastUpdate[] = current_time
end
where UPDATE_LAT
is around 200 miliseconds. If that time is up, the next function is called to update the plot:
function updatePlot(val)
fxNode[] = FxV
fyNode[] = FyV
fzNode[] = FzV
txNode[] = TxV
tyNode[] = TyV
tzNode[] = TzV
# update limits:
for i in 1:6
AbstractPlotting.update_limits!(sArr[i])
end
AbstractPlotting.update!(scene)
end
Here’s an example picture what I’ve created (with some random noise):
I tried to lower the UPDATE_LAT
value to like 100 ms, but then plotting freezes out.
Overall I’m happy that it works, but could it be improved? And is this the way to do this kind of plotting, or should I do something completely different?
Some version infos:
julia> versioninfo()
Julia Version 1.0.2
Commit d789231e99 (2018-11-08 20:11 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)
Environment:
JULIA_EDITOR = "C:\Users\cstamas\AppData\Local\atom\app-1.34.0\atom.exe" -a
JULIA_NUM_THREADS = 4
(julia-RTPlot) pkg> st
Status `C:\Users\cstamas\Documents\Coding\julia-RTPlot\Project.toml`
[537997a7] AbstractPlotting v0.9.4 #master (https://github.com/JuliaPlots/AbstractPlotting.jl.git) [6e4b80f9] BenchmarkTools v0.4.2
[5789e2e9] FileIO v1.0.5
[e9467ef8] GLMakie v0.0.4 #master (https://github.com/JuliaPlots/GLMakie.jl.git)
[ee78f7c6] Makie v0.9.1 #master (https://github.com/JuliaPlots/Makie.jl.git)
[510215fc] Observables v0.2.3
(I feel this post a bit unnecessary as my code is working, but I’m curious, if I made some mistake and/or how could I improve it.)