Drone.Safety.Policy (ex_drone v0.2.0)

View Source

Safety policy struct and defaults.

A policy defines the safety rules applied to every command before it reaches the drone adapter. Policies are configured at connection time and cannot be changed while a drone is connected.

Presets

Example

Safety options can be passed to Drone.connect/2 either as a keyword list (built into a policy via new/1) or as an already-constructed %Policy{}:

{:ok, drone} = Drone.connect(:sim, name: :test, safety: [max_altitude_cm: 200, indoor: true])

policy = Drone.Safety.Policy.new(max_altitude_cm: 200, indoor: true)
{:ok, drone} = Drone.connect(:sim, name: :test, safety: policy)

Summary

Types

t()

Safety limits applied by Drone.Safety.check/3.

Functions

Default safety policy for outdoor flight.

Indoor safety policy with tighter limits.

Creates a new policy with the given options.

Unrestricted safety policy with no limits.

Types

t()

@type t() :: %Drone.Safety.Policy{
  allowlist: [atom()] | nil,
  battery_warning_percent: non_neg_integer(),
  dry_run: boolean(),
  geofence: Drone.Safety.Geofence.t() | nil,
  indoor: boolean(),
  max_altitude_cm: pos_integer() | nil,
  max_distance_cm: pos_integer() | nil,
  min_battery_percent: non_neg_integer(),
  prop_guards: boolean()
}

Safety limits applied by Drone.Safety.check/3.

Fields

FieldTypeDefaultMeaning
max_altitude_cmpos_integer() | nilpresetReject climbs above this height
max_distance_cmpos_integer() | nilpresetMax horizontal distance from origin
min_battery_percentnon_neg_integer()15Block takeoff below this %
battery_warning_percentnon_neg_integer()20Emit warning at/under this %
allowlist[atom()] | nilnilIf set, only these command types
dry_runboolean()falseValidate but do not send to adapter
indoorboolean()falseMarker / indoor preset flag
prop_guardsboolean()falseProp guards installed (flip warning)
geofenceDrone.Safety.Geofence.t() | nilnilOptional area restriction

Example

%Drone.Safety.Policy{
  max_altitude_cm: 200,
  max_distance_cm: 500,
  min_battery_percent: 20,
  battery_warning_percent: 30,
  allowlist: nil,
  dry_run: false,
  indoor: true,
  prop_guards: true,
  geofence: nil
}

Functions

default()

@spec default() :: t()

Default safety policy for outdoor flight.

  • Max altitude: 300 cm (3 meters)
  • Max distance: 1000 cm (10 meters)
  • Min battery: 15%
  • Battery warning: 20%

indoor()

@spec indoor() :: t()

Indoor safety policy with tighter limits.

  • Max altitude: 200 cm (2 meters)
  • Max distance: 500 cm (5 meters)
  • Min battery: 20%
  • Battery warning: 25%
  • Prop guards assumed: true

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new policy with the given options.

Options:

  • :max_altitude_cm -- maximum allowed altitude in cm (default: 300)
  • :max_distance_cm -- maximum distance from launch point in cm (default: 1000)
  • :min_battery_percent -- minimum battery for takeoff (default: 15)
  • :battery_warning_percent -- battery level for warnings (default: 20)
  • :allowlist -- list of allowed command types, or nil for all (default: nil)
  • :dry_run -- if true, commands pass safety but are not sent (default: false)
  • :indoor -- if true, applies indoor preset limits (default: false)
  • :unrestricted -- if true, applies the unrestricted preset (no limits)
  • :prop_guards -- whether prop guards are installed (default: false)
  • :geofence -- a geofence to restrict flight area (default: nil)

unrestricted()

@spec unrestricted() :: t()

Unrestricted safety policy with no limits.

Use with extreme caution. This disables all altitude, distance, and battery checks. Emergency commands still work.