Skip to content

Commit

Permalink
Merge pull request #7522 from ev-mp/HDR_enh
Browse files Browse the repository at this point in the history
HDR enhancements
  • Loading branch information
ev-mp authored Oct 8, 2020
2 parents 1b92f95 + 834ce73 commit 40b2bbf
Show file tree
Hide file tree
Showing 9 changed files with 858 additions and 97 deletions.
8 changes: 8 additions & 0 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,14 @@ namespace rs2
model->enable(false);
}

if (shared_filter->is<hdr_merge>())
{
// processing block will be skipped if the requested option is not supported
auto supported_options = s->get_supported_options();
if (std::find(supported_options.begin(), supported_options.end(), RS2_OPTION_SEQUENCE_ID) == supported_options.end())
continue;
}

post_processing.push_back(model);
}

Expand Down
17 changes: 17 additions & 0 deletions src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ namespace librealsense
return *it->second;
}

std::shared_ptr<option> get_option_handler(rs2_option id)
{
return (const_cast<const options_container*>(this)->get_option_handler(id));
}

std::shared_ptr<option> get_option_handler(rs2_option id) const
{
auto it = _options.find(id);
if (it == _options.end())
{
throw invalid_value_exception(to_string()
<< "Device does not support option "
<< get_option_name(id) << "!");
}
return it->second;
}

void register_option(rs2_option id, std::shared_ptr<option> option)
{
_options[id] = option;
Expand Down
36 changes: 32 additions & 4 deletions src/ds5/ds5-active.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,47 @@ namespace librealsense
auto&& raw_depth_ep = get_raw_depth_sensor();

auto emitter_enabled = std::make_shared<emitter_option>(raw_depth_ep);
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED, emitter_enabled);
std::shared_ptr<option> hdr_enabled_option(depth_ep.get_option_handler(RS2_OPTION_HDR_ENABLED));

//EMITTER ENABLED OPTION
if (hdr_enabled_option)
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED,
std::make_shared<gated_option>(
emitter_enabled,
hdr_enabled_option,
"Emitter status cannot be set while HDR is enabled"));
}
else
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED, emitter_enabled);
}

//LASER POWER OPTION
auto laser_power = std::make_shared<uvc_xu_option<uint16_t>>(raw_depth_ep,
depth_xu,
DS5_LASER_POWER,
"Manual laser power in mw. applicable only when laser power mode is set to Manual");

depth_ep.register_option(RS2_OPTION_LASER_POWER,
std::make_shared<auto_disabling_control>(
auto laser_power_auto_disabling = std::make_shared<auto_disabling_control>(
laser_power,
emitter_enabled,
std::vector<float>{0.f, 2.f}, 1.f));
std::vector<float>{0.f, 2.f}, 1.f);

if (hdr_enabled_option)
{
depth_ep.register_option(RS2_OPTION_LASER_POWER,
std::make_shared<gated_option>(
laser_power_auto_disabling,
hdr_enabled_option,
"Laser Power status cannot be set while HDR is enabled"));
}
else
{
depth_ep.register_option(RS2_OPTION_LASER_POWER, laser_power_auto_disabling);
}

//PROJECTOR TEMPERATURE OPTION
depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE,
std::make_shared<asic_and_projector_temperature_options>(raw_depth_ep,
RS2_OPTION_PROJECTOR_TEMPERATURE));
Expand Down
107 changes: 61 additions & 46 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,38 +756,9 @@ namespace librealsense
// minimal firmware version in which hdr feature is supported
firmware_version hdr_firmware_version("5.12.8.100");

// Alternating laser pattern is applicable for global shutter/active SKUs
auto mask = d400_caps::CAP_GLOBAL_SHUTTER | d400_caps::CAP_ACTIVE_PROJECTOR;
// Alternating laser pattern should be set and query in a different way according to the firmware version
bool is_fw_version_using_id = (_fw_version >= firmware_version("5.12.8.100"));
if ((_fw_version >= firmware_version("5.11.3.0")) && ((_device_capabilities & mask) == mask))
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<alternating_emitter_option>(*_hw_monitor, &raw_depth_sensor, is_fw_version_using_id));
}
else if (_fw_version >= firmware_version("5.10.9.0") &&
_fw_version.experimental()) // Not yet available in production firmware
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<emitter_on_and_off_option>(*_hw_monitor, &raw_depth_sensor));
}

if ((_fw_version >= firmware_version("5.12.1.0")) && ((_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER))
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ALWAYS_ON, std::make_shared<emitter_always_on_option>(*_hw_monitor, &depth_sensor));
}

if (_fw_version >= firmware_version("5.12.4.0") && (_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER)
{
depth_sensor.register_option(RS2_OPTION_INTER_CAM_SYNC_MODE,
std::make_shared<external_sync_mode2>(*_hw_monitor, &raw_depth_sensor));
}
else if (_fw_version >= firmware_version("5.9.15.1"))
{
depth_sensor.register_option(RS2_OPTION_INTER_CAM_SYNC_MODE,
std::make_shared<external_sync_mode>(*_hw_monitor));
}

std::shared_ptr<option> exposure_option = nullptr;
std::shared_ptr<option> gain_option = nullptr;
std::shared_ptr<hdr_option> hdr_enabled_option = nullptr;

//EXPOSURE AND GAIN - preparing uvc options
auto uvc_xu_exposure_option = std::make_shared<uvc_xu_option<uint32_t>>(raw_depth_sensor,
Expand All @@ -798,9 +769,16 @@ namespace librealsense
auto uvc_pu_gain_option = std::make_shared<uvc_pu_option>(raw_depth_sensor, RS2_OPTION_GAIN);
option_range gain_range = uvc_pu_gain_option->get_range();

//AUTO EXPOSURE
auto enable_auto_exposure = std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor,
depth_xu,
DS5_ENABLE_AUTO_EXPOSURE,
"Enable Auto Exposure");
depth_sensor.register_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, enable_auto_exposure);

// register HDR options
//auto global_shutter_mask = d400_caps::CAP_GLOBAL_SHUTTER;
if ( (_fw_version >= hdr_firmware_version))// && ((_device_capabilities & global_shutter_mask) == global_shutter_mask) )
if ((_fw_version >= hdr_firmware_version))// && ((_device_capabilities & global_shutter_mask) == global_shutter_mask) )
{
auto ds5_depth = As<ds5_depth_sensor, synthetic_sensor>(&get_depth_sensor());
ds5_depth->init_hdr_config(exposure_range, gain_range);
Expand All @@ -820,11 +798,11 @@ namespace librealsense

option_range hdr_sequ_id_range = { 0.f /*min*/, 2.f /*max*/, 1.f /*step*/, 0.f /*default*/ };
auto hdr_sequ_id_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_SEQUENCE_ID, hdr_sequ_id_range,
std::map<float, std::string>{ {0.f, "0"}, { 1.f, "1"}, {2.f, "2"} });
std::map<float, std::string>{ {0.f, "UVC"}, { 1.f, "1" }, { 2.f, "2" } });
depth_sensor.register_option(RS2_OPTION_SEQUENCE_ID, hdr_sequ_id_option);

option_range hdr_enable_range = { 0.f /*min*/, 1.f /*max*/, 1.f /*step*/, 0.f /*default*/};
auto hdr_enabled_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_HDR_ENABLED, hdr_enable_range);
option_range hdr_enable_range = { 0.f /*min*/, 1.f /*max*/, 1.f /*step*/, 0.f /*default*/ };
hdr_enabled_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_HDR_ENABLED, hdr_enable_range);
depth_sensor.register_option(RS2_OPTION_HDR_ENABLED, hdr_enabled_option);

//EXPOSURE AND GAIN - preparing hdr options
Expand All @@ -837,6 +815,12 @@ namespace librealsense

exposure_option = hdr_conditional_exposure_option;
gain_option = hdr_conditional_gain_option;

depth_sensor.register_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE,
std::make_shared<gated_option>(
enable_auto_exposure,
hdr_enabled_option,
"Auto Exposure cannot be set while HDR is enabled"));
}
else
{
Expand All @@ -845,29 +829,60 @@ namespace librealsense
}

//EXPOSURE
depth_sensor.register_option(RS2_OPTION_EXPOSURE, exposure_option);

//GAIN
depth_sensor.register_option(RS2_OPTION_GAIN, gain_option);

//AUTO EXPOSURE
auto enable_auto_exposure = std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor,
depth_xu,
DS5_ENABLE_AUTO_EXPOSURE,
"Enable Auto Exposure");
depth_sensor.register_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, enable_auto_exposure);

depth_sensor.register_option(RS2_OPTION_EXPOSURE,
std::make_shared<auto_disabling_control>(
exposure_option,
enable_auto_exposure));

//GAIN
depth_sensor.register_option(RS2_OPTION_GAIN,
std::make_shared<auto_disabling_control>(
gain_option,
enable_auto_exposure));

// Alternating laser pattern is applicable for global shutter/active SKUs
auto mask = d400_caps::CAP_GLOBAL_SHUTTER | d400_caps::CAP_ACTIVE_PROJECTOR;
// Alternating laser pattern should be set and query in a different way according to the firmware version
bool is_fw_version_using_id = (_fw_version >= firmware_version("5.12.8.100"));
if ((_fw_version >= firmware_version("5.11.3.0")) && ((_device_capabilities & mask) == mask))
{
auto alternating_emitter_opt = std::make_shared<alternating_emitter_option>(*_hw_monitor, &raw_depth_sensor, is_fw_version_using_id);
if (_fw_version >= hdr_firmware_version)
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF,
std::make_shared<gated_option>(
alternating_emitter_opt,
hdr_enabled_option,
"Emitter ON/OFF cannot be set while HDR is enabled"));
}
else
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, alternating_emitter_opt);
}
}
else if (_fw_version >= firmware_version("5.10.9.0") &&
_fw_version.experimental()) // Not yet available in production firmware
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<emitter_on_and_off_option>(*_hw_monitor, &raw_depth_sensor));
}

if ((_fw_version >= firmware_version("5.12.1.0")) && ((_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER))
{
depth_sensor.register_option(RS2_OPTION_EMITTER_ALWAYS_ON, std::make_shared<emitter_always_on_option>(*_hw_monitor, &depth_sensor));
}

if (_fw_version >= firmware_version("5.12.4.0") && (_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER)
{
depth_sensor.register_option(RS2_OPTION_INTER_CAM_SYNC_MODE,
std::make_shared<external_sync_mode2>(*_hw_monitor, &raw_depth_sensor));
}
else if (_fw_version >= firmware_version("5.9.15.1"))
{
depth_sensor.register_option(RS2_OPTION_INTER_CAM_SYNC_MODE,
std::make_shared<external_sync_mode>(*_hw_monitor));
}


roi_sensor_interface* roi_sensor = dynamic_cast<roi_sensor_interface*>(&depth_sensor);
if (roi_sensor)
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor));
Expand Down
8 changes: 7 additions & 1 deletion src/ds5/ds5-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,13 @@ namespace librealsense
if (_hdr_cfg->is_config_in_process())
_hdr_option->set(value);
else
_uvc_option->set(value);
{
if (_hdr_cfg->is_enabled())
LOG_WARNING("The control - " << _uvc_option->get_description()
<< " - is locked while HDR mode is active.\n");
else
_uvc_option->set(value);
}
}

float hdr_conditional_option::query() const
Expand Down
30 changes: 30 additions & 0 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,36 @@ namespace librealsense
float _manual_value;
};

/** \brief gated_option class will permit the user to
* perform only read (query) of the read_only option when its affecting_option is set */
class gated_option : public proxy_option
{
public:
explicit gated_option(std::shared_ptr<option> leading_to_read_only,
std::shared_ptr<option> gated_option, std::string reason = "This option cannot be set right now")
: proxy_option(leading_to_read_only), _gated_option(gated_option), _reason(reason)
{}

void set(float value) override
{
auto strong = _gated_option.lock();
if (!strong)
return;
auto val = strong->query();

if (val)
LOG_WARNING(_reason.c_str());
else
_proxy->set(value);

_recording_function(*this);
}

private:
std::weak_ptr<option> _gated_option;
std::string _reason;
};

/** \brief class provided a control
* that changes min distance value when changing max distance value */
class max_distance_option : public proxy_option
Expand Down
61 changes: 61 additions & 0 deletions unit-tests/unit-tests-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,67 @@ inline rs2::stream_profile get_profile_by_resolution_type(rs2::sensor& s, res_ty
throw std::runtime_error(ss.str());
}

inline std::shared_ptr<rs2::device> do_with_waiting_for_camera_connection(rs2::context ctx, std::shared_ptr<rs2::device> dev, std::string serial, std::function<void()> operation)
{
std::mutex m;
bool disconnected = false;
bool connected = false;
std::shared_ptr<rs2::device> result;
std::condition_variable cv;

ctx.set_devices_changed_callback([&result, dev, &disconnected, &connected, &m, &cv, &serial](rs2::event_information info) mutable
{
if (info.was_removed(*dev))
{
std::unique_lock<std::mutex> lock(m);
disconnected = true;
cv.notify_all();
}
auto list = info.get_new_devices();
if (list.size() > 0)
{
for (auto cam : list)
{
if (serial == cam.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER))
{
std::unique_lock<std::mutex> lock(m);
connected = true;
result = std::make_shared<rs2::device>(cam);

disable_sensitive_options_for(*result);
cv.notify_all();
break;
}
}
}
});

operation();

std::unique_lock<std::mutex> lock(m);
REQUIRE(wait_for_reset([&]() {
return cv.wait_for(lock, std::chrono::seconds(20), [&]() { return disconnected; });
}, dev));
REQUIRE(cv.wait_for(lock, std::chrono::seconds(20), [&]() { return connected; }));
REQUIRE(result);
return result;
}

inline rs2::depth_sensor restart_first_device_and_return_depth_sensor(const rs2::context& ctx, const rs2::device_list& devices_list)
{
rs2::device dev = devices_list[0];
std::string serial;
REQUIRE_NOTHROW(serial = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));
//forcing hardware reset to simulate device disconnection
auto shared_dev = std::make_shared<rs2::device>(devices_list.front());
shared_dev = do_with_waiting_for_camera_connection(ctx, shared_dev, serial, [&]()
{
shared_dev->hardware_reset();
});
rs2::depth_sensor depth_sensor = dev.query_sensors().front();
return depth_sensor;
}


enum special_folder
{
Expand Down
Loading

0 comments on commit 40b2bbf

Please sign in to comment.