# Trying to get the seed trough position in lua

**URL:** <https://forum.farmbot.org/t/trying-to-get-the-seed-trough-position-in-lua/9653>\
**Category:** Software\
**Created:** [February 6, 2025, 8:55pm UTC](https://forum.farmbot.org/t/trying-to-get-the-seed-trough-position-in-lua/9653 "2025-02-06T20:55:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbourre](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/n/7993a0/32.png) [@nbourre](https://forum.farmbot.org/u/nbourre)\
**Post date:** [February 6, 2025, 8:55pm UTC](https://forum.farmbot.org/t/trying-to-get-the-seed-trough-position-in-lua/9653/1 "2025-02-06T20:55:03Z")

</div>

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.

```lua
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

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [February 8, 2025, 4:31am UTC](https://forum.farmbot.org/t/trying-to-get-the-seed-trough-position-in-lua/9653/2 "2025-02-08T04:31:23Z")

</div>

Hi @nbourre

> [@nbourre](#):
>
> get the position of the Seed Trough 1

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

> <https://github.com/FarmBot/farmbot_os/blob/b42e9abd5462c4aac2f149b9acd41dbfa3a0e615/priv/lua/mount_tool.lua#L12-L24>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.farmbot.org/user_avatar/forum.farmbot.org/system/32/4564_2.png) [@system](https://forum.farmbot.org/u/system)\
**Post date:** [March 10, 2025, 4:31am UTC](https://forum.farmbot.org/t/trying-to-get-the-seed-trough-position-in-lua/9653/3 "2025-03-10T04:31:43Z")

</div>

Closed on March 10, 2025, 4:31am UTC

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