tm-device.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include <memory>
6 #include <vector>
7 
8 #include "../device.h"
9 #include "../core/video.h"
10 #include "../core/motion.h"
11 #include "../media/playback/playback_device.h"
12 
13 #include "../usb/usb-device.h"
14 #include "../usb/usb-messenger.h"
15 
16 #include "t265-messages.h"
17 
18 namespace librealsense
19 {
20  class tm2_sensor;
21 
22  class tm2_device : public virtual device, public tm2_extensions
23  {
24  public:
25  tm2_device(std::shared_ptr<context> ctx,
27  bool register_device_notifications);
28 
29  virtual ~tm2_device();
30 
31  void hardware_reset() override;
32 
33  void enable_loopback(const std::string& source_file) override;
34  void disable_loopback() override;
35  bool is_enabled() const override;
36  void connect_controller(const std::array<uint8_t, 6>& mac_address) override {};
37  void disconnect_controller(int id) override {};
38 
39  std::vector<tagged_profile> get_profiles_tags() const override
40  {
41  return std::vector<tagged_profile>();
42  };
43  bool compress_while_record() const override { return false; }
44 
45  std::shared_ptr<tm2_sensor> get_tm2_sensor() { return _sensor; }
46 
47  protected:
49 
50  private:
51  static const char* tm2_device_name()
52  {
53  return "Intel RealSense T265";
54  }
55  std::shared_ptr<tm2_sensor> _sensor;
56 
60 
64 
65  std::mutex bulk_mutex;
66  template<typename Request, typename Response> platform::usb_status bulk_request_response(const Request &request, Response &response, size_t max_response_size = 0, bool assert_success = true);
67 
68  platform::rs_usb_request interrupt_read_request(std::vector<uint8_t> & buffer, std::shared_ptr<platform::usb_request_callback> callback);
69 
70  std::mutex stream_mutex;
72 
73  platform::rs_usb_request stream_read_request(std::vector<uint8_t> & buffer, std::shared_ptr<platform::usb_request_callback> callback);
74 
77 
78  friend class tm2_sensor;
79  };
80 
83  {
84  public:
85  tm2_sensor(tm2_device* owner);
86  virtual ~tm2_sensor();
87 
88  // sensor interface
91  void open(const stream_profiles& requests) override;
92  void close() override;
93  void start(frame_callback_ptr callback) override;
94  void stop() override;
95  rs2_intrinsics get_intrinsics(const stream_profile& profile) const override;
96  rs2_motion_device_intrinsic get_motion_intrinsics(const motion_stream_profile_interface& profile) const;
97  rs2_extrinsics get_extrinsics(const stream_profile_interface & profile, int sensor_id) const;
98 
99  void enable_loopback(std::shared_ptr<playback_device> input);
100  void disable_loopback();
101  bool is_loopback_enabled() const;
102  void dispose();
103  t265::sensor_temperature get_temperature(int sensor_id);
104  void set_exposure_and_gain(float exposure_ms, float gain);
105  void set_exposure(float value);
106  float get_exposure() const;
107  void set_gain(float value);
108  float get_gain() const;
109  bool is_manual_exposure() const { return manual_exposure; }
110  void set_manual_exposure(bool manual);
111 
112  // Pose interfaces
113  bool export_relocalization_map(std::vector<uint8_t>& lmap_buf) const override;
114  bool import_relocalization_map(const std::vector<uint8_t>& lmap_buf) const override;
115  bool set_static_node(const std::string& guid, const float3& pos, const float4& orient_quat) const override;
116  bool get_static_node(const std::string& guid, float3& pos, float4& orient_quat) const override;
117  bool remove_static_node(const std::string& guid) const override;
118 
119  // Wheel odometer
120  bool load_wheel_odometery_config(const std::vector<uint8_t>& odometry_config_buf) const override;
121  bool send_wheel_odometry(uint8_t wo_sensor_id, uint32_t frame_num, const float3& translational_velocity) const override;
122 
124  _async_init = 1 << 0,
125  _async_progress = 1 << 1,
126  _async_success = 1 << 2,
127  _async_fail = 1 << 3,
128  _async_max = 1 << 4
129  };
130 
131  // Async operations handler
132  async_op_state perform_async_transfer(std::function<bool()> transfer_activator,
133  std::function<void()> on_success, const std::string& op_description) const;
134  // Recording interfaces
135  virtual void create_snapshot(std::shared_ptr<pose_sensor_interface>& snapshot) const override {}
136  virtual void enable_recording(std::function<void(const pose_sensor_interface&)> record_action) override {}
137  virtual void create_snapshot(std::shared_ptr<wheel_odometry_interface>& snapshot) const override {}
138  virtual void enable_recording(std::function<void(const wheel_odometry_interface&)> record_action) override {}
139 
140  //calibration write interface
141  static const uint16_t ID_OEM_CAL = 6;
142  void set_intrinsics(const stream_profile_interface& stream_profile, const rs2_intrinsics& intr) override;
143  void set_extrinsics(const stream_profile_interface& from_profile, const stream_profile_interface& to_profile, const rs2_extrinsics& extr) override;
144  void set_motion_device_intrinsics(const stream_profile_interface& stream_profile, const rs2_motion_device_intrinsic& intr) override;
145  void reset_to_factory_calibration() override;
146  void write_calibration() override;
147  void set_extrinsics_to_ref(rs2_stream stream_type, int stream_index, const rs2_extrinsics& extr);
148 
150 
151  private:
152  void handle_imu_frame(unsigned long long tm_frame_ts, unsigned long long frame_number, rs2_stream stream_type, int index, float3 imu_data, float temperature);
153  void pass_frames_to_fw(frame_holder fref);
154  void raise_relocalization_event(const std::string& msg, double timestamp);
155  void raise_error_notification(const std::string& msg);
156 
157  mutable std::mutex _tm_op_lock;
158  std::shared_ptr<playback_device>_loopback;
159  mutable std::condition_variable _async_op;
161  mutable std::vector<uint8_t> _async_op_res_buffer;
162 
163  std::vector<t265::supported_raw_stream_libtm_message> _supported_raw_streams;
164  std::vector<t265::supported_raw_stream_libtm_message> _active_raw_streams;
165  bool _pose_output_enabled{false};
167 
168  void print_logs(const std::unique_ptr<t265::bulk_message_response_get_and_clear_event_log> & log);
169 
170  bool start_stream();
171  bool start_interrupt();
172  void stop_stream();
173  void stop_interrupt();
174  void time_sync();
175  void log_poll();
176  bool log_poll_once(std::unique_ptr<t265::bulk_message_response_get_and_clear_event_log> & log_buffer);
177  std::thread _time_sync_thread;
178  std::thread _log_poll_thread;
179  std::atomic<bool> _time_sync_thread_stop;
180  std::atomic<bool> _log_poll_thread_stop;
181 
184 
187 
188  float last_exposure = 200.f;
189  float last_gain = 1.f;
190  bool manual_exposure = false;
191 
192  std::atomic<int64_t> device_to_host_ns;
194  public:
195  std::chrono::duration<double, std::milli> device_ts;
196  std::chrono::duration<double, std::milli> global_ts;
197  std::chrono::duration<double, std::milli> arrival_ts;
198  };
200 
201  coordinated_ts get_coordinated_timestamp(uint64_t device_nanoseconds);
202 
203  template <t265::SIXDOF_MODE flag, t265::SIXDOF_MODE depends_on, bool invert> friend class tracking_mode_option;
204 
205  // threaded dispatch
206  std::shared_ptr<dispatcher> _data_dispatcher;
207  void dispatch_threaded(frame_holder frame);
208 
209  // interrupt endpoint receive
210  void receive_pose_message(const t265::interrupt_message_get_pose & message);
211  void receive_accel_message(const t265::interrupt_message_accelerometer_stream & message);
212  void receive_gyro_message(const t265::interrupt_message_gyro_stream & message);
213  void receive_set_localization_data_complete(const t265::interrupt_message_set_localization_data_stream & message);
214 
215  // stream endpoint receive
216  void receive_video_message(const t265::bulk_message_video_stream * message);
217  void receive_localization_data_chunk(const t265::interrupt_message_get_localization_data_stream * chunk);
218  };
219 }
std::vector< t265::supported_raw_stream_libtm_message > _supported_raw_streams
Definition: tm-device.h:163
GLenum GLuint GLenum GLsizei const GLchar * message
platform::usb_status stream_write(const t265::bulk_message_request_header *request)
Definition: tm-device.cpp:2069
Interrupt get pose message.
Interrupt raw accelerometer stream message.
platform::rs_usb_request _stream_request
Definition: tm-device.h:185
std::shared_ptr< usb_request > rs_usb_request
Definition: usb-request.h:41
Bulk message request header struct.
virtual void create_snapshot(std::shared_ptr< wheel_odometry_interface > &snapshot) const override
Definition: tm-device.h:137
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: src/types.h:1071
Interrupt Get Localization Data Stream message.
platform::rs_usb_request stream_read_request(std::vector< uint8_t > &buffer, std::shared_ptr< platform::usb_request_callback > callback)
Definition: tm-device.cpp:2090
coordinated_ts last_ts
Definition: tm-device.h:199
platform::rs_usb_device usb_device
Definition: tm-device.h:58
tm2_device * _device
Definition: tm-device.h:166
std::atomic< bool > _log_poll_thread_stop
Definition: tm-device.h:180
std::mutex stream_mutex
Definition: tm-device.h:70
GLfloat value
SIXDOF_MODE
Defines all 6dof modes.
Definition: t265-messages.h:83
Bulk raw video stream message.
GeneratorWrapper< std::vector< T > > chunk(size_t size, GeneratorWrapper< T > &&generator)
Definition: catch.hpp:4321
void register_stream_to_extrinsic_group(const stream_interface &stream, uint32_t group_index)
Definition: tm-device.cpp:2152
unsigned short uint16_t
Definition: stdint.h:79
GLsizei const GLchar *const * string
Interrupt raw gyro stream message.
unsigned char uint8_t
Definition: stdint.h:78
platform::usb_status bulk_request_response(const Request &request, Response &response, size_t max_response_size=0, bool assert_success=true)
Definition: tm-device.cpp:2026
GLenum GLfloat * buffer
static const textual_icon stop
Definition: model-views.h:225
std::thread _time_sync_thread
Definition: tm-device.h:177
std::shared_ptr< dispatcher > _data_dispatcher
Definition: tm-device.h:206
platform::rs_usb_endpoint endpoint_int_in
Definition: tm-device.h:63
enum librealsense::platform::_usb_status usb_status
std::condition_variable _async_op
Definition: tm-device.h:159
GLuint index
bool compress_while_record() const override
Definition: tm-device.h:43
friend class tm2_sensor
Definition: tm-device.h:78
platform::rs_usb_endpoint endpoint_int_out
Definition: tm-device.h:63
virtual void enable_recording(std::function< void(const wheel_odometry_interface &)> record_action) override
Definition: tm-device.h:138
Bulk Get Temperature Message.
std::chrono::duration< double, std::milli > global_ts
Definition: tm-device.h:196
virtual void create_snapshot(std::shared_ptr< pose_sensor_interface > &snapshot) const override
Definition: tm-device.h:135
std::atomic< bool > _time_sync_thread_stop
Definition: tm-device.h:179
platform::rs_usb_request_callback _interrupt_callback
Definition: tm-device.h:183
void disable_loopback() override
Definition: tm-device.cpp:2141
std::vector< rs2::stream_profile > init_stream_profiles(sw_context &sctx, std::shared_ptr< rs2::software_sensor > ss, std::string sensor_name, rs2::video_stream_profile c, rs2::video_stream_profile d)
static const char * tm2_device_name()
Definition: tm-device.h:51
unsigned int uint32_t
Definition: stdint.h:80
GLboolean GLuint group
Definition: glext.h:5688
std::shared_ptr< usb_endpoint > rs_usb_endpoint
Definition: usb-endpoint.h:24
std::chrono::duration< double, std::milli > arrival_ts
Definition: tm-device.h:197
std::shared_ptr< usb_request_callback > rs_usb_request_callback
Definition: usb-request.h:18
platform::rs_usb_endpoint endpoint_bulk_out
Definition: tm-device.h:62
std::atomic< int64_t > device_to_host_ns
Definition: tm-device.h:192
std::shared_ptr< playback_device > _loopback
Definition: tm-device.h:158
std::shared_ptr< usb_messenger > rs_usb_messenger
Definition: usb-messenger.h:26
def callback(frame)
Definition: t265_stereo.py:91
unsigned __int64 uint64_t
Definition: stdint.h:90
async_op_state _async_op_status
Definition: tm-device.h:160
std::chrono::duration< double, std::milli > device_ts
Definition: tm-device.h:195
GLuint start
std::shared_ptr< tm2_sensor > _sensor
Definition: tm-device.h:55
platform::rs_usb_endpoint endpoint_msg_in
Definition: tm-device.h:61
std::shared_ptr< tm2_sensor > get_tm2_sensor()
Definition: tm-device.h:45
bool is_enabled() const override
Definition: tm-device.cpp:2147
void connect_controller(const std::array< uint8_t, 6 > &mac_address) override
Definition: tm-device.h:36
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
void enable_loopback(const std::string &source_file) override
Definition: tm-device.cpp:2124
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
bool is_manual_exposure() const
Definition: tm-device.h:109
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
platform::rs_usb_messenger usb_messenger
Definition: tm-device.h:59
GLenum GLenum GLenum input
Definition: glext.h:10805
stream_profile to_profile(const stream_profile_interface *sp)
Definition: src/stream.h:185
void log(std::string message)
rs2_extrinsics extr
Definition: test-pose.cpp:258
Video stream intrinsics.
Definition: rs_types.h:58
float rs2_vector::* pos
platform::usb_device_info usb_info
Definition: tm-device.h:57
platform::rs_usb_request_callback _stream_callback
Definition: tm-device.h:186
platform::rs_usb_request interrupt_read_request(std::vector< uint8_t > &buffer, std::shared_ptr< platform::usb_request_callback > callback)
Definition: tm-device.cpp:2113
Interrupt Set Localization Data Stream message.
Motion device intrinsics: scale, bias, and variances.
Definition: rs_types.h:103
std::pair< uint32_t, rs2_extrinsics > get_extrinsics(const stream_interface &stream) const override
Definition: device.cpp:233
platform::rs_usb_endpoint endpoint_bulk_in
Definition: tm-device.h:62
platform::rs_usb_endpoint endpoint_msg_out
Definition: tm-device.h:61
std::vector< uint8_t > _async_op_res_buffer
Definition: tm-device.h:161
void hardware_reset() override
Definition: tm-device.cpp:2018
void disconnect_controller(int id) override
Definition: tm-device.h:37
tm2_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group, bool register_device_notifications)
Definition: tm-device.cpp:1916
std::vector< t265::supported_raw_stream_libtm_message > _active_raw_streams
Definition: tm-device.h:164
bool cancel_request(platform::rs_usb_request request)
Definition: tm-device.cpp:2105
virtual void enable_recording(std::function< void(const pose_sensor_interface &)> record_action) override
Definition: tm-device.h:136
std::vector< tagged_profile > get_profiles_tags() const override
Definition: tm-device.h:39
void submit_request(platform::rs_usb_request request)
Definition: tm-device.cpp:2098
std::shared_ptr< usb_device > rs_usb_device
Definition: usb-device.h:29
platform::rs_usb_request _interrupt_request
Definition: tm-device.h:182
std::thread _log_poll_thread
Definition: tm-device.h:178


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:12