Skip to content
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

Use dedicated TransformListener thread #551

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ void TFWrapper::initialize(
bool using_dedicated_thread)
{
initializeBuffer(clock, rviz_ros_node.lock()->get_raw_node(), using_dedicated_thread);
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
*buffer_, rviz_ros_node.lock()->get_raw_node(), false);
if (using_dedicated_thread) {
// TODO(pull/551): The TransformListener needs very quick spinning so it uses its own node
// here. Remove this in favor of a multithreaded spinner and ensure that the listener callback
// queue does not fill up.
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
*buffer_, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will actually create a new node, did you try what happens if you just use std::make_shared<tf2_ros::TransformListener>( *buffer_, rviz_ros_node.lock()->get_raw_node(), true); - shouldn't this already spin the TransformListener in a dedicated thread?

Copy link
Contributor Author

@ymd-stella ymd-stella Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Martin-Idel Martin-Idel Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see... So the correct way to solve this should be to actually make RViz multi-threaded and spin the transformer callback in its own thread then (and more often than e.g. the update loop).

I guess this is a much more subtle undertaking, so I would propose:

Copy link
Contributor Author

@ymd-stella ymd-stella Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a "todo" comment that this actually introduces a new node and should be done via threading,

If you provide the concrete comment, I'll add them to this PR. (I don't know the format of the TODO comments on this project.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real schema except for linters. The following should do (you can also add your name, but I find the naming inconsistent, it's just enforced by cpplint)

TODO(anyone): The TransformListener needs very quick spinning so it uses its own node here. Remove this in favor of a multithreaded spinner and ensure that the listener callback queue does not fill up.

You'll probably need to split it up into multiple lines.

@jacobperron The error analysis seems sound and the solution works on several machines. When this got ported we explicitly avoided making new nodes if possible, but making RViz multithreaded requires much more work, since this is an issue many people complained about, I think this is a good compromise - unless @ymd-stella wants to jump in and do this of course.
Maybe you could take a quick look?

Copy link
Member

@jacobperron jacobperron Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that a multithreaded executor sounds like the best way to go. I'm okay with merging this workaround in the meantime with a TODO as you suggest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the comment. I've written TODO(pull/551) to make it easier for those who found it to look up the details.

} else {
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
*buffer_, rviz_ros_node.lock()->get_raw_node(), false);
}
}

void TFWrapper::initializeBuffer(
Expand Down