Skip to content

Commit 6ff1342

Browse files
committed
Change timestamp source based on issue anqixu#37
1 parent f06e031 commit 6ff1342

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

include/ueye_cam/ueye_cam_driver.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ class UEyeCamDriver {
384384
* Sets a timestamp indicating the moment of the image capture
385385
*/
386386
bool getTimestamp(UEYETIME *timestamp);
387+
388+
/**
389+
* Sets a clock tick indicating the moment of the image capture
390+
*/
391+
bool getClockTick(uint64_t *tick);
387392

388393

389394
protected:

include/ueye_cam/ueye_cam_nodelet.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ class UEyeCamNodelet : public nodelet::Nodelet, public UEyeCamDriver {
162162
* Returns image's timestamp or current wall time if driver call fails.
163163
*/
164164
ros::Time getImageTimestamp();
165+
166+
/**
167+
* Returns image's timestamp based on device's internal clock or current wall time if driver call fails.
168+
*/
169+
ros::Time getImageTickTimestamp();
165170

166171
std::thread frame_grab_thread_;
167172
bool frame_grab_alive_;
@@ -182,6 +187,9 @@ class UEyeCamNodelet : public nodelet::Nodelet, public UEyeCamDriver {
182187
std::string cam_intr_filename_;
183188
std::string cam_params_filename_; // should be valid UEye INI file
184189
ueye_cam::UEyeCamConfig cam_params_;
190+
191+
ros::Time init_ros_time_;
192+
uint64_t init_clock_tick_;
185193
};
186194

187195

src/ueye_cam_driver.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1293,4 +1293,13 @@ bool UEyeCamDriver::getTimestamp(UEYETIME *timestamp) {
12931293
return false;
12941294
}
12951295

1296+
bool UEyeCamDriver::getClockTick(uint64_t *tick) {
1297+
UEYEIMAGEINFO ImageInfo;
1298+
if(is_GetImageInfo (cam_handle_, cam_buffer_id_, &ImageInfo, sizeof (ImageInfo)) == IS_SUCCESS) {
1299+
*tick = ImageInfo.u64TimestampDevice;
1300+
return true;
1301+
}
1302+
return false;
1303+
}
1304+
12961305
} // namespace ueye_cam

src/ueye_cam_nodelet.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,16 @@ void UEyeCamNodelet::frameGrabLoop() {
949949
INT eventTimeout = (cam_params_.auto_frame_rate || cam_params_.ext_trigger_mode) ?
950950
(INT) 2000 : (INT) (1000.0 / cam_params_.frame_rate * 2);
951951
if (processNextFrame(eventTimeout) != NULL) {
952-
ros_image_.header.stamp = ros_cam_info_.header.stamp = getImageTimestamp();
952+
if (init_ros_time_.isZero()) {
953+
if(getClockTick(&init_clock_tick_)) {
954+
init_ros_time_ = getImageTimestamp();
955+
956+
// Deal with instability in getImageTimestamp due to daylight savings time
957+
if (abs((ros::Time::now() - init_ros_time_).toSec()) > abs((ros::Time::now() - (init_ros_time_+ros::Duration(3600,0))).toSec())) { init_ros_time_ += ros::Duration(3600,0); }
958+
if (abs((ros::Time::now() - init_ros_time_).toSec()) > abs((ros::Time::now() - (init_ros_time_-ros::Duration(3600,0))).toSec())) { init_ros_time_ -= ros::Duration(3600,0); }
959+
}
960+
}
961+
ros_image_.header.stamp = ros_cam_info_.header.stamp = getImageTickTimestamp();
953962
// Process new frame
954963
#ifdef DEBUG_PRINTOUT_FRAME_GRAB_RATES
955964
grabbedFrameCount++;
@@ -1069,6 +1078,14 @@ ros::Time UEyeCamNodelet::getImageTimestamp() {
10691078
}
10701079
return ros::Time::now();
10711080
}
1081+
1082+
ros::Time UEyeCamNodelet::getImageTickTimestamp() {
1083+
uint64_t tick;
1084+
if(getClockTick(&tick)) {
1085+
return init_ros_time_ + ros::Duration(double(tick - init_clock_tick_)*1e-7);
1086+
}
1087+
return ros::Time::now();
1088+
}
10721089
// TODO: 0 bug where nodelet locks and requires SIGTERM when there are still subscribers (need to find where does code hang)
10731090

10741091
} // namespace ueye_cam

0 commit comments

Comments
 (0)