QCars
Description
QCars are considered “actors” in Quanser Interactive Labs.The QCar library can be used to acquire sensor data from the virtual environment and controls the motion of the vehicles.
See the QCar QCar Tutorial to get a better understanding of using QCars in Quanser Interactive Labs.
Library
Constants
- QLabsQCar.ID_QCAR = 160
Class ID
Note
CSI camera resolution is 820x410.
- QLabsQCar.CAMERA_CSI_RIGHT = 0
- QLabsQCar.CAMERA_CSI_BACK = 1
- QLabsQCar.CAMERA_CSI_LEFT = 2
- QLabsQCar.CAMERA_CSI_FRONT = 3
Note
RGB and depth resolution is 640x480.
- QLabsQCar.CAMERA_RGB = 4
- QLabsQCar.CAMERA_DEPTH = 5
Note
Overhead and trailing cameras support user zoom using the mouse wheel.
- QLabsQCar.CAMERA_OVERHEAD = 6
- QLabsQCar.CAMERA_TRAILING = 7
Member Variables
- QLabsQCar.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
- QLabsQCar.__init__(qlabs, verbose=False)[source]
Constructor Method
- Parameters
qlabs (object) – A QuanserInteractiveLabs object
verbose (boolean) – (Optional) Print error information to the console.
- QLabsQCar.spawn(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)[source]
Spawns a new QCar 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 and only uniform scaling is recommended. Sensor scaling will be based on scale[0].
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
- QLabsQCar.spawn_degrees(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)[source]
Spawns a new QCar 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 and only uniform scaling is recommended. Sensor scaling will be based on scale[0].
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
- QLabsQCar.spawn_id(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)[source]
Spawns a new QCar 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 and only uniform scaling is recommended. Sensor scaling will be based on scale[0].
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
- QLabsQCar.spawn_id_degrees(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)[source]
Spawns a new QCar 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 and only uniform scaling is recommended. Sensor scaling will be based on scale[0].
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
- QLabsQCar.set_transform_and_request_state(location, rotation, enableDynamics, headlights, leftTurnSignal, rightTurnSignal, brakeSignal, reverseSignal, waitForConfirmation=True)[source]
Sets the location, rotation, and other car 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. Multiply physical QCar locations by 10 to get full scale locations.
rotation (float array[3]) – An array of floats for the roll, pitch, and yaw in radians
enableDynamics (boolean) – (default True) Enables or disables gravity for set transform requests.
headlights (boolean) – Enable the headlights
leftTurnSignal (boolean) – Enable the left turn signal
rightTurnSignal (boolean) – Enable the right turn signal
brakeSignal (boolean) – Enable the brake lights (does not affect the motion of the vehicle)
reverseSignal (boolean) – Play a honking sound
waitForConfirmation (boolean) – (Optional) Wait for confirmation before proceeding. This makes the method a blocking operation. NOTE: Return data will only be valid if waitForConfirmation is True.
- Returns
status - True if successful or False otherwise
location - in full scale
rotation - in radians
forward vector - unit scale vector
up vector - unit scale vector
front bumper hit - True if in contact with a collision object, False otherwise
rear bumper hit - True if in contact with a collision object, False otherwise
- Return type
boolean, float array[3], float array[3], float array[3], float array[3], boolean, boolean
- QLabsQCar.set_transform_and_request_state_degrees(location, rotation, enableDynamics, headlights, leftTurnSignal, rightTurnSignal, brakeSignal, reverseSignal, waitForConfirmation=True)[source]
Sets the location, rotation, and other car 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. Multiply physical QCar locations by 10 to get full scale locations.
rotation (float array[3]) – An array of floats for the roll, pitch, and yaw in degrees
enableDynamics (boolean) – (default True) Enables or disables gravity for set transform requests.
headlights (boolean) – Enable the headlights
leftTurnSignal (boolean) – Enable the left turn signal
rightTurnSignal (boolean) – Enable the right turn signal
brakeSignal (boolean) – Enable the brake lights (does not affect the motion of the vehicle)
reverseSignal (boolean) – Play a honking sound
waitForConfirmation (boolean) – (Optional) Wait for confirmation before proceeding. This makes the method a blocking operation. NOTE: Return data will only be valid if waitForConfirmation is True.
- Returns
status - True if successful or False otherwise
location - in full scale
rotation - in radians
forward vector - unit scale vector
up vector - unit scale vector
front bumper hit - True if in contact with a collision object, False otherwise
rear bumper hit - True if in contact with a collision object, False otherwise
- Return type
boolean, float array[3], float array[3], float array[3], float array[3], boolean, boolean
- QLabsQCar.set_velocity_and_request_state(forward, turn, headlights, leftTurnSignal, rightTurnSignal, brakeSignal, reverseSignal)[source]
Sets the velocity, turn angle in radians, and other car properties.
- Parameters
forward – Speed in m/s of a full-scale car. Multiply physical QCar speeds by 10 to get full scale speeds.
turn (float) – Turn angle in radians. Positive values turn right.
headlights (boolean) – Enable the headlights
leftTurnSignal (boolean) – Enable the left turn signal
rightTurnSignal (boolean) – Enable the right turn signal
brakeSignal (boolean) – Enable the brake lights (does not affect the motion of the vehicle)
reverseSignal (boolean) – Play a honking sound
- Returns
status - True if successful, False otherwise
location
rotation - in radians
front bumper hit - True if in contact with a collision object, False otherwise
rear bumper hit - True if in contact with a collision object, False otherwise
- Return type
boolean, float array[3], float array[3], boolean, boolean
- QLabsQCar.set_velocity_and_request_state_degrees(forward, turn, headlights, leftTurnSignal, rightTurnSignal, brakeSignal, reverseSignal)[source]
Sets the velocity, turn angle in degrees, and other car properties.
- Parameters
forward – Speed in m/s of a full-scale car. Multiply physical QCar speeds by 10 to get full scale speeds.
turn (float) – Turn angle in degrees. Positive values turn right.
headlights (boolean) – Enable the headlights
leftTurnSignal (boolean) – Enable the left turn signal
rightTurnSignal (boolean) – Enable the right turn signal
brakeSignal (boolean) – Enable the brake lights (does not affect the motion of the vehicle)
reverseSignal (boolean) – Play a honking sound
- Returns
status - True if successful, False otherwise
location
rotation - in radians
front bumper hit - True if in contact with a collision object, False otherwise
rear bumper hit - True if in contact with a collision object, False otherwise
- Return type
boolean, float array[3], float array[3], boolean, boolean
- QLabsQCar.possess(camera=CAMERA_TRAILING)[source]
Possess (take control of) a QCar 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
- QLabsQCar.ghost_mode(enable=True, color=[0, 1, 0])[source]
Ghost mode changes the selected QCar actor into a transparent colored version. This can be useful as a reference actor or indicating a change in state.
- Parameters
enable (boolean) – Set the QCar to the defined transparent color, otherwise revert to the solid color scheme.
color (float array[3]) – Red, Green, Blue components of the RGB color on a 0.0 to 1.0 scale.
- Returns
status - True if possessing the camera was successful, False otherwise
- Return type
boolean
- QLabsQCar.get_image(camera)[source]
Request a JPG image from one of the QCar cameras.
- Parameters
camera (uint32) – Pre-defined camera constant. See CAMERA constants for available options. Trailing and Overhead cameras cannot be selected.
- Returns
status - True and image data if successful, False and empty otherwise
imageData - Image in a JPG format
- Return type
boolean, byte array with jpg data
- QLabsQCar.get_lidar(samplePoints=400)[source]
Request LIDAR data from a QCar.
- Parameters
samplePoints (uint32) – (Optional) Change the number of points per revolution of the LIDAR.
- Returns
True, angles in radians, and distances in m if successful, False, none, and none otherwise
- Return type
boolean, float array, float array
- QLabsQCar.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
- QLabsQCar.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
- QLabsQCar.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
- QLabsQCar.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]
- QLabsQCar.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 QCar actor.
Connection Points
Reference Frame Number |
Parent Frame |
Relative Transform to Parent (Location, Rotation) |
Description |
---|---|---|---|
0 |
The base frame is located at ground level, centered between the two rear wheels. This represents the location of the car with no filtering, suspension, or dynamics. Collision detection is connected to this reference frame. |
||
1 |
0 |
[0,0,0] [0,0,0] |
The filtered frame is co-located with connection point 0, but it is a filtered position to simulated the suspension and dynamic effects. All the visual elements and sensors of the QCar are connected to this frame. |
Component Extrinsics
“Extrinsics” refer to the external relationship of an object with respect to a specific frame of reference (in this case the body center of the QCar). Sometimes it’s important to know specific distances and orientation of extrinsic components, for instance, this can be use for obstacle detection and camera calibration. You will find a list of the important extrinsics below.
Distances From Body Center
Distances of the QCar in its virtual environment are 10 times larger then in real life when scaled at [1,1,1]. Therefore the distances to important components have been scaled accordingly below to match a scale of [1,1,1]:
Component |
x (m) |
y (m) |
z (m) |
---|---|---|---|
CG |
0.248 |
-0.074 |
0.606 |
Front axle |
1.300 |
0 |
0.207 |
Rear axle |
-1.300 |
0 |
0.207 |
CSI front |
1.930 |
0 |
0.850 |
CSI left |
0.140 |
0.438 |
0.850 |
CSI rear |
-1.650 |
0 |
0.850 |
CSI right |
0.140 |
-0.674 |
0.850 |
IMU |
1.278 |
0.223 |
0.792 |
RealSense |
0.822 |
0.003 |
1.479 |
RPLIDAR |
-0.108 |
-0.001 |
1.696 |
Transformation Matrices
All transformation matrices are built off of the body frame and camera frames for the QCar. To read more about this check out our documentation here by clicking on resources button and looking inside the zip folder for User Guides/System Hardware.pdf
QCar Tutorial
Example
Raw to download this tutorial: QCar Tutorial
.
1"""
2QCar Library Example
3----------------------
4This example will show you how to spawn cars, and use the qvl library commands
5to control the car 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 QCar Cityscape.
11
12"""
13
14from qvl.qlabs import QuanserInteractiveLabs
15from qvl.free_camera import QLabsFreeCamera
16from qvl.basic_shape import QLabsBasicShape
17from qvl.qcar import QLabsQCar
18from qvl.environment_outdoors import QLabsEnvironmentOutdoors
19
20import time
21import math
22import numpy as np
23import cv2
24import os
25
26import pyqtgraph as pg
27from pyqtgraph.Qt import QtWidgets
28
29lidar_rate = 0.01
30
31def main():
32 os.system('cls')
33
34 #Communications with qlabs
35
36 qlabs = QuanserInteractiveLabs()
37 cv2.startWindowThread()
38
39 print("Connecting to QLabs...")
40 try:
41 qlabs.open("localhost")
42 except:
43 print("Unable to connect to QLabs")
44 return
45
46 print("Connected")
47
48 qlabs.destroy_all_spawned_actors()
49
50 ### QCar
51
52 hCameraQCars = QLabsFreeCamera(qlabs)
53 hCameraQCars.spawn_id(actorNumber=1, location=[-15.075, 26.703, 6.074], rotation=[0, 0.564, -1.586])
54 hCameraQCars.possess()
55
56 print("\n\n---QCar---")
57
58 #spawning the QCar with radians
59 hQCar0 = QLabsQCar(qlabs)
60 hQCar0.spawn_id(actorNumber=0, location=[-8.700, 14.643, 0.005], rotation=[0,0,math.pi/2], waitForConfirmation=True)
61
62 #Spawn and destroy the existing QCar
63 hQCar1 = QLabsQCar(qlabs)
64 hQCar1.spawn_id(actorNumber=1, location=[-15.075, 26.703, 6.074], rotation=[0,0,math.pi/2], waitForConfirmation=True)
65 hQCar1.destroy()
66
67 #spawn a QCar with degrees
68 hQCar2 = QLabsQCar(qlabs)
69 x = hQCar2.spawn_id_degrees(actorNumber=2, location=[-11.048, 14.643, 0.005], rotation=[0,0,90], waitForConfirmation=True)
70
71 #pinging the QCar
72 hQCar2.ping()
73
74 # change the lighting in qlabs to turn on the car lights
75 hEnvironmentOutdoors = QLabsEnvironmentOutdoors(qlabs)
76 for env_time in range(60):
77 hEnvironmentOutdoors.set_time_of_day(12+env_time/10*2)
78
79 time.sleep(0.5)
80
81 # Set the velocity and direction of the QCar in radians while also turning on the headlights and right turn signal
82 hQCar2.set_velocity_and_request_state(forward=1, turn = -math.pi/6, headlights=True, leftTurnSignal=False, rightTurnSignal=True, brakeSignal=False, reverseSignal=False)
83 time.sleep(1)
84 # Set the velocity to 0 and direction of the QCar in radians while keeping the headlights on and right turn signal on
85 hQCar2.set_velocity_and_request_state(forward=0.0, turn = -math.pi/6, headlights=True, leftTurnSignal=False, rightTurnSignal=True, brakeSignal=False, reverseSignal=False)
86 # Set the velocity to 1 and direction of the QCar in degrees while keeping the headlights on and turning on the left turn signal
87 hQCar2.set_velocity_and_request_state_degrees(forward=1, turn = 30, headlights=True, leftTurnSignal=True, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
88 time.sleep(1)
89 # Set the velocity to 0 and direction of the QCar in degrees while keeping the headlights on and left turn signal on
90 success, location, rotation, frontHit, rearHit = hQCar2.set_velocity_and_request_state_degrees(forward=0.0, turn = 30, headlights=True, leftTurnSignal=True, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
91
92 # Possess another QCar
93 x = hQCar2.possess()
94
95 time.sleep(0.1)
96 # Set the velocity to 1 of the QCar in radians while keeping the headlights, brakeSignal and reverseSignal on
97 hQCar2.set_velocity_and_request_state(forward=1, turn = 0, headlights=True, leftTurnSignal=True, rightTurnSignal=True, brakeSignal=True, reverseSignal=True)
98 time.sleep(1)
99 # Set the velocity to 0 while keeping the headlights, brakeSignal and reverseSignal on and turning on the left turn signal and right turn signal
100 hQCar2.set_velocity_and_request_state(forward=0.0, turn = 0, headlights=True, leftTurnSignal=True, rightTurnSignal=True, brakeSignal=True, reverseSignal=True)
101
102 # Turn all the lights off
103 hQCar2.set_velocity_and_request_state(forward=0, turn = 0, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
104
105 # Set the time of day to change to light outside again
106 for env_time in range(60):
107 hEnvironmentOutdoors.set_time_of_day(env_time/10*2)
108
109 # Car bumper test
110 print("Testing bumper response...")
111 hCameraQCars.possess()
112 # Change the camera view to see the bumper test
113 hCameraQCars.set_transform(location=[-17.045, 32.589, 6.042], rotation=[0, 0.594, -1.568])
114
115 # Spawn some shapes for our bumper test
116 hCubeQCarBlocks = QLabsBasicShape(qlabs)
117 hCubeQCarBlocks .spawn_id(100, [-11.919, 26.289, 0.5], [0,0,0], [1,1,1], configuration=hCubeQCarBlocks.SHAPE_CUBE, waitForConfirmation=True)
118 hCubeQCarBlocks .spawn_id(101, [-19.919, 26.289, 0.5], [0,0,0], [1,1,1], configuration=hCubeQCarBlocks.SHAPE_CUBE, waitForConfirmation=True)
119
120 # Create another QCar
121 hQCar3 = QLabsQCar(qlabs)
122 hQCar3.spawn_id(actorNumber=3, location=[-13.424, 26.299, 0.005], rotation=[0,0,math.pi])
123
124 # Have the QCar drive forward to hit the front block
125 for count in range(10):
126 x, location, rotation, frontHit, rearHit = hQCar3.set_velocity_and_request_state(forward=2, turn = 0, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
127 time.sleep(0.25)
128
129 # Put the QCar in ghost mode
130 hQCar3.ghost_mode()
131
132 # Have the QCar drive backwards to hit the back bumper
133 for count in range(10):
134 x, location, rotation, frontHit, rearHit = hQCar3.set_velocity_and_request_state(forward=-2, turn = 0, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
135 time.sleep(0.25)
136
137 # Change the color of ghost mode to red
138 hQCar3.ghost_mode(enable=True, color=[1,0,0])
139 time.sleep(0.50)
140
141 # Set the velocity to 0 and turn all lights off
142 hQCar3.set_velocity_and_request_state(forward=0, turn = 0, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
143
144 # Set the location of the QCar and request the state of the car. If x== True and frontHit==True then the front bumper hit the block correctly.
145 x, location, rotation, forward_vector, up_vector, frontHit, rearHit = hQCar3.set_transform_and_request_state(location=[-16.1, 26.299, 0.005], rotation=[0,0,math.pi-0.01], enableDynamics=True, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
146 time.sleep(0.50)
147
148 # Getting and saving the world transform of the QCar in Quanser Interactive Labs
149 x, loc, rot, scale = hQCar3.get_world_transform()
150
151 # Set the location of the QCar and request the state of the car. If x== True and rearHit==True then the back bumper hit the block correctly.
152 x, location, rotation, forward_vector, up_vector, frontHit, rearHit = hQCar3.set_transform_and_request_state_degrees(location=[-13.1, 26.299, 0.005], rotation=[0,0,179], enableDynamics=True, headlights=False, leftTurnSignal=False, rightTurnSignal=False, brakeSignal=False, reverseSignal=False)
153 time.sleep(0.50)
154
155 #Turning off ghost mode for the QCar
156 hQCar3.ghost_mode(enable=False, color=[1,0,0])
157
158
159 # QCar Camera Tests
160 print("\nQCar Camera Tests...")
161
162 # Possessing the overhead camera on the QCar
163 hQCar2.possess(hQCar2.CAMERA_OVERHEAD)
164 time.sleep(0.5)
165
166 # Possessing the trailing camera on the QCar
167 hQCar2.possess(hQCar2.CAMERA_TRAILING)
168 time.sleep(0.5)
169
170 #Possessing the front csi camera on the QCar
171 hQCar2.possess(hQCar2.CAMERA_CSI_FRONT)
172 time.sleep(0.5)
173
174 # Possessing the right csi camera on the QCar
175 hQCar2.possess(hQCar2.CAMERA_CSI_RIGHT)
176 time.sleep(0.5)
177
178 # Possessing the back csi camera on the QCar
179 hQCar2.possess(hQCar2.CAMERA_CSI_BACK)
180 time.sleep(0.5)
181
182 # Possessing the left csi camera on the QCar
183 hQCar2.possess(hQCar2.CAMERA_CSI_LEFT)
184 time.sleep(0.5)
185
186 # Possessing the front Realsense RGB camera on the QCar
187 hQCar2.possess(hQCar2.CAMERA_RGB)
188 time.sleep(0.5)
189
190 # Possessing the Realsense depth camera on the QCar
191 hQCar2.possess(hQCar2.CAMERA_DEPTH)
192 time.sleep(0.5)
193
194 # Getting images from the different cameras
195 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_CSI_FRONT)
196 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_CSI_RIGHT)
197 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_CSI_BACK)
198 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_CSI_LEFT)
199 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_RGB)
200 x, camera_image = hQCar2.get_image(camera=hQCar2.CAMERA_DEPTH)
201
202
203 #LIDAR
204
205 hQCar3.possess(hQCar3.CAMERA_OVERHEAD)
206
207 # Creating a plot to plot the LIDAR data
208 lidarPlot = pg.plot(title="LIDAR")
209 squareSize = 100
210 lidarPlot.setXRange(-squareSize, squareSize)
211 lidarPlot.setYRange(-squareSize, squareSize)
212 lidarData = lidarPlot.plot([], [], pen=None, symbol='o', symbolBrush='r', symbolPen=None, symbolSize=2)
213
214 time.sleep(1)
215
216 print("Reading from LIDAR... if QLabs crashes or output isn't great, make sure FPS > 100 or fix the crash bug!")
217
218 # Obtaining and plotting lidar data for 0.2s
219 for count in range(20):
220
221 success, angle, distance = hQCar3.get_lidar(samplePoints=400)
222
223 x = np.sin(angle)*distance
224 y = np.cos(angle)*distance
225
226 lidarData.setData(x,y)
227 QtWidgets.QApplication.instance().processEvents()
228 time.sleep(lidar_rate) #lidar_rate is set at the top of this example
229
230 print("LIDAR successful")
231 print(lidar_rate == 0.01, "Passed LIDAR test with 100Hz (lidar_rate = 0.01 expected)")
232
233 time.sleep(5)
234
235 # Closing qlabs
236 qlabs.close()
237 print("Done!")
238
239
240main()