const classafParrotSdk2::Drone

sys::Obj
  afParrotSdk2::Drone

The main interface to the Parrot AR Drone 2.0.

Once the drone has been disconnected, this class instance can not be re-connected. Instead create a new Drone instance.

absoluteAccuracy

Source

Float absoluteAccuracy

How accurate absolute mode is. Should be a number between 0 - 1.

Defaults to 0.1f.

absoluteMode

Source

Bool absoluteMode

Turns the drone's absolute movement mode on and off. Absolute mode is where the drone's left / right / forward / backward movement is fixed to a set compass position and is not relative to where the drone is facing.

The compass direction is set when absolute mode is turned on. If you make sure the drone is facing away from you when this happens, then it should make for easier drone control.

animateFlight

Source

Void animateFlight(FlightAnimation anim, Duration? duration := null, Bool block := true)

Performs one of the pre-configured flight sequences.

drone.animateFlight(FlightAnimation.phiDance)

If duration is null then the default duration of the enum is used.

Corresponds to the control:flight_anim config cmd.

animateLeds

Source

Void animateLeds(LedAnimation anim, Duration duration, Float? freqInHz := null)

Plays one of the pre-configured LED animation sequences. Example:

drone.animateLeds(LedAnimation.snakeRed, 3sec)

If freqInHz is null then the default frequency of the enum is used.

Corresponds to the leds:leds_anim config cmd.

This method does not block.

calibrate

Source

Void calibrate(Int deviceNum)

Tell the drone to calibrate its magnetometer.

The drone calibrates its magnetometer by spinning around itself a few times, hence can only be performed when flying.

This method does not block.

clearEmergency

Source

Void clearEmergency(Duration? timeout := null)

Clears the emergency landing and the user emergency flags on the drone.

timeout is how long it should wait for an acknowledgement from the drone before throwing a TimeoutErr. If null then it defaults to NetworkConfig.configCmdAckTimeout.

config

Source

DroneConfig config()

Returns config for the drone. Note all data is backed by the raw configMap.

configMap

Source

Str:Str configMap()

Returns a read only map of the drone's raw configuration data, as read from the control (TCP 5559) port.

All config data is cached, see configRefresh() obtain fresh data from the drone.

configRefresh

Source

Void configRefresh()

Reloads the configMap with fresh data from the drone.

connect

Source

This connect()

Sets up the socket connections to the drone. Your device must already be connected to the drone's wifi hot spot.

Whilst there is no real concept of being connected to a drone, this method blocks until nav data is being received and all initiating commands have been acknowledged.

disconnect

Source

This disconnect(Duration timeout := 2sec)

Disconnects all comms to the drone. Performs the crashLandOnExit strategy should the drone still be flying.

This method blocks until it's finished.

droneVersion

Source

Version droneVersion { private set }

The version of the drone, as reported by an FTP of version.txt.

exitStrategy

Source

ExitStrategy exitStrategy

Should this Drone class instance disconnect from the drone whilst it is flying (or the VM otherwise exits) then this strategy governs what last commands should be sent to the drone before it exits.

(It's a useful feature I wish I'd implemented before the time my program crashed and I watched my drone sail up, up, and away, over the tree line!)

Defaults to land.

Note this can not guard against a forced process kill or a kill -9 command.

flatTrim

Source

Void flatTrim()

Sets a horizontal plane reference for the drone's internal control system.

Call before each flight, while making sure the drone is sitting horizontally on the ground. Not doing so will result in the drone not being unstable.

This method does not block.

flightState

Source

FlightState? flightState { private set }

Returns the current flight state of the Drone.

hover

Source

Void hover(Bool block := true, Duration? timeout := null)

Repeatedly sends a hover command to the drone until it reports its state as hovering.

If block is true then this method blocks until the drone hovers.

timeout is how long it should wait for the drone to reach the desired state before throwing a TimeoutErr. If null then it defaults to NetworkConfig.actionTimeout.

isConnected

Source

Bool isConnected()

Returns true if connected to the drone.

land

Source

Void land(Bool block := true, Duration? timeout := null)

Repeatedly sends a land command to the drone until it reports its state as landed.

If block is true then this method blocks until the drone has landed.

timeout is how long it should wait for the drone to reach the desired state before throwing a TimeoutErr. If null then it defaults to NetworkConfig.actionTimeout.

make

Source

new make(NetworkConfig networkConfig := NetworkConfig.<ctor>(), |This? f := null)

Creates a Drone instance, optionally passing in network configuration.

move

Source

|->Void? move(Float tiltRight, Float tiltBackward, Float verticalSpeed, Float clockwiseSpin, Duration? duration := null, Bool? block := (Bool?)true)

A combined move method encapsulating:

  • moveRight()
  • moveBackward()
  • moveUp()
  • spinClickwise()
moveBackward

Source

|->Void? moveBackward(Float tilt, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone backward.

The tilt (aka pitch or theta) is a percentage of the maximum inclination and should be a value between -1 and 1. A positive value makes the drone raise its nose, thus flying forward. A negative value makes the drone tilt forward.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveBackward(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:euler_angle_max.

moveDown

Source

|->Void? moveDown(Float verticalSpeed, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone vertically downwards.

verticalSpeed is a percentage of the maximum vertical speed and should be a value between -1 and 1. A positive value makes the drone descend in the air, a negative value makes it go up.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveDown(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config commands CONTROL:altitude_min, CONTROL:control_vz_max.

moveForward

Source

|->Void? moveForward(Float tilt, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone forward.

The tilt (aka pitch or theta) is a percentage of the maximum inclination and should be a value between -1 and 1. A positive value makes the drone drop its nose, thus flying forward. A negative value makes the drone tilt back.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveForward(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:euler_angle_max.

moveLeft

Source

|->Void? moveLeft(Float tilt, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone to the left.

tilt (aka roll or phi) is a percentage of the maximum inclination and should be a value between -1 and 1. A positive value makes the drone tilt to its left, thus flying leftward. A negative value makes the drone tilt to its right.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveLeft(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:euler_angle_max.

moveRight

Source

|->Void? moveRight(Float tilt, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone to the right.

The tilt (aka roll or phi) is a percentage of the maximum inclination and should be a value between -1 and 1. A positive value makes the drone tilt to its right, thus flying right. A negative value makes the drone tilt to its left.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveRight(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:euler_angle_max.

moveUp

Source

|->Void? moveUp(Float verticalSpeed, Duration? duration := null, Bool? block := (Bool?)true)

Moves the drone vertically upwards.

verticalSpeed is a percentage of the maximum vertical speed and should be a value between -1 and 1. A positive value makes the drone rise in the air, a negative value makes it go down.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.moveUp(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config commands CONTROL:altitude_max, CONTROL:control_vz_max.

Source

NavData? navData { private set }

Returns the latest Nav Data or null if not connected. Note that this instance always contains a culmination of all the latest nav options received.

networkConfig

Source

const NetworkConfig networkConfig

The network configuration as passed to the ctor.

onBatteryDrain

Source

|Int,Drone? onBatteryDrain

Event hook that's called when the drone's battery loses a percentage of charge. The function is called with the new battery percentage level (0 - 100).

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onBatteryLow

Source

|Drone? onBatteryLow

Event hook that's called when the drone's battery reaches a critical level ~ 20%.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onDisconnect

Source

|Bool,Drone? onDisconnect

Event hook that's called when the drone is disconnected. The abnormal boolean is set to true if the drone is disconnected due to a communication / socket error. This may happen if the battery drains too low or the drone is switched off.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onEmergency

Source

|Drone? onEmergency

Event hook that's called when the drone enters emergency mode. When this happens, the engines are cut and the drone will not respond to commands until emergency mode is cleared.

Note this hook is only called when the drone is flying.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onNavData

Source

|NavData,Drone? onNavData

Event hook that's notified when the drone sends new NavData. Expect the function to be called many times a second.

The nav data is raw from the drone so does not contain a culmination of all option data. Note Drone.navData is updated with the new contents before the hook is called.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onRecordErr

Source

|Err,Drone? onRecordErr

Event hook that's called when there's an error decoding the video record stream.

Given the nature of streaming chunks, errors may be un-recoverable and future video frames may not be decoded. Therefore on error, it is advised to restart the video comms with the drone.

onStateChange

Source

|FlightState,Drone? onStateChange

Event hook that's called when the drone's state is changed.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

onVideoErr

Source

|Err,Drone? onVideoErr

Event hook that's called when there's an error decoding the video stream.

Given the nature of streaming chunks, errors may be un-recoverable and future video frames may not be decoded. Therefore on error, it is advised to restart the video comms with the drone.

onVideoFrame

Source

|Buf,PaveHeader,Drone? onVideoFrame

Event hook that's called when a video frame is received. (On Drone TCP port 5555.)

The payload is a raw frame from the H.264 codec.

Setting this hook instructs the drone to start streaming live video. Setting to null instructs the drone to stop streaming video.

Throws NotImmutableErr if the function is not immutable. Note this hook is called from a different Actor / thread to the one that sets it.

sendCmd

Source

Void sendCmd(Cmd cmd, Cmd? cmd2 := null)

(Advanced) Sends the given Cmd to the drone. If a second Cmd is given, it is sent in the same UDP data packet.

This method does not block.

sendConfig

Source

Void sendConfig(Str key, Obj val, Int? sessionId := null, Int? userId := null, Int? appId := null)

(Advanced) Sends a config cmd to the drone, and blocks until it's been acknowledged.

val may be a Bool, Int, Float, Str, or a List of said types.

For multi-config support, pass in the appropriate IDs.

setUserEmergency

Source

Void setUserEmergency(Duration? timeout := null)

Sets the drone's emergency landing flag which cuts off the motors, causing a crash landing.

timeout is how long it should wait for an acknowledgement from the drone before throwing a TimeoutErr. If null then it defaults to NetworkConfig.configCmdAckTimeout.

spinAntiClockwise

Source

|->Void? spinAntiClockwise(Float angularSpeed, Duration? duration := null, Bool? block := (Bool?)true)

Spins the drone anti-clockwise.

The angularSpeed (aka yaw) is a percentage of the maximum angular speed and should be a value between -1 and 1. A positive value makes the drone spin anti-clockwise; a negative value makes it spin clockwise.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.spinAntiClockwise(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:control_yaw.

spinClockwise

Source

|->Void? spinClockwise(Float angularSpeed, Duration? duration := null, Bool? block := (Bool?)true)

Spins the drone clockwise.

The angularSpeed (aka yaw) is a percentage of the maximum angular speed and should be a value between -1 and 1. A positive value makes the drone spin clockwise; a negative value makes it spin anti-clockwise.

duration is how long the drone should move for, during which the move command is resent every config.cmdInterval. Movement is cancelled if land() is called or an emergency flag is set.

Should block be false, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before the duration interval is reached. Calling the function after duration does nothing.

// move the drone for 5secs
cancel := drone.spinClockwise(0.5f, 5sec, false)

// wait a bit
Actor.sleep(2sec) 

// cancel the move prematurely
cancel()

If duration is null then the movement command is sent just the once.

See config command CONTROL:control_yaw.

takeOff

Source

Void takeOff(Bool block := true, Duration? timeout := null)

Repeatedly sends a take off command to the drone until it reports its state as either hovering or flying.

If block is true then this method blocks until a stable hover has been achieved; which usually takes ~ 6 seconds.

timeout is how long it should wait for the drone to reach the desired state before throwing a TimeoutErr. If null then it defaults to NetworkConfig.actionTimeout.