Skip to content

Commit

Permalink
Merge pull request #8519 from nohayassin/dso_16596_fix
Browse files Browse the repository at this point in the history
Auto Exposure : range value setting limitation
  • Loading branch information
ev-mp authored Mar 25, 2021
2 parents b32c852 + 6594321 commit 0df661a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,10 @@ namespace librealsense
// Auto exposure and gain limit
if (_fw_version >= firmware_version("5.12.10.11"))
{
depth_sensor.register_option(RS2_OPTION_AUTO_EXPOSURE_LIMIT, std::make_shared<auto_exposure_limit_option>(*_hw_monitor, &depth_sensor));
depth_sensor.register_option(RS2_OPTION_AUTO_GAIN_LIMIT, std::make_shared<auto_gain_limit_option>(*_hw_monitor, &depth_sensor));
auto exposure_range = depth_sensor.get_option(RS2_OPTION_EXPOSURE).get_range();
auto gain_range = depth_sensor.get_option(RS2_OPTION_GAIN).get_range();
depth_sensor.register_option(RS2_OPTION_AUTO_EXPOSURE_LIMIT, std::make_shared<auto_exposure_limit_option>(*_hw_monitor, &depth_sensor, exposure_range));
depth_sensor.register_option(RS2_OPTION_AUTO_GAIN_LIMIT, std::make_shared<auto_gain_limit_option>(*_hw_monitor, &depth_sensor, gain_range));
}

// attributes of md_capture_timing
Expand Down
22 changes: 14 additions & 8 deletions src/ds5/ds5-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,17 +658,20 @@ namespace librealsense
return _uvc_option->is_enabled();
}

auto_exposure_limit_option::auto_exposure_limit_option(hw_monitor& hwm, sensor_base* ep)
: _hwm(hwm), _sensor(ep)
auto_exposure_limit_option::auto_exposure_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range)
: option_base(range), _hwm(hwm), _sensor(ep)
{
_range = [this]()
_range = [range]()
{
return option_range{ 0, 165000, 1, 0 };
return range;
};
}

void auto_exposure_limit_option::set(float value)
{
if (!is_valid(value))
throw invalid_value_exception("set(enable_auto_exposure) failed! Invalid Auto-Exposure mode request " + std::to_string(value));

command cmd_get(ds::AUTO_CALIB);
cmd_get.param1 = 5;
std::vector<uint8_t> ret = _hwm.send(cmd_get);
Expand Down Expand Up @@ -700,17 +703,20 @@ namespace librealsense
return *_range;
}

auto_gain_limit_option::auto_gain_limit_option(hw_monitor& hwm, sensor_base* ep)
: _hwm(hwm), _sensor(ep)
auto_gain_limit_option::auto_gain_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range)
: option_base(range), _hwm(hwm), _sensor(ep)
{
_range = [this]()
_range = [range]()
{
return option_range{ 0, 248, 1, 0 };
return range;
};
}

void auto_gain_limit_option::set(float value)
{
if (!is_valid(value))
throw invalid_value_exception("set(enable_auto_gain) failed! Invalid Auto-Gain mode request " + std::to_string(value));

command cmd_get(ds::AUTO_CALIB);
cmd_get.param1 = 5;
std::vector<uint8_t> ret = _hwm.send(cmd_get);
Expand Down
8 changes: 4 additions & 4 deletions src/ds5/ds5-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ namespace librealsense
std::shared_ptr<option> _hdr_option;
};

class auto_exposure_limit_option : public option
class auto_exposure_limit_option : public option_base
{
public:
auto_exposure_limit_option(hw_monitor& hwm, sensor_base* depth_ep);
auto_exposure_limit_option(hw_monitor& hwm, sensor_base* depth_ep, option_range range);
virtual ~auto_exposure_limit_option() = default;
virtual void set(float value) override;
virtual float query() const override;
Expand All @@ -376,10 +376,10 @@ namespace librealsense
sensor_base* _sensor;
};

class auto_gain_limit_option : public option
class auto_gain_limit_option : public option_base
{
public:
auto_gain_limit_option(hw_monitor& hwm, sensor_base* depth_ep);
auto_gain_limit_option(hw_monitor& hwm, sensor_base* depth_ep, option_range range);
virtual ~auto_gain_limit_option() = default;
virtual void set(float value) override;
virtual float query() const override;
Expand Down
42 changes: 42 additions & 0 deletions unit-tests/internal/internal-tests-extrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,45 @@ TEST_CASE("Enable disable all streams", "[live]")
}
}
}
TEST_CASE("Controls limits validation", "[live]")
{
rs2::context ctx;
if (make_context(SECTION_FROM_TEST_NAME, &ctx))
{
auto list = ctx.query_devices();
REQUIRE(list.size());

for (auto&& device : list)
{
if (std::string(device.get_info(RS2_CAMERA_INFO_PRODUCT_LINE)) != "D400")
continue;
auto sensors = device.query_sensors();
float limit;
rs2_option controls[2] = { RS2_OPTION_AUTO_GAIN_LIMIT, RS2_OPTION_AUTO_EXPOSURE_LIMIT };
for (auto& control : controls)
{
for (auto& s : sensors)
{
std::string val = s.get_info(RS2_CAMERA_INFO_NAME);
if (!s.supports(control))
break;
auto range = s.get_option_range(control);
float set_value[3] = { range.min - 10, range.max + 10, std::floor((range.max + range.min) / 2) };
for (auto& val : set_value)
{
CAPTURE(val);
CAPTURE(range);
if (val < range.min || val > range.max)
REQUIRE_THROWS(s.set_option(control, val));
else
{
s.set_option(control, val);
limit = s.get_option(control);
REQUIRE(limit == val);
}
}
}
}
}
}
}

0 comments on commit 0df661a

Please sign in to comment.