test-l500-json-load.py
Go to the documentation of this file.
1 # License: Apache 2.0. See LICENSE file in root directory.
2 # Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #test:device L500*
5 
6 import pyrealsense2 as rs
7 from rspy import test, log
8 
9 devices = test.find_devices_by_product_line_or_exit(rs.product_line.L500)
10 device = devices[0]
11 depth_sensor = device.first_depth_sensor()
12 sd = rs.serializable_device(device)
13 
14 visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
15 visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))
16 
17 def json_to_dict( json ):
18  """
19  :param json: a string representing a json file
20  :return: a dictionary with all settings
21  """
22  translation_table = dict.fromkeys(map(ord, '",\''), None)
23  json_dict = {}
24  for line in json.splitlines():
25  if ':' not in line: # ignoring lines that are not for settings such as empty lines
26  continue
27  setting, value = line.split(':')
28  setting = setting.strip().translate(translation_table)
29  value = value.strip().translate(translation_table)
30  json_dict[ setting ] = value
31  return json_dict
32 
34  global depth_sensor, sd
35  depth_sensor.set_option(rs.option.visual_preset, int(rs.l500_visual_preset.low_ambient_light))
36  actual_data = str( sd.serialize_json() )
37  data_dict = json_to_dict( data )
38  actual_data_dict = json_to_dict( actual_data )
39  log.debug_indent()
40  try:
41  # logging the differences in the settings between the expected and the actual values
42  for key in actual_data_dict.keys():
43  if key not in data_dict:
44  log.d( "New setting added to json:", key)
45  elif "Visual Preset" in key or "Temperature" in key or "temperature" in key:
46  # the line regarding the visual preset will always be different because we load 1 from data but set it to
47  # 3 for low ambient. Also all lines regarding temperatures depend on the camera and don't affect the preset
48  continue
49  elif data_dict[ key ] != actual_data_dict[ key ]:
50  log.d( key, "was expected to have value of", data_dict[ key ],
51  "but actually had value of", actual_data_dict[ key ])
52  finally:
53  log.debug_unindent()
54 
55 #############################################################################################
56 # This test checks backward compatibility to old json files that saved with default preset
57 # The default preset is deprecated but json files that saved with default preset
58 # should be supported
59 # Here, we expect the data to fit a pre-defined "low-ambient" preset
60 # Note that, because FW defines them, the defaults can change from version to version and we need to keep this
61 # up-to-date with the latest. If the FW changes, this test will fail and output (in debug mode) any settings that
62 # changed...
63 
64 
65 low_ambient_data_with_default_preset = """
66 {
67  "Alternate IR": 0.0,
68  "Apd Temperature": -9999,
69  "Confidence Threshold": 1,
70  "Depth Offset": 4.5,
71  "Depth Units": 0.000250000011874363,
72  "Digital Gain": 2,
73  "Enable IR Reflectivity": 0.0,
74  "Enable Max Usable Range": 0.0,
75  "Error Polling Enabled": 1,
76  "Frames Queue Size": 16,
77  "Freefall Detection Enabled": 1,
78  "Global Time Enabled": 0.0,
79  "Host Performance": 0.0,
80  "Humidity Temperature": 32.8908233642578,
81  "Inter Cam Sync Mode": 0.0,
82  "Invalidation Bypass": 0.0,
83  "LDD temperature": 32.1463623046875,
84  "Laser Power": 100,
85  "Ma Temperature": 39.667610168457,
86  "Mc Temperature": 31.6955661773682,
87  "Min Distance": 190,
88  "Noise Estimation": 0.0,
89  "Noise Filtering": 4,
90  "Post Processing Sharpening": 1,
91  "Pre Processing Sharpening": 0.0,
92  "Receiver Gain": 18,
93  "Reset Camera Accuracy Health": 0.0,
94  "Sensor Mode": 0.0,
95  "Trigger Camera Accuracy Health": 0.0,
96  "Visual Preset": 1
97 }
98 """
99 
100 test.start("Trying to load settings with default preset from json")
101 try:
102  sd.load_json( low_ambient_data_with_default_preset )
103  visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
104  visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))
105 
106  # if this check fails it is most likely because FW changed the default settings
107  equal = test.check_equal(visual_preset_name, rs.l500_visual_preset.low_ambient_light)
108  if not equal:
109  log.w( "It is possible that FW changed the default settings of the camera." )
110  log_settings_differences( low_ambient_data_with_default_preset )
111 except:
112  test.unexpected_exception()
113 test.finish()
114 
115 #############################################################################################
116 # There is no default preset: so when one is specified, the code should calculate the preset!
117 # Here, we intentionally should not fit into any of the defined presets, and check that the result is CUSTOM
118 
119 wrong_data_with_default_preset = """
120 {
121  "Alternate IR": 0.0,
122  "Apd Temperature": -9999,
123  "Confidence Threshold": 1,
124  "Depth Offset": 4.5,
125  "Depth Units": 0.000250000011874363,
126  "Digital Gain": 2,
127  "Enable IR Reflectivity": 0.0,
128  "Enable Max Usable Range": 0.0,
129  "Error Polling Enabled": 1,
130  "Frames Queue Size": 16,
131  "Freefall Detection Enabled": 1,
132  "Global Time Enabled": 0.0,
133  "Host Performance": 0.0,
134  "Humidity Temperature": 32.8908233642578,
135  "Inter Cam Sync Mode": 0.0,
136  "Invalidation Bypass": 0.0,
137  "LDD temperature": 32.1463623046875,
138  "Laser Power": 100,
139  "Ma Temperature": 39.667610168457,
140  "Mc Temperature": 31.6955661773682,
141  "Min Distance": 490,
142  "Noise Estimation": 0.0,
143  "Noise Filtering": 4,
144  "Post Processing Sharpening": 1,
145  "Pre Processing Sharpening": 0.0,
146  "Receiver Gain": 18,
147  "Reset Camera Accuracy Health": 0.0,
148  "Sensor Mode": 0.0,
149  "Trigger Camera Accuracy Health": 0.0,
150  "Visual Preset": 1
151 }
152 """
153 
154 test.start("Trying to load wrong settings, should get custom preset")
155 try:
156  sd.load_json( wrong_data_with_default_preset )
157  visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
158  visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))
159 
160  test.check_equal(visual_preset_name, rs.l500_visual_preset.custom)
161 except:
162  test.unexpected_exception()
163 test.finish()
164 
165 #############################################################################################
166 # Here, the json specifies a "low-ambient" preset -- so the values of the individual controls (that are part of this preset)
167 # should not matter. The result of loading the following should still result in LOW_AMBIENT even when the controls
168 # do not fit (because they're overridden).
169 
170 wrong_data_with_low_ambient_preset = """
171 {
172  "Alternate IR": 0.0,
173  "Apd Temperature": -9999,
174  "Confidence Threshold": 1,
175  "Depth Offset": 4.5,
176  "Depth Units": 0.000250000011874363,
177  "Digital Gain": 2,
178  "Enable IR Reflectivity": 0.0,
179  "Enable Max Usable Range": 0.0,
180  "Error Polling Enabled": 1,
181  "Frames Queue Size": 16,
182  "Freefall Detection Enabled": 1,
183  "Global Time Enabled": 0.0,
184  "Host Performance": 0.0,
185  "Humidity Temperature": 32.8908233642578,
186  "Inter Cam Sync Mode": 0.0,
187  "Invalidation Bypass": 0.0,
188  "LDD temperature": 32.1463623046875,
189  "Laser Power": 100,
190  "Ma Temperature": 39.667610168457,
191  "Mc Temperature": 31.6955661773682,
192  "Min Distance": 490,
193  "Noise Estimation": 0.0,
194  "Noise Filtering": 4,
195  "Post Processing Sharpening": 1,
196  "Pre Processing Sharpening": 0.0,
197  "Receiver Gain": 18,
198  "Reset Camera Accuracy Health": 0.0,
199  "Sensor Mode": 0.0,
200  "Trigger Camera Accuracy Health": 0.0,
201  "Visual Preset": 3
202 }
203 """
204 
205 test.start("Trying to load wrong settings with specified preset")
206 try:
207  sd.load_json( wrong_data_with_low_ambient_preset )
208  visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
209  visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))
210 
211  test.check_equal(visual_preset_name, rs.l500_visual_preset.low_ambient_light)
212 except:
213  test.unexpected_exception()
214 test.finish()
215 
216 #############################################################################################
217 test.start("Trying to load non default presets")
218 presets = [rs.l500_visual_preset.custom,
219  rs.l500_visual_preset.no_ambient_light,
220  rs.l500_visual_preset.low_ambient_light,
221  rs.l500_visual_preset.max_range,
222  rs.l500_visual_preset.short_range]
223 
224 for preset in presets:
225  try:
226  depth_sensor.set_option(rs.option.visual_preset, int(preset))
227  serialized_json = sd.serialize_json()
228  # Changing the preset to make sure the load function changes it back
229  if preset == rs.l500_visual_preset.custom:
230  depth_sensor.set_option(rs.option.visual_preset, int(rs.l500_visual_preset.short_range))
231  else:
232  depth_sensor.set_option(rs.option.visual_preset, int(rs.l500_visual_preset.custom))
233  sd.load_json(serialized_json)
234  visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
235  visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))
236  test.check_equal(visual_preset_name, preset)
237  except:
238  test.unexpected_exception()
239 test.finish()
240 
241 #############################################################################################
242 test.print_results_and_exit()
def log_settings_differences(data)
virtual frame finish(frame f)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
Definition: catch.hpp:4271


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11