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

Suppress spam from calling canTransform #529

Merged
merged 3 commits into from
Aug 23, 2022
Merged

Conversation

gonzodepedro
Copy link
Contributor

@gonzodepedro gonzodepedro commented Jun 1, 2022

Based on #502

Closes #501

Grigoriy Lipenko and others added 2 commits June 1, 2022 15:40
@jacobperron
Copy link
Member

Do you mind also updating these other calls (from my other comment #502 (comment)):

canTransform(target_frame, source_frame, lookup_time, timeout);

canTransform(target_frame, target_time, source_frame, source_time, fixed_frame, timeout);

The user has few options to workaround potential console spam from canTransform.
If we want, it would be better to update the API to optional return the error string.

Signed-off-by: Jacob Perron <[email protected]>
@jacobperron jacobperron changed the title Grishalipenko/ros2 Suppress spam from calling canTransform Jun 20, 2022
@jacobperron
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Not to derail this, but I will point out that suppressing these error messages unconditionally basically constitutes a large behavior change in tf2_ros from previous versions. It also means that we won't get notified of real errors in the tf2 tree (like loops).

I'm not quite sure what we want to do here. Maybe it would be a better idea to rate-limit this instead of suppressing it completely, as we are going to be losing a lot of debugging information this way.

@jacobperron
Copy link
Member

jacobperron commented Jun 23, 2022

The code is a bit tangled, but I think these are the two behavior changes caused by this PR:

  1. Users calling tf2_ros::Buffer::canTransform with a timeout and errstr argument (that is not nullptr) now do not see a wall full of console warnings (3946b6e). Instead, errstr is set to any warning.
  2. Users calling t2_ros::Buffer::lookupTransform with a timeout argument now do not see a wall of console warnings (from the internal canTransform() invocation) (00fa842).

Correct me if I'm wrong, but I don't think (1) is disagreeable.

Regarding (2), the code is a bit hard to follow, but in both the previous and current behavior an exception is thrown from lookupTransform if there is an issue validating frames:

CompactFrameID BufferCore::validateFrameId(
const char * function_name_arg,
const std::string & frame_id) const
{
if (frame_id.empty()) {
std::string error_msg = "Invalid argument \"" + frame_id + "\" passed to " + function_name_arg +
" - in tf2 frame_ids cannot be empty";
throw tf2::InvalidArgumentException(error_msg.c_str());
}
if (startsWithSlash(frame_id)) {
std::string error_msg = "Invalid argument \"" + frame_id + "\" passed to " + function_name_arg +
" - in tf2 frame_ids cannot start with a '/'";
throw tf2::InvalidArgumentException(error_msg.c_str());
}
CompactFrameID id = lookupFrameNumber(frame_id);
if (id == 0) {
std::string error_msg = "\"" + frame_id + "\" passed to " + function_name_arg +
" does not exist. ";
throw tf2::LookupException(error_msg.c_str());
}

called from lookupTransform's implementation:

CompactFrameID target_id = validateFrameId("lookupTransform argument target_frame", target_frame);
CompactFrameID source_id = validateFrameId("lookupTransform argument source_frame", source_frame);

The only difference this PR introduces is that we don't get the (more or less) same message repeated to the console before the exception ultimately occurs. AFAICT, we're only calling canTransform inside lookupTransform as a lazy way to implement the timeout. Both canTransform and lookupTransform do frame ID validation, but the former prints warnings to console and the latter throws an exception.

I agree that the underlying issue of tf2::canTransform printing to console at an unholy rate should probably be fixed.
However, IMO, it doesn't make sense to print warnings to console while we're waiting for a transform to become available with lookupTransform, especially since we're already raising an exception with the same message if there's still a problem when the timeout is reached.

@jacobperron
Copy link
Member

jacobperron commented Jun 23, 2022

If I'm not mistaken, this change doesn't hide errors in the TF tree since lookupTransform still throws an exception with the same error message that was previously printed to console.

@audrow audrow changed the base branch from ros2 to rolling June 28, 2022 14:18
@jacobperron
Copy link
Member

@clalancette friendly ping 🙂

@clalancette
Copy link
Contributor

Correct me if I'm wrong, but I don't think (1) is disagreeable.

Agreed, this is desirable. The part of the patch that changes canTransform looks good.

Regarding (2), the code is a bit hard to follow, but in both the previous and current behavior an exception is thrown from lookupTransform if there is an issue validating frames:

And now looking at it in more detail, I agree with you. canTransform is basically being reused as a way to "wait" for the transform to come in, and as such should not print any warnings. Once that expires and we get to the lookupTransform API (which actually is inherited from the underlying tf2::BufferCore class), then if that transform still doesn't exist we'll throw an exception. That seems like sufficient warning to the user.

So with all of that said, I'm going to approve this. Thanks for the detailed explanation on what is going on here.

@jacobperron
Copy link
Member

jacobperron commented Aug 20, 2022

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status (unrelated cmake warning from osrf_testing_tools_cpp)

@jacobperron jacobperron merged commit 8c2aa5a into rolling Aug 23, 2022
@delete-merged-branch delete-merged-branch bot deleted the grishalipenko/ros2 branch August 23, 2022 17:50
@vincentrou
Copy link

@jacobperron
Thanks for merging this PR.
Is it possible to backport this to humble ?
Since it is the last LTS and there is a lot of related issues : #358

daisukes pushed a commit to CMU-cabot/geometry2 that referenced this pull request Feb 10, 2023
* suppress spam in canTransform

* Uncrustify

Signed-off-by: Gonzalo de Pedro <[email protected]>

* Suppress console spam in other calls to canTransform

The user has few options to workaround potential console spam from canTransform.
If we want, it would be better to update the API to optional return the error string.

Signed-off-by: Jacob Perron <[email protected]>

Signed-off-by: Gonzalo de Pedro <[email protected]>
Signed-off-by: Jacob Perron <[email protected]>
Co-authored-by: Grigoriy Lipenko <[email protected]>
Co-authored-by: Jacob Perron <[email protected]>
@leander2189
Copy link

Was this feature ever ported to humble? I am getting lots of messages in my tests, they make debugging a lot more difficult

@clalancette
Copy link
Contributor

@Mergifyio backport humble

@mergify
Copy link
Contributor

mergify bot commented Jul 24, 2023

backport humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jul 24, 2023
* suppress spam in canTransform

* Uncrustify

Signed-off-by: Gonzalo de Pedro <[email protected]>

* Suppress console spam in other calls to canTransform

The user has few options to workaround potential console spam from canTransform.
If we want, it would be better to update the API to optional return the error string.

Signed-off-by: Jacob Perron <[email protected]>

Signed-off-by: Gonzalo de Pedro <[email protected]>
Signed-off-by: Jacob Perron <[email protected]>
Co-authored-by: Grigoriy Lipenko <[email protected]>
Co-authored-by: Jacob Perron <[email protected]>
(cherry picked from commit 8c2aa5a)
clalancette pushed a commit that referenced this pull request Aug 3, 2023
* suppress spam in canTransform

* Uncrustify

Signed-off-by: Gonzalo de Pedro <[email protected]>

* Suppress console spam in other calls to canTransform

The user has few options to workaround potential console spam from canTransform.
If we want, it would be better to update the API to optional return the error string.

Signed-off-by: Jacob Perron <[email protected]>

Signed-off-by: Gonzalo de Pedro <[email protected]>
Signed-off-by: Jacob Perron <[email protected]>
Co-authored-by: Grigoriy Lipenko <[email protected]>
Co-authored-by: Jacob Perron <[email protected]>
(cherry picked from commit 8c2aa5a)

Co-authored-by: Gonzo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tf2_ros::Buffer::canTransform sends many warnings if frame does not exist
5 participants