-
Notifications
You must be signed in to change notification settings - Fork 81
Add new API for the RealtimePublisher #323
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: master
Are you sure you want to change the base?
Add new API for the RealtimePublisher #323
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #323 +/- ##
==========================================
+ Coverage 86.92% 87.06% +0.13%
==========================================
Files 17 17
Lines 1262 1291 +29
Branches 102 106 +4
==========================================
+ Hits 1097 1124 +27
+ Misses 98 97 -1
- Partials 67 70 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
@Juliaj This is the new API, could you please take a look when you have time :) |
should we start migration notes for this repo? |
[[deprecated( | ||
"Use the try_publish() method to publish the message instead of using this method. This method " | ||
"may be removed in future versions.")]] | ||
void lock() |
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.
We may still need the deprecated lock()
and unblock()
to handle the logic in
ForceTorqueSensorBroadcaster::on_configure
which seems to be different than publishing a msg. In on_configure
, only part of a message (e.g., msg_.header) needs modification without immediate publishing.
realtime_publisher_->lock();
realtime_publisher_->msg_.header.frame_id = params_.frame_id;
realtime_publisher_->unlock();
An alternative would be making a similar safer
version for modifying message field.
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.
Thanks for pointing it out. I don't think we would need that, because we can use the get_mutex()
and directly use the unique_lock there which is much better than the current approach.
On the other hand, I want the users to not directly access the Msg_ variable and instead pass through the try_publish method by having a local version of message in the controllers etc. In future, I would like to extend it with a publish
method where we can use an internal message queue (the size would be defined at the construction time) and this would make sure that the messages are always published. Right now, if it is unable to lock, we can never publish messages.
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 see, with the new get_mutex()
, above code could become
{
std::unique_lock<std::mutex> lock(realtime_publisher_->get_mutex());
realtime_publisher_->msg_.header.frame_id = params_.frame_id;
}
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.
In future, I would like to extend it with a
publish
method where we can use an internal message queue (the size would be defined at the construction time) and this would make sure that the messages are always published.
This will be really helpful.
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.
Yes exactly, just like your code snippet
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.
LGTM.
BTW, your fix in stop()
for the deadlock issue was made to jazzy
branch not master. i am assuming we also need that fix on master.
can we add the gcc pragmas to remove deprecation warnings from building the tests? or should we just remove the tests for the old API? do you want to backport this to jazzy as well? or better leave the API untouched there? we could also just add the new methods |
Sorry i missed this comment. yes, I would like to backport this to Jazzy |
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.
Please update https://github.com/ros-controls/realtime_tools/blob/master/realtime_tools/doc/realtime_publisher.rst
and release/migration notes if necessary.
This should avoid any dangling threads of the RealtimePublisher and handling lock and unlock is not safe in most of the situation, so, I've added can_publish and try_publish methods