BB.Robot.State (bb v0.4.0)
View SourceETS-backed mutable state for robot instances.
This module manages joint positions, velocities, and computed transforms for robot instances. Each robot instance has its own ETS table for concurrent read access.
State Structure
For each joint, the following state is stored:
position: current joint position (radians for revolute, meters for prismatic)velocity: current joint velocity (rad/s or m/s)
Usage
# Create state for a robot instance
{:ok, state} = BB.Robot.State.new(robot)
# Set/get joint positions
:ok = BB.Robot.State.set_joint_position(state, :shoulder, 0.5)
pos = BB.Robot.State.get_joint_position(state, :shoulder)
# Get all joint positions as a map
positions = BB.Robot.State.get_all_positions(state)
# Clean up when done
:ok = BB.Robot.State.delete(state)
Summary
Functions
Delete a state table and free resources.
Find the schema that applies to a given parameter path.
Get all joint positions as a map.
Get all joint velocities as a map.
Get the positions of joints along a path from root to a target link.
Get the current position of a joint.
Get the current velocity of a joint.
Get a parameter value by path.
Get the registered schema for a path prefix.
Get the current robot state machine state.
List all parameters, optionally filtered by path prefix.
Create a new state table for a robot.
Register a parameter schema for a component path.
Reset all joints to their default positions (0.0).
Set the position of a joint.
Set the velocity of a joint.
Set a parameter value by path.
Set multiple parameters atomically.
Set multiple joint positions at once.
Set the robot state machine state.
Set multiple joint velocities at once.
Types
@type t() :: %BB.Robot.State{robot: BB.Robot.t(), table: :ets.table()}
Functions
@spec delete(t()) :: :ok
Delete a state table and free resources.
@spec find_schema_for_parameter(t(), [atom()]) :: {:ok, [atom()], Spark.Options.t()} | {:error, :not_found}
Find the schema that applies to a given parameter path.
Searches for the longest matching schema prefix.
Get all joint positions as a map.
Examples
iex> positions = BB.Robot.State.get_all_positions(state)
%{shoulder: 0.0, elbow: 0.5, wrist: -0.3}
Get all joint velocities as a map.
Get the positions of joints along a path from root to a target link.
Returns a list of {joint_name, position} tuples in traversal order.
Get the current position of a joint.
Returns nil if the joint doesn't exist.
Get the current velocity of a joint.
Returns nil if the joint doesn't exist.
Get a parameter value by path.
Returns {:ok, value} if the parameter exists, {:error, :not_found} otherwise.
@spec get_parameter_schema(t(), [atom()]) :: {:ok, Spark.Options.t()} | {:error, :not_found}
Get the registered schema for a path prefix.
Returns {:ok, schema} if found, {:error, :not_found} otherwise.
Get the current robot state machine state.
Returns the state atom (e.g., :disarmed, :idle, :executing).
List all parameters, optionally filtered by path prefix.
Returns a list of {path, metadata} tuples where metadata includes
the current value and schema information if registered.
@spec new(BB.Robot.t()) :: {:ok, t()}
Create a new state table for a robot.
Returns {:ok, state} on success.
@spec register_parameter_schema(t(), [atom()], Spark.Options.t()) :: :ok
Register a parameter schema for a component path.
The schema is stored and used for validation and metadata.
@spec reset(t()) :: :ok
Reset all joints to their default positions (0.0).
Set the position of a joint.
Set the velocity of a joint.
Set a parameter value by path.
This is a low-level function that does not validate or notify.
Use BB.Parameter.set/3 for the validated, notifying version.
Set multiple parameters atomically.
This is a low-level function that does not validate or notify.
Set multiple joint positions at once.
Examples
:ok = BB.Robot.State.set_positions(state, %{
shoulder: 0.5,
elbow: -0.3,
wrist: 0.0
})
Set the robot state machine state.
Set multiple joint velocities at once.