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

Global Camera Time #3909

Merged
merged 21 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 14 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
4 changes: 4 additions & 0 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,10 @@ namespace rs2
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
else if (timestamp_domain == RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME)
{
ImGui::SetTooltip("Timestamp: Global Time");
}
else
{
ImGui::SetTooltip("Timestamp: Hardware clock");
Expand Down
3 changes: 2 additions & 1 deletion examples/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ For a detailed explanations and API documentation see our [Documentation](../doc
8. [realsense-ir-to-vaapi-h264](https://github.com/bmegli/realsense-ir-to-vaapi-h264) - hardware encode infrared stream to H.264 with Intel VAAPI
9. [EtherSense](https://github.com/krejov100/EtherSense) - Ethernet client and server for RealSense using python's Asyncore
10. [Unofficial OpenVino example + D400](https://github.com/gbr1/ros_openvino) - example of using OpenVino with RealSense and ROS for object detection
11. [Vimeo Depth Viewer](https://github.com/vimeo/vimeo-depth-viewer) - A RealSense depth viewer using [nanogui](https://github.com/wjakob/nanogui)
11. [keijiro/Rsvfx](https://github.com/keijiro/Rsvfx) - An example that shows how to connect RealSense depth camera to Unity VFX Graph
12. [Vimeo Depth Viewer](https://github.com/vimeo/vimeo-depth-viewer) - A RealSense depth viewer using [nanogui](https://github.com/wjakob/nanogui)
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef enum rs2_timestamp_domain
{
RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK, /**< Frame timestamp was measured in relation to the camera clock */
RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME, /**< Frame timestamp was measured in relation to the OS system clock */
RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME, /**< Frame timestamp was measured in relation to the camera clock and converted to OS system clock by constantly measure the difference*/
RS2_TIMESTAMP_DOMAIN_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_timestamp_domain;
const char* rs2_timestamp_domain_to_string(rs2_timestamp_domain info);
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/device_hub.cpp"
"${CMAKE_CURRENT_LIST_DIR}/environment.cpp"
"${CMAKE_CURRENT_LIST_DIR}/error-handling.cpp"
"${CMAKE_CURRENT_LIST_DIR}/global_timestamp_reader.cpp"
"${CMAKE_CURRENT_LIST_DIR}/hw-monitor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/image.cpp"
"${CMAKE_CURRENT_LIST_DIR}/image-avx.cpp"
Expand All @@ -80,6 +81,7 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/environment.h"
"${CMAKE_CURRENT_LIST_DIR}/error-handling.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-archive.h"
"${CMAKE_CURRENT_LIST_DIR}/global_timestamp_reader.h"
"${CMAKE_CURRENT_LIST_DIR}/hw-monitor.h"
"${CMAKE_CURRENT_LIST_DIR}/image.h"
"${CMAKE_CURRENT_LIST_DIR}/image-avx.h"
Expand Down
5 changes: 5 additions & 0 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ void device::hardware_reset()
throw not_implemented_exception(to_string() << __FUNCTION__ << " is not implemented for this device!");
}

double device::get_device_time()
{
throw not_implemented_exception(to_string() << __FUNCTION__ << " is not implemented for this device!");
}

std::shared_ptr<matcher> librealsense::device::create_matcher(const frame_holder& frame) const
{

Expand Down
2 changes: 2 additions & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace librealsense
virtual bool compress_while_record() const override { return true; }

virtual bool contradicts(const stream_profile_interface* a, const std::vector<stream_profile>& others) const override;
virtual double get_device_time(); // Returns time in miliseconds.

protected:
int add_sensor(std::shared_ptr<sensor_interface> sensor_base);
int assign_sensor(std::shared_ptr<sensor_interface> sensor_base, uint8_t idx);
Expand Down
5 changes: 4 additions & 1 deletion src/ds5/ds5-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ds5-private.h"
#include "ds5-options.h"
#include "ds5-timestamp.h"
#include "global_timestamp_reader.h"
#include "environment.h"

namespace librealsense
Expand Down Expand Up @@ -45,9 +46,11 @@ namespace librealsense
{
auto&& backend = ctx->get_backend();
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));

auto color_ep = std::make_shared<ds5_color_sensor>(this, backend.create_uvc_device(color_devices_info.front()),
std::unique_ptr<frame_timestamp_reader>(new ds5_timestamp_reader_from_metadata(move(ds5_timestamp_reader_backup))));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));


_color_device_idx = add_sensor(color_ep);

Expand Down
33 changes: 29 additions & 4 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ namespace librealsense
for (auto&& info : filter_by_mi(all_device_infos, 0)) // Filter just mi=0, DEPTH
depth_devices.push_back(backend.create_uvc_device(info));

std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(timestamp_reader_backup)));
auto depth_ep = std::make_shared<ds5_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
std::unique_ptr<frame_timestamp_reader>(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup))));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper)));

depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera

depth_ep->register_pixel_format(pf_z16); // Depth
Expand All @@ -342,8 +344,9 @@ namespace librealsense
_left_ir_stream(new stream(RS2_STREAM_INFRARED, 1)),
_right_ir_stream(new stream(RS2_STREAM_INFRARED, 2)),
_device_capabilities(ds::d400_caps::CAP_UNDEFINED),
_depth_device_idx(add_sensor(create_depth_device(ctx, group.uvc_devices)))
_tf_keeper(std::make_shared<time_diff_keeper>(this, 100))
{
_depth_device_idx = add_sensor(create_depth_device(ctx, group.uvc_devices));
init(ctx, group);
}

Expand Down Expand Up @@ -613,6 +616,7 @@ namespace librealsense
});
notification_thread.detach();
}
_tf_keeper->start();
}

notification ds5_notification_decoder::decode(int value)
Expand Down Expand Up @@ -645,6 +649,25 @@ namespace librealsense
return platform::usb_undefined;
}


double ds5_device::get_device_time()
{
if (!_hw_monitor)
throw wrong_api_call_sequence_exception("_hw_monitor is not initialized yet");

command cmd(ds::MRD, ds::REGISTER_CLOCK_0, ds::REGISTER_CLOCK_0 + 4);
auto res = _hw_monitor->send(cmd);

if (res.size() < sizeof(uint32_t))
{
LOG_DEBUG("size(res):" << res.size());
throw std::runtime_error("Not enough bytes returned from the firmware!");
}
uint32_t dt = *(uint32_t*)res.data();
double ts = dt * TIMESTAMP_USEC_TO_MSEC;
return ts;
}

std::shared_ptr<uvc_sensor> ds5u_device::create_ds5u_depth_device(std::shared_ptr<context> ctx,
const std::vector<platform::uvc_device_info>& all_device_infos)
{
Expand All @@ -657,8 +680,10 @@ namespace librealsense
depth_devices.push_back(backend.create_uvc_device(info));

std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));
auto depth_ep = std::make_shared<ds5u_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
std::unique_ptr<frame_timestamp_reader>(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup))));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));

depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera

depth_ep->register_pixel_format(pf_z16); // Depth
Expand Down
3 changes: 3 additions & 0 deletions src/ds5/ds5-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "core/debug.h"
#include "core/advanced_mode.h"
#include "device.h"
#include "global_timestamp_reader.h"

namespace librealsense
{
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace librealsense
void create_snapshot(std::shared_ptr<debug_interface>& snapshot) const override;
void enable_recording(std::function<void(const debug_interface&)> record_action) override;
platform::usb_spec get_usb_spec() const;
double get_device_time();

protected:

Expand Down Expand Up @@ -77,6 +79,7 @@ namespace librealsense

std::unique_ptr<polling_error_handler> _polling_error_handler;
std::shared_ptr<lazy<rs2_extrinsics>> _left_right_extrinsics;
std::shared_ptr<time_diff_keeper> _tf_keeper;
};

class ds5u_device : public ds5_device
Expand Down
10 changes: 7 additions & 3 deletions src/ds5/ds5-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ namespace librealsense

static const char* custom_sensor_fw_ver = "5.6.0.0";

std::unique_ptr<frame_timestamp_reader> iio_hid_ts_reader(new iio_hid_timestamp_reader());
std::unique_ptr<frame_timestamp_reader> custom_hid_ts_reader(new ds5_custom_hid_timestamp_reader());
auto hid_ep = std::make_shared<ds5_hid_sensor>(this, ctx->get_backend().create_hid_device(all_hid_infos.front()),
std::unique_ptr<frame_timestamp_reader>(new iio_hid_timestamp_reader()),
std::unique_ptr<frame_timestamp_reader>(new ds5_custom_hid_timestamp_reader()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(iio_hid_ts_reader), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(custom_hid_ts_reader), _tf_keeper)),
fps_and_sampling_frequency_per_rs2_stream,
sensor_name_and_hid_profiles);

hid_ep->register_pixel_format(pf_accel_axes);
hid_ep->register_pixel_format(pf_gyro_axes);

Expand Down Expand Up @@ -377,8 +380,9 @@ namespace librealsense

std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(environment::get_instance().get_time_service()));
auto&& backend = ctx->get_backend();
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));
auto fisheye_ep = std::make_shared<ds5_fisheye_sensor>(this, backend.create_uvc_device(fisheye_infos.front()),
std::unique_ptr<frame_timestamp_reader>(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup))));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));

fisheye_ep->register_xu(fisheye_xu); // make sure the XU is initialized everytime we power the camera
fisheye_ep->register_pixel_format(pf_raw8);
Expand Down
3 changes: 3 additions & 0 deletions src/ds5/ds5-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ namespace librealsense
const platform::extension_unit fisheye_xu = { 3, 12, 2,
{ 0xf6c3c3d1, 0x5cde, 0x4477,{ 0xad, 0xf0, 0x41, 0x33, 0xf5, 0x8d, 0xa6, 0xf4 } } };

const int REGISTER_CLOCK_0 = 0x0001613c;

enum fw_cmd : uint8_t
{
MRD = 0x01, // Read Register
GLD = 0x0f, // FW logs
GVD = 0x10, // camera details
GETINTCAL = 0x15, // Read calibration table
Expand Down
Loading