Drone.Adapters.Crazyflie (ex_drone v0.3.0)

View Source

Crazyflie 2.x adapter over Crazyradio (or an in-process mock transport).

Implements Drone.Adapter. Prefer connecting through Drone.connect/2 rather than calling this module directly.

Supported configuration (v0.3.0)

  • Crazyflie 2.1 / 2.1+ with a documented CRTP protocol version
  • Crazyradio PA / Crazyradio 2.0 via a pluggable USB backend
  • High-level position commands with a positioning system (:flow, :lighthouse, :loco)
  • One Crazyflie per adapter process

Connection options

OptionTypeDefaultMeaning
:uriString.t()"mock://ready"Link URI (mock://… or radio://…)
:transportmodule()from URIOverride transport module
:usb_backendmodule()USB.UnavailableRequired for radio://
:positioningatom():flowPositioning system label
:default_height_cmpos_integer()50Takeoff height in centimeters
:default_speed_cm_spos_integer()50Horizontal move speed

Connection

{:ok, drone} =
  Drone.connect(:crazyflie,
    name: :cf_1,
    uri: "mock://ready",
    positioning: :flow,
    default_height_cm: 50
  )

:ok = Drone.connect_sdk(drone)

connect_sdk/1 is a documented no-op that succeeds for mission compatibility. Real radio URIs require usb_backend: YourUSBModule implementing Drone.Adapters.Crazyflie.USB.

Deferred

BLE, direct Crazyflie USB flight control, raw attitude setpoints, trajectory upload, parameter editing, firmware flashing, and multi-Crazyflie swarms.

Summary

Types

t()

Crazyflie adapter state held by Drone.Vehicle.

Functions

Returns Crazyflie capability metadata for the connected state.

Executes a normalized Drone.Command over CRTP.

Opens a Crazyflie link and returns initial adapter state.

Closes the CRTP session and releases the transport.

Returns a telemetry snapshot for the vehicle safety / state machine.

Types

t()

@type t() :: %Drone.Adapters.Crazyflie{
  armed: boolean(),
  battery: integer() | nil,
  capabilities: Drone.Adapter.Capabilities.t() | nil,
  default_height_cm: integer() | nil,
  default_speed_cm_s: integer() | nil,
  estimator_ready: boolean() | nil,
  firmware: String.t() | nil,
  flying: boolean(),
  last_error: term() | nil,
  link_quality: integer() | nil,
  mode: atom(),
  move_speed_cm_s: integer() | nil,
  positioning: atom() | nil,
  protocol_version: integer() | nil,
  serial_number: String.t() | nil,
  session: Drone.Adapters.Crazyflie.Session.t() | nil,
  telemetry_at: integer() | nil,
  uri: String.t() | nil,
  x: integer(),
  y: integer(),
  yaw: integer(),
  z: integer()
}

Crazyflie adapter state held by Drone.Vehicle.

FieldTypeMeaning
:sessionDrone.Adapters.Crazyflie.Session.t()Open CRTP session
:uriString.t()Connection URI used at open
:positioningatom():flow, :lighthouse, :loco, …
:default_height_cminteger()Takeoff target height (cm)
:default_speed_cm_sinteger()Initial move speed (cm/s)
:move_speed_cm_sinteger()Current move speed (updated by :speed)
:protocol_versioninteger() | nilNegotiated CRTP protocol version
:capabilitiesDrone.Adapter.Capabilities.t()Advertised capabilities
:modeatom():idle, :sdk_mode, :flying, :emergency
:flyingboolean()Whether a takeoff is considered active
:armedboolean()Supervisor arm state
:x, :y, :zinteger()Estimated position in centimeters
:yawinteger()Yaw in degrees
:batteryinteger()Battery percent 0..100
:estimator_readyboolean()Positioning estimator readiness
:link_qualityinteger()Link quality percent (best-effort)
:telemetry_atinteger() | nilMonotonic ms of last telemetry touch
:firmwareString.t()Firmware label when known
:last_errorterm() | nilMost recent link/command error

Example

%Drone.Adapters.Crazyflie{
  uri: "mock://ready",
  positioning: :flow,
  default_height_cm: 50,
  mode: :flying,
  flying: true,
  z: 50,
  battery: 95,
  estimator_ready: true,
  protocol_version: 8
}

Functions

capabilities(crazyflie)

Returns Crazyflie capability metadata for the connected state.

Parameters

Returns

Drone.Adapter.Capabilities.t() (includes :requires_estimator, :link).

Examples

caps = Drone.Adapters.Crazyflie.capabilities(state)
:fire_and_forget = caps.maneuver_completion

command(state, arg2)

Executes a normalized Drone.Command over CRTP.

Supported types include :sdk_mode (no-op success), :takeoff, :land, :emergency, :move, :rotate, :stop, :hover, :speed, and :query. :flip returns {:error, :unsupported_command, state}.

Takeoff arms the supervisor, then sends high-level TAKEOFF_2. Land and emergency use commander/supervisor packets. Moves and rotates use relative GO_TO_2 with unit conversion via Units.

Parameters

  • state (t/0) — current adapter state
  • command (Drone.Command.t()) — command from the vehicle pipeline

Returns

  • {:ok, reply, t()}reply is usually :ok or a query value
  • {:error, reason, t()} — readiness, link, or unsupported command

Examples

{:ok, :ok, state} =
  Drone.Adapters.Crazyflie.command(state, Drone.Command.takeoff())

{:ok, pct, state} =
  Drone.Adapters.Crazyflie.command(
    state,
    Drone.Command.query(:battery)
  )

connect(opts)

Opens a Crazyflie link and returns initial adapter state.

Resolves a transport via Transport.resolve/1, runs the CRTP handshake through Session.connect/2, and seeds telemetry via optional c:Transport.telemetry/1.

disconnect(crazyflie)

Closes the CRTP session and releases the transport.

Parameters

  • state (t/0) — final adapter state

Returns

Always :ok.

Examples

:ok = Drone.Adapters.Crazyflie.disconnect(state)

telemetry(state)

Returns a telemetry snapshot for the vehicle safety / state machine.

Transport-reported readiness fields are synced via optional c:Transport.telemetry/1. Pose (x/y/z/yaw) is maintained by the adapter from commanded moves.