alt-ir-common.h
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 #include <unit-tests/test.h>
6 
7 using namespace rs2;
8 
9 
11 {
12  REQUIRE( depth_sens );
13 
14  if( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) )
15  return true;
16 
17  std::cout << "FW version " << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
18  << " doesn't support alt IR option";
19  return false;
20 }
21 
22 void set_alt_ir_if_needed( const rs2::depth_sensor & depth_sens, float val )
23 {
24  REQUIRE( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) );
25  auto alt_ir = depth_sens.get_option( RS2_OPTION_ALTERNATE_IR );
26  if( alt_ir != val )
28 }
29 
31  const rs2::device & dev,
32  const rs2::depth_sensor & depth_sens,
33  const std::vector< stream_profile > & expected_profiles )
34 {
35  std::vector< stream_profile > profiles = expected_profiles;
36  REQUIRE_NOTHROW( depth_sens.open( profiles ) );
37  REQUIRE_NOTHROW( depth_sens.start( [&]( rs2::frame f ) {} ) );
38 
39  set_alt_ir_if_needed( depth_sens, 1 );
40 
41  auto calib = dev.as< rs2::device_calibration >();
42  if( calib )
43  {
45  calib.register_calibration_change_callback( [&]( rs2_calibration_status cal_status ) {
46  status = cal_status;
47  } );
48 
49  // Before throwing, AC will notify of a BAD_CONDITIONS status
50  REQUIRE_THROWS( calib.trigger_device_calibration( RS2_CALIBRATION_MANUAL_DEPTH_TO_RGB ) );
51 
53  }
54 
55  REQUIRE_NOTHROW( depth_sens.stop() );
56  REQUIRE_NOTHROW( depth_sens.close() );
57 }
58 
60  const rs2::device & dev,
61  const rs2::depth_sensor & depth_sens,
62  const std::vector< stream_profile > & expected_profiles )
63 {
64  std::vector< stream_profile > profiles = expected_profiles;
65  REQUIRE_NOTHROW( depth_sens.open( profiles ) );
66 
67  std::condition_variable cv;
68  std::mutex m;
69 
70  auto wait_for_streams = [&]() {
71  profiles = expected_profiles;
72  std::unique_lock< std::mutex > lock( m );
73  REQUIRE( cv.wait_for( lock, std::chrono::seconds( 20 ), [&]() {
74  return profiles.size() == 0;
75  } ) );
76  };
77 
78  REQUIRE_NOTHROW( depth_sens.start( [&]( rs2::frame f ) {
79  std::unique_lock< std::mutex > lock( m );
80  remove_all_streams_arrived( f, profiles );
81  cv.notify_one();
82  } ) );
83 
84  set_alt_ir_if_needed( depth_sens, 1 );
85  wait_for_streams();
86 
87  set_alt_ir_if_needed( depth_sens, 0 );
88  wait_for_streams();
89 
90  set_alt_ir_if_needed( depth_sens, 1 );
91  wait_for_streams();
92 
93  REQUIRE_NOTHROW( depth_sens.stop() );
94  REQUIRE_NOTHROW( depth_sens.close() );
95 
96 }
static const textual_icon lock
Definition: model-views.h:219
void stop() const
Definition: rs_sensor.hpp:195
GLuint GLfloat * val
void start(T callback) const
Definition: rs_sensor.hpp:185
std::mutex m
void enable_alt_ir_and_check_that_AC_fails(const rs2::device &dev, const rs2::depth_sensor &depth_sens, const std::vector< stream_profile > &expected_profiles)
Definition: alt-ir-common.h:30
Definition: animated.h:9
bool supports(rs2_camera_info info) const
Definition: rs_sensor.hpp:125
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
T as() const
Definition: rs_device.hpp:129
float get_option(rs2_option option) const
Definition: rs_options.hpp:72
void open(const stream_profile &profile) const
Definition: rs_sensor.hpp:111
bool alt_ir_supported_or_message(const rs2::depth_sensor &depth_sens)
Definition: alt-ir-common.h:10
std::ostream & cout()
void set_alt_ir_if_needed(const rs2::depth_sensor &depth_sens, float val)
Definition: alt-ir-common.h:22
#define REQUIRE(...)
Definition: catch.hpp:17398
rs2_calibration_status
Definition: rs_device.h:408
static std::condition_variable cv
#define REQUIRE_THROWS(...)
Definition: catch.hpp:17401
REQUIRE_NOTHROW(rs2_log(RS2_LOG_SEVERITY_INFO, "Log message using rs2_log()", nullptr))
void close() const
Definition: rs_sensor.hpp:173
void enable_alt_ir_and_check_that_all_streams_arrived(const rs2::device &dev, const rs2::depth_sensor &depth_sens, const std::vector< stream_profile > &expected_profiles)
Definition: alt-ir-common.h:59
void set_option(rs2_option option, float value) const
Definition: rs_options.hpp:99
GLdouble f
const char * get_info(rs2_camera_info info) const
Definition: rs_sensor.hpp:138


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Thu Dec 22 2022 03:41:41