Don't auto-activate ROS time if clock topic is being published#559
Don't auto-activate ROS time if clock topic is being published#559
Conversation
| if (it.second->value.bool_value) { | ||
| parameter_state_ = SET_TRUE; | ||
| enable_ros_time(); | ||
| create_clock_sub(); |
There was a problem hiding this comment.
Is this in danger of being called more than once and therefore recreating the topic?
| create_clock_sub(); | ||
| } else { | ||
| parameter_state_ = SET_FALSE; | ||
| disable_ros_time(); |
There was a problem hiding this comment.
Should the topic be destroyed here explicitly? (opposite of create_clock_sub())
There was a problem hiding this comment.
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.
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.
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
| : ros_time_active_(false) | ||
| { | ||
| this->attachNode(node); | ||
| clock_subscription_.reset(); |
There was a problem hiding this comment.
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).
| // Subscription already destroyed/never created. | ||
| return; | ||
| } | ||
| clock_subscription_.reset(); |
There was a problem hiding this comment.
This call is always safe, so you can do it ever if !clock_subscription_.
* 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_timewas set to false (#515).Now, ROS time will only be set active if the
use_sim_timeparameter 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)