Watering a group of plants

Hello,

Me or Chatgpt can’t figure out how to create a sequence that:

  1. mount watering nozzle
  2. water plant in a chosen group
  3. dismount the tool
  4. returns to home.

It always ends up with that the UMT dismount the tool and returning home after it has water the first plant. I can’t get it o water all plants in the group before heading for dismounting the tool.

Does anyone have an idea? My skills in LUA are not that good.

Hi @micaelaman

First thing you need is a defined PLANT GROUP containing plants you wish to water.
Your sequence should have a VARIABLE which allows you to select that PLANT GROUP when you press RUN ( you may need to scroll that downdown list to find your Plant Groups )
e.g.

The Farmbot Sequence runner willl then iterate the all the code steps in you sequence over that group.

Hi,
Thanks for the reply.
i attached my sequence and the trail.

With this sequence it goes to custom coordinate (home) after each plant, as can be seen on the trail. I want it to water all plants in my group and after that go to custom coordinates.

Yes, that’s what should happen. :neutral_face:

To water a plant group and finally go to home, you need to

  • Remove that MOVE-home step from your ‘group watering’ sequence
  • Create a new sequence which runs your ‘group watering’ sequence (EXECUTE SEQUENCE) and has your MOVE-home step after that.

I have tried all sorts of combinations with sequences in other sequences with no luck.

However I found the error. It is the variable causing the problem.

This work as i want (not using a variable)


This does not work, it dismount the tool and return to home after each plant.

My workaround will be to create a water sequence for each plant group.

1 Like

Here is the code for the watering all plants.

I have improved the reliability of the base code so it attempts to read the plant list several times (dealing with network glitches) and recoded the movement so it performs a serpent movement. (Meaning it moves more logical in my mind).

Whack this into an LUA code block and wrap it with mount tool before and dismount tool after.
Job done.

If you need more help or LUA code assistance, I can help you there too.

Matt

local wt=variable(“Watering Time (Seconds)”)
local st=os.time()*1000
local tries=9
local delay=20
local fail=1
local pts
local wateringHeight=0

while tries>0 do
tries=tries-1
pts=api({method=“GET”,url=“/api/points”})
if pts then
toast(“Plant list obtained”,“info”)
tries=0
fail=0
else
toast(“Error - Retrying”,“warn”)
wait(delay*1000)
end
end

if fail==1 then
toast(“Fatal Error - No plants”,“error”)
return
end

local pls={}
for _,v in pairs(pts)do
if v.pointer_type==“Plant” then
table.insert(pls,{n=v.name,x=v.x,y=v.y})
end
end

– Dynamic X clustering with serpentine Y sweep
local tol=50
table.sort(pls,function(a,b)return a.x<b.x end)
local grps={{}}
for _,p in ipairs(pls)do
local g=grps[#grps]
if #g==0 then
table.insert(g,p)
else
if math.abs(p.x-g[1].x)<=tol then
table.insert(g,p)
else
table.insert(grps,{p})
end
end
end

local s_pls={}
for i,g in ipairs(grps)do
table.sort(g,function(a,b)return a.y<b.y end)
if i%2==0 then
local rev={}
for j=#g,1,-1 do table.insert(rev,g[j])end
g=rev
end
for _,p in ipairs(g)do table.insert(s_pls,p)end
end
pls=s_pls

local c=0
local t=#pls
local job=“Watering “…t…” plants”
send_message(“info”,job…" for "…wt…“s each”,“toast”)

for _,v in pairs(pls)do
local cn=“(”…math.floor(v.x)…“,”…math.floor(v.y)…“)”
local pn=v.n or"plant"
if #pn>20 then pn=string.sub(pn,1,20)…"…"end
set_job_progress(job,{percent=100c/t,status="Moving to “…pn…” "…cn,time=st})
move_absolute(v.x,v.y,wateringHeight)
set_job_progress(job,{percent=100
(c+0.5)/t,status="Watering "…pn,time=st})
write_pin(8,“digital”,1)
wait(wt*1000)
write_pin(8,“digital”,0)
c=c+1
end

set_job_progress(job,{percent=100,status=“Complete”,time=st})

1 Like