Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
rs_device.hpp
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
4#ifndef LIBREALSENSE_RS2_DEVICE_HPP
5#define LIBREALSENSE_RS2_DEVICE_HPP
6
7#include "rs_types.hpp"
8#include "rs_sensor.hpp"
9#include <array>
10
11namespace rs2
12{
13 class context;
14 class device_list;
15 class pipeline_profile;
16 class device_hub;
17
18 class device
19 {
20 public:
25 std::vector<sensor> query_sensors() const
26 {
27 rs2_error* e = nullptr;
28 std::shared_ptr<rs2_sensor_list> list(
29 rs2_query_sensors(_dev.get(), &e),
32
33 auto size = rs2_get_sensors_count(list.get(), &e);
35
36 std::vector<sensor> results;
37 for (auto i = 0; i < size; i++)
38 {
39 std::shared_ptr<rs2_sensor> dev(
40 rs2_create_sensor(list.get(), i, &e),
43
44 sensor rs2_dev(dev);
45 results.push_back(rs2_dev);
46 }
47
48 return results;
49 }
50
51 template<class T>
52 T first() const
53 {
54 for (auto&& s : query_sensors())
55 {
56 if (auto t = s.as<T>()) return t;
57 }
58 throw rs2::error("Could not find requested sensor type!");
59 }
60
66 bool supports(rs2_camera_info info) const
67 {
68 rs2_error* e = nullptr;
69 auto is_supported = rs2_supports_device_info(_dev.get(), info, &e);
71 return is_supported > 0;
72 }
73
79 const char* get_info(rs2_camera_info info) const
80 {
81 rs2_error* e = nullptr;
82 auto result = rs2_get_device_info(_dev.get(), info, &e);
84 return result;
85 }
86
91 {
92 rs2_error* e = nullptr;
93
94 rs2_hardware_reset(_dev.get(), &e);
96 }
97
98 device& operator=(const std::shared_ptr<rs2_device> dev)
99 {
100 _dev.reset();
101 _dev = dev;
102 return *this;
103 }
105 {
106 *this = nullptr;
107 _dev = dev._dev;
108 return *this;
109 }
110 device() : _dev(nullptr) {}
111
112 operator bool() const
113 {
114 return _dev != nullptr;
115 }
116 const std::shared_ptr<rs2_device>& get() const
117 {
118 return _dev;
119 }
120
121 template<class T>
122 bool is() const
123 {
124 T extension(*this);
125 return extension;
126 }
127
128 template<class T>
129 T as() const
130 {
131 T extension(*this);
132 return extension;
133 }
134 virtual ~device()
135 {
136 }
137
138 explicit operator std::shared_ptr<rs2_device>() { return _dev; };
139 explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
140 protected:
141 friend class rs2::context;
142 friend class rs2::device_list;
144 friend class rs2::device_hub;
145
146 std::shared_ptr<rs2_device> _dev;
147
148 };
149
150 template<class T>
152 {
153 T _callback;
154
155 public:
156 explicit update_progress_callback(T callback) : _callback(callback) {}
157
158 void on_update_progress(const float progress) override
159 {
160 _callback(progress);
161 }
162
163 void release() override { delete this; }
164 };
165
166 class updatable : public device
167 {
168 public:
171 : device(d.get())
172 {
173 rs2_error* e = nullptr;
175 {
176 _dev.reset();
177 }
178 error::handle(e);
179 }
180
181 // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
183 {
184 rs2_error* e = nullptr;
185 rs2_enter_update_state(_dev.get(), &e);
186 error::handle(e);
187 }
188
189 // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
190 // loaded back to the device, but it does contain all calibration and device information."
191 std::vector<uint8_t> create_flash_backup() const
192 {
193 std::vector<uint8_t> results;
194
195 rs2_error* e = nullptr;
196 std::shared_ptr<const rs2_raw_data_buffer> list(
197 rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
199 error::handle(e);
200
201 auto size = rs2_get_raw_data_size(list.get(), &e);
202 error::handle(e);
203
204 auto start = rs2_get_raw_data(list.get(), &e);
205
206 results.insert(results.begin(), start, start + size);
207
208 return results;
209 }
210
211 template<class T>
212 std::vector<uint8_t> create_flash_backup(T callback) const
213 {
214 std::vector<uint8_t> results;
215
216 rs2_error* e = nullptr;
217 std::shared_ptr<const rs2_raw_data_buffer> list(
218 rs2_create_flash_backup_cpp(_dev.get(), new update_progress_callback<T>(std::move(callback)), &e),
220 error::handle(e);
221
222 auto size = rs2_get_raw_data_size(list.get(), &e);
223 error::handle(e);
224
225 auto start = rs2_get_raw_data(list.get(), &e);
226
227 results.insert(results.begin(), start, start + size);
228
229 return results;
230 }
231
232 // check firmware compatibility with SKU
233 bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
234 {
235 rs2_error* e = nullptr;
236 auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
237 error::handle(e);
238 return res;
239 }
240
241 // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
242 void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
243 {
244 rs2_error* e = nullptr;
245 rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
246 error::handle(e);
247 }
248
249 // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread and it supports progress notifications via the callback.
250 template<class T>
251 void update_unsigned(const std::vector<uint8_t>& image, T callback, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
252 {
253 rs2_error* e = nullptr;
254 rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), int(image.size()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
255 error::handle(e);
256 }
257 };
258
259 class update_device : public device
260 {
261 public:
264 : device(d.get())
265 {
266 rs2_error* e = nullptr;
268 {
269 _dev.reset();
270 }
271 error::handle(e);
272 }
273
274 // Update an updatable device to the provided firmware.
275 // This call is executed on the caller's thread.
276 void update(const std::vector<uint8_t>& fw_image) const
277 {
278 rs2_error* e = nullptr;
279 rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
280 error::handle(e);
281 }
282
283 // Update an updatable device to the provided firmware.
284 // This call is executed on the caller's thread and it supports progress notifications via the callback.
285 template<class T>
286 void update(const std::vector<uint8_t>& fw_image, T callback) const
287 {
288 rs2_error* e = nullptr;
289 rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
290 error::handle(e);
291 }
292 };
293
294 typedef std::vector<uint8_t> calibration_table;
295
297 {
298 public:
300 : device(d.get())
301 {}
302
306 void write_calibration() const
307 {
308 rs2_error* e = nullptr;
309 rs2_write_calibration(_dev.get(), &e);
310 error::handle(e);
311 }
312
317 {
318 rs2_error* e = nullptr;
320 error::handle(e);
321 }
322 };
323
325 {
326 public:
329 {
330 rs2_error* e = nullptr;
332 {
333 _dev.reset();
334 }
335 error::handle(e);
336 }
337
373 template<class T>
374 calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
375 {
376 std::vector<uint8_t> results;
377
378 rs2_error* e = nullptr;
379 auto buf = rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
380 error::handle(e);
381
382 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
383
384 auto size = rs2_get_raw_data_size(list.get(), &e);
385 error::handle(e);
386
387 auto start = rs2_get_raw_data(list.get(), &e);
388
389 results.insert(results.begin(), start, start + size);
390
391 return results;
392 }
393
428 calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
429 {
430 std::vector<uint8_t> results;
431
432 rs2_error* e = nullptr;
433 const rs2_raw_data_buffer* buf = rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), static_cast< int >( json_content.size() ), health, nullptr, timeout_ms, &e);
434 error::handle(e);
435 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
436
437 auto size = rs2_get_raw_data_size(list.get(), &e);
438 error::handle(e);
439
440 auto start = rs2_get_raw_data(list.get(), &e);
441 error::handle(e);
442
443 results.insert(results.begin(), start, start + size);
444
445 return results;
446 }
447
479 template<class T>
480 calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
481 {
482 std::vector<uint8_t> results;
483
484 rs2_error* e = nullptr;
485 const rs2_raw_data_buffer* buf = rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
486 error::handle(e);
487 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
488
489 auto size = rs2_get_raw_data_size(list.get(), &e);
490 error::handle(e);
491
492 auto start = rs2_get_raw_data(list.get(), &e);
493
494 results.insert(results.begin(), start, start + size);
495
496 return results;
497 }
498
529 calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
530 {
531 std::vector<uint8_t> results;
532
533 rs2_error* e = nullptr;
534 const rs2_raw_data_buffer* buf = rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), static_cast< int >( json_content.size() ), health, nullptr, timeout_ms, &e);
535 error::handle(e);
536 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
537
538 auto size = rs2_get_raw_data_size(list.get(), &e);
539 error::handle(e);
540
541 auto start = rs2_get_raw_data(list.get(), &e);
542
543 results.insert(results.begin(), start, start + size);
544
545 return results;
546 }
547
556 template<class T>
557 calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
558 {
559 std::vector<uint8_t> results;
560
561 rs2_error* e = nullptr;
562 const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
563 error::handle(e);
564 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
565
566 auto size = rs2_get_raw_data_size(list.get(), &e);
567 error::handle(e);
568
569 auto start = rs2_get_raw_data(list.get(), &e);
570
571 results.insert(results.begin(), start, start + size);
572
573 return results;
574 }
575
583 calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
584 {
585 std::vector<uint8_t> results;
586
587 rs2_error* e = nullptr;
588 const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
589 error::handle(e);
590 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
591
592 auto size = rs2_get_raw_data_size(list.get(), &e);
593 error::handle(e);
594
595 auto start = rs2_get_raw_data(list.get(), &e);
596
597 results.insert(results.begin(), start, start + size);
598
599 return results;
600 }
601
607 {
608 std::vector<uint8_t> results;
609
610 rs2_error* e = nullptr;
611 std::shared_ptr<const rs2_raw_data_buffer> list(
614 error::handle(e);
615
616 auto size = rs2_get_raw_data_size(list.get(), &e);
617 error::handle(e);
618
619 auto start = rs2_get_raw_data(list.get(), &e);
620
621 results.insert(results.begin(), start, start + size);
622
623 return results;
624 }
625
631 {
632 rs2_error* e = nullptr;
633 rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
634 error::handle(e);
635 }
636
648 std::vector<uint8_t> run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides,
649 float* ratio, float* angle) const
650 {
651 std::vector<uint8_t> results;
652
653 rs2_error* e = nullptr;
654 std::shared_ptr<const rs2_raw_data_buffer> list(
655 rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle, nullptr, &e),
657 error::handle(e);
658
659 auto size = rs2_get_raw_data_size(list.get(), &e);
660 error::handle(e);
661
662 auto start = rs2_get_raw_data(list.get(), &e);
663
664 results.insert(results.begin(), start, start + size);
665
666 return results;
667 }
668
680 template<class T>
681 std::vector<uint8_t> run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides,
682 float* ratio, float* angle, T callback) const
683 {
684 std::vector<uint8_t> results;
685
686 rs2_error* e = nullptr;
687 std::shared_ptr<const rs2_raw_data_buffer> list(
688 rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
689 new update_progress_callback<T>(std::move(callback)), &e),
691 error::handle(e);
692
693 auto size = rs2_get_raw_data_size(list.get(), &e);
694 error::handle(e);
695
696 auto start = rs2_get_raw_data(list.get(), &e);
697
698 results.insert(results.begin(), start, start + size);
699
700 return results;
701 }
702
714 std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
715 float* health, int health_size) const
716 {
717 std::vector<uint8_t> results;
718
719 rs2_error* e = nullptr;
720 std::shared_ptr<const rs2_raw_data_buffer> list(
721 rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size, nullptr, &e),
723 error::handle(e);
724
725 auto size = rs2_get_raw_data_size(list.get(), &e);
726 error::handle(e);
727
728 auto start = rs2_get_raw_data(list.get(), &e);
729
730 results.insert(results.begin(), start, start + size);
731
732 return results;
733 }
734
747 template<class T>
748 std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
749 float* health, int health_size, T callback) const
750 {
751 std::vector<uint8_t> results;
752
753 rs2_error* e = nullptr;
754 std::shared_ptr<const rs2_raw_data_buffer> list(
755 rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
756 new update_progress_callback<T>(std::move(callback)), &e),
758 error::handle(e);
759
760 auto size = rs2_get_raw_data_size(list.get(), &e);
761 error::handle(e);
762
763 auto start = rs2_get_raw_data(list.get(), &e);
764
765 results.insert(results.begin(), start, start + size);
766
767 return results;
768 }
769
779 float target_width, float target_height) const
780 {
781 rs2_error* e = nullptr;
782 float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
783 target_width, target_height, nullptr, &e);
784 error::handle(e);
785
786 return result;
787 }
788
798 template<class T>
800 float target_width, float target_height, T callback) const
801 {
802 rs2_error* e = nullptr;
803 float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
804 target_width, target_height, new update_progress_callback<T>(std::move(callback)), &e);
805 error::handle(e);
806
807 return result;
808 }
809 };
810
811 /*
812 Wrapper around any callback function that is given to calibration_change_callback.
813 */
814 template< class callback >
816 {
817 //using callback = std::function< void( rs2_calibration_status ) >;
818 callback _callback;
819 public:
820 calibration_change_callback( callback cb ) : _callback( cb ) {}
821
822 void on_calibration_change( rs2_calibration_status status ) noexcept override
823 {
824 _callback( status );
825 }
826 void release() override { delete this; }
827 };
828
830 {
831 public:
834 : device(d.get())
835 {
836 rs2_error* e = nullptr;
838 {
839 _dev.reset();
840 }
841 error::handle(e);
842 }
843
844 /*
845 Your callback should look like this, for example:
846 sensor.register_calibration_change_callback(
847 []( rs2_calibration_status ) noexcept
848 {
849 ...
850 })
851 */
852 template< typename T >
854 {
855 // We wrap the callback with an interface and pass it to librealsense, who will
856 // now manage its lifetime. Rather than deleting it, though, it will call its
857 // release() function, where (back in our context) it can be safely deleted:
858 rs2_error* e = nullptr;
860 _dev.get(),
861 new calibration_change_callback< T >(std::move(callback)),
862 &e);
863 error::handle(e);
864 }
865 };
866
868 {
869 public:
872 {
873 rs2_error* e = nullptr;
875 {
876 _dev = d.get();
877 }
878 error::handle( e );
879 }
880
885 {
886 rs2_error* e = nullptr;
887 rs2_trigger_device_calibration( _dev.get(), type, &e );
888 error::handle( e );
889 }
890 };
891
892 class debug_protocol : public device
893 {
894 public:
896 : device(d.get())
897 {
898 rs2_error* e = nullptr;
899 if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
900 {
901 _dev.reset();
902 }
903 error::handle(e);
904 }
905
906 std::vector<uint8_t> build_command(uint32_t opcode,
907 uint32_t param1 = 0,
908 uint32_t param2 = 0,
909 uint32_t param3 = 0,
910 uint32_t param4 = 0,
911 std::vector<uint8_t> const & data = {}) const
912 {
913 std::vector<uint8_t> results;
914
915 rs2_error* e = nullptr;
916 auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
917 (void*)data.data(), (uint32_t)data.size(), &e);
918 std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
919 error::handle(e);
920
921 auto size = rs2_get_raw_data_size(list.get(), &e);
922 error::handle(e);
923
924 auto start = rs2_get_raw_data(list.get(), &e);
925 error::handle(e);
926
927 results.insert(results.begin(), start, start + size);
928
929 return results;
930 }
931
932 std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
933 {
934 std::vector<uint8_t> results;
935
936 rs2_error* e = nullptr;
937 std::shared_ptr<const rs2_raw_data_buffer> list(
938 rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
940 error::handle(e);
941
942 auto size = rs2_get_raw_data_size(list.get(), &e);
943 error::handle(e);
944
945 auto start = rs2_get_raw_data(list.get(), &e);
946 error::handle(e);
947
948 results.insert(results.begin(), start, start + size);
949
950 return results;
951 }
952 };
953
955 {
956 public:
957 explicit device_list(std::shared_ptr<rs2_device_list> list)
958 : _list(move(list)) {}
959
961 : _list(nullptr) {}
962
963 operator std::vector<device>() const
964 {
965 std::vector<device> res;
966 for (auto&& dev : *this) res.push_back(dev);
967 return res;
968 }
969
970 bool contains(const device& dev) const
971 {
972 rs2_error* e = nullptr;
973 auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
974 error::handle(e);
975 return res;
976 }
977
978 device_list& operator=(std::shared_ptr<rs2_device_list> list)
979 {
980 _list = move(list);
981 return *this;
982 }
983
984 device operator[](uint32_t index) const
985 {
986 rs2_error* e = nullptr;
987 std::shared_ptr<rs2_device> dev(
988 rs2_create_device(_list.get(), index, &e),
990 error::handle(e);
991
992 return device(dev);
993 }
994
995 uint32_t size() const
996 {
997 rs2_error* e = nullptr;
998 auto size = rs2_get_device_count(_list.get(), &e);
999 error::handle(e);
1000 return size;
1001 }
1002
1003 device front() const { return std::move((*this)[0]); }
1004 device back() const
1005 {
1006 return std::move((*this)[size() - 1]);
1007 }
1008
1010 {
1012 const device_list& device_list,
1013 uint32_t uint32_t)
1014 : _list(device_list),
1015 _index(uint32_t)
1016 {
1017 }
1018
1019 public:
1021 {
1022 return _list[_index];
1023 }
1024 bool operator!=(const device_list_iterator& other) const
1025 {
1026 return other._index != _index || &other._list != &_list;
1027 }
1028 bool operator==(const device_list_iterator& other) const
1029 {
1030 return !(*this != other);
1031 }
1033 {
1034 _index++;
1035 return *this;
1036 }
1037 private:
1038 friend device_list;
1039 const device_list& _list;
1040 uint32_t _index;
1041 };
1042
1044 {
1045 return device_list_iterator(*this, 0);
1046 }
1048 {
1049 return device_list_iterator(*this, size());
1050 }
1052 {
1053 return _list.get();
1054 }
1055
1056 operator std::shared_ptr<rs2_device_list>() { return _list; };
1057
1058 private:
1059 std::shared_ptr<rs2_device_list> _list;
1060 };
1061
1071 class tm2 : public calibrated_device // TODO: add to wrappers [Python done]
1072 {
1073 public:
1076 {
1077 rs2_error* e = nullptr;
1078 if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_TM2, &e) == 0 && !e)
1079 {
1080 _dev.reset();
1081 }
1082 error::handle(e);
1083 }
1084
1089 void enable_loopback(const std::string& from_file)
1090 {
1091 rs2_error* e = nullptr;
1092 rs2_loopback_enable(_dev.get(), from_file.c_str(), &e);
1093 error::handle(e);
1094 }
1095
1100 {
1101 rs2_error* e = nullptr;
1102 rs2_loopback_disable(_dev.get(), &e);
1103 error::handle(e);
1104 }
1105
1111 {
1112 rs2_error* e = nullptr;
1113 int is_enabled = rs2_loopback_is_enabled(_dev.get(), &e);
1114 error::handle(e);
1115 return is_enabled != 0;
1116 }
1117
1122 void connect_controller(const std::array<uint8_t, 6>& mac_addr)
1123 {
1124 rs2_error* e = nullptr;
1125 rs2_connect_tm2_controller(_dev.get(), mac_addr.data(), &e);
1126 error::handle(e);
1127 }
1128
1134 {
1135 rs2_error* e = nullptr;
1136 rs2_disconnect_tm2_controller(_dev.get(), id, &e);
1137 error::handle(e);
1138 }
1139
1145 void set_intrinsics(int fisheye_sensor_id, const rs2_intrinsics& intrinsics)
1146 {
1147 rs2_error* e = nullptr;
1148 auto fisheye_sensor = get_sensor_profile(RS2_STREAM_FISHEYE, fisheye_sensor_id);
1149 rs2_set_intrinsics(fisheye_sensor.first.get().get(), fisheye_sensor.second.get(), &intrinsics, &e);
1150 error::handle(e);
1151 }
1152
1161 void set_extrinsics(rs2_stream from_stream, int from_id, rs2_stream to_stream, int to_id, rs2_extrinsics& extrinsics)
1162 {
1163 rs2_error* e = nullptr;
1164 auto from_sensor = get_sensor_profile(from_stream, from_id);
1165 auto to_sensor = get_sensor_profile(to_stream, to_id);
1166 rs2_set_extrinsics(from_sensor.first.get().get(), from_sensor.second.get(), to_sensor.first.get().get(), to_sensor.second.get(), &extrinsics, &e);
1167 error::handle(e);
1168 }
1169
1175 void set_motion_device_intrinsics(rs2_stream stream_type, const rs2_motion_device_intrinsic& motion_intriniscs)
1176 {
1177 rs2_error* e = nullptr;
1178 auto motion_sensor = get_sensor_profile(stream_type, 0);
1179 rs2_set_motion_device_intrinsics(motion_sensor.first.get().get(), motion_sensor.second.get(), &motion_intriniscs, &e);
1180 error::handle(e);
1181 }
1182
1183 private:
1184
1185 std::pair<sensor, stream_profile> get_sensor_profile(rs2_stream stream_type, int stream_index) {
1186 for (auto s : query_sensors()) {
1187 for (auto p : s.get_stream_profiles()) {
1188 if (p.stream_type() == stream_type && p.stream_index() == stream_index)
1189 return std::pair<sensor, stream_profile>(s, p);
1190 }
1191 }
1192 return std::pair<sensor, stream_profile>();
1193 }
1194 };
1195}
1196#endif // LIBREALSENSE_RS2_DEVICE_HPP
Definition: rs_device.hpp:325
calibration_table process_calibration_frame(rs2::frame f, float *const health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:557
calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:480
auto_calibrated_device(device d)
Definition: rs_device.hpp:327
float calculate_target_z(rs2::frame_queue queue1, rs2::frame_queue queue2, rs2::frame_queue queue3, float target_width, float target_height) const
Definition: rs_device.hpp:778
std::vector< uint8_t > run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides, float *ratio, float *angle) const
Definition: rs_device.hpp:648
calibration_table get_calibration_table()
Definition: rs_device.hpp:606
std::vector< uint8_t > run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides, float *ratio, float *angle, T callback) const
Definition: rs_device.hpp:681
std::vector< uint8_t > run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only, float *health, int health_size) const
Definition: rs_device.hpp:714
calibration_table run_on_chip_calibration(std::string json_content, float *health, int timeout_ms=5000) const
Definition: rs_device.hpp:428
float calculate_target_z(rs2::frame_queue queue1, rs2::frame_queue queue2, rs2::frame_queue queue3, float target_width, float target_height, T callback) const
Definition: rs_device.hpp:799
void set_calibration_table(const calibration_table &calibration)
Definition: rs_device.hpp:630
calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float *health, int timeout_ms=5000) const
Definition: rs_device.hpp:529
std::vector< uint8_t > run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only, float *health, int health_size, T callback) const
Definition: rs_device.hpp:748
calibration_table run_on_chip_calibration(std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:374
calibration_table process_calibration_frame(rs2::frame f, float *const health, int timeout_ms=5000) const
Definition: rs_device.hpp:583
Definition: rs_device.hpp:297
calibrated_device(device d)
Definition: rs_device.hpp:299
void write_calibration() const
Definition: rs_device.hpp:306
void reset_to_factory_calibration()
Definition: rs_device.hpp:316
Definition: rs_device.hpp:816
calibration_change_callback(callback cb)
Definition: rs_device.hpp:820
void on_calibration_change(rs2_calibration_status status) noexcept override
Definition: rs_device.hpp:822
void release() override
Definition: rs_device.hpp:826
Definition: rs_device.hpp:830
calibration_change_device(device d)
Definition: rs_device.hpp:833
void register_calibration_change_callback(T callback)
Definition: rs_device.hpp:853
Definition: rs_context.hpp:97
Definition: rs_device.hpp:893
debug_protocol(device d)
Definition: rs_device.hpp:895
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition: rs_device.hpp:932
std::vector< uint8_t > build_command(uint32_t opcode, uint32_t param1=0, uint32_t param2=0, uint32_t param3=0, uint32_t param4=0, std::vector< uint8_t > const &data={}) const
Definition: rs_device.hpp:906
Definition: rs_device.hpp:868
void trigger_device_calibration(rs2_calibration_type type)
Definition: rs_device.hpp:884
device_calibration(device d)
Definition: rs_device.hpp:871
Definition: rs_context.hpp:225
Definition: rs_device.hpp:1010
device_list_iterator & operator++()
Definition: rs_device.hpp:1032
device operator*() const
Definition: rs_device.hpp:1020
bool operator==(const device_list_iterator &other) const
Definition: rs_device.hpp:1028
bool operator!=(const device_list_iterator &other) const
Definition: rs_device.hpp:1024
Definition: rs_device.hpp:955
device_list(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:957
device back() const
Definition: rs_device.hpp:1004
device operator[](uint32_t index) const
Definition: rs_device.hpp:984
bool contains(const device &dev) const
Definition: rs_device.hpp:970
device_list & operator=(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:978
uint32_t size() const
Definition: rs_device.hpp:995
device_list_iterator end() const
Definition: rs_device.hpp:1047
device front() const
Definition: rs_device.hpp:1003
const rs2_device_list * get_list() const
Definition: rs_device.hpp:1051
device_list_iterator begin() const
Definition: rs_device.hpp:1043
device_list()
Definition: rs_device.hpp:960
Definition: rs_device.hpp:19
device(std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:139
virtual ~device()
Definition: rs_device.hpp:134
void hardware_reset()
Definition: rs_device.hpp:90
T as() const
Definition: rs_device.hpp:129
T first() const
Definition: rs_device.hpp:52
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:98
device & operator=(const device &dev)
Definition: rs_device.hpp:104
const std::shared_ptr< rs2_device > & get() const
Definition: rs_device.hpp:116
bool is() const
Definition: rs_device.hpp:122
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:146
std::vector< sensor > query_sensors() const
Definition: rs_device.hpp:25
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:79
device()
Definition: rs_device.hpp:110
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:66
Definition: rs_types.hpp:93
static void handle(rs2_error *e)
Definition: rs_types.hpp:144
Definition: rs_sensor.hpp:406
Definition: rs_processing.hpp:135
std::shared_ptr< rs2_frame_queue > get()
Definition: rs_processing.hpp:240
Definition: rs_frame.hpp:346
rs2_frame * get() const
Definition: rs_frame.hpp:592
Definition: rs_sensor.hpp:390
Definition: rs_pipeline.hpp:19
Definition: rs_sensor.hpp:103
const std::shared_ptr< rs2_sensor > & get() const
Definition: rs_sensor.hpp:320
Definition: rs_device.hpp:1072
void disconnect_controller(int id)
Definition: rs_device.hpp:1133
void set_motion_device_intrinsics(rs2_stream stream_type, const rs2_motion_device_intrinsic &motion_intriniscs)
Definition: rs_device.hpp:1175
void connect_controller(const std::array< uint8_t, 6 > &mac_addr)
Definition: rs_device.hpp:1122
void disable_loopback()
Definition: rs_device.hpp:1099
bool is_loopback_enabled() const
Definition: rs_device.hpp:1110
void enable_loopback(const std::string &from_file)
Definition: rs_device.hpp:1089
void set_extrinsics(rs2_stream from_stream, int from_id, rs2_stream to_stream, int to_id, rs2_extrinsics &extrinsics)
Definition: rs_device.hpp:1161
void set_intrinsics(int fisheye_sensor_id, const rs2_intrinsics &intrinsics)
Definition: rs_device.hpp:1145
tm2(device d)
Definition: rs_device.hpp:1074
Definition: rs_device.hpp:167
bool check_firmware_compatibility(const std::vector< uint8_t > &image) const
Definition: rs_device.hpp:233
updatable()
Definition: rs_device.hpp:169
std::vector< uint8_t > create_flash_backup() const
Definition: rs_device.hpp:191
void enter_update_state() const
Definition: rs_device.hpp:182
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:242
updatable(device d)
Definition: rs_device.hpp:170
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:251
std::vector< uint8_t > create_flash_backup(T callback) const
Definition: rs_device.hpp:212
Definition: rs_device.hpp:260
update_device()
Definition: rs_device.hpp:262
update_device(device d)
Definition: rs_device.hpp:263
void update(const std::vector< uint8_t > &fw_image) const
Definition: rs_device.hpp:276
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition: rs_device.hpp:286
Definition: rs_device.hpp:152
void release() override
Definition: rs_device.hpp:163
update_progress_callback(T callback)
Definition: rs_device.hpp:156
void on_update_progress(const float progress) override
Definition: rs_device.hpp:158
Definition: rs_processing_gl.hpp:13
std::vector< uint8_t > calibration_table
Definition: rs_device.hpp:294
const unsigned char * rs2_get_raw_data(const rs2_raw_data_buffer *buffer, rs2_error **error)
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
rs2_device * rs2_create_device(const rs2_device_list *info_list, int index, rs2_error **error)
int rs2_get_device_count(const rs2_device_list *info_list, rs2_error **error)
void rs2_update_firmware_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, rs2_error **error)
rs2_calibration_type
Definition: rs_device.h:397
void rs2_trigger_device_calibration(rs2_device *dev, rs2_calibration_type type, rs2_error **error)
void rs2_reset_to_factory_calibration(const rs2_device *device, rs2_error **e)
#define RS2_UNSIGNED_UPDATE_MODE_UPDATE
Definition: rs_device.h:223
void rs2_set_calibration_table(const rs2_device *device, const void *calibration, int calibration_size, rs2_error **error)
void rs2_delete_device(rs2_device *device)
const rs2_raw_data_buffer * rs2_get_calibration_table(const rs2_device *dev, rs2_error **error)
int rs2_is_device_extendable_to(const rs2_device *device, rs2_extension extension, rs2_error **error)
void rs2_write_calibration(const rs2_device *device, rs2_error **e)
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
int rs2_check_firmware_compatibility(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_error **error)
const rs2_raw_data_buffer * rs2_send_and_receive_raw_data(rs2_device *device, void *raw_data_to_send, unsigned size_of_raw_data_to_send, rs2_error **error)
void rs2_connect_tm2_controller(const rs2_device *device, const unsigned char *mac_addr, rs2_error **error)
void rs2_update_firmware_unsigned_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, int update_mode, rs2_error **error)
int rs2_loopback_is_enabled(const rs2_device *device, rs2_error **error)
int rs2_supports_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
const rs2_raw_data_buffer * rs2_process_calibration_frame(rs2_device *dev, const rs2_frame *f, float *const health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
const rs2_raw_data_buffer * rs2_create_flash_backup_cpp(const rs2_device *device, rs2_update_progress_callback *callback, rs2_error **error)
int rs2_device_list_contains(const rs2_device_list *info_list, const rs2_device *device, rs2_error **error)
const rs2_raw_data_buffer * rs2_run_on_chip_calibration_cpp(rs2_device *device, const void *json_content, int content_size, float *health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
const rs2_raw_data_buffer * rs2_build_debug_protocol_command(rs2_device *device, unsigned opcode, unsigned param1, unsigned param2, unsigned param3, unsigned param4, void *data, unsigned size_of_data, rs2_error **error)
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
void rs2_loopback_disable(const rs2_device *device, rs2_error **error)
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
void rs2_loopback_enable(const rs2_device *device, const char *from_file, rs2_error **error)
void rs2_register_calibration_change_callback_cpp(rs2_device *dev, rs2_calibration_change_callback *callback, rs2_error **error)
rs2_calibration_status
Definition: rs_device.h:409
const rs2_raw_data_buffer * rs2_run_uv_map_calibration_cpp(rs2_device *device, rs2_frame_queue *left_queue, rs2_frame_queue *color_queue, rs2_frame_queue *depth_queue, int py_px_only, float *health, int health_size, rs2_update_progress_callback *progress_callback, rs2_error **error)
float rs2_calculate_target_z_cpp(rs2_device *device, rs2_frame_queue *queue1, rs2_frame_queue *queue2, rs2_frame_queue *queue3, float target_width, float target_height, rs2_update_progress_callback *callback, rs2_error **error)
const rs2_raw_data_buffer * rs2_run_tare_calibration_cpp(rs2_device *dev, float ground_truth_mm, const void *json_content, int content_size, float *health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
const rs2_raw_data_buffer * rs2_run_focal_length_calibration_cpp(rs2_device *device, rs2_frame_queue *left_queue, rs2_frame_queue *right_queue, float target_width, float target_height, int adjust_both_sides, float *ratio, float *angle, rs2_update_progress_callback *progress_callback, rs2_error **error)
void rs2_disconnect_tm2_controller(const rs2_device *device, int id, rs2_error **error)
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:43
@ RS2_STREAM_FISHEYE
Definition: rs_sensor.h:48
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
void rs2_set_extrinsics(const rs2_sensor *from_sensor, const rs2_stream_profile *from_profile, rs2_sensor *to_sensor, const rs2_stream_profile *to_profile, const rs2_extrinsics *extrinsics, rs2_error **error)
void rs2_delete_sensor(rs2_sensor *sensor)
rs2_sensor * rs2_create_sensor(const rs2_sensor_list *list, int index, rs2_error **error)
int rs2_get_sensors_count(const rs2_sensor_list *info_list, rs2_error **error)
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
Definition: rs_sensor.h:22
void rs2_set_motion_device_intrinsics(const rs2_sensor *sensor, const rs2_stream_profile *profile, const rs2_motion_device_intrinsic *intrinsics, rs2_error **error)
void rs2_set_intrinsics(const rs2_sensor *sensor, const rs2_stream_profile *profile, const rs2_intrinsics *intrinsics, rs2_error **error)
@ RS2_EXTENSION_DEBUG
Definition: rs_types.h:169
@ RS2_EXTENSION_UPDATABLE
Definition: rs_types.h:205
@ RS2_EXTENSION_AUTO_CALIBRATED_DEVICE
Definition: rs_types.h:209
@ RS2_EXTENSION_TM2
Definition: rs_types.h:190
@ RS2_EXTENSION_DEVICE_CALIBRATION
Definition: rs_types.h:217
@ RS2_EXTENSION_UPDATE_DEVICE
Definition: rs_types.h:206
@ RS2_EXTENSION_CALIBRATION_CHANGE_DEVICE
Definition: rs_types.h:223
struct rs2_device_list rs2_device_list
Definition: rs_types.h:267
struct rs2_error rs2_error
Definition: rs_types.h:259
struct rs2_raw_data_buffer rs2_raw_data_buffer
Definition: rs_types.h:261
Definition: rs_types.hpp:63
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented.
Definition: rs_sensor.h:99
Video stream intrinsics.
Definition: rs_types.h:59
Motion device intrinsics: scale, bias, and variances.
Definition: rs_types.h:104
Definition: rs_types.hpp:84