Add handler for axis load for express boards
parent
97e0440678
commit
8f29577394
|
@ -28,6 +28,11 @@ defmodule FarmbotCore.BotState do
|
|||
def set_position(bot_state_server \\ __MODULE__, x, y, z) do
|
||||
GenServer.call(bot_state_server, {:set_position, x, y, z})
|
||||
end
|
||||
|
||||
@doc "Sets the location_data.load"
|
||||
def set_load(bot_state_server \\ __MODULE__, x, y, z) do
|
||||
GenServer.call(bot_state_server, {:set_load, x, y, z})
|
||||
end
|
||||
|
||||
@doc "Sets the location_data.encoders_scaled"
|
||||
def set_encoders_scaled(bot_state_server \\ __MODULE__, x, y, z) do
|
||||
|
@ -217,6 +222,16 @@ defmodule FarmbotCore.BotState do
|
|||
{:reply, reply, state}
|
||||
end
|
||||
|
||||
def handle_call({:set_load, x, y, z}, _from, state) do
|
||||
change = %{location_data: %{load: %{x: x, y: y, z: z}}}
|
||||
|
||||
{reply, state} =
|
||||
BotStateNG.changeset(state.tree, change)
|
||||
|> dispatch_and_apply(state)
|
||||
|
||||
{:reply, reply, state}
|
||||
end
|
||||
|
||||
def handle_call({:set_encoders_scaled, x, y, z}, _from, state) do
|
||||
change = %{location_data: %{scaled_encoders: %{x: x, y: y, z: z}}}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule FarmbotCore.BotStateNG.LocationData do
|
|||
embeds_one(:scaled_encoders, Vec3, on_replace: :update)
|
||||
embeds_one(:raw_encoders, Vec3, on_replace: :update)
|
||||
embeds_one(:position, Vec3, on_replace: :update)
|
||||
embeds_one(:load, Vec3, on_replace: :update)
|
||||
embeds_one(:axis_states, Vec3String, on_replace: :update)
|
||||
end
|
||||
|
||||
|
@ -20,6 +21,7 @@ defmodule FarmbotCore.BotStateNG.LocationData do
|
|||
|> put_embed(:scaled_encoders, Vec3.new(), [])
|
||||
|> put_embed(:raw_encoders, Vec3.new(), [])
|
||||
|> put_embed(:position, Vec3.new(), [])
|
||||
|> put_embed(:load, Vec3.new(), [])
|
||||
|> put_embed(:axis_states, Vec3String.new(), [])
|
||||
|> apply_changes()
|
||||
end
|
||||
|
@ -29,6 +31,7 @@ defmodule FarmbotCore.BotStateNG.LocationData do
|
|||
scaled_encoders: Vec3.view(location_data.scaled_encoders),
|
||||
raw_encoders: Vec3.view(location_data.raw_encoders),
|
||||
position: Vec3.view(location_data.position),
|
||||
load: Vec3.view(location_data.load),
|
||||
axis_states: Vec3String.view(location_data.axis_states)
|
||||
}
|
||||
end
|
||||
|
@ -39,6 +42,7 @@ defmodule FarmbotCore.BotStateNG.LocationData do
|
|||
|> cast_embed(:scaled_encoders)
|
||||
|> cast_embed(:raw_encoders)
|
||||
|> cast_embed(:position)
|
||||
|> cast_embed(:load)
|
||||
|> cast_embed(:axis_states)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,11 @@ defmodule FarmbotCore.FirmwareSideEffects do
|
|||
:ok = BotState.set_position(x, y, z)
|
||||
end
|
||||
|
||||
@impl FarmbotFirmware.SideEffects
|
||||
def handle_load(x: x, y: y, z: z) do
|
||||
:ok = BotState.set_load(x, y, z)
|
||||
end
|
||||
|
||||
@impl FarmbotFirmware.SideEffects
|
||||
def handle_position_change([{_axis, _value}]) do
|
||||
:noop
|
||||
|
|
|
@ -675,6 +675,14 @@ defmodule FarmbotFirmware do
|
|||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_report({:report_load, load} = code, state) do
|
||||
if state.caller_pid, do: send(state.caller_pid, {state.tag, code})
|
||||
for {pid, _code} <- state.command_queue, do: send(pid, {state.tag, {:report_busy, []}})
|
||||
|
||||
side_effects(state, :handle_load, [load])
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_report({:report_axis_state, axis_state} = code, state) do
|
||||
if state.caller_pid, do: send(state.caller_pid, {state.tag, code})
|
||||
for {pid, _code} <- state.command_queue, do: send(pid, {state.tag, {:report_busy, []}})
|
||||
|
|
|
@ -23,6 +23,7 @@ defmodule FarmbotFirmware.GCODE do
|
|||
| :report_invalid
|
||||
| :report_home_complete
|
||||
| :report_position
|
||||
| :report_load
|
||||
| :report_position_change
|
||||
| :report_parameters_complete
|
||||
| :report_parameter_value
|
||||
|
|
|
@ -47,6 +47,7 @@ defmodule FarmbotFirmware.GCODE.Decoder do
|
|||
|
||||
def do_decode("R87", []), do: {:report_emergency_lock, []}
|
||||
def do_decode("R88", []), do: {:report_no_config, []}
|
||||
def do_decode("R89", xyz), do: {:report_load, decode_floats(xyz)}
|
||||
def do_decode("R99", debug), do: {:report_debug_message, [Enum.join(debug, " ")]}
|
||||
|
||||
def do_decode("G00", xyzs), do: {:command_movement, decode_floats(xyzs)}
|
||||
|
|
|
@ -46,6 +46,7 @@ defmodule FarmbotFirmware.GCODE.Encoder do
|
|||
|
||||
def do_encode(:report_emergency_lock, []), do: "R87"
|
||||
def do_encode(:report_no_config, []), do: "R88"
|
||||
def do_encode(:report_load, xyz), do: "R89 " <> encode_floats(xyz)
|
||||
def do_encode(:report_debug_message, [message]), do: "R99 " <> message
|
||||
|
||||
def do_encode(:command_movement, xyzs), do: "G00 " <> encode_floats(xyzs)
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule FarmbotFirmware.SideEffects do
|
|||
@callback load_params :: [{Param.t(), float() | nil}]
|
||||
|
||||
@callback handle_position(x: float(), y: float(), z: float()) :: any()
|
||||
@callback handle_load(x: float(), y: float(), z: float()) :: any()
|
||||
@callback handle_position_change([{axis(), float()}]) :: any()
|
||||
@callback handle_encoders_scaled(x: float(), y: float(), z: float()) :: any()
|
||||
@callback handle_encoders_raw(x: float(), y: float(), z: float()) :: any()
|
||||
|
|
|
@ -105,6 +105,9 @@ defmodule FarmbotFirmware.StubSideEffects do
|
|||
@impl SideEffects
|
||||
def handle_position(_), do: :noop
|
||||
|
||||
@impl SideEffects
|
||||
def handle_load(_), do: :noop
|
||||
|
||||
@impl SideEffects
|
||||
def handle_position_change(_), do: :noop
|
||||
|
||||
|
|
Loading…
Reference in New Issue