···6868DEBUG_GET_ONCE_NUM_OPTION(slam_prediction_type, "SLAM_PREDICTION_TYPE", long(SLAM_PRED_SP_SO_IA_SL))
6969DEBUG_GET_ONCE_BOOL_OPTION(slam_write_csvs, "SLAM_WRITE_CSVS", false)
7070DEBUG_GET_ONCE_OPTION(slam_csv_path, "SLAM_CSV_PATH", "evaluation/")
7171+DEBUG_GET_ONCE_BOOL_OPTION(slam_timing_stat, "SLAM_TIMING_STAT", true)
71727273//! Namespace for the interface to the external SLAM tracking system
7374namespace xrt::auxiliary::tracking::slam {
7475constexpr int UI_TIMING_POSE_COUNT = 192;
7576constexpr int UI_GTDIFF_POSE_COUNT = 192;
7777+constexpr int NUM_CAMS = 2; //!< This should be used as little as possible to allow setups that are not stereo
76787779using std::ifstream;
7880using std::make_shared;
7979-using std::make_unique;
8081using std::map;
8182using std::ofstream;
8283using std::shared_ptr;
8384using std::string;
8485using std::to_string;
8585-using std::unique_ptr;
8686using std::vector;
8787using std::filesystem::create_directories;
8888using Trajectory = map<timepoint_ns, xrt_pose>;
···367367 //! Tracker timing info for performance evaluation
368368 struct
369369 {
370370+ bool ext_available = false; //!< Whether the SLAM system supports the timing extension
371371+ bool ext_enabled = false; //!< Whether the timing extension is enabled
370372 float dur_ms[UI_TIMING_POSE_COUNT]; //!< Timing durations in ms
371373 int idx = 0; //!< Index of latest entry in @ref dur_ms
372374 u_var_combo start_ts; //!< UI combo box to select initial timing measurement
···374376 int start_ts_idx; //!< Selected initial timing measurement in @ref start_ts
375377 int end_ts_idx; //!< Selected final timing measurement in @ref end_ts
376378 struct u_var_timing ui; //!< Realtime UI for tracker durations
377377- bool ext_enabled = false; //!< Whether the SLAM system supports the timing extension
378379 vector<string> columns; //!< Column names of the measured timestamps
379380 string joined_columns; //!< Column names as a null separated string
381381+ struct u_var_button enable_btn; //!< Toggle tracker timing reports
380382 } timing;
381383382384 //! Ground truth related fields
···401403static void
402404timing_ui_setup(TrackerSlam &t)
403405{
406406+ // Setup toggle button
407407+ static const char *msg[2] = {"[OFF] Enable timing", "[ON] Disable timing"};
408408+ u_var_button_cb cb = [](void *t_ptr) {
409409+ TrackerSlam *t = (TrackerSlam *)t_ptr;
410410+ u_var_button &btn = t->timing.enable_btn;
411411+ bool &e = t->timing.ext_enabled;
412412+ e = !e;
413413+ snprintf(btn.label, sizeof(btn.label), "%s", msg[e]);
414414+ const auto params = make_shared<FPARAMS_EPET>(e);
415415+ shared_ptr<void> _;
416416+ t->slam->use_feature(F_ENABLE_POSE_EXT_TIMING, params, _);
417417+ };
418418+ t.timing.enable_btn.cb = cb;
419419+ t.timing.enable_btn.disabled = !t.timing.ext_available;
420420+ t.timing.enable_btn.ptr = &t;
421421+ u_var_add_button(&t, &t.timing.enable_btn, msg[t.timing.ext_enabled]);
422422+423423+ // Setup graph
424424+404425 // Construct null-separated array of options for the combo box
405426 using namespace std::string_literals;
406427 t.timing.joined_columns = "";
···440461 vector<timepoint_ns> tss = {p.timestamp, now};
441462442463 // Add extra timestamps if the SLAM tracker provides them
443443- if (t.timing.ext_enabled) {
444444- shared_ptr<pose_extension> ext = p.find_pose_extension(pose_ext_type::TIMING);
445445- SLAM_DASSERT(ext != nullptr, "An enabled extension was null");
464464+ shared_ptr<pose_extension> ext = p.find_pose_extension(pose_ext_type::TIMING);
465465+ if (ext) {
446466 pose_ext_timing pet = *std::static_pointer_cast<pose_ext_timing>(ext);
447467 tss.insert(tss.begin() + 1, pet.timing.begin(), pet.timing.end());
448468 }
···615635 gt_ui_push(t, nts, rel.pose);
616636 t.slam_traj_writer->push(nts, rel.pose);
617637618618- auto tss = timing_ui_push(t, np);
619619- t.slam_times_writer->push(tss);
638638+ if (t.timing.ext_enabled) {
639639+ auto tss = timing_ui_push(t, np);
640640+ t.slam_times_writer->push(tss);
641641+ }
620642621643 dequeued = t.slam->try_dequeue_pose(tracked_pose);
622644 }
···788810 const t_stereo_camera_calibration *stereo_calib,
789811 const t_slam_calib_extras *extra_calib)
790812{
791791- for (int i = 0; i < 2; i++) {
813813+ for (int i = 0; i < NUM_CAMS; i++) {
792814 const t_camera_calibration &view = stereo_calib->view[i];
793815 const auto &extra = extra_calib->cams[i];
794816 const auto params = make_shared<FPARAMS_ACC>();
···10501072 config->prediction = t_slam_prediction_type(debug_get_num_option_slam_prediction_type());
10511073 config->write_csvs = debug_get_bool_option_slam_write_csvs();
10521074 config->csv_path = debug_get_option_slam_csv_path();
10751075+ config->timing_stat = debug_get_bool_option_slam_timing_stat();
10531076 config->stereo_calib = NULL;
10541077 config->imu_calib = NULL;
10551078 config->extra_calib = NULL;
···1138116111391162 t.gt.trajectory = new Trajectory{};
1140116311641164+ // Setup timing extension
11651165+11411166 // Probe for timing extension.
11421142- // We provide two timing columns by default, even if the external system does
11431143- // not support the timing extension for reporting internal timestamps.
11441144- t.timing.columns = {"sampled", "received_by_monado"};
11451167 bool has_timing_extension = t.slam->supports_feature(F_ENABLE_POSE_EXT_TIMING);
11681168+ t.timing.ext_available = has_timing_extension;
11691169+11701170+ // We provide two timing columns by default, even if there is no extension support
11711171+ t.timing.columns = {"sampled", "received_by_monado"};
11721172+11461173 if (has_timing_extension) {
11471147- const auto params = make_shared<FPARAMS_EPET>(true);
11741174+ bool enable_timing_extension = config->timing_stat;
11751175+11761176+ const auto params = make_shared<FPARAMS_EPET>(enable_timing_extension);
11481177 shared_ptr<void> result;
11491149- t.slam->use_feature(FID_EPET, params, result);
11501150- t.timing.ext_enabled = true;
11781178+ t.slam->use_feature(F_ENABLE_POSE_EXT_TIMING, params, result);
11791179+ vector<string> cols = *std::static_pointer_cast<FRESULT_EPET>(result);
1151118011521152- vector<string> cols = *std::static_pointer_cast<FRESULT_EPET>(result);
11531181 t.timing.columns.insert(t.timing.columns.begin() + 1, cols.begin(), cols.end());
11821182+ t.timing.ext_enabled = enable_timing_extension;
11541183 }
1155118411561185 // Setup CSV files
+1
src/xrt/auxiliary/tracking/t_tracking.h
···469469 enum t_slam_prediction_type prediction; //!< Which level of prediction to use
470470 bool write_csvs; //!< Whether to enable CSV writers from the start for later analysis
471471 const char *csv_path; //!< Path to write CSVs to
472472+ bool timing_stat; //!< Enable timing metric in external system
472473473474 // Instead of a slam_config file you can set custom calibration data
474475 const struct t_stereo_camera_calibration *stereo_calib; //!< Camera calibration data