test-triggers.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 from rspy import test
7 test.set_env_vars({"RS2_AC_DISABLE_CONDITIONS":"1",
8  "RS2_AC_DISABLE_RETRIES":"1",
9  "RS2_AC_FORCE_BAD_RESULT":"1",
10  "RS2_AC_LOG_TO_STDOUT":"1"
11  #,"RS2_AC_IGNORE_LIMITERS":"1"
12  })
13 
14 import pyrealsense2 as rs
15 from rspy import ac
16 
17 # rs.log_to_file( rs.log_severity.debug, "rs.log" )
18 
19 dev = test.find_first_device_or_exit()
20 depth_sensor = dev.first_depth_sensor()
21 color_sensor = dev.first_color_sensor()
22 
23 # Resetting sensors to factory calibration
24 dcs = rs.calibrated_sensor(depth_sensor)
25 dcs.reset_calibration()
26 
27 ccs = rs.calibrated_sensor(color_sensor)
28 ccs.reset_calibration()
29 
30 d2r = rs.device_calibration(dev)
31 d2r.register_calibration_change_callback( ac.status_list_callback )
32 
33 cp = next(p for p in color_sensor.profiles if p.fps() == 30
34  and p.stream_type() == rs.stream.color
35  and p.format() == rs.format.yuyv
36  and p.as_video_stream_profile().width() == 1280
37  and p.as_video_stream_profile().height() == 720)
38 
39 dp = next(p for p in
40  depth_sensor.profiles if p.fps() == 30
41  and p.stream_type() == rs.stream.depth
42  and p.format() == rs.format.z16
43  and p.as_video_stream_profile().width() == 1024
44  and p.as_video_stream_profile().height() == 768)
45 
46 # This is the expected sequence of statuses for a successful calibration
47 successful_calibration_status_list = [rs.calibration_status.triggered,
48  rs.calibration_status.special_frame,
49  rs.calibration_status.started,
50  rs.calibration_status.successful]
51 
52 # Possible statuses that are irrelevant for this test
53 irrelevant_statuses = [rs.calibration_status.retry,
54  rs.calibration_status.scene_invalid,
55  rs.calibration_status.bad_result]
56 
58  """
59  Removes consecutive special frame statuses from the status list since we have a built-in
60  retry mechanism and more than one request can be made.
61  E.g., [triggered, special_frame, special_frame, started, successful]
62  """
63  i = 1
64  while i < len(list):
65  if list[i - 1] == list[i] == rs.calibration_status.special_frame:
66  del list[i]
67  else:
68  i += 1
69 
70 #############################################################################################
71 # Test #1
72 test.start("Depth sensor is off, should get an error")
73 try:
74  d2r.trigger_device_calibration( rs.calibration_type.manual_depth_to_rgb )
75  ac.wait_for_calibration()
76 except Exception as e:
77  test.check_exception(e, RuntimeError, "not streaming")
78 else:
79  test.unexpected_exception() # No error Occurred, should have received a RuntimeError
80 test.check(ac.status_list_is_empty()) # No status changes are expected, list should remain empty
82 
83 #############################################################################################
84 # Test #2
85 test.start("Color sensor is off, calibration should succeed")
86 ac.reset_status_list() # Deleting previous test
87 depth_sensor.open( dp )
88 depth_sensor.start( lambda f: None )
89 try:
90  d2r.trigger_device_calibration( rs.calibration_type.manual_depth_to_rgb )
91  ac.wait_for_calibration()
92  ac.trim_irrelevant_statuses(irrelevant_statuses)
93  filter_special_frames( ac.status_list )
94  test.check_equal_lists(ac.status_list, successful_calibration_status_list)
95 except Exception:
96  test.unexpected_exception()
97 try:
98  # Since the sensor was closed before calibration started, it should have been returned to a
99  # closed state
100  color_sensor.stop()
101 except Exception as e:
102  test.check_exception(e, RuntimeError, "tried to stop sensor without starting it")
103 else:
104  test.unexpected_exception()
105 # Leave the depth sensor open for the next test
106 test.finish()
107 
108 #############################################################################################
109 # Test #3
110 test.start("Color sensor is on")
111 ac.reset_status_list()
112 dcs.reset_calibration()
113 ccs.reset_calibration()
114 color_sensor.open( cp )
115 color_sensor.start( lambda f: None )
116 try:
117  d2r.trigger_device_calibration( rs.calibration_type.manual_depth_to_rgb )
118  ac.wait_for_calibration()
119  ac.trim_irrelevant_statuses(irrelevant_statuses)
120  filter_special_frames( ac.status_list )
121  test.check_equal_lists(ac.status_list, successful_calibration_status_list)
122 except:
123  test.unexpected_exception()
124 try:
125  # This time the color sensor was on before calibration so it should remain on at the end
126  color_sensor.stop()
127 except:
128  test.unexpected_exception()
129 # Leave the depth sensor open for the next test
130 test.finish()
131 
132 #############################################################################################
133 # Test #4
134 test.start("2 AC triggers in a row")
135 ac.reset_status_list()
136 dcs.reset_calibration()
137 ccs.reset_calibration()
138 color_sensor.start( lambda f: None )
139 try:
140  d2r.trigger_device_calibration( rs.calibration_type.manual_depth_to_rgb )
141  try:
142  d2r.trigger_device_calibration( rs.calibration_type.manual_depth_to_rgb )
143  ac.wait_for_calibration()
144  except Exception as e: # Second trigger should throw exception
145  test.check_exception(e, RuntimeError, "Camera Accuracy Health is already active")
146  else:
147  test.unexpected_exception()
148  ac.wait_for_calibration() # First trigger should continue and finish successfully
149  ac.trim_irrelevant_statuses(irrelevant_statuses)
150  filter_special_frames( ac.status_list )
151  test.check_equal_lists(ac.status_list, successful_calibration_status_list)
152 except:
153  test.unexpected_exception()
154 color_sensor.stop()
155 color_sensor.close()
156 depth_sensor.stop()
157 depth_sensor.close()
158 test.finish()
159 
160 #############################################################################################
161 test.print_results_and_exit()
def filter_special_frames(list)
virtual frame finish(frame f)
void next(auto_any_t cur, type2type< T, C > *)
Definition: foreach.hpp:757


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