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

SR305 added #5997

Merged
merged 3 commits into from
Mar 10, 2020
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
101 changes: 63 additions & 38 deletions src/ivcam/sr300.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,24 @@ namespace librealsense
};

std::shared_ptr<device_interface> sr300_info::create(std::shared_ptr<context> ctx,
bool register_device_notifications) const
bool register_device_notifications) const
{
return std::make_shared<sr300_camera>(ctx, _color, _depth, _hwm,
this->get_device_data(),
register_device_notifications);
auto pid = _depth.pid;
switch (pid)
{
case SR300_PID:
return std::make_shared<sr300_camera>(ctx, _color, _depth, _hwm,
this->get_device_data(),
register_device_notifications);
case SR300v2_PID:
return std::make_shared<sr305_camera>(ctx, _color, _depth, _hwm,
this->get_device_data(),
register_device_notifications);
default:
throw std::runtime_error(to_string() << "Unsupported SR300 model! 0x"
<< std::hex << std::setw(4) << std::setfill('0') << (int)pid);
}

}

std::vector<std::shared_ptr<device_info>> sr300_info::pick_sr300_devices(
Expand Down Expand Up @@ -400,17 +413,17 @@ namespace librealsense
}

sr300_camera::sr300_camera(std::shared_ptr<context> ctx, const platform::uvc_device_info &color,
const platform::uvc_device_info &depth,
const platform::usb_device_info &hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications)
const platform::uvc_device_info &depth,
const platform::usb_device_info &hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications)
: device(ctx, group, register_device_notifications),
_depth_device_idx(add_sensor(create_depth_device(ctx, depth))),
_color_device_idx(add_sensor(create_color_device(ctx, color))),
_hw_monitor(std::make_shared<hw_monitor>(std::make_shared<locked_transfer>(ctx->get_backend().create_usb_device(hwm_device), get_raw_depth_sensor()))),
_depth_stream(new stream(RS2_STREAM_DEPTH)),
_ir_stream(new stream(RS2_STREAM_INFRARED)),
_color_stream(new stream(RS2_STREAM_COLOR))
_depth_device_idx(add_sensor(create_depth_device(ctx, depth))),
_depth_stream(new stream(RS2_STREAM_DEPTH)),
_ir_stream(new stream(RS2_STREAM_INFRARED)),
_color_stream(new stream(RS2_STREAM_COLOR)),
_color_device_idx(add_sensor(create_color_device(ctx, color))),
_hw_monitor(std::make_shared<hw_monitor>(std::make_shared<locked_transfer>(ctx->get_backend().create_usb_device(hwm_device), get_raw_depth_sensor())))
{
using namespace ivcam;
static auto device_name = "Intel RealSense SR300";
Expand All @@ -429,16 +442,16 @@ namespace librealsense
auto pid_hex_str = hexify(color.pid);
//auto recommended_fw_version = firmware_version(SR3XX_RECOMMENDED_FIRMWARE_VERSION);

register_info(RS2_CAMERA_INFO_NAME, device_name);
register_info(RS2_CAMERA_INFO_SERIAL_NUMBER, serial);
register_info(RS2_CAMERA_INFO_NAME, device_name);
register_info(RS2_CAMERA_INFO_SERIAL_NUMBER, serial);
register_info(RS2_CAMERA_INFO_ASIC_SERIAL_NUMBER, serial);
register_info(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID, serial);
register_info(RS2_CAMERA_INFO_FIRMWARE_VERSION, fw_version);
register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, depth.device_path);
register_info(RS2_CAMERA_INFO_DEBUG_OP_CODE, std::to_string(static_cast<int>(fw_cmd::GLD)));
register_info(RS2_CAMERA_INFO_PRODUCT_ID, pid_hex_str);
register_info(RS2_CAMERA_INFO_PRODUCT_LINE, "SR300");
register_info(RS2_CAMERA_INFO_CAMERA_LOCKED, _is_locked ? "YES" : "NO");
register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, depth.device_path);
register_info(RS2_CAMERA_INFO_DEBUG_OP_CODE, std::to_string(static_cast<int>(fw_cmd::GLD)));
register_info(RS2_CAMERA_INFO_PRODUCT_ID, pid_hex_str);
register_info(RS2_CAMERA_INFO_PRODUCT_LINE, "SR300");
register_info(RS2_CAMERA_INFO_CAMERA_LOCKED, _is_locked ? "YES" : "NO");
//register_info(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION, recommended_fw_version);

register_autorange_options();
Expand All @@ -462,20 +475,32 @@ namespace librealsense
register_stream_to_extrinsic_group(*_color_stream, 0);

get_depth_sensor().register_option(RS2_OPTION_DEPTH_UNITS,
std::make_shared<const_value_option>("Number of meters represented by a single depth unit",
lazy<float>([this]() {
auto c = *_camer_calib_params;
return (c.Rmax / 1000 / 0xFFFF);
})));
std::make_shared<const_value_option>("Number of meters represented by a single depth unit",
lazy<float>([this]() {
auto c = *_camer_calib_params;
return (c.Rmax / 1000 / 0xFFFF);
})));

if (firmware_version(fw_version) >= firmware_version("3.26.2.0"))
{
roi_sensor_interface* roi_sensor;
if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&get_sensor(_color_device_idx))))
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor,
(ds::fw_cmd)ivcam::fw_cmd::SetRgbAeRoi));
}
}

sr305_camera::sr305_camera(std::shared_ptr<context> ctx, const platform::uvc_device_info &color,
const platform::uvc_device_info &depth,
const platform::usb_device_info &hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications)
: sr300_camera(ctx, color, depth, hwm_device, group, register_device_notifications) {

static auto device_name = "Intel RealSense SR305";
update_info(RS2_CAMERA_INFO_NAME, device_name);

roi_sensor_interface* roi_sensor;
if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&get_sensor(_color_device_idx))))
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor,
(ds::fw_cmd)ivcam::fw_cmd::SetRgbAeRoi));

}


void sr300_camera::create_snapshot(std::shared_ptr<debug_interface>& snapshot) const
{
//TODO: implement
Expand All @@ -490,7 +515,7 @@ namespace librealsense
{
std::lock_guard<std::recursive_mutex> lock(_mtx);

if(has_metadata_ts(frame))
if (has_metadata_ts(frame))
{
auto f = std::dynamic_pointer_cast<librealsense::frame>(frame);
if (!f)
Expand Down Expand Up @@ -551,18 +576,18 @@ namespace librealsense
{
std::lock_guard<std::recursive_mutex> lock(_mtx);

return (has_metadata_ts(frame))? RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK : _backup_timestamp_reader->get_frame_timestamp_domain(frame);
return (has_metadata_ts(frame)) ? RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK : _backup_timestamp_reader->get_frame_timestamp_domain(frame);
}

std::shared_ptr<matcher> sr300_camera::create_matcher(const frame_holder& frame) const
{
std::vector<std::shared_ptr<matcher>> depth_matchers;

std::vector<stream_interface*> streams = { _depth_stream.get(), _ir_stream.get()};
std::vector<stream_interface*> streams = { _depth_stream.get(), _ir_stream.get() };

for (auto& s : streams)
{
depth_matchers.push_back(std::make_shared<identity_matcher>( s->get_unique_id(), s->get_stream_type()));
depth_matchers.push_back(std::make_shared<identity_matcher>(s->get_unique_id(), s->get_stream_type()));
}
std::vector<std::shared_ptr<matcher>> matchers;
if (!frame.frame->supports_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER))
Expand All @@ -574,7 +599,7 @@ namespace librealsense
matchers.push_back(std::make_shared<frame_number_composite_matcher>(depth_matchers));
}

auto color_matcher = std::make_shared<identity_matcher>( _color_stream->get_unique_id(), _color_stream->get_stream_type());
auto color_matcher = std::make_shared<identity_matcher>(_color_stream->get_unique_id(), _color_stream->get_stream_type());
matchers.push_back(color_matcher);

return std::make_shared<timestamp_composite_matcher>(matchers);
Expand Down
63 changes: 39 additions & 24 deletions src/ivcam/sr300.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace librealsense
LOG_ERROR("Frame is not valid. Failed to downcast to librealsense::frame.");
return RS2_TIMESTAMP_DOMAIN_COUNT;
}
if(f->additional_data.metadata_size >= platform::uvc_header_size )
if (f->additional_data.metadata_size >= platform::uvc_header_size)
return RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK;
else
return RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME;
Expand All @@ -101,10 +101,10 @@ namespace librealsense

class sr300_timestamp_reader_from_metadata : public frame_timestamp_reader
{
std::unique_ptr<sr300_timestamp_reader> _backup_timestamp_reader;
bool one_time_note;
mutable std::recursive_mutex _mtx;
arithmetic_wraparound<uint32_t,uint64_t > ts_wrap;
std::unique_ptr<sr300_timestamp_reader> _backup_timestamp_reader;
bool one_time_note;
mutable std::recursive_mutex _mtx;
arithmetic_wraparound<uint32_t, uint64_t > ts_wrap;

protected:

Expand All @@ -117,8 +117,8 @@ namespace librealsense
return false;
}
// Metadata support for a specific stream is immutable
const bool has_md_ts = [&]{ std::lock_guard<std::recursive_mutex> lock(_mtx);
return ((f->additional_data.metadata_blob.data() != nullptr) && (f->additional_data.metadata_size >= platform::uvc_header_size) && ((byte*)f->additional_data.metadata_blob.data())[0] >= platform::uvc_header_size);
const bool has_md_ts = [&] { std::lock_guard<std::recursive_mutex> lock(_mtx);
return ((f->additional_data.metadata_blob.data() != nullptr) && (f->additional_data.metadata_size >= platform::uvc_header_size) && ((byte*)f->additional_data.metadata_blob.data())[0] >= platform::uvc_header_size);
}();

return has_md_ts;
Expand All @@ -134,7 +134,7 @@ namespace librealsense
}
// Metadata support for a specific stream is immutable
const bool has_md_frame_counter = [&] { std::lock_guard<std::recursive_mutex> lock(_mtx);
return ((f->additional_data.metadata_blob.data() != nullptr) && (f->additional_data.metadata_size > platform::uvc_header_size) && ((byte*)f->additional_data.metadata_blob.data())[0] > platform::uvc_header_size);
return ((f->additional_data.metadata_blob.data() != nullptr) && (f->additional_data.metadata_size > platform::uvc_header_size) && ((byte*)f->additional_data.metadata_blob.data())[0] > platform::uvc_header_size);
}();

return has_md_frame_counter;
Expand All @@ -160,14 +160,14 @@ namespace librealsense
{
public:
std::shared_ptr<device_interface> create(std::shared_ptr<context> ctx,
bool register_device_notifications) const override;
bool register_device_notifications) const override;

sr300_info(std::shared_ptr<context> ctx,
platform::uvc_device_info color,
platform::uvc_device_info depth,
platform::usb_device_info hwm)
platform::uvc_device_info color,
platform::uvc_device_info depth,
platform::usb_device_info hwm)
: device_info(ctx), _color(std::move(color)),
_depth(std::move(depth)), _hwm(std::move(hwm)) {}
_depth(std::move(depth)), _hwm(std::move(hwm)) {}

static std::vector<std::shared_ptr<device_info>> pick_sr300_devices(
std::shared_ptr<context> ctx,
Expand All @@ -185,7 +185,7 @@ namespace librealsense
platform::usb_device_info _hwm;
};

class sr300_camera final : public virtual device, public debug_interface, public updatable
class sr300_camera : public device, public debug_interface, public updatable
{
public:
std::vector<tagged_profile> get_profiles_tags() const override
Expand Down Expand Up @@ -228,7 +228,7 @@ namespace librealsense

explicit preset_option(sr300_camera& owner, const option_range& opt_range)
: option_base(opt_range),
_owner(owner)
_owner(owner)
{}

private:
Expand Down Expand Up @@ -387,19 +387,19 @@ namespace librealsense
}

synthetic_sensor& get_depth_sensor() { return dynamic_cast<synthetic_sensor&>(get_sensor(_depth_device_idx)); }

uvc_sensor& get_raw_depth_sensor()
{
synthetic_sensor& depth_sensor = get_depth_sensor();
return dynamic_cast<uvc_sensor&>(*depth_sensor.get_raw_sensor());
}

sr300_camera(std::shared_ptr<context> ctx,
const platform::uvc_device_info& color,
const platform::uvc_device_info& depth,
const platform::usb_device_info& hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications);
const platform::uvc_device_info& color,
const platform::uvc_device_info& depth,
const platform::usb_device_info& hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications);

void rs2_apply_ivcam_preset(int preset)
{
Expand Down Expand Up @@ -439,7 +439,7 @@ namespace librealsense
{ 1, 1, 6, 1, -1 }, /* GRCursor */
{ 16, 1, 5, 3, 9 }, /* Default */
{ 1, 1, 5, 1, -1 }, /* MidRange */
{ 1, -1, -1, -1, - 1 } /* IROnly */
{ 1, -1, -1, -1, -1 } /* IROnly */
};

// The Default preset is handled differently from all the rest,
Expand Down Expand Up @@ -476,10 +476,10 @@ namespace librealsense

virtual std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const override;



private:
const uint8_t _depth_device_idx;
const uint8_t _color_device_idx;
std::shared_ptr<hw_monitor> _hw_monitor;
bool _is_locked = true;

template<class T>
Expand Down Expand Up @@ -528,5 +528,20 @@ namespace librealsense
std::shared_ptr<lazy<rs2_extrinsics>> _depth_to_color_extrinsics;

lazy<ivcam::camera_calib_params> _camer_calib_params;

protected:
const uint8_t _color_device_idx;
std::shared_ptr<hw_monitor> _hw_monitor;
};

class sr305_camera final : public sr300_camera {
public:
sr305_camera(std::shared_ptr<context> ctx,
const platform::uvc_device_info& color,
const platform::uvc_device_info& depth,
const platform::usb_device_info& hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications);
};

}
Loading