Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset Auto Exp/Gain Limit back to default value 0 #9692

Merged
merged 28 commits into from
Oct 12, 2021

Conversation

nohayassin
Copy link
Contributor

Track on DSO-17393

Copy link
Collaborator

@ev-mp ev-mp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the segment that shows how the manual control overrides the toggle

Comment on lines 29 to 30
RS2_OPTION_ENABLE_EXPOSURE_LIMIT, /**< Enable / disable color image auto-exposure*/
RS2_OPTION_ENABLE_GAIN_LIMIT, /**< Enable / disable color image auto-gain*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options must be added at the end of enum for back-compat.
Rename the according to the main controls: auto_exposure_limit_on, auto_gain_limit_on

@@ -378,6 +378,63 @@ namespace librealsense
sensor_base* _sensor;
};

// Limits Enable/ Disable

class limits_option : public option
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a new class?

virtual ~limits_option() = default;
virtual void set(float value) override
{
_value = value; // 0: gain limit set by user is enabled, 1 : gain limit is disabled (all range 16-248 is valid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should correspond to off, 1 -> On

Comment on lines 395 to 396
if (value == 1) // disabled: save current limit
_cached_limit = _sensor->get_option(RS2_OPTION_AUTO_GAIN_LIMIT).query();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.Shouldn't be in the base class
2. What happens in case polling the data returns 0?

src/types.cpp Outdated
Comment on lines 449 to 450
case RS2_OPTION_ENABLE_GAIN_LIMIT: return "Disable gain limit";
case RS2_OPTION_ENABLE_EXPOSURE_LIMIT: return "Disable exposure limit";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it required here?

@@ -113,7 +113,9 @@ extern "C" {
RS2_OPTION_TRANSMITTER_FREQUENCY, /**<changes the transmitter frequencies increasing effective range over sharpness. */
RS2_OPTION_VERTICAL_BINNING, /**< Enables vertical binning which increases the maximal sensed distance. */
RS2_OPTION_RECEIVER_SENSITIVITY, /**< Control receiver sensitivity to incoming light, both projected and ambient (same as APD on L515). */
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
RS2_OPTION_COUNT, /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add those before count which must remain last

Comment on lines 1079 to 1080
std::shared_ptr<auto_exposure_limit_option> auto_exposure_limit_enable_option = nullptr;
std::shared_ptr<auto_gain_limit_option> auto_gain_limit_enable_option = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine the declaration and allocation into a single statement

auto_exposure_limit_enable_option = std::make_shared<auto_exposure_limit_option>(*_hw_monitor, &depth_sensor, exposure_range);
auto_gain_limit_enable_option = std::make_shared<auto_gain_limit_option>(*_hw_monitor, &depth_sensor, gain_range);

option_range enable_range = { 0.f /*min*/, 1.f /*max*/, 1.f /*step*/, 1.f /*default*/ };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it disabled by default


//GAIN Limit
std::shared_ptr<gain_limit_option> gain_limit_enable_option = nullptr;
gain_limit_enable_option = std::make_shared<gain_limit_option>(RS2_OPTION_AUTO_GAIN_LIMIT_ON, enable_range, auto_gain_limit_enable_option.get());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the dependent option with via shared/weak_ptr according to the content

@@ -666,9 +666,12 @@ namespace librealsense

void auto_exposure_limit_option::set(float value)
{
if (!is_valid(value))
if (!is_valid(value) && value != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_valid shall handle all cases, why the extra clause?

if (value != 0)
_cached_limit = value;
else
value = get_range().max;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injecting "0" is not a valid use-case for the control, - must have the same range as the corresponding UVC control

@@ -711,9 +714,13 @@ namespace librealsense

void auto_gain_limit_option::set(float value)
{
if (!is_valid(value))
if (!is_valid(value) && value != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

src/types.cpp Outdated
Comment on lines 449 to 450
case RS2_OPTION_AUTO_GAIN_LIMIT_ON: return "Enable gain limit";
case RS2_OPTION_AUTO_EXPOSURE_LIMIT_ON: return "Enable exposure limit";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo redundant here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required by design

Comment on lines 395 to 433
virtual ~limits_option() = default;
virtual void set(float) override = 0;
virtual float query() const override { return _value; };
virtual option_range get_range() const override { return _toggle_range; };
virtual bool is_enabled() const override { return true; }
virtual const char* get_description() const override { return "Enable Limits Option"; };
virtual void enable_recording(std::function<void(const option&)> record_action) override { _record_action = record_action; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the override re-implement the base-class functionality.
Needs refactoring

_cached_limit = value;

_exposure_limit_enable->set_cached_limit(value);
if (value != get_range().max && _exposure_limit_enable->query() == 0.f)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the max value is not allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the toggle off at the beginning but I can remove the max-value condition.
The second part of the condition is relevant to prevent redundant commands to FW.

@@ -655,24 +655,24 @@ namespace librealsense
return _uvc_option->is_enabled();
}

auto_exposure_limit_option::auto_exposure_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range)
: option_base(range), _hwm(hwm), _sensor(ep)
auto_exposure_limit_option::auto_exposure_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range, limits_option* exposure_limit_enable)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, pass and store the option's handler via weak_ptr

Comment on lines 1097 to 1099
std::shared_ptr<limits_option> exposure_limit_enable_option = std::make_shared<limits_option>(RS2_OPTION_AUTO_EXPOSURE_LIMIT_ON, enable_range, "Enable Exposure auto-Limit", *_hw_monitor);
std::shared_ptr<auto_exposure_limit_option> auto_exposure_limit_enable_option = std::make_shared<auto_exposure_limit_option>(*_hw_monitor, &depth_sensor, exposure_range, exposure_limit_enable_option.get());
depth_sensor.register_option(RS2_OPTION_AUTO_EXPOSURE_LIMIT_ON, exposure_limit_enable_option);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names are confusing, make it more distinct, like "ae_limit_toggle_control", "ae_limit_value_control"

//GAIN Limit
std::shared_ptr<gain_limit_option> gain_limit_enable_option = std::make_shared<gain_limit_option>(RS2_OPTION_AUTO_GAIN_LIMIT_ON, enable_range, auto_gain_limit_enable_option.get());
depth_sensor.register_option(RS2_OPTION_AUTO_GAIN_LIMIT, auto_gain_limit_enable_option);
std::shared_ptr<limits_option> gain_limit_enable_option = std::make_shared<limits_option>(RS2_OPTION_AUTO_GAIN_LIMIT_ON, enable_range, "Enable Gain auto-Limit", *_hw_monitor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Enable Gain auto-Limit" -> "Toggle Auto-Gain Limit"

src/types.cpp Outdated
@@ -446,8 +446,8 @@ namespace librealsense
CASE(TRANSMITTER_FREQUENCY)
CASE(VERTICAL_BINNING)
CASE(RECEIVER_SENSITIVITY)
case RS2_OPTION_AUTO_GAIN_LIMIT_ON: return "Enable gain limit";
case RS2_OPTION_AUTO_EXPOSURE_LIMIT_ON: return "Enable exposure limit";
CASE(AUTO_GAIN_LIMIT_ON)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls rename the options to RS2_OPTION_AUTO_XXX_LIMIT_TOGGLE

@@ -700,20 +705,26 @@ namespace librealsense
return *_range;
}

auto_gain_limit_option::auto_gain_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range)
: option_base(range), _hwm(hwm), _sensor(ep)
auto_gain_limit_option::auto_gain_limit_option(hw_monitor& hwm, sensor_base* ep, option_range range, limits_option* gain_limit_enable)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace flat pointer with smart

}

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));

_gain_limit_enable->set_cached_limit(value);
if(value != get_range().max && _gain_limit_enable->query() == 0.f)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the value is valid the toggle shall be set on.
At this point the valid is already verified to be within the range - I don't think the check is required

class auto_exposure_limit_option : public option_base
{
public:
auto_exposure_limit_option(hw_monitor& hwm, sensor_base* depth_ep, option_range range);
auto_exposure_limit_option(hw_monitor& hwm, sensor_base* depth_ep, option_range range, limits_option* exposure_limit_enable);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use smart_ptrs here and below

src/ds5/ds5-options.h Outdated Show resolved Hide resolved
std::cout << "1. Check if initial values of limit control is set to max value" << std::endl;
auto init_limit = s.get_option(limit_control);
//auto enable = s.get_option(enable_limit);
REQUIRE(init_limit == range.max);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't use this assumption, the value is stored in FW only

Comment on lines 54 to 60
// 1. Toggle :
// - if toggle is off check that control limit value is 0
// - if toggle is on check that control value is in the correct range
auto limit = s.get_option(limits_value[i]);
auto toggle = s.get_option(limits_toggle[i]);
if (toggle == 0)
REQUIRE(limit == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the limit control zero is not in the valid range. It is only applicable to the toggle

s.set_option(enable_limit, 0.f);
auto post_disable = s.get_option(limit_control);
REQUIRE(post_disable == range.max);
for (auto i = 0; i < 2; i++) // exposure or gain
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also run the following check:

  • toggle on both dev1 and dev2 and set two distinct values for the auto-exposure /gain.
  • toggle both dev1 and dev2 off.
  • toggle dev1 on:
    • verify that the limit value is the value that was stored (cached) in dev1.
    • verify that for dev2 both the limit and the toggle values are similar to those of dev1

Comment on lines 49 to 50
std::string val = s.get_info(RS2_CAMERA_INFO_NAME);
if (!s.supports(limits_value[i]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to simplify the flow extract the depth sensor and check if the option is supported in

std::array < std::vector, 2> sensors = { dev1.query_sensors(), dev2.query_sensors() };

@ev-mp
Copy link
Collaborator

ev-mp commented Sep 13, 2021

Note that there is a merge conflict with the dev branch - needs to be resolved

Copy link
Collaborator

@ev-mp ev-mp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple unrequired files in src/types_XXX.cpp form to be removed

Comment on lines 442 to 454
float query_limit_value()
{
auto offset = 0;
if (_option == RS2_OPTION_AUTO_GAIN_LIMIT_TOGGLE)
offset = 4;
command cmd(ds::AUTO_CALIB);
cmd.param1 = 5;
auto res = _hwm.send(cmd);
if (res.empty())
throw invalid_value_exception("auto_exposure_limit_option::query result is empty!");

return static_cast<float>(*(reinterpret_cast<uint32_t*>(res.data() + offset)));
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call returns the actual value stored, rather than [0,1]. Is it intended?

Copy link
Contributor Author

@nohayassin nohayassin Oct 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func is redundant - removed

src/types.cpp Outdated
Comment on lines 15 to 18
#define STRCASE(T, X) case RS2_##T##_##X: {\
static const std::string s##T##_##X##_str = make_less_screamy(#X);\
return s##T##_##X##_str.c_str(); }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the code - this segment has been moved to "ro-string.cpp"


private:
std::function<void(const option&)> _record_action = [](const option&) {};
rs2_option _option;
float _value;
option_range _toggle_range;
const std::map<float, std::string> _description_per_value;
float _cached_limit;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need here - use the original "float _value;"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not used

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add maintainer's comment then

@@ -107,6 +108,11 @@ namespace librealsense
lazy<std::vector<uint8_t>> _color_calib_table_raw;
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
bool _is_locked = true;

std::shared_ptr<limits_option> _gain_limit_toggle_control;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_gain_limit_toggle_control and _ae_limit_toggle_control are registered directly into the options container. No need for extra owner

@@ -353,7 +353,7 @@ namespace librealsense
lazy<option_range> _range;
hw_monitor& _hwm;
sensor_base* _sensor;
std::shared_ptr<limits_option> _exposure_limit_enable;
std::shared_ptr<limits_option> _exposure_limit_toggle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store a weak_ptr to the handle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with weak_ptr

@@ -377,7 +377,7 @@ namespace librealsense
lazy<option_range> _range;
hw_monitor& _hwm;
sensor_base* _sensor;
std::shared_ptr<limits_option> _gain_limit_enable;
std::shared_ptr<limits_option> _gain_limit_toggle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines 431 to 432
virtual bool is_enabled() const override { return true; }
virtual const char* get_description() const override { return _description; };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if those already exist in the base class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not implemented in base class

Comment on lines 442 to 454
float query_limit_value()
{
auto offset = 0;
if (_option == RS2_OPTION_AUTO_GAIN_LIMIT_TOGGLE)
offset = 4;
command cmd(ds::AUTO_CALIB);
cmd.param1 = 5;
auto res = _hwm.send(cmd);
if (res.empty())
throw invalid_value_exception("auto_exposure_limit_option::query result is empty!");

return static_cast<float>(*(reinterpret_cast<uint32_t*>(res.data() + offset)));
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see references in code - where is it used?

Copy link
Collaborator

@ev-mp ev-mp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes required

@@ -662,17 +662,17 @@ namespace librealsense
{
return range;
};
_exposure_limit_toggle->set_cached_limit(range.max);
_exposure_limit_toggle.lock()->set_cached_limit(range.max);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for weak->share ptr conversion is successful

_exposure_limit_toggle->set_cached_limit(value);
if (_exposure_limit_toggle->query() == 0.f)
_exposure_limit_toggle->set(1);
_exposure_limit_toggle.lock()->set_cached_limit(value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here and below in 703, 720, 728-30, 759

Copy link
Collaborator

@ev-mp ev-mp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ev-mp ev-mp merged commit dd48c6d into IntelRealSense:development Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants