Drone. Adapters. Sim. State
(ex_drone v0.3.0)
View Source
In-process simulator state for Drone.Adapters.Sim.
Tracks pose, battery, mode, and command history without network I/O.
Created via new/1 from the simulator adapter's connect/1 callback.
Summary
Functions
Increments the flight time by the given number of seconds.
Decreases battery by amount, floored at 0.
Builds a new simulator state from connection options.
Records cmd as the last command and prepends it to history.
Types
@type t() :: %Drone.Adapters.Sim.State{ battery: number(), command_history: [Drone.Command.t()], config: map(), flight_time_seconds: non_neg_integer(), flying: boolean(), last_command: Drone.Command.t() | nil, mode: :idle | :sdk_mode | :flying | :emergency, speed: integer(), x: integer(), y: integer(), yaw: integer(), z: integer() }
Simulator adapter state.
Fields
| Field | Type | Default | Meaning |
|---|---|---|---|
x | integer() | 0 or :initial_x | World X cm |
y | integer() | 0 or :initial_y | World Y cm (yaw 0 faces +Y) |
z | integer() | 0 or :initial_z | Altitude cm |
yaw | integer() | 0 or :initial_yaw | Heading degrees |
flying | boolean() | false | Motors / airborne |
battery | number() | 100 | Percent (may be fractional internally) |
speed | integer() | 0 | cm/s |
mode | :idle | :sdk_mode | :flying | :emergency | :idle | State machine mode |
flight_time_seconds | non_neg_integer() | 0 | Cumulative motor-on time |
last_command | Drone.Command.t() | nil | nil | Most recent command |
command_history | [Drone.Command.t()] | [] | Newest-first history |
config | map() | drain / failure opts | Simulator configuration |
Example
%Drone.Adapters.Sim.State{
x: -50,
y: 0,
z: 30,
yaw: 0,
flying: true,
battery: 97.5,
speed: 0,
mode: :flying,
flight_time_seconds: 8,
last_command: %Drone.Command{type: :takeoff, args: [], raw: nil},
command_history: [],
config: %{failure_rate: 0.0, fail_commands: []}
}
Functions
@spec add_flight_time(t(), non_neg_integer()) :: t()
Increments the flight time by the given number of seconds.
Used to simulate time elapsed during command execution.
Parameters
state(t/0)seconds(non_neg_integer())
Returns
Updated t/0.
Decreases battery by amount, floored at 0.
Parameters
state(t/0)amount(float())
Returns
Updated t/0.
Builds a new simulator state from connection options.
Parameters
opts(keyword()) — supported keys::initial_x,:initial_y,:initial_z,:initial_yaw(integer()):battery(number()):battery_drain_per_move,:battery_drain_per_takeoff,:battery_drain_per_land,:battery_drain_per_query(float()):failure_rate(float()0.0..1.0):fail_commands([atom()]) — always fail these command types
Returns
Example
state = Drone.Adapters.Sim.State.new(initial_x: -50, battery: 80)
state.x
#=> -50
@spec push_command(t(), Drone.Command.t()) :: t()
Records cmd as the last command and prepends it to history.
Parameters
state(t/0)cmd(Drone.Command.t())
Returns
Updated t/0.