1212// **************Symbolic Constant Macros (defines) *************
1313#define STREAM_RUN_TIME_SEC 4
1414#define ERROR_START_STREAM_TIME 10000
15+ #define SECOND_TO_MICROSECONDS (sec ) (sec * 1000 * 1000 )
1516
1617// Total ACC range is +/- 147.15 m/s^2.
1718#define MIN_ACC_READING -15 .0f
@@ -85,6 +86,8 @@ static void RunStreamConfig(k4a_device_t device, uint32_t expected_fps)
8586 tickcounter_ms_t end_ms;
8687 tickcounter_ms_t delta_ms;
8788 uint32_t error_tolerance;
89+ int first_sample_inspected = 0 ;
90+ uint64_t fps_period_us;
8891
8992 stream_count = STREAM_RUN_TIME_SEC * expected_fps;
9093 tick_count = tickcounter_create ();
@@ -95,8 +98,11 @@ static void RunStreamConfig(k4a_device_t device, uint32_t expected_fps)
9598 config.color_resolution = K4A_COLOR_RESOLUTION_2160P;
9699 config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
97100 config.camera_fps = K4A_FRAMES_PER_SECOND_30;
101+ config.synchronized_images_only = true ;
98102 ASSERT_EQ (K4A_RESULT_SUCCEEDED, k4a_device_start_cameras (device, &config));
99103
104+ fps_period_us = HZ_TO_PERIOD_US (k4a_convert_fps_to_uint (config.camera_fps ));
105+
100106 // start streaming.
101107 ASSERT_EQ (K4A_RESULT_SUCCEEDED, k4a_device_start_imu (device));
102108
@@ -114,7 +120,16 @@ static void RunStreamConfig(k4a_device_t device, uint32_t expected_fps)
114120 {
115121 // get frames as available
116122 ASSERT_EQ (K4A_WAIT_RESULT_SUCCEEDED, k4a_device_get_imu_sample (device, &imu_sample, timeout_ms));
117-
123+ if (!first_sample_inspected)
124+ {
125+ // Time stamps should not go backwards and the first time stamps should be around zero as the color camera
126+ // staring will device time stamps reset to zero.
127+ ASSERT_LT (imu_sample.acc_timestamp_usec , SECOND_TO_MICROSECONDS (2 ));
128+ ASSERT_LT (imu_sample.gyro_timestamp_usec , SECOND_TO_MICROSECONDS (2 ));
129+ std::cout << " Initial Timestamps are: " << imu_sample.gyro_timestamp_usec << " and "
130+ << imu_sample.gyro_timestamp_usec << " \n " ;
131+ first_sample_inspected = 1 ;
132+ }
118133 ASSERT_GT (imu_sample.acc_timestamp_usec , last_acc_dev_ts);
119134 last_acc_dev_ts = imu_sample.acc_timestamp_usec ;
120135 ASSERT_GT (imu_sample.gyro_timestamp_usec , last_gyro_dev_ts);
@@ -128,6 +143,34 @@ static void RunStreamConfig(k4a_device_t device, uint32_t expected_fps)
128143 ASSERT_EQ (true , is_float_in_range (imu_sample.gyro_sample .xyz .y , MIN_GYRO_READING, MAX_GYRO_READING, " GYRO_Y" ));
129144 ASSERT_EQ (true , is_float_in_range (imu_sample.gyro_sample .xyz .z , MIN_GYRO_READING, MAX_GYRO_READING, " GYRO_Z" ));
130145
146+ {
147+ k4a_capture_t capture;
148+ k4a_wait_result_t wresult;
149+ ASSERT_NE (wresult = k4a_device_get_capture (device, &capture, 0 ), K4A_WAIT_RESULT_FAILED);
150+ if (wresult == K4A_WAIT_RESULT_SUCCEEDED)
151+ {
152+ k4a_image_t image = k4a_capture_get_color_image (capture);
153+ int64_t ts_c_dev = (int64_t )k4a_image_get_device_timestamp_usec (image);
154+ EXPECT_LT (std::abs (ts_c_dev - (int64_t )imu_sample.gyro_timestamp_usec ), (int64_t )fps_period_us * 4 );
155+ EXPECT_LT (std::abs (ts_c_dev - (int64_t )imu_sample.acc_timestamp_usec ), (int64_t )fps_period_us * 4 );
156+ k4a_image_release (image);
157+
158+ image = k4a_capture_get_ir_image (capture);
159+ int64_t ts_ir_dev = (int64_t )k4a_image_get_device_timestamp_usec (image);
160+ EXPECT_LT (std::abs (ts_ir_dev - (int64_t )imu_sample.gyro_timestamp_usec ), (int64_t )fps_period_us * 4 );
161+ EXPECT_LT (std::abs (ts_ir_dev - (int64_t )imu_sample.acc_timestamp_usec ), (int64_t )fps_period_us * 4 );
162+ k4a_image_release (image);
163+
164+ // printf("IMU PTS delta %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " \n",
165+ // (int64_t)imu_sample.gyro_timestamp_usec - ts_c_dev,
166+ // (int64_t)imu_sample.acc_timestamp_usec - ts_c_dev,
167+ // (int64_t)imu_sample.gyro_timestamp_usec - ts_ir_dev,
168+ // (int64_t)imu_sample.acc_timestamp_usec - ts_ir_dev);
169+
170+ k4a_capture_release (capture);
171+ }
172+ }
173+
131174 stream_count--;
132175 };
133176
0 commit comments