diff --git a/docs/celery_script/assert expressions.md b/docs/celery_script/assert expressions.md index 399cf797..93348805 100644 --- a/docs/celery_script/assert expressions.md +++ b/docs/celery_script/assert expressions.md @@ -86,6 +86,10 @@ return check_position({x = 1.0, y = 0; z = 0}, 0.50); move_absolute(20, 100, 100); return check_position(coordinate(20, 100, 100), 1); +-- With a speed param. Should be a percent 0-100 +move_absolute(100.6, 200, 0, 100); +return check_position(coordinate(100.6, 200, 0), 1); + -- read_status(arg0) -- Get a field on farmbot's current state diff --git a/farmbot_os/lib/farmbot_os/lua/ext/firmware.ex b/farmbot_os/lib/farmbot_os/lua/ext/firmware.ex index e469fcde..3417f948 100644 --- a/farmbot_os/lib/farmbot_os/lua/ext/firmware.ex +++ b/farmbot_os/lib/farmbot_os/lua/ext/firmware.ex @@ -53,7 +53,12 @@ defmodule FarmbotOS.Lua.Ext.Firmware do @doc "Moves in a straight line to a location" def move_absolute([x, y, z], lua) when is_number(x) and is_number(y) and is_number(z) do - case SysCalls.move_absolute(x, y, z, 100) do + move_absolute([x, y, z, 100], lua) + end + + def move_absolute([x, y, z, speed], lua) + when is_number(x) and is_number(y) and is_number(z) and is_number(speed) do + case SysCalls.move_absolute(x, y, z, speed) do :ok -> {[true], lua} @@ -63,6 +68,10 @@ defmodule FarmbotOS.Lua.Ext.Firmware do end def move_absolute([table], lua) when is_list(table) do + move_absolute([table, 100], lua) + end + + def move_absolute([table, speed], lua) when is_list(table) and is_number(speed) do axis_finder = fn axis, {axis, nil} -> apply(SysCalls, :"get_current_#{axis}", []) axis, {axis, value} -> value @@ -72,7 +81,7 @@ defmodule FarmbotOS.Lua.Ext.Firmware do x = Enum.find_value(table, &axis_finder.("x", &1)) y = Enum.find_value(table, &axis_finder.("y", &1)) z = Enum.find_value(table, &axis_finder.("z", &1)) - move_absolute([x, y, z], lua) + move_absolute([x, y, z, speed], lua) end @doc """