Update find_home to not take a speed arg
parent
c01360659c
commit
db54e2117d
|
@ -378,18 +378,18 @@ defmodule FarmbotCeleryScript.Compiler do
|
|||
end
|
||||
|
||||
# Expands find_home(all) into three find_home/1 calls
|
||||
compile :find_home, %{axis: "all", speed: speed} do
|
||||
compile :find_home, %{axis: "all"} do
|
||||
quote location: :keep do
|
||||
find_home("x", unquote(compile_ast(speed)))
|
||||
find_home("y", unquote(compile_ast(speed)))
|
||||
find_home("z", unquote(compile_ast(speed)))
|
||||
find_home("x")
|
||||
find_home("y")
|
||||
find_home("z")
|
||||
end
|
||||
end
|
||||
|
||||
# compiles find_home
|
||||
compile :find_home, %{axis: axis, speed: speed} do
|
||||
compile :find_home, %{axis: axis} do
|
||||
quote location: :keep do
|
||||
find_home(unquote(compile_ast(axis)), unquote(compile_ast(speed)))
|
||||
find_home(unquote(compile_ast(axis)))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ defmodule FarmbotCeleryScript.SysCalls do
|
|||
@callback point(point_type, resource_id) :: coordinate | error
|
||||
@callback move_absolute(x :: axis_position, y :: axis_position, z :: axis_position, axis_speed) ::
|
||||
:ok | error
|
||||
@callback find_home(axis, axis_speed) :: :ok | error
|
||||
@callback find_home(axis) :: :ok | error
|
||||
|
||||
@callback calibrate(axis) :: :ok | error
|
||||
|
||||
|
@ -147,8 +147,8 @@ defmodule FarmbotCeleryScript.SysCalls do
|
|||
end
|
||||
end
|
||||
|
||||
def find_home(module \\ @sys_call_implementation, axis, speed) do
|
||||
case module.find_home(axis, speed) do
|
||||
def find_home(module \\ @sys_call_implementation, axis) do
|
||||
case module.find_home(axis) do
|
||||
:ok -> :ok
|
||||
{:error, reason} when is_binary(reason) -> error(reason)
|
||||
end
|
||||
|
|
|
@ -133,13 +133,13 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
|
||||
test "find_home", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
assert :ok = SysCalls.find_home(TestSysCalls, "x", 100)
|
||||
assert_receive {:find_home, ["x", 100]}
|
||||
assert :ok = SysCalls.find_home(TestSysCalls, "x")
|
||||
assert_receive {:find_home, ["x"]}
|
||||
|
||||
:ok = shim_fun_error(shim, "home lost")
|
||||
|
||||
assert_raise RuntimeError, "home lost", fn ->
|
||||
SysCalls.find_home(TestSysCalls, "x", 100)
|
||||
SysCalls.find_home(TestSysCalls, "x")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ defmodule FarmbotOS.SysCalls do
|
|||
end
|
||||
|
||||
defp get_position(axis) do
|
||||
axis = assert_axis!(axis)
|
||||
|
||||
case FarmbotFirmware.request({nil, {:position_read, []}}) do
|
||||
{:ok, {_, {:report_position, params}}} ->
|
||||
Keyword.fetch!(params, axis)
|
||||
|
@ -86,15 +88,49 @@ defmodule FarmbotOS.SysCalls do
|
|||
end
|
||||
|
||||
def calibrate(axis) do
|
||||
axis = assert_axis!(axis)
|
||||
|
||||
case FarmbotFirmware.command({:command_movement_calibrate, axis}) do
|
||||
:ok ->
|
||||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
{:error, "Firmware error: #{inspect(reason)}"}
|
||||
end
|
||||
end
|
||||
|
||||
def find_home(axis) do
|
||||
axis = assert_axis!(axis)
|
||||
|
||||
case FarmbotFirmware.command({:command_movement_find_home, axis}) do
|
||||
:ok ->
|
||||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, "Firmware error: #{inspect(reason)}"}
|
||||
end
|
||||
end
|
||||
|
||||
defp assert_axis!(axis) when is_atom(axis),
|
||||
do: axis
|
||||
|
||||
defp assert_axis!(axis) when axis in ~w(x y z),
|
||||
do: String.to_existing_atom(axis)
|
||||
|
||||
defp assert_axis!(axis) do
|
||||
# {:error, "unknown axis #{axis}"}
|
||||
raise("unknown axis #{axis}")
|
||||
end
|
||||
|
||||
def wait(ms) do
|
||||
Process.sleep(ms)
|
||||
:ok
|
||||
end
|
||||
|
||||
def named_pin(kind, id) do
|
||||
{:error, "unknown pin kind: #{kind} of id: #{id}"}
|
||||
end
|
||||
|
||||
def get_sequence(id) do
|
||||
case Asset.get_sequence(id: id) do
|
||||
nil -> {:error, "sequence not found"}
|
||||
|
|
|
@ -92,8 +92,8 @@ defmodule Farmbot.TestSupport.CeleryScript.TestSysCalls do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def find_home(axis, speed) do
|
||||
call({:find_home, [axis, speed]})
|
||||
def find_home(axis) do
|
||||
call({:find_home, [axis]})
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
|
Loading…
Reference in New Issue