Trying to get the seed trough position in lua

Hi everyone!

I’m trying to create an automated sequence using Lua script, but the documentation is not very helpful.

I’m stuck at trying to get the position of the Seed Trough 1, I can’t find in documentation anything related to getting the position of a specific tool.

Here’s my script. I’m trying to get the value for tray_coordinates.

Be aware that this is a Work in progress. The code is in a non-functional state.

grid_points = variable("Number of points")

cell_depth = 15
vacuum_pump_pin = 9
seed_depth = env("planting_depth")
-- tray_coordinates = get_coordinate("Seed trough 1") -- LOOK HERE!!!!

if verify_tool() then
    send_message("info", "Dismounting tool")
    dismount_tool()
end

send_message("info", "Mounting Seeder tool")
mount_tool("Seeder")

local grid = grid ({
  grid_points = grid_points,
  start = variable("Starting location"),
  spacing = variable("Spacing")
})

job = "Pick and Plant x" .. grid.total

toast("Executing Pick and Plant sequence on a " ..
      grid_points.x .. " x " .. grid_points.y ..
      " grid with " .. grid.total .. " points.")

grid.each(function(cell)

    -- Move above tray
    send_message("info", "Moving above seed tray cell " .. cell_label .. tray_coordinates)
    move_absolute({
        x = tray_cell.x,
        y = tray_cell.y,
        z = tray_cell.z + 25,
        safe_z = true
    })

    send_message("info", "Lowering to pick up seed from " .. tray_coordinates)
    move_absolute({
        x = tray_cell.x,
        y = tray_cell.y,
        z = tray_cell.z - cell_depth,
        safe_z = true
    })

    send_message("info", "Activating vacuum pump")
    write_pin(vacuum_pump_pin, "digital", 1)  -- Turn on vacuum pump

    -- Wait briefly to ensure suction
    wait(500)

    -- Move up with the seed
    send_message("info", "Lifting seed")
    move_absolute({
        x = tray_cell.x,
        y = tray_cell.y,
        z = tray_cell.z + 25,
        safe_z = true
    })

    -- Move to planting location
    local grid_point_coordinates = "(" .. cell.x .. ", " .. cell.y .. ", " .. cell.z .. ")"
    send_message("info", "Moving to planting location " .. grid_point_coordinates)
    move_absolute(cell.x, cell.y, cell.z)

    -- Lower to plant
    send_message("info", "Lowering to plant seed")
    move_absolute({
        x = cell.x,
        y = cell.y,
        z = cell.z - 5,  -- Lower slightly to ensure seed lands properly
        safe_z = true
    })

    -- Deactivate vacuum to release seed
    send_message("info", "Releasing seed")
    write_pin(vacuum_pump_pin, "digital", 0)  -- Turn off vacuum pump

    -- Wait briefly to ensure release
    wait(500)

    -- Move up after planting
    send_message("info", "Lifting after planting")
    move_absolute({
        x = cell.x,
        y = cell.y,
        z = cell.z + 25,
        safe_z = true
    })
end)

complete_job(job)

Thanks for helping

Hi @nbourre

Best to look at the Lua code on GitHub that implements featured sequence Mount Tool.

You will see that the code has to locate your chosen ‘tool’ (“Seed Trough 1”) from the set of all Points because only the Point object has location attribute values.

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