Drone.Adapters.Crazyflie.Commander (ex_drone v0.3.0)

View Source

High-level commander CRTP payload builders (port setpoint_hl).

Packet layouts follow the documented Crazyflie high-level commander commands (TAKEOFF_2, LAND_2, STOP, GO_TO_2). Floats are little-endian.

These helpers return Drone.Adapters.Crazyflie.CRTP.packet() maps ready for Session.send_packet/2. Public Drone distances remain centimeters; convert with Drone.Adapters.Crazyflie.Units before calling.

Examples

packet =
  Drone.Adapters.Crazyflie.Commander.takeoff_2(0.5, 2.0,
    yaw: 0.0,
    use_current_yaw: true
  )

8 = packet.port
<<7, _rest::binary>> = packet.payload

Summary

Functions

Builds a STOP packet (motors off / cancel trajectory).

Builds a TAKEOFF_2 packet.

Functions

go_to_2(x, y, z, yaw, duration_s, opts \\ [])

Builds a GO_TO_2 packet.

Parameters

  • x, y, z (number()) — position in meters (absolute or relative)
  • yaw (number()) — yaw in radians
  • duration_s (number()) — maneuver duration in seconds
  • opts (keyword()) — optional:
    • :group_mask (byte()) — default 0
    • :relative (boolean()) — treat XYZ as deltas when true (default false)
    • :linear (boolean()) — linear interpolation hint (default false)

Returns

Drone.Adapters.Crazyflie.CRTP.packet().

Examples

# Relative forward 0.3 m over 1 s
packet =
  Drone.Adapters.Crazyflie.Commander.go_to_2(
    0.0,
    0.3,
    0.0,
    0.0,
    1.0,
    relative: true
  )

<<12, 0, 1, 0, _rest::binary>> = packet.payload

land_2(height_m, duration_s, opts \\ [])

Builds a LAND_2 packet.

Parameters

  • height_m (number()) — landing height in meters (often 0.0)
  • duration_s (number()) — maneuver duration in seconds
  • opts (keyword()) — same as takeoff_2/3 (:group_mask, :yaw, :use_current_yaw)

Returns

Drone.Adapters.Crazyflie.CRTP.packet().

Examples

packet = Drone.Adapters.Crazyflie.Commander.land_2(0.0, 2.0)
<<8, 0, _rest::binary>> = packet.payload

stop(opts \\ [])

Builds a STOP packet (motors off / cancel trajectory).

Parameters

  • opts (keyword()) — optional:
    • :group_mask (byte()) — default 0

Returns

Drone.Adapters.Crazyflie.CRTP.packet() with payload <<3, group>>.

Examples

%{payload: <<3, 0>>} = Drone.Adapters.Crazyflie.Commander.stop()

takeoff_2(height_m, duration_s, opts \\ [])

Builds a TAKEOFF_2 packet.

Parameters

  • height_m (number()) — absolute takeoff height in meters
  • duration_s (number()) — maneuver duration in seconds
  • opts (keyword()) — optional:
    • :group_mask (byte()) — commander group mask (default 0 = all)
    • :yaw (number()) — yaw setpoint in radians (default 0.0)
    • :use_current_yaw (boolean()) — keep current yaw when true (default)

Returns

Drone.Adapters.Crazyflie.CRTP.packet() on port :setpoint_hl, channel 0.

Examples

packet = Drone.Adapters.Crazyflie.Commander.takeoff_2(0.4, 1.5)
<<7, 0, _height::little-float-32, _rest::binary>> = packet.payload