Skip to content
Permalink
Browse files

Add optional speed parameter to Lua API

  • Loading branch information...
ConnorRigby committed Oct 1, 2019
1 parent be08732 commit e8a78485912f584faa47978aa1cf24f722b80c75
Showing with 15 additions and 2 deletions.
  1. +4 −0 docs/celery_script/assert expressions.md
  2. +11 −2 farmbot_os/lib/farmbot_os/lua/ext/firmware.ex
@@ -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
@@ -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 """

0 comments on commit e8a7848

Please sign in to comment.
You can’t perform that action at this time.