Drone. Safety. Policy
(ex_drone v0.1.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
Drone.Safety.Policy.default/0-- safe defaults for outdoor flightDrone.Safety.Policy.indoor/0-- tighter limits for indoor flightDrone.Safety.Policy.unrestricted/0-- no safety limits (use with caution)
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
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
@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() }
Functions
@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%
@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
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)
@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.