-
Notifications
You must be signed in to change notification settings - Fork 138
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
feat: override_timestamps_with_wall_time
parameter
#562
Merged
azeey
merged 11 commits into
gazebosim:ros2
from
nobleo:feat/override_timestamps_with_wall_time
Jul 31, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
489affd
feat: `override_timestamps_with_wall_time` parameter
reinzor 5b3fc44
uncrustify
reinzor f5c9ce5
Merge remote-tracking branch 'upstream/ros2' into feat/override_times…
reinzor 252f175
Merge branch 'ros2' into feat/override_timestamps_with_wall_time
reinzor 25b6ae3
Merge branch 'ros2' into feat/override_timestamps_with_wall_time
reinzor 3c0844e
Merge branch 'ros2' into feat/override_timestamps_with_wall_time
reinzor 9837d6a
declare parameter only once
reinzor 0ae220c
Merge branch 'feat/override_timestamps_with_wall_time' of github.com:…
reinzor a6ef7d0
Merge branch 'feat/override_timestamps_with_wall_time' of github.com:…
reinzor fec2c4d
Merge branch 'feat/override_timestamps_with_wall_time' of github.com:…
reinzor 99b0da0
Added missing includes
reinzor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,11 @@ | |
#ifndef FACTORY_HPP_ | ||
#define FACTORY_HPP_ | ||
|
||
#include <chrono> | ||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <type_traits> | ||
|
||
#include <gz/transport/Node.hh> | ||
#include <gz/transport/SubscribeOptions.hh> | ||
|
@@ -28,6 +30,16 @@ | |
|
||
#include "factory_interface.hpp" | ||
|
||
template<class T, class = void> | ||
struct has_header : std::false_type | ||
{ | ||
}; | ||
|
||
template<class T> | ||
struct has_header<T, std::void_t<decltype(T::header)>>: std::true_type | ||
{ | ||
}; | ||
|
||
namespace ros_gz_bridge | ||
{ | ||
|
||
|
@@ -104,12 +116,13 @@ class Factory : public FactoryInterface | |
std::shared_ptr<gz::transport::Node> node, | ||
const std::string & topic_name, | ||
size_t /*queue_size*/, | ||
rclcpp::PublisherBase::SharedPtr ros_pub) | ||
rclcpp::PublisherBase::SharedPtr ros_pub, | ||
bool override_timestamps_with_wall_time) | ||
{ | ||
std::function<void(const GZ_T &)> subCb = | ||
[this, ros_pub](const GZ_T & _msg) | ||
[this, ros_pub, override_timestamps_with_wall_time](const GZ_T & _msg) | ||
{ | ||
this->gz_callback(_msg, ros_pub); | ||
this->gz_callback(_msg, ros_pub, override_timestamps_with_wall_time); | ||
}; | ||
|
||
// Ignore messages that are published from this bridge. | ||
|
@@ -139,10 +152,20 @@ class Factory : public FactoryInterface | |
static | ||
void gz_callback( | ||
const GZ_T & gz_msg, | ||
rclcpp::PublisherBase::SharedPtr ros_pub) | ||
rclcpp::PublisherBase::SharedPtr ros_pub, | ||
bool override_timestamps_with_wall_time) | ||
{ | ||
ROS_T ros_msg; | ||
convert_gz_to_ros(gz_msg, ros_msg); | ||
if constexpr (has_header<ROS_T>::value) { | ||
if (override_timestamps_with_wall_time) { | ||
auto now = std::chrono::system_clock::now().time_since_epoch(); | ||
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. include |
||
auto ns = | ||
std::chrono::duration_cast<std::chrono::nanoseconds>(now).count(); | ||
ros_msg.header.stamp.sec = ns / 1e9; | ||
ros_msg.header.stamp.nanosec = ns - ros_msg.header.stamp.sec * 1e9; | ||
} | ||
} | ||
std::shared_ptr<rclcpp::Publisher<ROS_T>> pub = | ||
std::dynamic_pointer_cast<rclcpp::Publisher<ROS_T>>(ros_pub); | ||
if (pub != nullptr) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
include
<type_traits>