# `BB.Message.Actuator.EndMotion`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/message/actuator/end_motion.ex#L5)

Message published by actuators when motion ends.

Optional counterpart to `BeginMotion`. Useful for actuators with partial
feedback (limit switches, stall detection) that can report when motion
completes but may not have continuous position sensing.

## Fields

- `position` - Position when motion ended (radians or metres)
- `reason` - Why motion ended (`:completed`, `:cancelled`, `:limit_reached`, `:fault`)
- `detail` - Optional atom with additional context (e.g. `:end_stop`, `:stall`)
- `message` - Optional human-readable information for operators
- `command_id` - Optional correlation ID from the originating command

## Examples

    alias BB.Message
    alias BB.Message.Actuator.EndMotion

    # Simple completion
    {:ok, msg} = Message.new(EndMotion, :shoulder,
      position: 1.57,
      reason: :completed
    )

    # Limit reached with detail
    {:ok, msg} = Message.new(EndMotion, :shoulder,
      position: 0.0,
      reason: :limit_reached,
      detail: :end_stop
    )

    # Fault with message
    {:ok, msg} = Message.new(EndMotion, :shoulder,
      position: 0.52,
      reason: :fault,
      detail: :stall,
      message: "Motor stall detected at 30% travel"
    )

# `reason`

```elixir
@type reason() :: :completed | :cancelled | :limit_reached | :fault
```

# `t`

```elixir
@type t() :: %BB.Message.Actuator.EndMotion{
  command_id: reference() | nil,
  detail: atom() | nil,
  message: String.t() | nil,
  position: float(),
  reason: reason()
}
```

# `new`

```elixir
@spec new(
  atom(),
  keyword()
) :: {:ok, BB.Message.t()} | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
