DobotStudio Pro can run several Lua scripts at the same time. This article shows how to use that parallelism to monitor digital inputs (DI signals) independently of the main program, which is ideal for logging and event handling in robot automation.
Parallel tasks in DobotStudio Pro
DobotStudio Pro identifies tasks through a file naming scheme: src0.lua is the main program (task 0), while src1.lua, src2.lua and any further files run as parallel tasks. All tasks run independently and at the same time, so time critical sequences in the main program are never blocked.
DI monitoring as a parallel task
The following task monitors input DI1 continuously for state changes and records every edge. The check runs every 10 milliseconds:
log("Starting DI monitoring...")
local last = nil
while true do
local current = DI(1)
if last ~= nil and current ~= last then
local state = current == 1 and "ON" or "OFF"
log("DI1 state changed: " .. state)
end
last = current
Sleep(10) -- check every 10ms
end
Conclusion
Parallel Lua scripts make permanent signal monitoring possible without affecting the main program. Combined with central logging, for example through our log server Leif, this grows into complete monitoring for your production.
Frequently asked questions
How do I run several Lua scripts at the same time on a Dobot?
Through the file naming scheme of DobotStudio Pro: src0.lua is the main program, while src1.lua, src2.lua and so on start as parallel tasks and run independently of each other.
How do I read a digital input in Dobot Lua?
With the DI(n) function, for example DI(1) for input 1. The return value is 1 (ON) or 0 (OFF). In a loop with Sleep(10) the input can be monitored continuously.