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
Don't auto-activate ROS time if clock topic is being published #559
Conversation
@@ -190,6 +194,7 @@ void TimeSource::on_parameter_event(const rcl_interfaces::msg::ParameterEvent::S | |||
if (it.second->value.bool_value) { | |||
parameter_state_ = SET_TRUE; | |||
enable_ros_time(); | |||
create_clock_sub(); |
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.
Is this in danger of being called more than once and therefore recreating the topic?
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.
for posterity: 9ddb1ae
@@ -190,6 +194,7 @@ void TimeSource::on_parameter_event(const rcl_interfaces::msg::ParameterEvent::S | |||
if (it.second->value.bool_value) { | |||
parameter_state_ = SET_TRUE; | |||
enable_ros_time(); | |||
create_clock_sub(); | |||
} else { | |||
parameter_state_ = SET_FALSE; | |||
disable_ros_time(); |
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.
Should the topic be destroyed here explicitly? (opposite of create_clock_sub()
)
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.
I had reasoned that if the sim param had been set at some point then it wouldn't be so bad to leave the subscription around, but being symmetric might be better hey (so it reflects the same state a node that never had sim time set would have).
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.
Yeah, I'm not sure it will ever come up, but conversely I don't think it would be wrong to remove the subscription if the parameter were allowed to be changed during runtime (not sure where we landed on that point).
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.
yeah, it can be changed at runtime (there are parameter callbacks that will get triggered): 9ddb1ae
oops this was sitting in the in-progress column accidentally. Good for review thanks! |
rclcpp/src/rclcpp/time_source.cpp
Outdated
@@ -37,6 +37,7 @@ TimeSource::TimeSource(std::shared_ptr<rclcpp::Node> node) | |||
: ros_time_active_(false) | |||
{ | |||
this->attachNode(node); | |||
clock_subscription_.reset(); |
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.
Is there a reason this has to go after this->attachNode(node);
? It would be better (in my opinion) to do this in the member initialization section of the constructor as clock_subscription_(nullptr)
.
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.
nah, there wasn't a reason: 73d4a7b
rclcpp/src/rclcpp/time_source.cpp
Outdated
// Subscription already destroyed/never created. | ||
return; | ||
} | ||
clock_subscription_.reset(); |
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.
This call is always safe, so you can do it ever if !clock_subscription_
.
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.
Updated in e34e0d7
* fix return type of rcl_publisher_get_subscription_count * fix it in c file too
closes #514 and #515
Previously, the clock subscription was always created. When messages were received on the clock topic, ROS time was set to active (#514), even if
use_sim_time
was set to false (#515).Now, ROS time will only be set active if the
use_sim_time
parameter is explicitly set true. The subscription is only created if the parameter is set (can be set after node startup).In progress because CI might uncover things relying on the previous behaviour (the /chatter topic won't appear by default now)