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

Advanced mode - add disparity modulation function control #4100

Merged
merged 3 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion common/realsense-ui-advanced-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct advanced_mode_control
param_group<STDepthTableControl> depth_table;
param_group<STAEControl> ae;
param_group<STCensusRadius> census;
param_group<STAFactor> amp_factor;
};

inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced,
Expand All @@ -215,6 +216,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced,
amc.cc.vals[k] = advanced.get_color_correction(k);
amc.depth_table.vals[k] = advanced.get_depth_table(k);
amc.census.vals[k] = advanced.get_census(k);
amc.amp_factor.vals[k] = advanced.get_amp_factor(k);
}
amc.hdad.vals[0] = advanced.get_hdad();
amc.hdad.vals[1] = amc.hdad.vals[0]; //setting min/max to the same value
Expand Down Expand Up @@ -601,5 +603,31 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced,

ImGui::TreePop();
}
}

if (ImGui::TreeNode("Disparity Modulation"))
{
ImGui::PushItemWidth(-1);

auto to_set = false;

slider_float(error_message, "Amplitude Factor", amc.amp_factor.vals, &STAFactor::amplitude, to_set);

ImGui::PopItemWidth();

if (to_set)
{
try
{
advanced.set_amp_factor(amc.amp_factor.vals[0]);
}
catch (...)
{
ImGui::TreePop();
throw;
}
was_set = true;
}

ImGui::TreePop();
}
}
5 changes: 5 additions & 0 deletions include/librealsense2/h/rs_advanced_mode_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ typedef struct
uint32_t vDiameter;
}STCensusRadius;

typedef struct
{
float amplitude;
}STAFactor;

#ifdef __cplusplus
extern "C"{
#endif
Expand Down
5 changes: 5 additions & 0 deletions include/librealsense2/rs_advanced_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ void rs2_set_census(rs2_device* dev, const STCensusRadius* group, rs2_error** e

void rs2_get_census(rs2_device* dev, STCensusRadius* group, int mode, rs2_error** error);

void rs2_set_amp_factor(rs2_device* dev, const STAFactor* group, rs2_error** error);

/* Gets new values for STAFactor, returns 0 if success */
void rs2_get_amp_factor(rs2_device* dev, STAFactor* group, int mode, rs2_error** error);

/* Load JSON and apply advanced-mode controls, returns 0 if success */
void rs2_load_json(rs2_device* dev, const void* json_content, unsigned content_size, rs2_error** error);

Expand Down
23 changes: 23 additions & 0 deletions include/librealsense2/rs_advanced_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef R4XX_ADVANCED_MODE_HPP
#define R4XX_ADVANCED_MODE_HPP

#include <cmath>
#include "rs.hpp"
#include "rs_advanced_mode.h"

Expand Down Expand Up @@ -244,6 +245,23 @@ namespace rs400
return group;
}

void set_amp_factor(const STAFactor& group)
{
rs2_error* e = nullptr;
rs2_set_amp_factor(_dev.get(), &group, &e);
rs2::error::handle(e);
}

STAFactor get_amp_factor(int mode = 0) const
{
rs2_error* e = nullptr;
STAFactor group{};
rs2_get_amp_factor(_dev.get(), &group, mode, &e);
rs2::error::handle(e);

return group;
}

std::string serialize_json() const
{
std::string results;
Expand Down Expand Up @@ -389,5 +407,10 @@ inline bool operator==(const STCensusRadius& a, const STCensusRadius& b)
a.vDiameter == b.vDiameter);
}

inline bool operator==(const STAFactor& a, const STAFactor& b)
{
return (fabs(a.amplitude - b.amplitude) < std::numeric_limits<float>::epsilon());
}


#endif // R4XX_ADVANCED_MODE_HPP
4 changes: 2 additions & 2 deletions src/command_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ namespace librealsense

auto hwm = *it;
uint32_t transfered_count = 0;
auto sts = m->bulk_transfer(hwm->first_endpoint(RS2_USB_ENDPOINT_DIRECTION_WRITE), const_cast<uint8_t*>(data.data()), data.size(), transfered_count, timeout_ms);
auto sts = m->bulk_transfer(hwm->first_endpoint(RS2_USB_ENDPOINT_DIRECTION_WRITE), const_cast<uint8_t*>(data.data()), static_cast<uint32_t>(data.size()), transfered_count, timeout_ms);

if (sts != RS2_USB_STATUS_SUCCESS)
throw std::runtime_error("command transfer failed to execute bulk transfer, error: " + usb_status_to_string.at(sts));

std::vector<uint8_t> output(DEFAULT_BUFFER_SIZE);
sts = m->bulk_transfer(hwm->first_endpoint(RS2_USB_ENDPOINT_DIRECTION_READ), output.data(), output.size(), transfered_count, timeout_ms);
sts = m->bulk_transfer(hwm->first_endpoint(RS2_USB_ENDPOINT_DIRECTION_READ), output.data(), static_cast<uint32_t>(output.size()), transfered_count, timeout_ms);

if (sts != RS2_USB_STATUS_SUCCESS)
throw std::runtime_error("command transfer failed to execute bulk transfer, error: " + usb_status_to_string.at(sts));
Expand Down
10 changes: 9 additions & 1 deletion src/core/advanced_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ typedef enum
etDepthTableControl = 9,
etAEControl = 10,
etCencusRadius9 = 11,
etLastAdvancedModeGroup = 12, // Must be last
etAFactor = 12,
etLastAdvancedModeGroup = 13, // Must be last
}
EtAdvancedModeRegGroup;

Expand All @@ -51,6 +52,7 @@ namespace librealsense
MAP_ADVANCED_MODE(STDepthTableControl, etDepthTableControl);
MAP_ADVANCED_MODE(STAEControl, etAEControl);
MAP_ADVANCED_MODE(STCensusRadius, etCencusRadius9);
MAP_ADVANCED_MODE(STAFactor, etAFactor);


class ds5_advanced_mode_interface : public recordable<ds5_advanced_mode_interface>
Expand All @@ -76,6 +78,7 @@ namespace librealsense
virtual void get_depth_table_control(STDepthTableControl* ptr, int mode = 0) const = 0;
virtual void get_ae_control(STAEControl* ptr, int mode = 0) const = 0;
virtual void get_census_radius(STCensusRadius* ptr, int mode = 0) const = 0;
virtual void get_amp_factor(STAFactor* ptr, int mode = 0) const = 0;

virtual void set_depth_control_group(const STDepthControlGroup& val) = 0;
virtual void set_rsm(const STRsm& val) = 0;
Expand All @@ -89,6 +92,7 @@ namespace librealsense
virtual void set_depth_table_control(const STDepthTableControl& val) = 0;
virtual void set_ae_control(const STAEControl& val) = 0;
virtual void set_census_radius(const STCensusRadius& val) = 0;
virtual void set_amp_factor(const STAFactor& val) = 0;

virtual std::vector<uint8_t> serialize_json() const = 0;
virtual void load_json(const std::string& json_content) = 0;
Expand Down Expand Up @@ -129,6 +133,7 @@ namespace librealsense
void get_depth_table_control(STDepthTableControl* ptr, int mode = 0) const override;
void get_ae_control(STAEControl* ptr, int mode = 0) const override;
void get_census_radius(STCensusRadius* ptr, int mode = 0) const override;
void get_amp_factor(STAFactor* ptr, int mode = 0) const override;

void set_depth_control_group(const STDepthControlGroup& val) override;
void set_rsm(const STRsm& val) override;
Expand All @@ -142,6 +147,7 @@ namespace librealsense
void set_depth_table_control(const STDepthTableControl& val) override;
void set_ae_control(const STAEControl& val) override;
void set_census_radius(const STCensusRadius& val) override;
void set_amp_factor(const STAFactor& val) override;

std::vector<uint8_t> serialize_json() const override;
void load_json(const std::string& json_content) override;
Expand Down Expand Up @@ -199,6 +205,8 @@ namespace librealsense
lazy<ds5_color_sensor*> _color_sensor;
lazy<bool> _enabled;
std::shared_ptr<advanced_mode_preset_option> _preset_opt;
bool _rgb_exposure_gain_bind;
bool _amplitude_factor_support;

static const uint16_t HW_MONITOR_COMMAND_SIZE = 1000;
static const uint16_t HW_MONITOR_BUFFER_SIZE = 1024;
Expand Down
28 changes: 26 additions & 2 deletions src/ds5/advanced_mode/advanced_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace librealsense
uvc_sensor& depth_sensor)
: _hw_monitor(hwm),
_depth_sensor(depth_sensor),
_color_sensor(nullptr)
_color_sensor(nullptr),
_rgb_exposure_gain_bind(false),
_amplitude_factor_support(false)
{
_enabled = [this]() {
auto results = send_receive(encode_command(ds::fw_cmd::UAMG));
Expand All @@ -38,6 +40,8 @@ namespace librealsense
}
return (ds5_color_sensor*)nullptr;
};
auto fw_ver = firmware_version(_depth_sensor.get_device().get_info(rs2_camera_info::RS2_CAMERA_INFO_FIRMWARE_VERSION));
_amplitude_factor_support = _rgb_exposure_gain_bind = (fw_ver >= firmware_version("5.11.9.0"));
}

bool ds5_advanced_mode_base::is_enabled() const
Expand Down Expand Up @@ -225,6 +229,12 @@ namespace librealsense
*ptr = get<STCensusRadius>(advanced_mode_traits<STCensusRadius>::group, nullptr, mode);
}

void ds5_advanced_mode_base::get_amp_factor(STAFactor* ptr, int mode) const
{
*ptr = _amplitude_factor_support ? get<STAFactor>(advanced_mode_traits<STAFactor>::group, nullptr, mode) :
[]() { STAFactor af; af.amplitude = 0.f; return af; }();
}

bool ds5_advanced_mode_base::supports_option(const uvc_sensor& sensor, rs2_option opt) const
{
return sensor.supports_option(opt);
Expand Down Expand Up @@ -481,6 +491,15 @@ namespace librealsense
_preset_opt->set(RS2_RS400_VISUAL_PRESET_CUSTOM);
}

void ds5_advanced_mode_base::set_amp_factor(const STAFactor& val)
{
if (_amplitude_factor_support)
{
set(val, advanced_mode_traits<STAFactor>::group);
_preset_opt->set(RS2_RS400_VISUAL_PRESET_CUSTOM);
}
}

void ds5_advanced_mode_base::set_laser_power(const laser_power_control& val)
{
if (val.was_set)
Expand Down Expand Up @@ -679,6 +698,7 @@ namespace librealsense
get_depth_table_control(&p.depth_table);
get_ae_control(&p.ae);
get_census_radius(&p.census);
get_amp_factor(&p.amplitude_factor);
get_laser_power(&p.laser_power);
get_laser_state(&p.laser_state);
get_depth_exposure(&p.depth_exposure);
Expand Down Expand Up @@ -719,6 +739,8 @@ namespace librealsense
set(p.depth_table , advanced_mode_traits<STDepthTableControl>::group);
set(p.ae , advanced_mode_traits<STAEControl>::group);
set(p.census , advanced_mode_traits<STCensusRadius>::group);
if (_amplitude_factor_support)
set(p.amplitude_factor, advanced_mode_traits<STAFactor>::group);

set_laser_state(p.laser_state);
if (p.laser_state.was_set && p.laser_state.laser_state == 1) // 1 - on
Expand All @@ -733,12 +755,14 @@ namespace librealsense

set_color_auto_exposure(p.color_auto_exposure);
if (p.color_auto_exposure.was_set && p.color_auto_exposure.auto_exposure == 0)
{
set_color_exposure(p.color_exposure);
set_color_gain(p.color_gain);
}

set_color_backlight_compensation(p.color_backlight_compensation);
set_color_brightness(p.color_brightness);
set_color_contrast(p.color_contrast);
set_color_gain(p.color_gain);
set_color_gamma(p.color_gamma);
set_color_hue(p.color_hue);
set_color_saturation(p.color_saturation);
Expand Down
6 changes: 6 additions & 0 deletions src/ds5/advanced_mode/json_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace librealsense
param_group<STDepthTableControl> depth_table;
param_group<STAEControl> ae;
param_group<STCensusRadius> census;
param_group<STAFactor> a_factor;
param_group<laser_state_control> laser_state;
param_group<laser_power_control> laser_power;
param_group<exposure_control> depth_exposure;
Expand Down Expand Up @@ -87,6 +88,7 @@ namespace librealsense
depth_table.vals[0] = other.depth_table;
ae.vals[0] = other.ae;
census.vals[0] = other.census;
a_factor.vals[0] = other.amplitude_factor;
laser_state.vals[0] = other.laser_state;
laser_power.vals[0] = other.laser_power;
depth_exposure.vals[0] = other.depth_exposure;
Expand Down Expand Up @@ -391,6 +393,9 @@ namespace librealsense
{ "param-censususize", make_field(p.census, &STCensusRadius::uDiameter) },
{ "param-censusvsize", make_field(p.census, &STCensusRadius::vDiameter) },

// Depth Linearity
{ "param-amplitude-factor", make_field(p.a_factor, &STAFactor::amplitude) },

// Ignored fields
{ "param-regionspatialthresholdu", make_ignored_field() },
{ "param-regionspatialthresholdv", make_ignored_field() },
Expand Down Expand Up @@ -506,6 +511,7 @@ namespace librealsense
update_preset_control(in_preset.depth_table , p.depth_table);
update_preset_control(in_preset.ae , p.ae);
update_preset_control(in_preset.census , p.census);
update_preset_control(in_preset.amplitude_factor , p.a_factor);
update_preset_camera_control(in_preset.laser_power , p.laser_power);
update_preset_camera_control(in_preset.laser_state , p.laser_state);
update_preset_camera_control(in_preset.depth_exposure , p.depth_exposure);
Expand Down
1 change: 1 addition & 0 deletions src/ds5/advanced_mode/presets.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace librealsense
STDepthTableControl depth_table;
STAEControl ae;
STCensusRadius census;
STAFactor amplitude_factor;
laser_state_control laser_state;
laser_power_control laser_power;
exposure_control depth_exposure;
Expand Down
21 changes: 21 additions & 0 deletions src/ds5/advanced_mode/rs_advanced_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,27 @@ void rs2_get_census(rs2_device* dev, STCensusRadius* group, int mode, rs2_error*
}
HANDLE_EXCEPTIONS_AND_RETURN(, dev, group, mode)

void rs2_set_amp_factor(rs2_device* dev, const STAFactor* group, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);
VALIDATE_NOT_NULL(group);
auto advanced_mode = VALIDATE_INTERFACE(dev->device, librealsense::ds5_advanced_mode_interface);
advanced_mode->set_amp_factor(*group);
}
HANDLE_EXCEPTIONS_AND_RETURN(, dev, group)

void rs2_get_amp_factor(rs2_device* dev, STAFactor* group, int mode, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);
VALIDATE_NOT_NULL(group);
auto advanced_mode = VALIDATE_INTERFACE(dev->device, librealsense::ds5_advanced_mode_interface);
advanced_mode->get_amp_factor(group, mode);
}
HANDLE_EXCEPTIONS_AND_RETURN(, dev, group, mode)
void rs2_set_amp_factor(rs2_device* dev, const STAFactor* group, rs2_error** error);

void rs2_get_amp_factor(rs2_device* dev, STAFactor* group, int mode, rs2_error** error);

void rs2_load_json(rs2_device* dev, const void* json_content, unsigned content_size, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);
Expand Down
2 changes: 1 addition & 1 deletion src/ds5/ds5-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ namespace librealsense
hid_ep->register_on_before_frame_callback(align_imu_axes);
}

if (!motion_module_fw_version.empty())
if ((!motion_module_fw_version.empty()) && ("255.255.255.255" != motion_module_fw_version))
register_info(RS2_CAMERA_INFO_FIRMWARE_VERSION, motion_module_fw_version);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ EXPORTS
rs2_get_ae_control
rs2_set_census
rs2_get_census
rs2_get_amp_factor
rs2_set_amp_factor
rs2_rs400_visual_preset_to_string
rs2_is_enabled
rs2_toggle_advanced_mode
Expand Down
1 change: 1 addition & 0 deletions tools/depth-quality/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif()
./depth-quality-model.cpp
./depth-metrics.h
../../common/rendering.h
../../common/realsense-ui-advanced-mode.h
../../common/ux-window.h
../../common/ux-window.cpp
../../common/model-views.h
Expand Down
1 change: 1 addition & 0 deletions tools/realsense-viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ endif()
../../third-party/imgui/imgui-fonts-karla.hpp
../../third-party/imgui/imgui-fonts-fontawesome.hpp
../../common/rendering.h
../../common/realsense-ui-advanced-mode.h
../../common/model-views.h
../../common/model-views.cpp
../../common/ux-window.h
Expand Down