Drone.Adapters.Sim (ex_drone v0.3.0)

View Source

Simulator adapter for ex_drone.

The simulator adapter implements Drone.Adapter with an in-process state machine. It requires no hardware, no network, and no external dependencies.

This is the primary adapter for development, testing, and education. It enforces the same state machine and command protocol as the Tello adapter, but uses pure Elixir state instead of UDP communication.

Usage

{:ok, drone} = Drone.connect(:sim, name: :test)
Drone.connect_sdk(drone)
Drone.takeoff(drone)
Drone.move(drone, :forward, 100)
Drone.land(drone)
Drone.disconnect(drone)

Failure Injection

The simulator can be configured to inject failures for testing error handling:

{:ok, drone} = Drone.connect(:sim,
  name: :test,
  failure_rate: 1.0,        # always fail
  fail_commands: [:takeoff]  # only fail takeoff
)

Battery Simulation

Battery drains at configurable rates per command. Set battery: 50 to start with 50% battery.

{:ok, drone} = Drone.connect(:sim, name: :test, battery: 30)

Initial Pose

For multi-drone simulation, set a shared world frame offset:

{:ok, drone} = Drone.connect(:sim,
  name: :left,
  initial_x: -50,
  initial_y: 0,
  initial_z: 0,
  initial_yaw: 0
)

Summary

Functions

Returns Tello-like capability metadata.

Executes a command against the in-process simulator state machine.

Builds in-process simulator state from connect options.

No-op disconnect for the in-process simulator.

Returns a telemetry snapshot from simulator state.

Functions

capabilities(state)

Returns Tello-like capability metadata.

Returns

Drone.Adapter.Capabilities.tello_like/0.

command(state, cmd)

Executes a command against the in-process simulator state machine.

Applies optional failure injection, mode checks, then updates pose / battery.

Parameters

  • state (Drone.Adapters.Sim.State.t()) — current sim state
  • cmd (Drone.Command.t()) — command to run

Returns

  • {:ok, reply, State.t()} — usually reply is :ok or a query value
  • {:error, reason, State.t()} — simulated failure or mode error

Examples

{:ok, state} = Drone.Adapters.Sim.connect([])
{:ok, :ok, state} =
  Drone.Adapters.Sim.command(state, Drone.Command.sdk_mode())

connect(opts)

Builds in-process simulator state from connect options.

Parameters

  • opts (keyword()) — simulator knobs forwarded to Drone.Adapters.Sim.State.new/1, including:
    • :battery, :battery_drain_per_*
    • :failure_rate, :fail_commands
    • :initial_x, :initial_y, :initial_z, :initial_yaw

Returns

{:ok, Drone.Adapters.Sim.State.t()}.

Examples

{:ok, state} =
  Drone.Adapters.Sim.connect(battery: 80, initial_x: -50)

disconnect(state)

No-op disconnect for the in-process simulator.

Returns

Always :ok.

telemetry(state)

Returns a telemetry snapshot from simulator state.

Parameters

  • state (Drone.Adapters.Sim.State.t())

Returns

{:ok, map(), State.t()} including pose, battery, mode, and command counts.