test-set-option.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 #test:device D400*
6 
7 import platform
8 import pyrealsense2 as rs
9 from rspy import test
10 from rspy import log
11 import time
12 
13 dev = test.find_first_device_or_exit()
14 depth_sensor = dev.first_depth_sensor()
15 color_sensor = dev.first_color_sensor()
16 
17 previous_depth_frame_number = -1
18 previous_color_frame_number = -1
19 after_set_option = False
20 
21 
23  global after_set_option
24  # On Linux, there is a known issue (RS5-7148) where up to 4 frame drops can occur
25  # sequentially after setting control values during streaming... on Windows this
26  # does not occur.
27  if platform.system() == 'Linux' and after_set_option:
28  return 4
29  # Our KPI is to prevent sequential frame drops, therefore single frame drop is allowed.
30  return 1
31 
32 def set_new_value(sensor, option, value):
33  global after_set_option
34  after_set_option = True
35  sensor.set_option(option, value)
36  time.sleep( 0.5 ) # collect frames
37  after_set_option = False
38 
40  global previous_depth_frame_number
41  allowed_drops = get_allowed_drops()
42  test.check_frame_drops(frame, previous_depth_frame_number, allowed_drops)
43  previous_depth_frame_number = frame.get_frame_number()
44 
46  global previous_color_frame_number
47  allowed_drops = get_allowed_drops()
48  test.check_frame_drops(frame, previous_color_frame_number, allowed_drops)
49  previous_color_frame_number = frame.get_frame_number()
50 
51 # Use a profile that's common to both L500 and D400
52 depth_profile = next(p for p in
53  depth_sensor.profiles if p.fps() == 30
54  and p.stream_type() == rs.stream.depth
55  and p.format() == rs.format.z16
56  and p.as_video_stream_profile().width() == 640
57  and p.as_video_stream_profile().height() == 480)
58 
59 color_profile = next(p for p in color_sensor.profiles if p.fps() == 30
60  and p.stream_type() == rs.stream.color
61  and p.format() == rs.format.yuyv
62  and p.as_video_stream_profile().width() == 640
63  and p.as_video_stream_profile().height() == 480)
64 
65 depth_sensor.open( depth_profile )
66 depth_sensor.start( check_depth_frame_drops )
67 color_sensor.open( color_profile )
68 color_sensor.start( check_color_frame_drops )
69 
70 
71 #############################################################################################
72 # Test #1
73 
74 laser_power = rs.option.laser_power
75 current_laser_control = 10
76 
77 test.start("Checking for frame drops when setting laser power several times")
78 
79 for i in range(1,5):
80  new_value = current_laser_control + 10*i
81  set_new_value(depth_sensor, laser_power, new_value)
82 
84 
85 # reset everything back
86 depth_sensor.set_option( rs.option.visual_preset, int(rs.l500_visual_preset.max_range) )
87 
88 
89 #############################################################################################
90 
91 product_line = dev.get_info(rs.camera_info.product_line)
92 options_to_ignore = []
93 
94 if product_line == "L500":
95  options_to_ignore = [rs.option.host_performance, rs.option.trigger_camera_accuracy_health, rs.option.reset_camera_accuracy_health]
96 
97 def test_option_changes( sensor ):
98  global options_to_ignore
99  options = sensor.get_supported_options()
100  for option in options:
101  try:
102  if option in options_to_ignore:
103  continue
104  if sensor.is_option_read_only(option):
105  continue
106  old_value = sensor.get_option( option )
107  range = sensor.get_option_range( option )
108  new_value = range.min
109  if old_value == new_value:
110  new_value = range.max
111  if not log.d( str(option), old_value, '->', new_value ):
112  test.info( str(option), new_value, persistent = True )
113  set_new_value( sensor, option, new_value )
114  sensor.set_option( option, old_value )
115  except:
116  test.unexpected_exception()
117  break
118  finally:
119  test.reset_info( persistent = True )
120 
121 
122 #############################################################################################
123 time.sleep(0.5) # jic
124 test.start("Checking frame drops when setting options on depth")
125 test_option_changes( depth_sensor )
126 test.finish()
127 
128 
129 #############################################################################################
130 time.sleep(0.5) # jic
131 test.start("Checking frame drops when setting options on color")
132 test_option_changes( color_sensor )
133 test.finish()
134 
135 
136 #############################################################################################
137 depth_sensor.stop()
138 depth_sensor.close()
139 
140 color_sensor.stop()
141 color_sensor.close()
142 
143 test.print_results_and_exit()
def check_depth_frame_drops(frame)
def test_option_changes(sensor)
def set_new_value(sensor, option, value)
virtual frame finish(frame f)
void next(auto_any_t cur, type2type< T, C > *)
Definition: foreach.hpp:757
def check_color_frame_drops(frame)


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