Skip to content

Commit

Permalink
Merge pull request #3066 from ev-mp/alternating_emitter
Browse files Browse the repository at this point in the history
D430 Alternating emitter (on/off) mode control
  • Loading branch information
ev-mp authored Jan 20, 2019
2 parents a3e279d + 20cfc12 commit 73b4471
Show file tree
Hide file tree
Showing 14 changed files with 572 additions and 80 deletions.
25 changes: 16 additions & 9 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ namespace rs2
<< "/" << (long long)this;

subdevice_model::populate_options(options_metadata,
ss.str().c_str(),owner , block, owner ? &owner->options_invalidated : nullptr, error_message);
ss.str().c_str(),owner , block, owner ? &owner->_options_invalidated : nullptr, error_message);
}

subdevice_model::subdevice_model(
Expand Down Expand Up @@ -934,7 +934,7 @@ namespace rs2
ss << "##" << dev.get_info(RS2_CAMERA_INFO_NAME)
<< "/" << s->get_info(RS2_CAMERA_INFO_NAME)
<< "/" << (long long)this;
populate_options(options_metadata, ss.str().c_str(), this, s, &options_invalidated, error_message);
populate_options(options_metadata, ss.str().c_str(), this, s, &_options_invalidated, error_message);

try
{
Expand Down Expand Up @@ -1385,6 +1385,8 @@ namespace rs2

s->stop();

_options_invalidated = true;

queues.foreach([&](frame_queue& q)
{
frame f;
Expand Down Expand Up @@ -1444,15 +1446,16 @@ namespace rs2
throw;
}

_options_invalidated = true;
streaming = true;
}

void subdevice_model::update(std::string& error_message, notifications_model& notifications)
{
if (options_invalidated)
if (_options_invalidated)
{
next_option = 0;
options_invalidated = false;
_options_invalidated = false;
}
if (next_option < RS2_OPTION_COUNT)
{
Expand Down Expand Up @@ -2662,7 +2665,7 @@ namespace rs2
ImGui::Text("%s:", motion.name.c_str());
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip(motion.toolTip.c_str());
ImGui::SetTooltip("%s",motion.toolTip.c_str());
}
ImGui::PopStyleColor(1);

Expand Down Expand Up @@ -2740,7 +2743,7 @@ namespace rs2
ImGui::Text("%s:", pose.name.c_str());
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip(pose.toolTip.c_str());
ImGui::SetTooltip("%s",pose.toolTip.c_str());
}

switch (pose_frame.tracker_confidence) //color the line according to confidence
Expand Down Expand Up @@ -3002,7 +3005,8 @@ namespace rs2

device_model::device_model(device& dev, std::string& error_message, viewer_model& viewer)
: dev(dev),
syncer(viewer.syncer)
syncer(viewer.syncer),
_update_readonly_options_timer(std::chrono::seconds(6))
{
for (auto&& sub : dev.query_sensors())
{
Expand Down Expand Up @@ -5887,7 +5891,6 @@ namespace rs2
std::string& error_message,
device_model*& device_to_remove,
viewer_model& viewer, float windows_width,
bool update_read_only_options,
std::vector<std::function<void()>>& draw_later,
bool load_json_if_streaming,
json_loading_func json_loading,
Expand All @@ -5904,6 +5907,8 @@ namespace rs2
const float left_space = 3.f;
const float upper_space = 3.f;

bool update_read_only_options = _update_readonly_options_timer;

const ImVec2 initial_screen_pos = ImGui::GetCursorScreenPos();
//Upper Space
ImGui::GetWindowDrawList()->AddRectFilled({ initial_screen_pos.x,initial_screen_pos.y }, { initial_screen_pos.x + panel_width,initial_screen_pos.y + upper_space }, ImColor(black));
Expand Down Expand Up @@ -6160,6 +6165,7 @@ namespace rs2
{
viewer.synchronization_enable = false;
}
_update_readonly_options_timer.signal();
sub->play(profiles, viewer, dev_syncer);
}
catch (const error& e)
Expand Down Expand Up @@ -6219,6 +6225,7 @@ namespace rs2
}))
{
stop_recording = true;
_update_readonly_options_timer.signal();
}
}
if (ImGui::IsItemHovered())
Expand Down Expand Up @@ -6307,7 +6314,7 @@ namespace rs2
{
if (draw_advanced_controls(viewer, window, error_message))
{
sub->options_invalidated = true;
sub->_options_invalidated = true;
selected_file_preset.clear();
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ namespace rs2

frame_queues queues;
std::mutex _queue_lock;
bool options_invalidated = false;
bool _options_invalidated = false;
int next_option = RS2_OPTION_COUNT;
bool streaming = false;

Expand Down Expand Up @@ -554,7 +554,6 @@ namespace rs2
std::string& error_message,
device_model*& device_to_remove,
viewer_model& viewer, float windows_width,
bool update_read_only_options,
std::vector<std::function<void()>>& draw_later,
bool load_json_if_streaming = false,
json_loading_func json_loading = [](std::function<void()> load) {load(); },
Expand Down Expand Up @@ -612,6 +611,7 @@ namespace rs2

std::shared_ptr<recorder> _recorder;
std::vector<std::shared_ptr<subdevice_model>> live_subdevices;
periodic_timer _update_readonly_options_timer;
};

struct notification_data
Expand Down
5 changes: 5 additions & 0 deletions common/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,11 @@ namespace rs2
return false;
}

void signal() const
{
_last = _time.now() - _delta;
}

private:
timer _time;
mutable clock::time_point _last;
Expand Down
12 changes: 11 additions & 1 deletion src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ namespace librealsense
val |= d400_caps::CAP_IMU_SENSOR;
if (0xFF != (gvd_buf[fisheye_sensor_lb] & gvd_buf[fisheye_sensor_hb]))
val |= d400_caps::CAP_FISHEYE_SENSOR;
if (0x1 == gvd_buf[depth_sensor_type])
val |= d400_caps::CAP_ROLLING_SHUTTER; // Standard depth
if (0x2 == gvd_buf[depth_sensor_type])
val |= d400_caps::CAP_GLOBAL_SHUTTER; // Wide depth

return val;
}
Expand Down Expand Up @@ -464,7 +468,13 @@ namespace librealsense
RS2_OPTION_ASIC_TEMPERATURE));
}

if (_fw_version >= firmware_version("5.10.9.0") &&
// Alternating laser pattern is applicable for global shutter/active SKUs
auto mask = d400_caps::CAP_GLOBAL_SHUTTER | d400_caps::CAP_ACTIVE_PROJECTOR;
if ((_fw_version >= firmware_version("5.11.0.44")) && ((_device_capabilities & mask) == mask))
{
depth_ep.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<alternating_emitter_option>(*_hw_monitor, &depth_ep));
}
else if (_fw_version >= firmware_version("5.10.9.0") &&
_fw_version.experimental()) // Not yet available in production firmware
{
depth_ep.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<emitter_on_and_off_option>(*_hw_monitor, &depth_ep));
Expand Down
2 changes: 1 addition & 1 deletion src/ds5/ds5-motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace librealsense
}
else
{
LOG_INFO("IMU Extrinsic table error, switch to default calubration");
LOG_INFO("IMU Extrinsic table error, switch to default calibration");
// D435i specific - BMI055 assembly transformation based on mechanical drawing (mm)
// ([[ -1. , 0. , 0. , 5.52],
// [ 0. , 1. , 0. , 5.1 ],
Expand Down
32 changes: 32 additions & 0 deletions src/ds5/ds5-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,36 @@ namespace librealsense
{
return *_range;
}

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

void alternating_emitter_option::set(float value)
{
std::vector<uint8_t> pattern{};
if (static_cast<int>(value))
pattern = ds::alternating_emitter_pattern;

command cmd(ds::SETSUBPRESET, static_cast<int>(pattern.size()));
cmd.data = pattern;
auto res = _hwm.send(cmd);
_record_action(*this);
}

float alternating_emitter_option::query() const
{
command cmd(ds::GETSUBPRESETNAME);
auto res = _hwm.send(cmd);
if (res.size()>20)
throw invalid_value_exception("HWMON::GETSUBPRESETNAME invalid size");

static std::vector<uint8_t> alt_emitter_name(ds::alternating_emitter_pattern.begin()+2,ds::alternating_emitter_pattern.begin()+22);
return (alt_emitter_name == res);
}
}
22 changes: 22 additions & 0 deletions src/ds5/ds5-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,26 @@ namespace librealsense
hw_monitor& _hwm;
sensor_base* _sensor;
};

class alternating_emitter_option : public option
{
public:
alternating_emitter_option(hw_monitor& hwm, sensor_base* depth_ep);
virtual ~alternating_emitter_option() = default;
virtual void set(float value) override;
virtual float query() const override;
virtual option_range get_range() const override { return *_range; }
virtual bool is_enabled() const override { return true; }
virtual const char* get_description() const override
{
return "Alternating Emitter Pattern: 0:disabled(default), 1:enabled( emitter is toggled on/off on per-frame basis)";
}
virtual void enable_recording(std::function<void(const option &)> record_action) { _record_action = record_action; }

private:
std::function<void(const option &)> _record_action = [](const option&) {};
lazy<option_range> _range;
hw_monitor& _hwm;
sensor_base* _sensor;
};
}
53 changes: 50 additions & 3 deletions src/ds5/ds5-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,44 @@ namespace librealsense
GETRGBAEROI = 0x76, // get RGB auto-exposure region of interest
SET_PWM_ON_OFF = 0x77, // set emitter on and off mode
GET_PWM_ON_OFF = 0x78, // get emitter on and off mode
};
SETSUBPRESET = 0x7B, // Download sub-preset
GETSUBPRESET = 0x7C, // Upload the current sub-preset
GETSUBPRESETNAME= 0x7D, // Retrieve sub-preset's name
};

#define TOSTRING(arg) #arg
#define VAR_ARG_STR(x) TOSTRING(x)
#define ENUM2STR(x) case(x):return VAR_ARG_STR(x);

inline std::string fw_cmd2str(const fw_cmd state)
{
switch(state)
{
ENUM2STR(GLD);
ENUM2STR(GVD);
ENUM2STR(GETINTCAL);
ENUM2STR(OBW);
ENUM2STR(SET_ADV);
ENUM2STR(GET_ADV);
ENUM2STR(EN_ADV);
ENUM2STR(UAMG);
ENUM2STR(SETAEROI);
ENUM2STR(GETAEROI);
ENUM2STR(MMER);
ENUM2STR(GET_EXTRINSICS);
ENUM2STR(SET_CAM_SYNC);
ENUM2STR(GET_CAM_SYNC);
ENUM2STR(SETRGBAEROI);
ENUM2STR(GETRGBAEROI);
ENUM2STR(SET_PWM_ON_OFF);
ENUM2STR(GET_PWM_ON_OFF);
ENUM2STR(SETSUBPRESET);
ENUM2STR(GETSUBPRESET);
ENUM2STR(GETSUBPRESETNAME);
default:
return (to_string() << "Unrecognized FW command " << state);
}
}

const int etDepthTableControl = 9; // Identifier of the depth table control

Expand All @@ -163,6 +200,8 @@ namespace librealsense
CAP_RGB_SENSOR = (1u << 1), // Dedicated RGB sensor
CAP_FISHEYE_SENSOR = (1u << 2), // TM1
CAP_IMU_SENSOR = (1u << 3),
CAP_GLOBAL_SHUTTER = (1u << 4),
CAP_ROLLING_SHUTTER = (1u << 5),
CAP_MAX
};

Expand All @@ -171,7 +210,9 @@ namespace librealsense
{ d400_caps::CAP_ACTIVE_PROJECTOR, "Active Projector" },
{ d400_caps::CAP_RGB_SENSOR, "RGB Sensor" },
{ d400_caps::CAP_FISHEYE_SENSOR, "Fisheye Sensor" },
{ d400_caps::CAP_IMU_SENSOR, "IMU Sensor" }
{ d400_caps::CAP_IMU_SENSOR, "IMU Sensor" },
{ d400_caps::CAP_GLOBAL_SHUTTER, "Global Shutter" },
{ d400_caps::CAP_ROLLING_SHUTTER, "Rolling Shutter" }
};

inline d400_caps operator &(const d400_caps lhs, const d400_caps rhs)
Expand All @@ -192,7 +233,8 @@ namespace librealsense
inline std::ostream& operator <<(std::ostream& stream, const d400_caps& cap)
{
for (auto i : { d400_caps::CAP_ACTIVE_PROJECTOR,d400_caps::CAP_RGB_SENSOR,
d400_caps::CAP_FISHEYE_SENSOR, d400_caps::CAP_IMU_SENSOR})
d400_caps::CAP_FISHEYE_SENSOR, d400_caps::CAP_IMU_SENSOR,
d400_caps::CAP_GLOBAL_SHUTTER, d400_caps::CAP_ROLLING_SHUTTER })
{
if (i==(i&cap))
stream << d400_capabilities_names.at(i) << " ";
Expand Down Expand Up @@ -486,6 +528,7 @@ namespace librealsense
module_serial_offset = 48,
fisheye_sensor_lb = 112,
fisheye_sensor_hb = 113,
depth_sensor_type = 166,
active_projector = 170,
rgb_sensor = 174,
imu_sensor = 178,
Expand Down Expand Up @@ -623,5 +666,9 @@ namespace librealsense

std::vector<platform::uvc_device_info> filter_device_by_capability(const std::vector<platform::uvc_device_info>& devices, d400_caps caps);

const std::vector<uint8_t> alternating_emitter_pattern { 0x19, 0,
0x41, 0x6c, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x45, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0,
0, 0x2, 0, 0x5, 0, 0x1, 0x1, 0, 0, 0, 0, 0, 0, 0, 0x5, 0, 0x1, 0x1, 0, 0, 0, 0x1, 0, 0, 0 };

} // librealsense::ds
} // namespace librealsense
5 changes: 3 additions & 2 deletions src/hw-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ namespace librealsense
details.receivedOpcode[1], details.receivedOpcode[0]);
if (opCodeAsUint32 != opCodeXmit)
{
throw invalid_value_exception(to_string() << "OpCodes do not match! Sent "
<< opCodeXmit << " but received " << static_cast<int>(opCodeAsUint32) << "!");
auto err_type = static_cast<hwmon_response>(opCodeAsUint32);
throw invalid_value_exception(to_string() << "hwmon command 0x" << std::hex << opCodeXmit << " failed. Error type: "
<< hwmon_error2str(err_type) << " (" << std::dec <<(int)err_type << ").");
}

return std::vector<uint8_t>(newCommand.receivedCommandData,
Expand Down
Loading

0 comments on commit 73b4471

Please sign in to comment.