20 using namespace ivcam2;
36 auto&& backend = ctx->get_backend();
39 auto enable_global_time_option = std::shared_ptr<global_time_option>(
new global_time_option());
40 auto raw_color_ep = std::make_shared<uvc_sensor>(
"RGB Camera", ctx->get_backend().create_uvc_device(color_devices_info.front()),
50 color_ep->register_processing_block(
51 processing_block_factory::create_pbf_vector< yuy2_converter >(
54 [=]( std::shared_ptr< generic_processing_block > pb )
56 auto cpb = std::make_shared< composite_processing_block >();
57 cpb->add(std::make_shared< ac_trigger::color_processing_block >(_autocal));
64 color_ep->register_processing_block(
65 processing_block_factory::create_pbf_vector< yuy2_converter >(
89 std::make_shared<auto_disabling_control>(
91 auto_white_balance_option));
98 std::make_shared<auto_disabling_control>(
100 auto_exposure_option));
104 std::map<float, std::string>{ { 0.f,
"Disabled"},
107 { 3.f,
"Auto" }, }));
167 color_ep->register_calibration_controls();
179 if (color_devs_info.size() != 1)
181 << color_devs_info.size() <<
" found");
207 "Failed to read FW table 0x" 211 to_string() <<
"Failed to read FW table 0x" << std::hex
232 using namespace ivcam2;
234 auto & intrinsic = *_owner->_color_intrinsics_table;
236 auto num_of_res = intrinsic.resolution.num_of_resolutions;
238 for(
auto i = 0;
i < num_of_res;
i++ )
240 auto model = intrinsic.resolution.intrinsic_resolution[
i];
241 if(
model.height == height &&
model.width == width )
246 intrinsics.
fx =
model.ipm.focal_length.x;
247 intrinsics.
fy =
model.ipm.focal_length.y;
248 intrinsics.
ppx =
model.ipm.principal_point.x;
249 intrinsics.
ppy =
model.ipm.principal_point.y;
251 if(
model.distort.radial_k1 ||
model.distort.radial_k2
252 ||
model.distort.tangential_p1 ||
model.distort.tangential_p2
253 ||
model.distort.radial_k3 )
257 intrinsics.
coeffs[2] =
model.distort.tangential_p1;
258 intrinsics.
coeffs[3] =
model.distort.tangential_p2;
268 throw std::runtime_error(
to_string() <<
"intrinsics for resolution " << width <<
"," 269 << height <<
" don't exist" );
288 res.fx = intr.
fx * width / 2;
289 res.fy = intr.
fy * height / 2;
290 res.ppx = ( intr.
ppx + 1 ) * width / 2;
291 res.ppy = ( intr.
ppy + 1 ) * height / 2;
302 if( ! _k_thermal_intrinsics)
306 return get_raw_intrinsics( profile.
width, profile.
height );
369 _owner->_color_intrinsics_table.reset();
370 reset_k_thermal_intrinsics();
395 throw std::logic_error(
"color sensor does not support DSM parameters" );
400 throw std::logic_error(
"color sensor does not support DSM parameters" );
406 _k_thermal_intrinsics = std::make_shared< rs2_intrinsics >(
normalize(intr) );
411 _k_thermal_intrinsics.reset();
416 return *_owner->_thermal_table;
449 _owner->_color_intrinsics_table.reset();
450 reset_k_thermal_intrinsics();
453 *_owner->_depth_stream,
454 *_owner->_color_stream,
456 AC_LOG(
INFO,
"Color sensor calibration has been reset" );
461 std::lock_guard<std::mutex>
lock(_state_mutex);
463 if (_state != sensor_state::OWNED_BY_USER)
494 _owner->_hw_monitor->send(cmdTprocGranEp5);
497 _owner->_hw_monitor->send(cmdTprocThresholdEp5);
499 LOG_DEBUG(
"Color usb tproc granularity and TRB threshold updated.");
502 LOG_WARNING(
"Failed to update color usb tproc granularity and TRB threshold. performance and stability maybe impacted on certain platforms.");
507 LOG_DEBUG(
"Default host performance mode, color usb tproc granularity and TRB threshold not changed");
511 delayed_start(callback);
517 std::lock_guard<std::mutex>
lock(_state_mutex);
520 if (_state != sensor_state::OWNED_BY_USER)
529 std::lock_guard< std::mutex >
lock( _state_mutex );
531 if( sensor_state::OWNED_BY_AUTO_CAL == _state )
539 AC_LOG(
DEBUG,
"Calibration color stream was on, Closing color sensor..." );
543 restore_pre_calibration_controls();
545 set_sensor_state( sensor_state::CLOSED );
549 set_sensor_state( sensor_state::OWNED_BY_USER );
555 std::lock_guard< std::mutex >
lock( _state_mutex );
557 if( _state != sensor_state::OWNED_BY_USER )
561 set_sensor_state(sensor_state::CLOSED);
576 std::lock_guard< std::mutex >
lock( _state_mutex );
579 if( _state == sensor_state::CLOSED )
581 set_calibration_controls_to_defaults();
584 set_sensor_state(sensor_state::OWNED_BY_AUTO_CAL);
585 AC_LOG(
DEBUG,
"Starting color sensor stream -- for calibration" );
589 if( ! is_streaming() )
594 "The color sensor was opened but never started by the user; streaming may not work" );
597 AC_LOG(
DEBUG,
"Color sensor is already streaming (" << state_to_string(_state) <<
")" );
603 std::lock_guard< std::mutex >
lock( _state_mutex );
605 if( _state == sensor_state::OWNED_BY_AUTO_CAL )
607 AC_LOG(
DEBUG,
"Closing color sensor stream from calibration");
619 restore_pre_calibration_controls();
622 set_sensor_state( sensor_state::CLOSED );
626 AC_LOG(
DEBUG,
"Color sensor was not opened by us; no need to close" );
634 case sensor_state::CLOSED:
636 case sensor_state::OWNED_BY_AUTO_CAL:
637 return "OWNED_BY_AUTO_CAL";
638 case sensor_state::OWNED_BY_USER:
639 return "OWNED_BY_USER";
641 LOG_DEBUG(
"Invalid color sensor state: " << static_cast<int>(state));
642 return "Unknown state";
649 for (
auto && calib_control : _calib_controls)
651 auto && control = get_option(calib_control.option);
653 auto curr_val = control.query();
654 if (curr_val != calib_control.default_value)
657 <<
" from: " << curr_val
658 <<
" to: " << calib_control.default_value );
659 calib_control.need_to_restore =
true;
660 calib_control.previous_value = curr_val;
661 control.set(calib_control.default_value);
666 <<
" current value is: " << curr_val
667 <<
" which is the default value");
674 for (
auto && calib_control : _calib_controls)
676 auto && control = get_option(calib_control.option);
678 auto curr_val = control.query();
679 if( calib_control.need_to_restore &&
680 ( curr_val == calib_control.default_value ) )
683 <<
" from: " << curr_val
684 <<
" to: " << calib_control.previous_value);
685 control.set(calib_control.previous_value);
689 std::stringstream ss;
690 ss <<
"Calibration - no need to restore option : " 692 <<
" current value is: " << curr_val;
694 if( curr_val == calib_control.default_value ) ss <<
" which is the default value";
695 else ss <<
" which is the user value";
699 calib_control.need_to_restore =
false;
710 auto && control = get_option(
option);
711 _calib_controls.push_back({
option, control.get_range().def });
717 std::vector<tagged_profile>
tags;
721 int width = usb3mode ? 1280 : 960;
722 int height = usb3mode ? 720 : 540;
735 if (response_vec.empty())
738 auto resolutions_rgb_table_ptr =
reinterpret_cast<const ivcam2::intrinsic_rgb *
>(response_vec.data());
744 - num_of_resolutions)
750 if (expected_size > response_vec.size() ||
754 to_string() <<
"Calibration data invalid, number of resolutions is: " << num_of_resolutions <<
755 ", expected size: " << expected_size <<
" , actual size: " << response_vec.size());
761 librealsense::copy(&resolutions_rgb_table_output, resolutions_rgb_table_ptr, expected_size);
763 return resolutions_rgb_table_output;
std::shared_ptr< hw_monitor > _hw_monitor
static const textual_icon lock
std::shared_ptr< lazy< rs2_extrinsics > > _color_extrinsic
void start(frame_callback_ptr callback) override
l500_color(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
std::string state_to_string(sensor_state state)
void restore_pre_calibration_controls()
void open(const stream_profiles &requests) override
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
void open(const stream_profiles &requests) override
std::shared_ptr< stream_interface > _color_stream
void reset_calibration() override
rs2_dsm_params get_dsm_params() const override
const char * rs2_option_to_string(rs2_option option)
Video DSM (Digital Sync Module) parameters for calibration (same layout as in FW ac_depth_params) Thi...
void set_intrinsics(rs2_intrinsics const &)
rs2_intrinsics denormalize(const rs2_intrinsics &intr, const uint32_t &width, const uint32_t &height)
std::map< uint32_t, rs2_format > l500_color_fourcc_to_rs2_format
void override_dsm_params(rs2_dsm_params const &dsm_params) override
GLsizei const GLchar *const * string
void override_extrinsics(const stream_interface &from, const stream_interface &to, rs2_extrinsics const &extr)
platform::usb_spec _usb_mode
rs2_host_perf_mode
values for RS2_OPTION_HOST_PERFORMANCE option.
std::shared_ptr< stream_interface > _depth_stream
void stop_stream_for_calibration()
rs2_intrinsics get_raw_intrinsics(uint32_t width, uint32_t height) const
uint32_t power_line_frequency
ivcam2::intrinsic_rgb read_intrinsics_table() const
algo::thermal_loop::l500::thermal_calibration_table get_thermal_table() const
void register_extrinsics(const stream_interface &from, const stream_interface &to, std::weak_ptr< lazy< rs2_extrinsics >> extr)
void update_write_fields()
rs2_extrinsics to_raw_extrinsics(rs2_extrinsics extr)
rs2_extrinsics from_raw_extrinsics(rs2_extrinsics extr)
uint8_t num_of_resolutions
uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
GLint GLsizei GLsizei height
rs2_intrinsics get_intrinsics(const stream_profile &profile) const override
rs2_intrinsics normalize(const rs2_intrinsics &intr)
static std::vector< byte > read_fw_table_raw(const hw_monitor &hwm, int table_id, hwmon_response &response)
frame_callback_ptr make_frame_callback(T callback)
void override_extrinsics(rs2_extrinsics const &extr) override
std::shared_ptr< md_attribute_parser_base > make_uvc_header_parser(Attribute St::*attribute, attrib_modifyer mod=nullptr)
A utility function to create UVC metadata header parser.
l500_color_sensor * get_color_sensor() override
void write_fw_table(hw_monitor &hwm, uint16_t const table_id, T const &table, uint16_t const version=0x0100)
static const uint16_t table_id
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
static environment & get_instance()
int add_sensor(const std::shared_ptr< sensor_interface > &sensor_base)
#define AC_LOG(TYPE, MSG)
extrinsics_graph & get_extrinsics_graph()
std::vector< uint8_t > get_raw_extrinsics_table() const
std::shared_ptr< synthetic_sensor > create_color_device(std::shared_ptr< context > ctx, const std::vector< platform::uvc_device_info > &color_devices_info)
uint8_t _color_device_idx
resolutions_rgb resolution
sensor_interface & get_sensor(size_t subdevice) override
GLenum GLenum GLsizei void * table
lazy< std::vector< uint8_t > > _color_extrinsics_table_raw
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
void set_calibration_controls_to_defaults()
std::shared_ptr< md_attribute_parser_base > make_attribute_parser(Attribute S::*attribute, Flag flag, unsigned long long offset, attrib_modifyer mod=nullptr)
A helper function to create a specialized attribute parser. Return it as a pointer to a base-class...
long long rs2_metadata_type
rs2_intrinsics get_intrinsics() const
lazy< ivcam2::intrinsic_rgb > _color_intrinsics_table
static const uint16_t eeprom_table_id
static const int MAX_NUM_OF_RGB_RESOLUTIONS
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
std::vector< tagged_profile > get_profiles_tags() const override
bool start_stream_for_calibration(const stream_profiles &requests)
void register_stream_to_extrinsic_group(const stream_interface &stream, uint32_t groupd_index)
void read_fw_table(hw_monitor &hwm, int table_id, T *ptable, table_header *pheader=nullptr, std::function< void() > init=nullptr)
auto group_multiple_fw_calls(synthetic_sensor &s, T action) -> decltype(action())
void register_calibration_controls()
#define offsetof(STRUCTURE, FIELD)
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
void override_intrinsics(rs2_intrinsics const &intr) override
pose get_color_stream_extrinsic(const std::vector< uint8_t > &raw_data)
void set_k_thermal_intrinsics(rs2_intrinsics const &intr)
lazy< algo::thermal_loop::l500::thermal_calibration_table > _thermal_table
uint32_t sensor_timestamp
void reset_k_thermal_intrinsics()
const rs2_distortion l500_distortion
rs2_extrinsics const & get_extrinsics() const
void copy(void *dst, void const *src, size_t size)
std::string to_string(T value)
std::map< uint32_t, rs2_stream > l500_color_fourcc_to_rs2_stream