Skip to content

Commit 4a6526b

Browse files
authored
Improve message filters error messages (#364)
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent f4ea234 commit 4a6526b

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tf2_ros/include/tf2_ros/message_filter.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ enum FilterFailureReason
8080
/// The message buffer overflowed, and this message was pushed off the back of the queue, but the
8181
// reason it was unable to be transformed is unknown.
8282
Unknown,
83-
/// The timestamp on the message is more than the cache length earlier than the newest data in
84-
// the transform cache
83+
/// The timestamp on the message is earlier than all the data in the transform cache
8584
OutTheBack,
8685
/// The frame_id on the message is empty
8786
EmptyFrameID,
87+
/// No transform found
88+
NoTransformFound,
89+
/// Queue size full
90+
QueueFull,
8891
/// Max enum value for iteration, keep it at the end of the enum
8992
FilterFailureReasonCount,
9093
};
@@ -95,14 +98,18 @@ static std::string get_filter_failure_reason_string(
9598
filter_failure_reasons::FilterFailureReason reason)
9699
{
97100
switch (reason) {
98-
case filter_failure_reasons::Unknown:
99-
return "Unknown";
100101
case filter_failure_reasons::OutTheBack:
101-
return "OutTheBack";
102+
return
103+
"the timestamp on the message is earlier than all the data in the transform cache";
102104
case filter_failure_reasons::EmptyFrameID:
103-
return "EmptyFrameID";
105+
return "the frame id of the message is empty";
106+
case filter_failure_reasons::NoTransformFound:
107+
return "did not find a valid transform, this usually happens at startup ...";
108+
case filter_failure_reasons::QueueFull:
109+
return "discarding message because the queue is full";
110+
case filter_failure_reasons::Unknown: // fallthrough
104111
default:
105-
return "Invalid Failure Reason";
112+
return "unknown";
106113
}
107114
}
108115

@@ -397,7 +404,7 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
397404
(mt::FrameId<M>::value(*front.event.getMessage())).c_str(),
398405
mt::TimeStamp<M>::value(*front.event.getMessage()).seconds());
399406

400-
messageDropped(front.event, filter_failure_reasons::Unknown);
407+
messageDropped(front.event, filter_failure_reasons::QueueFull);
401408

402409
messages_.pop_front();
403410
}
@@ -512,10 +519,12 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
512519
rclcpp::Time stamp = mt::TimeStamp<M>::value(*message);
513520

514521
bool transform_available = true;
522+
FilterFailureReason error = filter_failure_reasons::Unknown;
515523
try {
516524
future.get();
517525
} catch (...) {
518526
transform_available = false;
527+
error = filter_failure_reasons::OutTheBack;
519528
}
520529

521530
if (transform_available) {
@@ -557,7 +566,7 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
557566
TF2_ROS_MESSAGEFILTER_DEBUG(
558567
"Discarding message in frame %s at time %.3f, count now %d",
559568
frame_id.c_str(), stamp.seconds(), messages_.size());
560-
messageDropped(saved_event, filter_failure_reasons::Unknown);
569+
messageDropped(saved_event, error);
561570
}
562571
}
563572

tf2_ros/test/message_filter_test.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,13 @@ TEST(tf2_ros_message_filter, failure_reason_string_conversion)
200200
{
201201
// Sanity test defined messages
202202
EXPECT_EQ(
203-
"Unknown",
203+
"unknown",
204204
tf2_ros::get_filter_failure_reason_string(tf2_ros::filter_failure_reasons::Unknown)
205205
);
206-
EXPECT_EQ(
207-
"OutTheBack",
208-
tf2_ros::get_filter_failure_reason_string(tf2_ros::filter_failure_reasons::OutTheBack)
209-
);
210-
EXPECT_EQ(
211-
"EmptyFrameID",
212-
tf2_ros::get_filter_failure_reason_string(tf2_ros::filter_failure_reasons::EmptyFrameID)
213-
);
214-
215206
// Make sure all values have been given a string
216-
for (size_t i = 0; i < tf2_ros::filter_failure_reasons::FilterFailureReasonCount; i++) {
207+
for (size_t i = 1; i < tf2_ros::filter_failure_reasons::FilterFailureReasonCount; i++) {
217208
EXPECT_NE(
218-
"Invalid Failure Reason",
209+
"unknown",
219210
tf2_ros::get_filter_failure_reason_string(
220211
tf2_ros::filter_failure_reasons::FilterFailureReason(i))
221212
);
@@ -224,7 +215,7 @@ TEST(tf2_ros_message_filter, failure_reason_string_conversion)
224215
// Test that value outside the defined range has been given a string and that count was
225216
// maintained at the end
226217
EXPECT_EQ(
227-
"Invalid Failure Reason",
218+
"unknown",
228219
tf2_ros::get_filter_failure_reason_string(
229220
tf2_ros::filter_failure_reasons::FilterFailureReasonCount)
230221
);

0 commit comments

Comments
 (0)