Timing issue with custom settings

Hi, I provided a while ago a LUA script to cycle through the cells of the seed tray. This works fine, but on occasion there seems to be timing problems. I use a custom setting to set the next selected cell for each cycle. Sometimes this customer setting does not seem to propagate fast enough from the time I set it in the Lua code until the next cycle where the LUA code is checking the value again. It’s a very strange behavior. I tried to put a “sync” API call in each loop, but I do not know if this is the right approach. Can some one hint me in the right direction for that?
To save you the search effort, here is the LUA Script:
tray = variable(“Seed Tray”)
cell_label = env(“seed_tray_act_cell”)
if cell_label == nil then
– The variable doesn’t exist, so set a default value
cell_label = “A1”

function get_next_cell(cell_id)
– Extract the row letter and column number from the cell identifier
local row_letter = string.sub(cell_id, 1, 1)
local col_number = tonumber(string.sub(cell_id, 2))

– Calculate the row and column of the next cell
local next_row_letter = row_letter
local next_col_number = col_number + 1
if next_col_number > 4 then – Wrap around to the next row if necessary
next_col_number = 1
if row_letter == “D” then – Wrap around to the first row if necessary
next_row_letter = “A”
next_row_letter = string.char(string.byte(row_letter) + 1) – Increment the row letter

– Construct the identifier of the next cell
local next_cell_id = next_row_letter … string.format(“%d”, next_col_number)

return next_cell_id

cell = get_seed_tray_cell(tray, cell_label)
cell_depth = 7
vacuum_pump_pin = 9

– Checks
if not verify_tool() then

– Send message with cell info
local cell_coordinates = " (" … cell.x … ", " … cell.y … ", " … cell.z - cell_depth … “)”
send_message(“info”, "Picking up seed from cell " … cell_label … cell_coordinates, “toast”)

– Store next Cell Label
cell_label = get_next_cell(cell_label)

– Job
start_time = os.time() * 1000
function job(status, percent)
set_job_progress(“Pick from Seed Tray”, {
status = status,
percent = percent,
time = start_time

– Safe Z move to above the cell
job(“Moving to Seed Tray”, 25)
x = cell.x,
y = cell.y,
z = cell.z + 25,
safe_z = true

– Pick up seed
job(“Picking up seed”, 75)

write_pin(vacuum_pump_pin, “digital”, 1)
move_absolute(cell.x, cell.y, cell.z - cell_depth)

– Retract Z
job(“Retracting Z”, 90)
move_absolute(cell.x, cell.y, cell.z + 150)
job(“Complete”, 100)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.