QDrone 2

../_images/QDrone2_Banner.png

Description

QDrones are considered “actors” in Quanser Interactive Labs. The QDrone library can be used to acquire sensor data from the virtual environment and control the motion of the drones.

See the QDrone 2 Tutorial to get a better understanding of using QDrones in Quanser Interactive Labs.

Library

class qvl.qdrone2.QLabsQDrone2(qlabs, verbose=False)[source]

This class is for spawning a QDrone 2.

Constants

QLabsQDrone2.ID_QDRONE2 = 231

Note

VIEWPOINT constants are for the possess method. CAMERA constants are for the get_image method.

QLabsQDrone2.VIEWPOINT_CSI_LEFT = 0
QLabsQDrone2.VIEWPOINT_CSI_BACK = 1
QLabsQDrone2.VIEWPOINT_CSI_RIGHT = 2
QLabsQDrone2.VIEWPOINT_RGB = 3
QLabsQDrone2.VIEWPOINT_DEPTH = 4
QLabsQDrone2.VIEWPOINT_DOWNWARD = 5
QLabsQDrone2.VIEWPOINT_OPTICAL_FLOW = 6

Note

Overhead and trailing cameras support user zoom using the mouse wheel.

QLabsQDrone2.VIEWPOINT_OVERHEAD = 7
QLabsQDrone2.VIEWPOINT_TRAILING = 8

Note

CSI camera resolution is 820x410.

QLabsQDrone2.CAMERA_CSI_LEFT = 0
QLabsQDrone2.CAMERA_CSI_BACK = 1
QLabsQDrone2.CAMERA_CSI_RIGHT = 2

Note

RGB and depth resolution is 640x480.

QLabsQDrone2.CAMERA_RGB = 3
QLabsQDrone2.CAMERA_DEPTH = 4
QLabsQDrone2.CAMERA_DOWNWARD = 5
QLabsQDrone2.CAMERA_OPTICAL_FLOW = 6

Member Variables

QLabsQDrone2.actorNumber = None

The current actor number of this class to be addressed. This will be set by spawn methods and cleared by destroy methods. It will not be modified by the destroy all actors. This can be manually altered at any time to use one object to address multiple actors.

Methods

QLabsQDrone2.possess(camera=VIEWPOINT_TRAILING)[source]

Possess (take control of) a QDrone in QLabs with the selected camera.

Parameters

camera (uint32) – Pre-defined camera constant. See CAMERA constants for available options. Default is the trailing camera.

Returns

  • status - True if possessing the camera was successful, False otherwise

Return type

boolean

QLabsQDrone2.set_velocity_and_request_state(motorsEnabled=False, velocity=[0, 0, 0], orientation=[0, 0, 0])[source]

Sets the velocity, turn angle in radians, and other properties.

Parameters
  • motorsEnabled (boolean) – Enable the motors. Disabled by default immediately after spawning.

  • velocity (float array[3]) – The linear velocity in m/s in the body frame.

  • orientation (float array[3]) – The orientation in radians expressed in roll-pitch-yaw Euler angles.

Returns

  • status - True if successful, False otherwise. Other returned values are invalid if status is False.

  • location - World location in m

  • orientation - World orientation in radians (roll, pitch, yaw)

  • quaternion - World orientation in a quaternion vector

  • velocity - World linear velocity in m/s

  • TOF distance - Time of flight distance sensor. Returns 0 when outside the range of the sensor (too close or too far).

  • collision - The QDrone is currently colliding with another object or the environment.

  • collision location - Body frame location. Invalid if collision is False.

  • collision force vector - The vector along which the collision force is occuring. Invalid if collision is False.

Return type

boolean, float array[3], float array[3], float array[4], float array[3], float, boolean, float array[3], float array[3]

QLabsQDrone2.set_velocity_and_request_state_degrees(motorsEnabled=False, velocity=[0, 0, 0], orientation=[0, 0, 0])[source]

Sets the velocity, turn angle in radians, and other properties.

Parameters
  • motorsEnabled (boolean) – Enable the motors. Disabled by default immediately after spawning.

  • velocity (float array[3]) – The linear velocity in m/s in the body frame.

  • orientation (float array[3]) – The orientation in degrees expressed in roll-pitch-yaw Euler angles.

Returns

  • status - True if successful, False otherwise. Other returned values are invalid if status is False.

  • location - World location in m

  • orientation - World orientation in degrees (roll, pitch, yaw)

  • quaternion - World orientation in a quaternion vector

  • velocity - World linear velocity in m/s

  • TOF distance - Time of flight distance sensor. Returns 0 when outside the range of the sensor (too close or too far).

  • collision - The QDrone is currently colliding with another object or the environment.

  • collision location - Body frame location. Invalid if collision is False.

  • collision force vector - The vector along which the collision force is occuring. Invalid if collision is False.

Return type

boolean, float array[3], float array[3], float array[4], float array[3], float, boolean, float array[3], float array[3]

QLabsQDrone2.set_transform_and_dynamics(location, rotation, enableDynamics, waitForConfirmation=True)[source]

Sets the location, rotation, and other properties. Note that setting the location ignores collisions so ensure that the location is free of obstacles that may trap the actor if it is subsequently used in a dynamic mode. This transform can also be used to “playback” previously recorded position data without the need for a full dynamic model.

Parameters
  • location (float array[3]) – An array of floats for x, y and z coordinates in full-scale units.

  • rotation (float array[3]) – An array of floats for the roll, pitch, and yaw in radians

  • enableDynamics (boolean) – Enables or disables dynamics. The velocity commands will have no effect when the dynamics are disabled.

  • waitForConfirmation (boolean) – (Optional) Wait for confirmation before proceeding. This makes the method a blocking operation.

Returns

  • status - True if successful or False otherwise

Return type

boolean

QLabsQDrone2.get_image(camera)[source]

Request a JPG image from the QDrone camera.

Parameters

camera (int32) – Camera number to view from. Use the CAMERA constants.

Returns

  • status - True and image data if successful, False and empty otherwise

  • cameraNumber - The number of the camera currently being read

  • imageData - Image in a JPG format

Return type

boolean, int32, byte array with jpg data

QLabsQDrone2.set_image_capture_resolution(width=640, height=480)[source]

Change the default width and height of image resolution for capture

Parameters
  • width (uint32) – Must be an even number. Default 640

  • height (uint32) – Must be an even number. Default 480

Returns

True if spawn was successful, False otherwise

Return type

boolean

Parent Class (actor.py) Methods

QLabsQDrone2.__init__(qlabs, verbose=False)[source]

Constructor Method

Parameters
  • qlabs (object) – A QuanserInteractiveLabs object

  • verbose (boolean) – (Optional) Print error information to the console.

QLabsQDrone2.spawn(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)

Spawns a new actor with the next available actor number within this class.

Parameters
  • location (float array[3]) – (Optional) An array of floats for x, y and z coordinates

  • rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians

  • scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.

  • configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.

  • waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.

Returns

  • status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.

  • actorNumber - An actor number to use for future references.

Return type

int32, int32

QLabsQDrone2.spawn_degrees(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)

Spawns a new actor with the next available actor number within this class.

Parameters
  • location (float array[3]) – (Optional) An array of floats for x, y and z coordinates

  • rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in degrees

  • scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.

  • configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.

  • waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.

Returns

  • status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.

  • actorNumber - An actor number to use for future references.

Return type

int32, int32

QLabsQDrone2.spawn_id(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)

Spawns a new actor.

Parameters
  • actorNumber (uint32) – User defined unique identifier for the class actor in QLabs

  • location (float array[3]) – (Optional) An array of floats for x, y and z coordinates

  • rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians

  • scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.

  • configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.

  • waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.

Returns

  • status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error

Return type

int32

QLabsQDrone2.spawn_id_degrees(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)

Spawns a new actor.

Parameters
  • actorNumber (uint32) – User defined unique identifier for the class actor in QLabs

  • location (float array[3]) – (Optional) An array of floats for x, y and z coordinates

  • rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians

  • scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.

  • configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.

  • waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.

Returns

  • status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error

Return type

int32

QLabsQDrone2.destroy()

Find and destroy a specific actor. This is a blocking operation.

Returns

  • numActorsDestroyed - The number of actors destroyed. -1 if failed.

Return type

int32

QLabsQDrone2.destroy_all_actors_of_class()

Find and destroy all actors of this class. This is a blocking operation.

Returns

  • numActorsDestroyed - The number of actors destroyed. -1 if failed.

Return type

int32

QLabsQDrone2.ping()

Checks if the actor is still present in the environment. Note that if you did not spawn the actor with one of the spawn functions, you may need to manually set the actorNumber member variable.

Returns

  • status - True if successful, False otherwise

Return type

boolean

QLabsQDrone2.get_world_transform()

Get the location, rotation, and scale in world coordinates of the actor.

Returns

  • status - True if successful, False otherwise

  • location

  • rotation

  • scale

Return type

boolean, float array[3], float array[3], float array[3]

QLabsQDrone2.get_world_transform_degrees()

Get the location, rotation, and scale in world coordinates of the actor.

Returns

  • status - True if successful, False otherwise

  • location

  • rotation

  • scale

Return type

boolean, float array[3], float array[3], float array[3]

Configurations

There is only one configuration of the QDrone 2 actor.

QDrone 2 Tutorial