Drone

November 7, 2023 ยท View on GitHub

from tdw.add_ons.drone import Drone

A drone is a flying agent. From this API, you can set the drone's speed (lift, drive, turn) and turn its motor on and off.

The drone's output data, including images, is stored in drone.dynamic.


Class Variables

VariableTypeDescriptionValue
LIBRARY_NAMEstrThe drone's library file. You can override this to use a custom library (e.g. a local library)."drones.json"

Fields

  • initial_position The initial position of the drone.

  • initial_rotation The initial rotation of the drone in Euler angles.

  • dynamic The DroneDynamic data.

  • drone_id The ID of this drone.

  • avatar_id The ID of the drone's avatar (camera). This is used internally for API calls.

  • commands These commands will be appended to the commands of the next communicate() call.

  • initialized If True, this module has been initialized.


Functions

__init__

Drone()

Drone(drone_id=0, position=None, rotation=None, name="drone", forward_speed=3, backward_speed=3, rise_speed=3, drop_speed=3, acceleration=0.3, deceleration=0.2, stability=0.1, turn_sensitivity=2, enable_lights=False, motor_on=True, image_capture=True, image_passes=None)

ParameterTypeDefaultDescription
drone_idint0The ID of the drone.
positionPOSITIONNoneThe position of the drone as an x, y, z dictionary or numpy array. If None, defaults to {"x": 0, "y": 0, "z": 0}.
rotationROTATIONNoneThe rotation of the drone in Euler angles (degrees) as an x, y, z dictionary or numpy array. If None, defaults to {"x": 0, "y": 0, "z": 0}.
namestr"drone"The name of the drone model.
forward_speedfloat3Sets the drone's max forward speed.
backward_speedfloat3Sets the drone's max backward speed.
rise_speedfloat3Sets the drone's max vertical rise speed.
drop_speedfloat3Sets the drone's max vertical drop speed.
accelerationfloat0.3How fast the drone speeds up.
decelerationfloat0.2How fast the drone slows down.
stabilityfloat0.1How easily the drone is affected by outside forces.
turn_sensitivityfloat2The name of the drone model.
enable_lightsboolFalseSets whether or not the drone's lights are on.
motor_onboolTrueSets whether or not the drone is active on start.
image_captureboolTrueIf True, the drone will receive image and camera matrix data per communicate() call. Whether or not this is True, the drone will always render images in the simulation window.
image_passesList[str]NoneA list of image passes that will be captured. Ignored if image_capture == False. If None, defaults to ["_img", "_id"].

get_initialization_commands

self.get_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

Returns: A list of commands that will initialize this add-on.

on_send

self.on_send(resp)

This is called within Controller.communicate(commands) after commands are sent to the build and a response is received.

Use this function to send commands to the build on the next Controller.communicate(commands) call, given the resp response. Any commands in the self.commands list will be sent on the next Controller.communicate(commands) call.

ParameterTypeDefaultDescription
respList[bytes]The response from the build.

before_send

self.before_send(commands)

This is called within Controller.communicate(commands) before sending commands to the build. By default, this function doesn't do anything.

ParameterTypeDefaultDescription
commandsList[dict]The commands that are about to be sent to the build.

get_early_initialization_commands

self.get_early_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

These commands are added to the list being sent on communicate() before any other commands, including those added by the user and by other add-ons.

Usually, you shouldn't override this function. It is useful for a small number of add-ons, such as loading screens, which should initialize before anything else.

Returns: A list of commands that will initialize this add-on.

set_lift

self.set_lift(lift)

Set the drone's lift force.

ParameterTypeDefaultDescription
liftintThe lift force. Must be -1, 0, or 1.

set_drive

self.set_drive(drive)

Set the drone's drive force.

ParameterTypeDefaultDescription
driveintThe drive force. Must be -1, 0, or 1.

set_turn

self.set_turn(turn)

Set the drone's turn force.

ParameterTypeDefaultDescription
turnintThe turn force. Must be -1, 0, or 1.

set_motor

self.set_motor(motor_on)

Turn the drone's motor on or off.

ParameterTypeDefaultDescription
motor_onboolIf True, turn the motor on. If False, turn the motor off.

set_speed

self.set_speed()

self.set_speed(forward_speed=3)

Set the drone's forward and/or backward speeds.

ParameterTypeDefaultDescription
forward_speedfloat3The forward speed. Must be between 0 and 20.0.