-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
There was a problem hiding this 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
include/librealsense2/h/rs_option.h
Outdated
RS2_OPTION_ENABLE_EXPOSURE_LIMIT, /**< Enable / disable color image auto-exposure*/ | ||
RS2_OPTION_ENABLE_GAIN_LIMIT, /**< Enable / disable color image auto-gain*/ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a new class?
src/ds5/ds5-options.h
Outdated
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) |
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
if (value == 1) // disabled: save current limit | ||
_cached_limit = _sensor->get_option(RS2_OPTION_AUTO_GAIN_LIMIT).query(); |
There was a problem hiding this comment.
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
case RS2_OPTION_ENABLE_GAIN_LIMIT: return "Disable gain limit"; | ||
case RS2_OPTION_ENABLE_EXPOSURE_LIMIT: return "Disable exposure limit"; |
There was a problem hiding this comment.
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?
include/librealsense2/h/rs_option.h
Outdated
@@ -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. */ |
There was a problem hiding this comment.
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
src/ds5/ds5-device.cpp
Outdated
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; |
There was a problem hiding this comment.
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
src/ds5/ds5-device.cpp
Outdated
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*/ }; |
There was a problem hiding this comment.
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
src/ds5/ds5-device.cpp
Outdated
|
||
//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()); |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
@@ -666,9 +666,12 @@ namespace librealsense | |||
|
|||
void auto_exposure_limit_option::set(float value) | |||
{ | |||
if (!is_valid(value)) | |||
if (!is_valid(value) && value != 0) |
There was a problem hiding this comment.
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?
src/ds5/ds5-options.cpp
Outdated
if (value != 0) | ||
_cached_limit = value; | ||
else | ||
value = get_range().max; |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
@@ -711,9 +714,13 @@ namespace librealsense | |||
|
|||
void auto_gain_limit_option::set(float value) | |||
{ | |||
if (!is_valid(value)) | |||
if (!is_valid(value) && value != 0) |
There was a problem hiding this comment.
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
case RS2_OPTION_AUTO_GAIN_LIMIT_ON: return "Enable gain limit"; | ||
case RS2_OPTION_AUTO_EXPOSURE_LIMIT_ON: return "Enable exposure limit"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo redundant here
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
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; } |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
_cached_limit = value; | ||
|
||
_exposure_limit_enable->set_cached_limit(value); | ||
if (value != get_range().max && _exposure_limit_enable->query() == 0.f) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/ds5/ds5-options.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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
src/ds5/ds5-device.cpp
Outdated
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); |
There was a problem hiding this comment.
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"
src/ds5/ds5-device.cpp
Outdated
//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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
} | ||
|
||
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) |
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
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); |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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
// 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
std::string val = s.get_info(RS2_CAMERA_INFO_NAME); | ||
if (!s.supports(limits_value[i])) |
There was a problem hiding this comment.
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() };
Note that there is a merge conflict with the dev branch - needs to be resolved |
There was a problem hiding this 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
src/ds5/ds5-options.h
Outdated
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))); | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
#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(); } | ||
|
There was a problem hiding this comment.
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"
src/ds5/ds5-options.h
Outdated
|
||
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; |
There was a problem hiding this comment.
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;"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not used
There was a problem hiding this comment.
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
src/ds5/ds5-device.h
Outdated
@@ -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; |
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
@@ -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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/ds5/ds5-options.h
Outdated
virtual bool is_enabled() const override { return true; } | ||
virtual const char* get_description() const override { return _description; }; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/ds5/ds5-options.h
Outdated
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))); | ||
}; |
There was a problem hiding this comment.
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?
63bfa6a
to
6fee1ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes required
src/ds5/ds5-options.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
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
src/ds5/ds5-options.cpp
Outdated
_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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Track on DSO-17393