Use Pluto to control physical systems #958
Replies: 5 comments 11 replies
-
I'm actually considering Pluto for such applications (control of lab hardware and controlling/monitoring data acquisition. Pretty much our whole lab is Julia-based now, so it's the logical next step for us. Haven't done any real tests yet, but I'll gladly share feedback. |
Beta Was this translation helpful? Give feedback.
-
Hi @fonsp, An issue that comes to mind is the interaction between Pluto's re-evaluation of cells and code that has real-world side-effects. I haven't learned enough about how Pluto does re-evaluation to know it would be a problem, but it would be important to for Pluto to not unexpectedly re-run code that changes the physical state of the system. |
Beta Was this translation helpful? Give feedback.
-
Hi @fonsp The idea is to very quickly setup and connect to a real-time OBC or µcontroller using Pluto, with quick data logging & data processing. My first step was to use Pluto as a real-time charting system, taking advantage of the reactive nature of the notebook. I manage to create a very simple data logging system, however I cannot get the reactivity I would need to set up a real-time chart. (I can get the reactivity I want manually by spamming shift+enter but didn't find a way of doing programmatically) Having the possibility to trigger reactivity from a @async statement would be something needed for this type of application, where a background routine collect & process data while triggering reactive blocks in the note book to plot/analysis. What is remarkable is in term of efficiency, reading some serial, decoding and plotting is almost as easy as doing it with LabVIEW, however I feel like the notebook is still lacking key features to control reactivity. Here's an example of the code: begin
# Serial
sp = open("COM3", 100_000)
set_read_timeout(sp, 2)
set_write_timeout(sp, 2)
# Variable Init
const I_SP_INDEX = 2
const I_CV_INDEX = 7
t = DateTime[]
i_sp = Float64[]
i_cv = Float64[]
end @bind serial_state Radio(["Stop" => "Stop", "Run" => "Run"], default="Stop") begin
if serial_state == "Run"
# sp_flush(sp, SP_BUF_BOTH)
write(sp, "start\r\n") # Start Control Algorithm
@async begin
println("Capturing Data...")
elapsed = 0
x = empty!(t)
y = empty!(i_cv)
yr = empty!(i_sp)
while serial_state == "Run"
try
serial_data = String(readline(sp))
try
sdname, sdval = parse_serial_data(serial_data)
try
y = push!(i_cv, sdval[I_CV_INDEX])
yr = push!(i_sp, sdval[I_SP_INDEX])
x = push!(t, now())
catch
println("Allocation Error!")
end
catch
println("Parsing Error!")
end
catch
println("Reading Error!")
end
sleep(0.1)
elapsed += 0.1
println("$elapsed s")
end
println("Done...")
end
else
write(sp, "stop\r\n") # Stop Control
if !isempty(t)
dt = broadcast(-,t, t[1])./Millisecond(1000)
else
dt = []
end
x = dt
y = i_cv
yr = i_sp
end
end I've been working as a senior control systems engineer on lots of real physical platform (drones, satellites, robots...) with LabVIEW, Matlab, C, C++ & now Julia. I'll be more than happy to help regarding those problematics |
Beta Was this translation helpful? Give feedback.
-
I've written several lab instrumentation measurement/control systems in Labview, and my (positive!) experience with Pluto for data analysis would make me very hesitant to use it to control physical systems. There's a lot of promise here, and I'm excited by the idea, but also skeptical given the inflexibility of the physical world, and the high costs imposed (up to & including mortal danger) when a physical system goes astray. The reactive programming model works well at the scale of a small notebook, but as the complexity of any notebook grows, the unseen connections between cell dependencies become harder to untangle. Physical systems tend to have the same sort of interdependent behavior, and the more complex the system, the harder it is to control those interactions. Trying to manage feedback loops between reactive software and "reactive" (and possibly dangerous) physical systems could quickly turn into a nightmare. The best way to limit the scope of these interdependencies within Pluto would be allowing sub-notebooks with clearly-defined inputs & outputs (and certainly no implicit global state). The main challenge arises from the need to acquire/process sensor & control data without triggering unintentional reactivity. As an example, let's walk through the entire data-acquisition pipeline for the single most important part of any control system: a physical emergency stop button. The voltage across the E-stop button is read by some data-acquisition hardware (alongside several other simultaneous signal acquisitions for other sensors) at some regular interval (the "polling rate"). The data-acquisition hardware ("DAQ") communicates with the computer using some serial interface, and from there to software via an instrument driver. From there, Julia could either read the E-stop signal from the driver every time it is sent, drop the signal if it's busy with other tasks, or feed into a (circular/fixed-size/dynamic?) buffer. The corresponding variable ( On reflection, most of the issues that might arise when controlling a physical system with a reactive notebook could be handled by:
It'd also be nice to have 2D layouting and built-in (or at least fonsp-blessed) tools for prescribing the layout & appearance of buttons/switches/indicators/etc. |
Beta Was this translation helpful? Give feedback.
-
Here's a more detailed suggestion in this direction, that (hopefully) is in keeping with Pluto philosophy: |
Beta Was this translation helpful? Give feedback.
-
We are very interested to learn how Pluto can be used to control physical systems, and we would like to hear your ideas on how Pluto can be improved to better support this use case!
Why?
Controlling physical systems is important, but the software to do so is either difficult to use (e.g. C++), or incredibly easy to use (e.g. micro:bit) but not designed for 'adults'. Being able to control physical systems directly from Pluto would mean that you can work in the same environment as your analysis and modeling.
If you have experience in this subject, try out Pluto and tell us your ideas! We might have money for hardware and there might be options for a GSOC-like project, get in touch! fons@plutojl.org
Beta Was this translation helpful? Give feedback.
All reactions