Skip to content

Commit

Permalink
Merge pull request #8713 from nohayassin/dso_16719_start
Browse files Browse the repository at this point in the history
Adding SR300 derivative into SDK core
  • Loading branch information
ev-mp authored Apr 8, 2021
2 parents f6a250d + f643223 commit df2c793
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 126 deletions.
1 change: 1 addition & 0 deletions config/99-realsense-libusb.rules
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b0d", MODE:="066
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b3a", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b3d", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b48", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0aa3", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b49", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b4b", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b4d", MODE:="0666", GROUP:="plugdev"
Expand Down
2 changes: 1 addition & 1 deletion src/ivcam/ivcam-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace librealsense
{

result = *it;
if(result.mi == 4)
if(result.mi == 4 || result.mi == 2)
{
devices.erase(it);
return true;
Expand Down
143 changes: 100 additions & 43 deletions src/ivcam/sr300.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace librealsense
return std::make_shared<sr305_camera>(ctx, _color, _depth, _hwm,
this->get_device_data(),
register_device_notifications);
case SR306_PID:
return std::make_shared<sr306_camera>(ctx, _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);
Expand All @@ -69,33 +73,39 @@ namespace librealsense
std::vector<platform::uvc_device_info> chosen;
std::vector<std::shared_ptr<device_info>> results;

auto correct_pid = filter_by_product(uvc, { SR300_PID, SR300v2_PID });
auto correct_pid = filter_by_product(uvc, { SR300_PID, SR300v2_PID, SR306_PID });
auto group_devices = group_devices_by_unique_id(correct_pid);
for (auto& group : group_devices)
{
if (group.size() == 2 &&
mi_present(group, 0) &&
mi_present(group, 2))
{
auto color = get_mi(group, 0);
auto depth = get_mi(group, 2);
platform::usb_device_info hwm;
platform::usb_device_info hwm;
platform::uvc_device_info color;
platform::uvc_device_info depth;

if (ivcam::try_fetch_usb_device(usb, color, hwm))
{
auto info = std::make_shared<sr300_info>(ctx, color, depth, hwm);
chosen.push_back(color);
chosen.push_back(depth);
results.push_back(info);
}
else
if (mi_present(group, 0))
{
color = get_mi(group, 0);
chosen.push_back(color);
if (!ivcam::try_fetch_usb_device(usb, color, hwm))
{
LOG_WARNING("try_fetch_usb_device(...) failed.");
return results;
}
}
else

if (mi_present(group, 2))
{
depth = get_mi(group, 2);
chosen.push_back(depth);
}

if (!color.pid && !depth.pid)
LOG_WARNING("SR300 group_devices is empty.");
else
{
if (!depth.pid) // SR306 : only mi=0 is defined
std::swap(color, depth);
auto info = std::make_shared<sr300_info>(ctx, color, depth, hwm);
results.push_back(info);
}
}

Expand Down Expand Up @@ -164,7 +174,7 @@ namespace librealsense
return color_ep;
}

std::shared_ptr<synthetic_sensor> sr300_camera::create_depth_device(std::shared_ptr<context> ctx,
std::shared_ptr<synthetic_sensor> sr3xx_camera::create_depth_device(std::shared_ptr<context> ctx,
const platform::uvc_device_info& depth)
{
using namespace ivcam;
Expand Down Expand Up @@ -229,7 +239,7 @@ namespace librealsense
return depth_ep;
}

rs2_intrinsics sr300_camera::make_depth_intrinsics(const ivcam::camera_calib_params & c, const int2 & dims)
rs2_intrinsics sr3xx_camera::make_depth_intrinsics(const ivcam::camera_calib_params & c, const int2 & dims)
{
return{ dims.x, dims.y, (c.Kc[0][2] * 0.5f + 0.5f) * dims.x,
(c.Kc[1][2] * 0.5f + 0.5f) * dims.y,
Expand Down Expand Up @@ -261,37 +271,37 @@ namespace librealsense
return intrin;
}

float sr300_camera::read_mems_temp() const
float sr3xx_camera::read_mems_temp() const
{
command command(ivcam::fw_cmd::GetMEMSTemp);
auto data = _hw_monitor->send(command);
auto t = *reinterpret_cast<int32_t *>(data.data());
return static_cast<float>(t) / 100;
}

int sr300_camera::read_ir_temp() const
int sr3xx_camera::read_ir_temp() const
{
command command(ivcam::fw_cmd::GetIRTemp);
auto data = _hw_monitor->send(command);
return static_cast<int8_t>(data[0]);
}

void sr300_camera::force_hardware_reset() const
void sr3xx_camera::force_hardware_reset() const
{
command cmd(ivcam::fw_cmd::HWReset);
cmd.require_response = false;
_hw_monitor->send(cmd);
}

void sr300_camera::enable_timestamp(bool colorEnable, bool depthEnable) const
void sr3xx_camera::enable_timestamp(bool colorEnable, bool depthEnable) const
{
command cmd(ivcam::fw_cmd::TimeStampEnable);
cmd.param1 = depthEnable ? 1 : 0;
cmd.param2 = colorEnable ? 1 : 0;
_hw_monitor->send(cmd);
}

void sr300_camera::set_auto_range(const ivcam::cam_auto_range_request& c) const
void sr3xx_camera::set_auto_range(const ivcam::cam_auto_range_request& c) const
{
command cmd(ivcam::fw_cmd::SetAutoRange);
cmd.param1 = c.enableMvR;
Expand Down Expand Up @@ -322,7 +332,7 @@ namespace librealsense
_hw_monitor->send(cmd);
}

void sr300_camera::enter_update_state() const
void sr3xx_camera::enter_update_state() const
{
// Stop all data streaming/exchange pipes with HW
stop_activity();
Expand Down Expand Up @@ -350,7 +360,7 @@ namespace librealsense
}
}

std::vector<uint8_t> sr300_camera::backup_flash(update_progress_callback_ptr callback)
std::vector<uint8_t> sr3xx_camera::backup_flash(update_progress_callback_ptr callback)
{
// TODO: Refactor, unify with DS version
int flash_size = 1024 * 2048;
Expand Down Expand Up @@ -397,7 +407,7 @@ namespace librealsense
return flash;
}

void sr300_camera::update_flash(const std::vector<uint8_t>&, update_progress_callback_ptr, int)
void sr3xx_camera::update_flash(const std::vector<uint8_t>&, update_progress_callback_ptr, int)
{
throw std::runtime_error("update_flash is not supported by SR300");
}
Expand All @@ -421,7 +431,7 @@ namespace librealsense
TakeFromRAM = 2
};

ivcam::camera_calib_params sr300_camera::get_calibration() const
ivcam::camera_calib_params sr3xx_camera::get_calibration() const
{
command command(ivcam::fw_cmd::GetCalibrationTable);
command.param1 = static_cast<uint32_t>(cam_data_source::TakeFromRAM);
Expand All @@ -432,7 +442,7 @@ namespace librealsense
return rawCalib.CalibrationParameters;
}

sr300_camera::sr300_camera(std::shared_ptr<context> ctx, const platform::uvc_device_info &color,
sr3xx_camera::sr3xx_camera(std::shared_ptr<context> ctx,
const platform::uvc_device_info &depth,
const platform::usb_device_info &hwm_device,
const platform::backend_device_group& group,
Expand All @@ -442,12 +452,10 @@ namespace librealsense
_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";
static auto device_name = "Intel RealSense SR3xx";

// Temporal solution for HW Monitor injection - to be refactored
this->assign_hw_monitor(_hw_monitor);
Expand All @@ -458,13 +466,11 @@ namespace librealsense

auto fw_version = _hw_monitor->get_firmware_version_string(gvd_buff, fw_version_offset);
auto serial = _hw_monitor->get_module_serial_string(gvd_buff, module_serial_offset);
auto pid_hex_str = hexify(depth.pid);

_camer_calib_params = [this]() { return get_calibration(); };
enable_timestamp(true, true);

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_ASIC_SERIAL_NUMBER, serial);
Expand All @@ -475,7 +481,6 @@ namespace librealsense
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 @@ -491,11 +496,9 @@ namespace librealsense
});

environment::get_instance().get_extrinsics_graph().register_same_extrinsics(*_depth_stream, *_ir_stream);
environment::get_instance().get_extrinsics_graph().register_extrinsics(*_depth_stream, *_color_stream, _depth_to_color_extrinsics);

register_stream_to_extrinsic_group(*_depth_stream, 0);
register_stream_to_extrinsic_group(*_ir_stream, 0);
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",
Expand All @@ -506,6 +509,22 @@ 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)
: sr3xx_camera(ctx, depth, hwm_device, group, register_device_notifications),
device(ctx, group, register_device_notifications),
_color_stream(new stream(RS2_STREAM_COLOR)),
_color_device_idx(add_sensor(create_color_device(ctx, color)))
{
static auto device_name = "Intel RealSense SR300";
update_info(RS2_CAMERA_INFO_NAME, device_name);
environment::get_instance().get_extrinsics_graph().register_extrinsics(*_depth_stream, *_color_stream, _depth_to_color_extrinsics);
register_stream_to_extrinsic_group(*_color_stream, 0);
}

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,
Expand All @@ -515,7 +534,9 @@ namespace librealsense
device(ctx, group, register_device_notifications) {

static auto device_name = "Intel RealSense SR305";
//auto recommended_fw_version = firmware_version(SR3XX_RECOMMENDED_FIRMWARE_VERSION);
update_info(RS2_CAMERA_INFO_NAME, device_name);
//register_info(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION, recommended_fw_version);

roi_sensor_interface* roi_sensor;
if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&get_sensor(_color_device_idx))))
Expand All @@ -524,22 +545,35 @@ namespace librealsense

}

sr306_camera::sr306_camera(std::shared_ptr<context> ctx,
const platform::uvc_device_info& depth,
const platform::usb_device_info& hwm_device,
const platform::backend_device_group& group,
bool register_device_notifications)
: sr3xx_camera(ctx, depth, hwm_device, group, register_device_notifications),
device(ctx, group, register_device_notifications) {

static auto device_name = "Intel RealSense SR306";
//auto recommended_fw_version = firmware_version(SR306_RECOMMENDED_FIRMWARE_VERSION);
update_info(RS2_CAMERA_INFO_NAME, device_name);
//register_info(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION, recommended_fw_version);
}

command sr300_camera::get_firmware_logs_command() const
command sr3xx_camera::get_firmware_logs_command() const
{
return command{ ivcam::GLD, 0x1f4 };
}

command sr300_camera::get_flash_logs_command() const
command sr3xx_camera::get_flash_logs_command() const
{
return command{ ivcam::FlashRead, 0x000B6000, 0x3f8 };
}

void sr300_camera::create_snapshot(std::shared_ptr<debug_interface>& snapshot) const
void sr3xx_camera::create_snapshot(std::shared_ptr<debug_interface>& snapshot) const
{
//TODO: implement
}
void sr300_camera::enable_recording(std::function<void(const debug_interface&)> record_action)
void sr3xx_camera::enable_recording(std::function<void(const debug_interface&)> record_action)
{
//TODO: implement
}
Expand Down Expand Up @@ -613,6 +647,29 @@ namespace librealsense
return (has_metadata_ts(frame)) ? RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK : _backup_timestamp_reader->get_frame_timestamp_domain(frame);
}

std::shared_ptr<matcher> sr3xx_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() };

for (auto& s : streams)
{
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))
{
matchers.push_back(std::make_shared<timestamp_composite_matcher>(depth_matchers));
}
else
{
matchers.push_back(std::make_shared<frame_number_composite_matcher>(depth_matchers));
}

return std::make_shared<timestamp_composite_matcher>(matchers);
}

std::shared_ptr<matcher> sr300_camera::create_matcher(const frame_holder& frame) const
{
std::vector<std::shared_ptr<matcher>> depth_matchers;
Expand All @@ -637,8 +694,8 @@ namespace librealsense
matchers.push_back(color_matcher);

return std::make_shared<timestamp_composite_matcher>(matchers);

}

processing_blocks sr300_camera::sr300_depth_sensor::get_sr300_depth_recommended_proccesing_blocks()
{
auto res = get_depth_recommended_proccesing_blocks();
Expand Down
Loading

0 comments on commit df2c793

Please sign in to comment.