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.
- animateFlight
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
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
isnull
then the default frequency of the enum is used.Corresponds to the
leds:leds_anim
config cmd.This method does not block.
- calibrate
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.
- clearEmergencyLanding
Void clearEmergencyLanding(Duration? timeout := null)
Blocks until the emergency landing flag has been cleared.
If
timeout
isnull
it defaults toDroneConfig.configCmdAckTimeout
.- config
DroneConfig config()
Returns config for the drone. Note all data is backed by the raw
configMap
.- configMap
Str:Str configMap(Bool reRead := false)
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, pass a
reRead
value oftrue
to obtain fresh data from the drone.- connect
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.
If
timeout
isnull
it defaults toDroneConfig.actionTimeout
.- disconnect
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
Version? droneVersion { private set }
The version of the drone, as reported by an FTP of
version.txt
.- exitStrategy
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
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
FlightState? flightState { private set }
Returns the current flight state of the Drone.
- hover
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
istrue
then this method blocks until the drone hovers.If
timeout
isnull
it defaults toDroneConfig.defaultTimeout
.- isConnected
Bool isConnected()
Returns
true
if connected to the drone.- land
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
istrue
then this method blocks until the drone has landed.If
timeout
isnull
it defaults toDroneConfig.defaultTimeout
.- make
new make(NetworkConfig networkConfig := NetworkConfig.<ctor>())
Creates a
Drone
instance, optionally passing in network configuration.- move
|->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
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveBackward(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:euler_angle_max
.- moveDown
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveDown(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config commands
control:altitude_min
,control:control_vz_max
.- moveForward
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveForward(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:euler_angle_max
.- moveLeft
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveLeft(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:euler_angle_max
.- moveRight
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveRight(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:euler_angle_max
.- moveUp
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.moveUp(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config commands
control:altitude_max
,control:control_vz_max
.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
const NetworkConfig networkConfig
The network configuration as passed to the ctor.
- 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
|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
Event hook that's called when the drone is disconnected. The
abnormal
boolean is set totrue
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
|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.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.- onStateChange
|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.- onVideoFrame
|Buf,PaveHeader,Drone? onVideoFrame
Event hook that's called when 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 video. Setting this 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.- sendConfig
Void sendConfig(Str key, Obj val, Str? sessionId := null, Str? userId := null, Str? 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.
- setEmergencyLanding
Void setEmergencyLanding(Duration? timeout := null)
Sends a emergency signal which cuts off the drone's motors, causing a crash landing.
If
timeout
isnull
it defaults toDroneConfig.configCmdAckTimeout
.- spinAntiClockwise
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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.spinAntiClockwise(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:control_yaw
.- spinClockwise
|->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 everyconfig.cmdInterval
. Movement is cancelled ifland()
is called or an emergency flag is set.Should
block
befalse
, this method returns immediately and movement commands are sent in the background. Call the returned function to cancel movement before theduration
interval is reached. Calling the function afterduration
does nothing.// move the dronecancel := drone.spinClockwise(0.5f, 5sec, false)// wait a bitActor.sleep(2sec)// cancel the movecancel()If
duration
isnull
then the movement command is sent just the once.See config command
control:control_yaw
.- takeOff
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
orflying
.If
block
istrue
then this method blocks until a stable hover has been achieved; which usually takes ~ 6 seconds.If
timeout
isnull
it defaults toDroneConfig.defaultTimeout
.