BB.Transmission.Resolver (bb v0.20.1)

Copy Markdown View Source

Resolve an attachment's transmission against the runtime parameter store.

Transmissions are properties of individual attachments — actuators and joint-attached sensors. Their fields (reduction, offset, reversed?) may be literal values or BB.Dsl.ParamRef references. At compile time the parameterised fields appear as nil on the optimised attachment info and the parameter paths are recorded in BB.Robot.param_subscriptions. This module fills the nil fields in with current parameter values at process startup and re-resolves when the parameter changes.

Summary

Functions

Resolve an attachment's transmission against the current parameter store without subscribing to changes.

Resolve an attachment's transmission for use by a server process and subscribe to parameter changes for any parameterised fields.

Types

field()

@type field() :: :reduction | :offset | :reversed?

kind()

@type kind() :: :actuator | :sensor

subscriptions()

@type subscriptions() :: %{required(field()) => [atom()]}

Functions

handle_change(param_path, current, subscriptions, robot_module, kind, attachment_name)

@spec handle_change(
  [atom()],
  BB.Transmission.t(),
  subscriptions(),
  module(),
  kind(),
  atom()
) :: {:changed, BB.Transmission.t()} | :ignored

Re-resolve the transmission after a parameter change.

Call from a server's handle_info when a [:param | path] message arrives. Returns {:changed, new_transmission} if the change affects this transmission, or :ignored otherwise.

resolve(robot_module, kind, attachment_name)

@spec resolve(module(), kind(), atom()) :: BB.Transmission.t() | nil

Resolve an attachment's transmission against the current parameter store without subscribing to changes.

Suitable for one-shot lookups from helpers that don't run as a long-lived process (e.g. BB.Actuator.publish_begin_motion/3). Returns the resolved transmission, or nil if the attachment has no transmission.

resolve_and_subscribe(robot_module, kind, attachment_name)

@spec resolve_and_subscribe(module(), kind(), atom()) ::
  {BB.Transmission.t() | nil, subscriptions()}

Resolve an attachment's transmission for use by a server process and subscribe to parameter changes for any parameterised fields.

Returns {resolved_transmission_or_nil, subscriptions_map}. The subscriptions map maps each transmission field that came from a param/1 reference to its parameter path; the empty map means everything was a literal at compile time.

When the attachment has no transmission, returns {nil, %{}} and subscribes to nothing.