We are preparing to release a new beta version of FarmBot OS. This release contains some Lua updates that were requested by forum users.
Here’s what’s new:
The variable() Lua helper is now available in the ASSERT block and in formulas.
Lua behavior has been unified across all three environments: The ASSERT block, the LUA block and the inline formula features now all execute Lua in the same way.
You can now view attributes beyond x,y and z. Available attributes: id, tool_id, gantry_mounted, meta, name, openfarm_slug, plant_stage, pointer_type, pullout_direction, resource_id, resource_type, radius, x, y, z
The big news with this release is that you can access the radius and other properties of a variable. It makes geometric operations much easier to perform.
Below is an example of circling the gantry around a point’s radius:
parent = variable()
radius = parent.radius
for radians = 0, 6.2, 0.1 do
x = parent.x + (radius * math.cos(radians))
y = parent.y + (radius * math.sin(radians))
z = parent.z
move_absolute(x, y, z, 50)
end
Notice how in the Lua code we’re calling variable().radius and then using the built in Lua trig functions to calculate an arc.