Outdoor Environment
Description
The Environment Outdoors library is used to modify settings of the QLabs actor environment. Not all Open World environments support all environmental features.
Outdoor Environment Library
Constants
- QLabsEnvironmentOutdoors.ID_ENVIRONMENT_OUTDOORS = 1100
Class ID
- QLabsEnvironmentOutdoors.CLEAR_SKIES = 0
- QLabsEnvironmentOutdoors.PARTLY_CLOUDY = 1
- QLabsEnvironmentOutdoors.CLOUDY = 2
- QLabsEnvironmentOutdoors.OVERCAST = 3
- QLabsEnvironmentOutdoors.FOGGY = 4
- QLabsEnvironmentOutdoors.LIGHT_RAIN = 5
- QLabsEnvironmentOutdoors.RAIN = 6
- QLabsEnvironmentOutdoors.THUNDERSTORM = 7
- QLabsEnvironmentOutdoors.LIGHT_SNOW = 8
- QLabsEnvironmentOutdoors.SNOW = 9
- QLabsEnvironmentOutdoors.BLIZZARD = 10
Methods
- QLabsEnvironmentOutdoors.set_time_of_day(time)[source]
Set the time of day for an outdoor environment.
- Parameters
time (float) – A value from 0 to 24. Midnight is a value 0 or 24. Noon is a value of 12.
- Returns
True if setting the time was successful, False otherwise
- Return type
boolean
- QLabsEnvironmentOutdoors.set_outdoor_lighting(state)[source]
Overrides the outdoor lighting set by other environment functions
- Parameters
state – 0 force lights off, 1 force lights on
- Returns
True if setting the time was successful, False otherwise
- Return type
boolean
- QLabsEnvironmentOutdoors.set_weather_preset(weather_preset)[source]
Set the weather conditions for an outdoor environment with a preset value
- Parameters
weather_preset – A preset index (see defined constants for weather types)
- Returns
True if setting the time was successful, False otherwise
- Return type
boolean
Weather Tutorial
Python Tutorial
Raw to download this tutorial: Weather Tutorial (.py).
1"""
2Weather Example
3---------------
4
5.. note::
6
7 Make sure you have Quanser Interactive Labs open before running this
8 example. This example is designed to run in the Cityscape.
9
10"""
11
12from qvl.qlabs import QuanserInteractiveLabs
13from qvl.free_camera import QLabsFreeCamera
14from qvl.environment_outdoors import QLabsEnvironmentOutdoors
15from qvl.system import QLabsSystem
16
17import time
18import os
19
20def main():
21 # Creates a server connection with Quanser Interactive Labs and manages
22 # the communications
23 qlabs = QuanserInteractiveLabs()
24
25 # Ensure that QLabs is running on your local machine
26 print("Connecting to QLabs...")
27 if (not qlabs.open("localhost")):
28 print("Unable to connect to QLabs")
29 return
30
31 print("Connected")
32
33 hSystem = QLabsSystem(qlabs)
34
35
36 ### Outdoor Environment
37 hEnvironmentOutdoors2 = QLabsEnvironmentOutdoors(qlabs)
38
39 # Force outdoor lighting (buildings, street lights) off
40 hEnvironmentOutdoors2.set_outdoor_lighting(0)
41
42 # Create a camera at spawn location to allow us to see the weather changes
43 hCameraWeather = QLabsFreeCamera(qlabs)
44 x = hCameraWeather.spawn(location=[0.075, -8.696, 1.576], rotation=[0, -0.141, 1.908])
45 hCameraWeather.possess()
46
47 time.sleep(2.5)
48
49 # Run through different weather possibilities in QLabs
50 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.CLEAR_SKIES)
51 hSystem.set_title_string('Clear skies')
52 time.sleep(2.5)
53
54 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.PARTLY_CLOUDY)
55 hSystem.set_title_string('Partly cloudy')
56 time.sleep(2.5)
57
58 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.CLOUDY)
59 hSystem.set_title_string('Cloudy')
60 time.sleep(2.5)
61
62 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.OVERCAST)
63 # Force outdoor lighting (buildings, street lights) on
64 hEnvironmentOutdoors2.set_outdoor_lighting(1)
65 hSystem.set_title_string('Overcast')
66 time.sleep(2.5)
67
68 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.FOGGY)
69 hSystem.set_title_string('Foggy')
70 time.sleep(2.5)
71
72 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.LIGHT_RAIN)
73 hEnvironmentOutdoors2.set_outdoor_lighting(0)
74 hSystem.set_title_string('Light rain')
75 time.sleep(2.5)
76
77 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.RAIN)
78 hEnvironmentOutdoors2.set_outdoor_lighting(1)
79 hSystem.set_title_string('Rain')
80 time.sleep(2.5)
81
82 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.THUNDERSTORM)
83 hSystem.set_title_string('Thunderstorm')
84 time.sleep(2.5)
85
86 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.LIGHT_SNOW)
87 hEnvironmentOutdoors2.set_outdoor_lighting(0)
88 hSystem.set_title_string('Light snow')
89 time.sleep(2.5)
90
91 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.SNOW)
92 hEnvironmentOutdoors2.set_outdoor_lighting(1)
93 hSystem.set_title_string('Snow')
94 time.sleep(2.5)
95
96 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.BLIZZARD)
97 hSystem.set_title_string('Blizzard')
98 time.sleep(2.5)
99
100 hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.PARTLY_CLOUDY)
101 hEnvironmentOutdoors2.set_outdoor_lighting(0)
102 hSystem.set_title_string('QLABS WEATHER')
103
104
105 print("\n\n------------------------------ Communications --------------------------------\n")
106
107 qlabs.close()
108 print("Done!")
109
110main()
Matlab Tutorial
Raw to download this tutorial: Weather Tutorial (.m).
1% Weather Example
2% -------------------------
3%
4% .. note::
5%
6% Make sure you have Quanser Interactive Labs open before running this
7% example. This example is designed to best be run in QCar Cityscape
8
9close all;
10clear all;
11clc;
12
13% --------------------------------------------------------------
14% Setting MATLAB Path for the libraries
15% Always keep at the start, it will make sure it finds the correct references
16newPathEntry = fullfile(getenv('QAL_DIR'), '0_libraries', 'matlab', 'qvl');
17pathCell = regexp(path, pathsep, 'split');
18if ispc % Windows is not case-sensitive
19 onPath = any(strcmpi(newPathEntry, pathCell));
20else
21 onPath = any(strcmp(newPathEntry, pathCell));
22end
23
24if onPath == 0
25 path(path, newPathEntry)
26 savepath
27end
28% --------------------------------------------------------------
29fprintf('\n\n----------------- Communications -------------------\n\n');
30
31qlabs = QuanserInteractiveLabs();
32connection_established = qlabs.open('localhost');
33
34if connection_established == false
35 disp("Failed to open connection.")
36 return
37end
38
39
40disp('Connected')
41
42num_destroyed = qlabs.destroy_all_spawned_actors();
43
44fprintf('%d actors destroyed', num_destroyed);
45
46
47hSystem = QLabsSystem(qlabs);
48
49
50%%% Outdoor Environment
51fprintf("\n\n---Outdoor Environment---")
52
53hEnvironmentOutdoors2 = QLabsEnvironmentOutdoors(qlabs);
54hEnvironmentOutdoors2.set_outdoor_lighting(0)
55
56% Create a camera at spawn location to allow us to see the weather changes
57hCameraWeather = QLabsFreeCamera(qlabs);
58x = hCameraWeather.spawn([0.075, -8.696, 1.576], [0, -0.141, 1.908]);
59hCameraWeather.possess()
60
61pause(2.5);
62
63% Run through different weather possibilities in QLabs
64% the constants can come from both the object or directly from QLabsEnvironmentOutdoors
65hEnvironmentOutdoors2.set_weather_preset(QLabsEnvironmentOutdoors.CLEAR_SKIES)
66hSystem.set_title_string('Clear skies')
67pause(2.5);
68
69hEnvironmentOutdoors2.set_weather_preset(QLabsEnvironmentOutdoors.PARTLY_CLOUDY)
70hSystem.set_title_string('Partly cloudy')
71pause(2.5);
72
73hEnvironmentOutdoors2.set_weather_preset(QLabsEnvironmentOutdoors.CLOUDY)
74hSystem.set_title_string('Cloudy')
75pause(2.5);
76
77hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.OVERCAST)
78hEnvironmentOutdoors2.set_outdoor_lighting(1)
79hSystem.set_title_string('Overcast')
80pause(2.5);
81
82hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.FOGGY)
83hSystem.set_title_string('Foggy')
84pause(2.5);
85
86hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.LIGHT_RAIN)
87hEnvironmentOutdoors2.set_outdoor_lighting(0)
88hSystem.set_title_string('Light rain')
89pause(2.5);
90
91hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.RAIN)
92hEnvironmentOutdoors2.set_outdoor_lighting(1)
93hSystem.set_title_string('Rain')
94pause(2.5);
95
96hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.THUNDERSTORM)
97hSystem.set_title_string('Thunderstorm')
98pause(2.5);
99
100hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.LIGHT_SNOW)
101hEnvironmentOutdoors2.set_outdoor_lighting(0)
102hSystem.set_title_string('Light snow')
103pause(2.5);
104
105hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.SNOW)
106hEnvironmentOutdoors2.set_outdoor_lighting(1)
107hSystem.set_title_string('Snow')
108pause(2.5);
109
110hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.BLIZZARD)
111hSystem.set_title_string('Blizzard')
112pause(2.5);
113
114hEnvironmentOutdoors2.set_weather_preset(hEnvironmentOutdoors2.PARTLY_CLOUDY)
115hEnvironmentOutdoors2.set_outdoor_lighting(0)
116hSystem.set_title_string('QLABS WEATHER')
117
118
119fprintf("\n\n------------------------------ Communications --------------------------------\n")
120
121qlabs.close()
122disp("Done!")