-
Notifications
You must be signed in to change notification settings - Fork 110
Fetch the cameras's timestamp associated with an image #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: indigo-devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,6 +277,32 @@ bool PylonCameraImpl<CameraTraitT>::setupSequencer(const std::vector<float>& exp | |
| } | ||
| } | ||
|
|
||
| template <typename CameraTraitT> | ||
| bool PylonCameraImpl<CameraTraitT>::enableTimestampChunk() | ||
| { | ||
| // Enable chunks in general | ||
| if (GenApi::IsWritable(cam_->ChunkModeActive)) | ||
| { | ||
| cam_->ChunkModeActive.SetValue(true); | ||
| } | ||
| else | ||
| { | ||
| ROS_ERROR( "The camera doesn't support chunk features, which are needed for timestamps"); | ||
| return false; | ||
| } | ||
| // Enable time stamp chunks | ||
| cam_->ChunkSelector.SetValue(ChunkSelectorEnums::ChunkSelector_Timestamp); | ||
| cam_->ChunkEnable.SetValue(true); | ||
| /* As explained in grab(std::vector<uint8_t>& image, ros::Time& stamp) below, | ||
| * a small GenICam node map is required for accessing chunk data each time. | ||
| * The node maps are usually created dynamically when StartGrabbing() is called. | ||
| * To avoid a delay caused by node map creation, | ||
| * we create a static pool of node maps once before grabbing. | ||
| */ | ||
| cam_->StaticChunkNodeMapPoolSize = cam_->MaxNumBuffer.GetValue(); | ||
| return true; | ||
| } | ||
|
|
||
| template <typename CameraTraitT> | ||
| bool PylonCameraImpl<CameraTraitT>::startGrabbing(const PylonCameraParameter& parameters) | ||
| { | ||
|
|
@@ -287,6 +313,10 @@ bool PylonCameraImpl<CameraTraitT>::startGrabbing(const PylonCameraParameter& pa | |
| setShutterMode(parameters.shutter_mode_); | ||
| } | ||
|
|
||
| if (parameters.fetch_camera_timestamp_) { | ||
| enableTimestampChunk(); | ||
| } | ||
|
|
||
| available_image_encodings_ = detectAvailableImageEncodings(); | ||
| if ( !setImageEncoding(parameters.imageEncoding()) ) | ||
| { | ||
|
|
@@ -341,6 +371,47 @@ bool PylonCameraImpl<CameraTrait>::grab(std::vector<uint8_t>& image) | |
| return true; | ||
| } | ||
|
|
||
| template <typename CameraTrait> | ||
| bool PylonCameraImpl<CameraTrait>::grab(std::vector<uint8_t>& image, ros::Time& stamp) | ||
| { | ||
| Pylon::CGrabResultPtr ptr_grab_result; | ||
| if ( !grab(ptr_grab_result) ) | ||
| { | ||
| ROS_ERROR("Error: Grab was not successful"); | ||
| return false; | ||
| } | ||
|
|
||
| const uint8_t *pImageBuffer = reinterpret_cast<uint8_t*>(ptr_grab_result->GetBuffer()); | ||
| image.assign(pImageBuffer, pImageBuffer + img_size_byte_); | ||
|
|
||
| /* Get pointer to the chunkTimestamp via the chunk data node map. | ||
| * To avoid delay caused by repeated dynamic road map creation, | ||
| * we create a static pool of node maps once at startup in enableTimestampChunk() above, | ||
| * as explained in Grab_ChunkImage.cpp of pylon C++ Sample code. | ||
| */ | ||
| GenApi::CIntegerPtr chunkTimestamp(ptr_grab_result->GetChunkDataNodeMap().GetNode( "ChunkTimestamp")); | ||
| if (GenApi::IsReadable(chunkTimestamp)) | ||
| { | ||
| uint64_t chunckTimestampCopy = chunkTimestamp->GetValue(); | ||
| /* chunckTimestamp is based on a counter that counts the number of clock ticks generated by the camera. | ||
| * The unit of each tick is 8ns. So, we need to multiply the variable by 8. | ||
| * Note that multiplied value will wrap around from 0 if chunckTimestamp >= 2^61, | ||
| * or roughly 26687 days after the camera setup. */ | ||
| chunckTimestampCopy <<= 3; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @briansmlee Thanks for this implementation. I have tested it and confirmed this works. I wanted to point out an issue with hardcoding the mapping from ticks to time elapsed. I understand most cameras with PTP enabled have a mapping of You can confirm if there are any cameras that have a In any case, it might be a good idea to have this as a parameter in the config file like you have done for enabling timestamp fetching. Thanks, |
||
| stamp.fromNSec(chunckTimestampCopy); | ||
| } | ||
| else | ||
| { | ||
| ROS_WARN("Error: unable to read time stamp from camera"); | ||
| return false; | ||
| } | ||
|
|
||
| if ( !is_ready_ ) | ||
| is_ready_ = true; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| template <typename CameraTrait> | ||
| bool PylonCameraImpl<CameraTrait>::grab(uint8_t* image) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env python | ||
| # simple script to test the feature to fetch camera's time stamp. | ||
| # compares ros time and camera time | ||
| import rospy | ||
| from sensor_msgs.msg import Image | ||
|
|
||
| prev_ros_time = prev_img_time = None | ||
|
|
||
| def callback(msg): | ||
| global prev_ros_time, prev_img_time | ||
| new_ros_time = rospy.Time.now() | ||
| new_img_time = msg.header.stamp | ||
| if prev_ros_time is not None and prev_img_time is not None: | ||
| ros_dur = new_ros_time - prev_ros_time | ||
| img_dur = new_img_time - prev_img_time | ||
| rospy.loginfo('ros time: %d seconds and %d nanoseconds', new_ros_time.secs, new_ros_time.nsecs) | ||
| rospy.loginfo('img time: %d seconds and %d nanoseconds', new_img_time.secs, new_img_time.nsecs) | ||
| rospy.loginfo('ros duration: %d seconds and %d nanoseconds', ros_dur.secs, ros_dur.nsecs) | ||
| rospy.loginfo('img duration: %d seconds and %d nanoseconds', img_dur.secs, img_dur.nsecs) | ||
| prev_ros_time = new_ros_time | ||
| prev_img_time = new_img_time | ||
|
|
||
| rospy.init_node('compare_ros_and_image_timestamp') | ||
| sub = rospy.Subscriber('/pylon_camera_node/image_raw', Image, callback) | ||
| rospy.spin() |

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, add a description to README.md?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!