Drone.Safety.Geofence (ex_drone v0.3.0)

View Source

Geofence definitions for restricting drone flight area.

A geofence defines an allowed flight area. Movement commands that would take the drone outside the geofence are rejected by the safety pipeline.

Two geofence shapes are supported:

  • Circle: defined by a center point and radius
  • Polygon: defined by a list of vertices

Coordinates are in centimeters from the launch point.

Examples

fence = Drone.Safety.Geofence.radius(300)
true = Drone.Safety.Geofence.contains?(fence, {100, 100})
false = Drone.Safety.Geofence.contains?(fence, {400, 0})

Summary

Types

t()

Geofence struct describing an allowed XY region in centimeters.

Functions

Creates a circular geofence centred at the given point with the given radius.

Checks whether a point is inside the geofence.

Creates a polygon geofence from a list of vertices.

Creates a circular geofence centred at the origin with the given radius.

Types

t()

@type t() :: %Drone.Safety.Geofence{
  center: {integer(), integer()} | nil,
  points: [{integer(), integer()}] | nil,
  radius_cm: pos_integer() | nil,
  type: :circle | :polygon
}

Geofence struct describing an allowed XY region in centimeters.

FieldTypeMeaning
:type:circle | :polygonShape discriminant
:center{integer(), integer()} | nilCircle center (x, y) cm
:radius_cmpos_integer() | nilCircle radius in centimeters
:points[{integer(), integer()}] | nilPolygon vertices in order

Examples

%Drone.Safety.Geofence{type: :circle, center: {0, 0}, radius_cm: 250}

%Drone.Safety.Geofence{
  type: :polygon,
  points: [{0, 0}, {200, 0}, {200, 200}, {0, 200}]
}

Functions

circle(center, radius_cm)

@spec circle(
  {integer(), integer()},
  pos_integer()
) :: t()

Creates a circular geofence centred at the given point with the given radius.

Parameters

  • center ({integer(), integer()}) — (x, y) in centimeters
  • radius_cm (pos_integer()) — allowed radius in centimeters

Returns

t/0 with :type :circle.

Examples

fence = Drone.Safety.Geofence.circle({50, -20}, 150)
:circle = fence.type

contains?(arg1, point)

@spec contains?(
  t() | nil,
  {integer(), integer()}
) :: boolean()

Checks whether a point is inside the geofence.

Returns true if the point is inside or on the boundary, false otherwise. A nil fence always contains every point.

Parameters

  • fence (t/0 \| nil) — geofence or disabled (nil)
  • point ({integer(), integer()}) — (x, y) in centimeters

Returns

boolean().

Examples

fence = Drone.Safety.Geofence.circle({0, 0}, 100)
true = Drone.Safety.Geofence.contains?(fence, {0, 100})
false = Drone.Safety.Geofence.contains?(fence, {101, 0})
true = Drone.Safety.Geofence.contains?(nil, {10_000, 10_000})

polygon(points)

@spec polygon([{integer(), integer()}]) :: t()

Creates a polygon geofence from a list of vertices.

The polygon must have at least 3 vertices. The last vertex is automatically connected to the first.

Parameters

  • points ([{integer(), integer()}]) — vertices in centimeters (3+)

Returns

t/0 with :type :polygon.

Examples

fence =
  Drone.Safety.Geofence.polygon([
    {0, 0},
    {300, 0},
    {300, 200},
    {0, 200}
  ])

:polygon = fence.type

radius(radius_cm)

@spec radius(pos_integer()) :: t()

Creates a circular geofence centred at the origin with the given radius.

Convenience for a radius around the launch point.

Parameters

  • radius_cm (pos_integer()) — radius in centimeters

Returns

t/0 circle centered at {0, 0}.

Examples

%Drone.Safety.Geofence{center: {0, 0}, radius_cm: 200} =
  Drone.Safety.Geofence.radius(200)