Add optional speed parameter to Lua API

pull/1035/head
Connor Rigby 2019-10-01 09:52:20 -07:00 committed by Connor Rigby
parent be08732601
commit e8a7848591
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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 """