QDrone 2

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
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
Python Tutorial
Raw to download this tutorial: QDrone 2 Tutorial (.py)
.
1"""
2QDrone 2 Library Example
3--------------------------
4This example will show you how to spawn qdrones, and use the qvl library commands
5to control the drone and its related functions.
6
7.. note::
8
9 Make sure you have Quanser Interactive Labs open before running this
10 example. This example is designed to best be run in the open warehouse or plane.
11
12"""
13
14from qvl.qlabs import QuanserInteractiveLabs
15from qvl.free_camera import QLabsFreeCamera
16from qvl.basic_shape import QLabsBasicShape
17from qvl.qdrone2 import QLabsQDrone2
18
19import time
20import numpy as np
21import cv2
22import os
23
24from qvl.system import QLabsSystem
25
26
27
28def main():
29 os.system('cls')
30
31 #Communications with qlabs
32
33 qlabs = QuanserInteractiveLabs()
34 cv2.startWindowThread()
35
36 print("Connecting to QLabs...")
37 if (not qlabs.open("localhost")):
38 print("Unable to connect to QLabs")
39 return
40
41 print("Connected")
42
43 qlabs.destroy_all_spawned_actors()
44
45 # Use hSystem to set the tutorial title in the upper left of the qlabs window
46 hSystem = QLabsSystem(qlabs)
47 hSystem.set_title_string('QDrone Tutorial')
48
49
50 hCamera = QLabsFreeCamera(qlabs)
51 hCamera.spawn_id(actorNumber=1, location=[-1.683, 2.333, 1.787], rotation=[-0, 0.391, -1.541])
52 hCamera.possess()
53
54 print("\n---QDrone---")
55
56 #spawning the QDrone. Rotation in radians
57 myQDrone = QLabsQDrone2(qlabs)
58 myQDrone.spawn_id(actorNumber=0, location=[-2,0,0], rotation=[0,0,np.pi/2], waitForConfirmation=True)
59 time.sleep(1)
60
61 myQDrone2 = QLabsQDrone2(qlabs)
62 myQDrone2.spawn_degrees(location=[0,0,0], rotation=[0,0,45], waitForConfirmation=True)
63 x = myQDrone2.ping()
64 print('QDrone 2 ping test:', x)
65 time.sleep(2)
66
67 myQDrone2.destroy()
68 x = myQDrone2.ping()
69 print('QDrone 2 ping test:', x)
70
71 velocities = [.2, .5, .8, -.8, -.5, -.2]
72 # setting the velocity of the drone in the z direction to make it go up and down.
73 for count in range(6):
74 x = myQDrone.set_velocity_and_request_state(motorsEnabled=True, velocity=[0,0, velocities[count]], orientation=[0,0,0])
75 time.sleep(1)
76
77 myQDrone.set_velocity_and_request_state_degrees(motorsEnabled=True, velocity=[0,0, 0], orientation=[0,0,90])
78 time.sleep(1)
79 # this is just here to disable motors, so speed and orientation does not matter.
80 myQDrone.set_velocity_and_request_state(motorsEnabled=False, velocity=[0,0, 0], orientation=[0,0,0])
81 time.sleep(1)
82
83 # adding a few shapes to the scene for understanding the camera views
84 rectangle = QLabsBasicShape(qlabs)
85 rectangle.spawn(location=[0,0,0], rotation=[0,0,0], scale=[.2,.2,1], configuration=rectangle.SHAPE_CUBE, waitForConfirmation=True)
86 rectangle.set_material_properties(color=[1,0,0])
87 time.sleep(.25)
88 rectangle2 = QLabsBasicShape(qlabs)
89 rectangle2.spawn(location=[-4,-3,0], rotation=[0,0,0], scale=[.2,.2,1], configuration=rectangle.SHAPE_CUBE, waitForConfirmation=True)
90 rectangle2.set_material_properties(color=[0,1,0])
91 time.sleep(.25)
92 cone = QLabsBasicShape(qlabs)
93 cone.spawn(location=[-1.4,0,0], rotation=[0,0,0], scale=[.2,.2,1], configuration=rectangle.SHAPE_CONE, waitForConfirmation=True)
94 cone.set_material_properties(color=[0,0,1])
95 time.sleep(.25)
96 rectangle3 = QLabsBasicShape(qlabs)
97 rectangle3.spawn(location=[-2,1.5,0], rotation=[0,0,0], scale=[.2,.2,1], configuration=rectangle.SHAPE_CUBE, waitForConfirmation=True)
98 time.sleep(1)
99
100 myQDrone.set_transform_and_dynamics(location=[-2,0,1], rotation=[0,0,np.pi/2], enableDynamics=True)
101 time.sleep(1.5)
102
103 # cycle through camera views
104
105 cameras = [myQDrone.VIEWPOINT_CSI_LEFT, myQDrone.VIEWPOINT_CSI_BACK, myQDrone.VIEWPOINT_CSI_RIGHT, myQDrone.VIEWPOINT_RGB, myQDrone.VIEWPOINT_DEPTH, myQDrone.VIEWPOINT_DOWNWARD, myQDrone.VIEWPOINT_OPTICAL_FLOW, myQDrone.VIEWPOINT_OVERHEAD, myQDrone.VIEWPOINT_TRAILING]
106 cameraNames = ['LEFT', 'BACK', 'RIGHT', 'RGB', 'DEPTH', 'DOWNWARD', 'OPTICAL FLOW', 'OVERHEAD', 'TRAILING']
107 for count in range(9):
108 x = myQDrone.possess(camera=cameras[count])
109 hSystem.set_title_string(cameraNames[count])
110 time.sleep(1.5)
111
112 hCamera.possess()
113 hSystem.set_title_string('QDrone Tutorial')
114 # using get world transform to get current location of the drone
115 myQDrone.set_transform_and_dynamics(location=[-2,0,1.2], rotation=[0,0,np.pi/2], enableDynamics=True)
116 print(myQDrone.get_world_transform())
117 time.sleep(1)
118
119 myQDrone.set_transform_and_dynamics(location=[-2,0,0], rotation=[0,0,np.pi/2], enableDynamics=True)
120 print(myQDrone.get_world_transform_degrees())
121 time.sleep(1)
122
123
124 # Getting images from the different cameras
125 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_CSI_LEFT)
126 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_CSI_RIGHT)
127 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_CSI_BACK)
128
129 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_RGB)
130 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_DEPTH)
131 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_DOWNWARD)
132 status, camera_number, camera_image = myQDrone.get_image(camera=myQDrone.CAMERA_OPTICAL_FLOW)
133
134
135 # Closing qlabs
136 qlabs.close()
137 print("Done!")
138
139
140main()
Coming Soon!