diff --git a/sensing/autoware_gnss_poser/README.md b/sensing/autoware_gnss_poser/README.md
index d6a1cc0967..78d4a552aa 100644
--- a/sensing/autoware_gnss_poser/README.md
+++ b/sensing/autoware_gnss_poser/README.md
@@ -11,7 +11,7 @@ This node subscribes to NavSatFix to publish the pose of **base_link**. The data
The antenna is rigidly mounted on the vehicle, so this transformation is expected to be static; an antenna that moves relative to `base_link` is out of scope. Publishing it on `/tf_static` is recommended, but a setup that publishes the same fixed relation on `/tf` is supported as well: the node looks up the latest transform rather than the transform at the fix's `header.stamp`, which `/tf` cannot always provide.
-If the transformation from `base_link` to the antenna cannot be obtained, it outputs the pose of the antenna position without performing coordinate transformation.
+If the transformation from `base_link` to the antenna cannot be obtained, the fix is skipped: `gnss_fixed` still reports the receiver's status, but no pose is published. Depending on the startup order, the transformation may arrive after the first fixes, so the fixes are skipped silently for the first 5 seconds, counted by the `header.stamp` of the fixes from the first fix (whatever its status). After that, a fix that cannot get the transformation makes the node log an error once, naming both frames, so that a `header.frame_id` that never gets a transformation is visible instead of silently yielding no pose. When TF has the transformations but the lookup still fails, for example because `header.frame_id` is not a frame name TF accepts (empty, or starting with `/`), waiting does not help, so it is logged as an error at once. Each of the two problems is logged once, and again only after the transformation has been obtained in between. A rosbag replayed in a loop gets the 5 seconds only on its first pass.
## Inputs / Outputs
diff --git a/sensing/autoware_gnss_poser/package.xml b/sensing/autoware_gnss_poser/package.xml
index 74c348c3ce..8dfda8b83f 100644
--- a/sensing/autoware_gnss_poser/package.xml
+++ b/sensing/autoware_gnss_poser/package.xml
@@ -26,6 +26,7 @@
geographic_msgs
geographiclib
geometry_msgs
+ libexpected-dev
rclcpp
rclcpp_components
sensor_msgs
diff --git a/sensing/autoware_gnss_poser/src/gnss_poser.cpp b/sensing/autoware_gnss_poser/src/gnss_poser.cpp
index d696b88fc3..51bc870660 100644
--- a/sensing/autoware_gnss_poser/src/gnss_poser.cpp
+++ b/sensing/autoware_gnss_poser/src/gnss_poser.cpp
@@ -47,6 +47,12 @@ bool is_fixed(const sensor_msgs::msg::NavSatStatus & nav_sat_status_msg)
return nav_sat_status_msg.status >= sensor_msgs::msg::NavSatStatus::STATUS_FIX;
}
+/// The stamp as the time since the epoch of the clock that stamped it.
+std::chrono::nanoseconds to_stamp_time(const builtin_interfaces::msg::Time & stamp)
+{
+ return std::chrono::seconds(stamp.sec) + std::chrono::nanoseconds(stamp.nanosec);
+}
+
/// True when the receiver reports a covariance type other than UNKNOWN.
bool can_get_covariance(const sensor_msgs::msg::NavSatFix & nav_sat_fix_msg)
{
@@ -228,20 +234,22 @@ void GnssPoser::set_ins_orientation(
GnssPoser::Result GnssPoser::input_fix(const sensor_msgs::msg::NavSatFix & fix)
{
+ if (!first_fix_stamp_.has_value()) {
+ first_fix_stamp_ = to_stamp_time(fix.header.stamp);
+ }
+
// Return immediately if map_projector_info has not been received yet.
if (!received_map_projector_info_) {
- return {Outcome::NoProjectorInfo, std::nullopt, std::nullopt, std::nullopt, std::nullopt};
+ return {Outcome::NoProjectorInfo};
}
if (projector_info_.projector_type == autoware_map_msgs::msg::MapProjectorInfo::LOCAL) {
- return {Outcome::LocalProjector, std::nullopt, std::nullopt, std::nullopt, std::nullopt};
+ return {Outcome::LocalProjector};
}
// check fixed topic
if (!is_fixed(fix.status)) {
- return {
- Outcome::NotFixed, make_gnss_fixed(fix.header.stamp, false), std::nullopt, std::nullopt,
- std::nullopt};
+ return {Outcome::NotFixed, make_gnss_fixed(fix.header.stamp, false)};
}
// get position
@@ -256,9 +264,7 @@ GnssPoser::Result GnssPoser::input_fix(const sensor_msgs::msg::NavSatFix & fix)
// fill position buffer
position_buffer_.push_front(position);
if (!position_buffer_.full()) {
- return {
- Outcome::Buffering, make_gnss_fixed(fix.header.stamp, true), std::nullopt, std::nullopt,
- std::nullopt};
+ return {Outcome::Buffering, make_gnss_fixed(fix.header.stamp, true)};
}
// publish average pose or median pose of position buffer
gnss_antenna_pose.position = (params_.gnss_pose_pub_method == GnssPosePubMethod::Average)
@@ -281,11 +287,23 @@ GnssPoser::Result GnssPoser::input_fix(const sensor_msgs::msg::NavSatFix & fix)
gnss_antenna_pose.orientation = orientation;
- // get TF from gnss_antenna to base_link. If it cannot be obtained, the antenna pose is published
- // as the base_link pose, i.e. the identity transform is used (a default-constructed Transform has
- // zero translation and rotation w = 1).
- const geometry_msgs::msg::Transform antenna_to_base_link =
- lookup_antenna_to_base_link_(fix.header.frame_id).value_or(geometry_msgs::msg::Transform{});
+ // get TF from gnss_antenna to base_link.
+ const auto transform = lookup_antenna_to_base_link_(fix.header.frame_id);
+ // Drop this fix if its antenna transform is not available: the fix cannot be expressed as a
+ // base_link pose without it. The transform is static, so this does not resolve by asking for
+ // another time; it resolves once the transform is published.
+ if (!transform.has_value()) {
+ const TransformLookupError error = transform.error();
+ Result result{Outcome::TransformLookupFailed, make_gnss_fixed(fix.header.stamp, true)};
+ if (should_report_transform_error(error, fix.header.stamp)) {
+ mark_transform_error_reported(error);
+ result.antenna_transform_error = error;
+ }
+ return result;
+ }
+ transform_unavailable_reported_ = false;
+ transform_lookup_failed_reported_ = false;
+ const geometry_msgs::msg::Transform antenna_to_base_link = transform.value();
std::array rotation_variances{};
if (params_.use_gnss_ins_orientation) {
@@ -316,4 +334,38 @@ GnssPoser::Result GnssPoser::input_fix(const sensor_msgs::msg::NavSatFix & fix)
make_transform_stamped(pose, params_.gnss_base_frame)};
}
+bool GnssPoser::should_report_transform_error(
+ const TransformLookupError error, const builtin_interfaces::msg::Time & stamp) const
+{
+ bool expected = false;
+ bool reported = false;
+ switch (error) {
+ case TransformLookupError::Unavailable:
+ // Expected within the grace period, as /tf_static may arrive after the first fixes.
+ expected = first_fix_stamp_.has_value() &&
+ to_stamp_time(stamp) - first_fix_stamp_.value() <= antenna_transform_grace_period;
+ reported = transform_unavailable_reported_;
+ break;
+
+ case TransformLookupError::Failed:
+ // Never expected: it does not resolve by waiting.
+ reported = transform_lookup_failed_reported_;
+ break;
+ }
+ return !expected && !reported;
+}
+
+void GnssPoser::mark_transform_error_reported(const TransformLookupError error)
+{
+ switch (error) {
+ case TransformLookupError::Unavailable:
+ transform_unavailable_reported_ = true;
+ break;
+
+ case TransformLookupError::Failed:
+ transform_lookup_failed_reported_ = true;
+ break;
+ }
+}
+
} // namespace autoware::gnss_poser
diff --git a/sensing/autoware_gnss_poser/src/gnss_poser.hpp b/sensing/autoware_gnss_poser/src/gnss_poser.hpp
index 1437c8623a..d467089fd4 100644
--- a/sensing/autoware_gnss_poser/src/gnss_poser.hpp
+++ b/sensing/autoware_gnss_poser/src/gnss_poser.hpp
@@ -14,6 +14,9 @@
#ifndef GNSS_POSER_HPP_
#define GNSS_POSER_HPP_
+#include
+#include
+
#include
#include
#include
@@ -27,6 +30,7 @@
#include
#include
+#include
#include
#include
#include
@@ -61,6 +65,11 @@ constexpr std::array default_unknown_position_variances = {10.0, 10.0
constexpr std::array default_motion_rotation_variances = {0.1, 0.1, 1.0}; // [rad^2]
constexpr double default_ins_placeholder_rmse = 1.0; // [rad]
+// How long after the first fix the antenna transform may be unavailable without being an issue:
+// depending on the startup order, /tf_static may arrive after the first fixes. Measured by the fix
+// header stamps, so that it follows the data, e.g. a rosbag replayed at another rate.
+constexpr std::chrono::seconds antenna_transform_grace_period{5};
+
/// \brief The covariance values above, as GnssPoser takes them.
///
/// Not node parameters: GnssPoserNode constructs GnssPoser without them, so the values are the
@@ -85,8 +94,17 @@ struct GnssPoserCovarianceDefaults
class GnssPoser
{
public:
+ /// \brief Why a TransformLookup could not provide the transform.
+ enum class TransformLookupError {
+ /// TF is not ready for the lookup yet: it has not received the frames, or not the transforms
+ /// that connect them. Expected right after startup, until the transform is published.
+ Unavailable,
+ /// TF was ready for the lookup, but the lookup failed.
+ Failed,
+ };
+
/// \brief Resolves the transform from the antenna frame named in the fix header to base_link,
- /// or std::nullopt when it cannot be resolved.
+ /// or the reason it cannot be resolved.
///
/// The antenna is rigidly mounted on the vehicle, so this transform does not change over time
/// and no stamp is passed; a moving antenna is out of scope. input_fix() calls the lookup only
@@ -94,7 +112,8 @@ class GnssPoser
/// Obtaining the transform (TF lookup, logging) is the caller's business; what to do when there
/// is none is decided here.
using TransformLookup =
- std::function(const std::string & antenna_frame)>;
+ std::function(
+ const std::string & antenna_frame)>;
/// \param lookup_antenna_to_base_link see TransformLookup; kept for the lifetime of the object.
/// \param covariance_defaults see GnssPoserCovarianceDefaults; the node leaves it at its
@@ -110,7 +129,9 @@ class GnssPoser
LocalProjector, ///< the map uses a local projector, so a GNSS fix cannot be converted
NotFixed, ///< the receiver reports no fix; its status is known but no pose is computed
Buffering, ///< the position buffer is not full yet (average and median methods)
- Published, ///< a pose was computed, see Result::gnss_pose
+ /// TransformLookup gave a TransformLookupError, of either kind.
+ TransformLookupFailed,
+ Published, ///< a pose was computed, see Result::gnss_pose
};
/// \brief What the fix produced, as the messages to publish.
@@ -124,13 +145,17 @@ class GnssPoser
Outcome outcome;
/// The receiver's fix status. Empty for a fix that was rejected before the fixed check,
/// which says nothing about the receiver.
- std::optional gnss_fixed;
+ std::optional gnss_fixed = std::nullopt;
/// The base_link pose in the map frame.
- std::optional gnss_pose;
+ std::optional gnss_pose = std::nullopt;
/// The same pose with its 6x6 covariance (only the diagonal is filled).
- std::optional gnss_pose_cov;
+ std::optional gnss_pose_cov = std::nullopt;
/// The same pose as a transform, map_frame -> gnss_base_frame, ready to broadcast.
- std::optional transform;
+ std::optional transform = std::nullopt;
+ /// Why the antenna transform is missing, at the fix where that is to be logged: the first
+ /// Unavailable after the grace period from the first fix, or the first Failed. Each is set
+ /// once, and again only after a fix has got the transform.
+ std::optional antenna_transform_error = std::nullopt;
};
void set_projector_info(const autoware_map_msgs::msg::MapProjectorInfo & projector_info);
@@ -140,10 +165,20 @@ class GnssPoser
void set_ins_orientation(const autoware_sensing_msgs::msg::GnssInsOrientation & orientation);
/// \brief Process one fix: gate, project, buffer, orient, compose with the antenna transform and
- /// attach the covariance.
+ /// attach the covariance. A fix whose antenna transform cannot be resolved is dropped; it has
+ /// still been observed, so the position buffer and the motion orientation take it into account.
Result input_fix(const sensor_msgs::msg::NavSatFix & fix);
private:
+ // Whether a fix stamped `stamp` whose antenna transform lookup failed with `error` reports it as
+ // Result::antenna_transform_error: not Unavailable within the grace period from the first fix,
+ // and not an error of a kind already reported since the transform was last obtained.
+ bool should_report_transform_error(
+ TransformLookupError error, const builtin_interfaces::msg::Time & stamp) const;
+ // Record that `error` has been reported, so that its kind is not reported again until the
+ // transform is obtained.
+ void mark_transform_error_reported(TransformLookupError error);
+
GnssPoserParams params_;
TransformLookup lookup_antenna_to_base_link_;
GnssPoserCovarianceDefaults covariance_defaults_;
@@ -154,6 +189,13 @@ class GnssPoser
geometry_msgs::msg::Point prev_position_;
bool has_prev_position_ = false;
autoware_sensing_msgs::msg::GnssInsOrientation ins_orientation_;
+ // The header stamp of the first fix, whatever its status, from which the grace period runs. Set
+ // once, so a rosbag replayed in a loop gets the grace period only on its first pass.
+ std::optional first_fix_stamp_;
+ // Whether Result::antenna_transform_error has been set to Unavailable, and to Failed, since a
+ // fix last got the transform: each kind is reported once.
+ bool transform_unavailable_reported_ = false;
+ bool transform_lookup_failed_reported_ = false;
};
} // namespace autoware::gnss_poser
diff --git a/sensing/autoware_gnss_poser/src/gnss_poser_node.cpp b/sensing/autoware_gnss_poser/src/gnss_poser_node.cpp
index 7402762a7a..821010d318 100644
--- a/sensing/autoware_gnss_poser/src/gnss_poser_node.cpp
+++ b/sensing/autoware_gnss_poser/src/gnss_poser_node.cpp
@@ -14,12 +14,12 @@
#include "gnss_poser_node.hpp"
+#include
#include
#include
#include
-#include
#include
#include
#include
@@ -127,9 +127,16 @@ void GnssPoserNode::callback_nav_sat_fix(
"Buffering Position. Output Skipped.");
break;
+ // A missing antenna transform is logged below, when the result says it is to be reported;
+ // every fix without it would be too many.
+ case GnssPoser::Outcome::TransformLookupFailed:
case GnssPoser::Outcome::Published:
break;
}
+ if (result.antenna_transform_error.has_value()) {
+ log_antenna_transform_error(
+ nav_sat_fix_msg_ptr->header.frame_id, result.antenna_transform_error.value());
+ }
publish_data(result);
}
@@ -152,6 +159,26 @@ void GnssPoserNode::publish_data(const GnssPoser::Result & result)
}
}
+void GnssPoserNode::log_antenna_transform_error(
+ const std::string & antenna_frame, const GnssPoser::TransformLookupError error)
+{
+ switch (error) {
+ case GnssPoser::TransformLookupError::Unavailable:
+ RCLCPP_ERROR_STREAM(
+ this->get_logger(), "No transform from "
+ << antenna_frame << " to " << base_frame_
+ << " is available; please publish it on TF. Fixes are skipped.");
+ break;
+
+ case GnssPoser::TransformLookupError::Failed:
+ RCLCPP_ERROR_STREAM(
+ this->get_logger(), "Failed to look up the transform from \"" << antenna_frame << "\" to \""
+ << base_frame_
+ << "\". Fixes are skipped.");
+ break;
+ }
+}
+
void GnssPoserNode::callback_gnss_ins_orientation_stamped(
const AUTOWARE_MESSAGE_CONST_SHARED_PTR(autoware_sensing_msgs::msg::GnssInsOrientationStamped) &
msg)
@@ -159,7 +186,8 @@ void GnssPoserNode::callback_gnss_ins_orientation_stamped(
gnss_poser_.set_ins_orientation(msg->orientation);
}
-std::optional GnssPoserNode::get_static_transform(
+tl::expected
+GnssPoserNode::get_static_transform(
const std::string & target_frame, const std::string & source_frame)
{
if (target_frame == source_frame) {
@@ -173,13 +201,15 @@ std::optional GnssPoserNode::get_static_transform
// than /tf_static and the fix is newer than the last /tf message, which tf2 refuses to
// extrapolate.
return tf2_buffer_.lookupTransform(target_frame, source_frame, tf2::TimePointZero).transform;
- } catch (tf2::TransformException & ex) {
- RCLCPP_WARN_STREAM_THROTTLE(
- this->get_logger(), *this->get_clock(), std::chrono::milliseconds(1000).count(), ex.what());
- RCLCPP_WARN_STREAM_THROTTLE(
- this->get_logger(), *this->get_clock(), std::chrono::milliseconds(1000).count(),
- "Please publish TF " << target_frame.c_str() << " to " << source_frame.c_str());
- return std::nullopt;
+ } catch (const tf2::LookupException &) {
+ // A frame has not been received.
+ return tl::unexpected(GnssPoser::TransformLookupError::Unavailable);
+ } catch (const tf2::ConnectivityException &) {
+ // The transforms that connect the frames have not been received.
+ return tl::unexpected(GnssPoser::TransformLookupError::Unavailable);
+ } catch (const tf2::TransformException &) {
+ // e.g. InvalidArgumentException for a frame name that TF does not accept.
+ return tl::unexpected(GnssPoser::TransformLookupError::Failed);
}
}
diff --git a/sensing/autoware_gnss_poser/src/gnss_poser_node.hpp b/sensing/autoware_gnss_poser/src/gnss_poser_node.hpp
index 4d6902a5cc..e4455df13e 100644
--- a/sensing/autoware_gnss_poser/src/gnss_poser_node.hpp
+++ b/sensing/autoware_gnss_poser/src/gnss_poser_node.hpp
@@ -20,6 +20,7 @@
#include
#include
#include
+#include
#include
#include
@@ -31,7 +32,6 @@
#include
#include
-#include
#include
namespace autoware::gnss_poser
@@ -54,13 +54,16 @@ class GnssPoserNode : public autoware::agnocast_wrapper::Node
const AUTOWARE_MESSAGE_CONST_SHARED_PTR(autoware_sensing_msgs::msg::GnssInsOrientationStamped) &
msg);
- // The latest transform between the two frames, or std::nullopt (with a throttled warning) when TF
- // cannot provide it. The antenna sits rigidly on the vehicle, so the transform is static and the
- // latest one is the one that applies to every fix.
- std::optional get_static_transform(
+ // The latest transform between the two frames, or why TF cannot provide it. The antenna sits
+ // rigidly on the vehicle, so the transform is static and the latest one is the one that applies
+ // to every fix.
+ tl::expected get_static_transform(
const std::string & target_frame, const std::string & source_frame);
// Publish the messages the pose computation produced.
void publish_data(const GnssPoser::Result & result);
+ // Log why the antenna transform is missing, at the fix where GnssPoser says to.
+ void log_antenna_transform_error(
+ const std::string & antenna_frame, GnssPoser::TransformLookupError error);
// Declared before tf2_listener_, so that a missing or invalid parameter throws before the
// listener starts its spin thread. If the listener is destroyed before that thread enters
diff --git a/sensing/autoware_gnss_poser/test/test_gnss_poser.cpp b/sensing/autoware_gnss_poser/test/test_gnss_poser.cpp
index be398690e4..f93abccc92 100644
--- a/sensing/autoware_gnss_poser/test/test_gnss_poser.cpp
+++ b/sensing/autoware_gnss_poser/test/test_gnss_poser.cpp
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
#include
#include
@@ -44,6 +45,7 @@
#include
#include
+#include
#include
#include
#include
@@ -62,6 +64,9 @@ using geometry_msgs::msg::Quaternion;
using geometry_msgs::msg::Transform;
using sensor_msgs::msg::NavSatFix;
using sensor_msgs::msg::NavSatStatus;
+using TransformLookupError = GnssPoser::TransformLookupError;
+using std::chrono_literals::operator""ms;
+using std::chrono_literals::operator""s;
// ---------------------------------------------------------------------------------------
// Reference input used throughout (same point as autoware_geography_utils' own tests).
@@ -404,10 +409,10 @@ void expect_rotation_variances_near(
EXPECT_NEAR(covariance[cov_yaw_yaw], yaw, rmse_squared_tolerance);
}
-// The fixes of these cases carry the frame `gnss`, for which the node had no transform and
-// composed with the identity; the lookup that stands in for TF provides the identity directly.
+// The lookup that stands in for TF provides the identity, so that the cases taken from the node
+// characterization stay about what they check rather than about the antenna transform.
const GnssPoser::TransformLookup identity_lookup = [](const std::string &) {
- return std::optional(Transform{});
+ return tl::expected(Transform{});
};
// A GnssPoser that has received the MGRS projector info.
@@ -496,6 +501,57 @@ struct CovarianceType
class GnssPoserKnownCovarianceType : public ::testing::TestWithParam
{
};
+
+// A failed antenna transform lookup.
+struct MissingTransformCase
+{
+ const char * name;
+ TransformLookupError error;
+};
+
+class GnssPoserMissingTransform : public ::testing::TestWithParam
+{
+};
+
+constexpr std::chrono::milliseconds grace_period =
+ autoware::gnss_poser::antenna_transform_grace_period;
+constexpr std::chrono::milliseconds beyond_grace_period = grace_period + 1ms;
+
+// `stamp` advanced by `offset`.
+builtin_interfaces::msg::Time stamp_after(
+ const builtin_interfaces::msg::Time & stamp, const std::chrono::nanoseconds offset)
+{
+ const std::chrono::nanoseconds time =
+ std::chrono::seconds(stamp.sec) + std::chrono::nanoseconds(stamp.nanosec) + offset;
+ const std::chrono::seconds sec = std::chrono::floor(time);
+ builtin_interfaces::msg::Time advanced;
+ advanced.sec = static_cast(sec.count());
+ advanced.nanosec = static_cast((time - sec).count());
+ return advanced;
+}
+
+constexpr TransformLookupError unavailable = TransformLookupError::Unavailable;
+constexpr TransformLookupError failed = TransformLookupError::Failed;
+
+// A GnssPoser with the MGRS projector whose antenna transform lookup gives `available`.
+class GnssPoserAntennaTransformReport : public ::testing::Test
+{
+protected:
+ void SetUp() override { poser.set_projector_info(make_mgrs_projector_info()); }
+
+ // The antenna transform error that the reference fix, stamped `offset` after the first fix,
+ // reports.
+ std::optional input_fix_at(const std::chrono::milliseconds offset)
+ {
+ NavSatFix fix = make_reference_fix();
+ fix.header.stamp = stamp_after(fix.header.stamp, offset);
+ return poser.input_fix(fix).antenna_transform_error;
+ }
+
+ // no transform until it is assigned
+ tl::expected available = tl::unexpected(unavailable);
+ GnssPoser poser{{}, [this](const std::string &) { return available; }};
+};
} // namespace
// =======================================================================================
@@ -1156,3 +1212,165 @@ TEST(GnssPoser, Covariance_UnknownType_PositionVariancesAreTen)
}
}
}
+
+// =======================================================================================
+// 6. Antenna transform
+// =======================================================================================
+
+// Without the antenna transform the fix cannot be expressed as a base_link pose, so it is dropped.
+// The receiver had a position solution, so its status is still reported. Either lookup error gives
+// the same outcome; Result::antenna_transform_error tells whether the transform may still become
+// available.
+TEST_P(GnssPoserMissingTransform, Tf_MissingTransform_PublishesOnlyGnssFixed)
+{
+ // Arrange
+ const TransformLookupError error = GetParam().error;
+ GnssPoser poser(
+ {}, [error](const std::string &) -> tl::expected {
+ return tl::unexpected(error);
+ });
+ poser.set_projector_info(make_mgrs_projector_info());
+
+ // Act
+ const auto result = poser.input_fix(make_reference_fix());
+
+ // Assert
+ EXPECT_EQ(result.outcome, GnssPoser::Outcome::TransformLookupFailed);
+ expect_only_gnss_fixed(result);
+ EXPECT_TRUE(result.gnss_fixed.value().data);
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ LookupErrors, GnssPoserMissingTransform,
+ ::testing::Values(
+ MissingTransformCase{"Unavailable", TransformLookupError::Unavailable},
+ MissingTransformCase{"Failed", TransformLookupError::Failed}),
+ [](const ::testing::TestParamInfo & info) {
+ return std::string(info.param.name);
+ });
+
+// A fix dropped for lack of the transform has still been observed: it stays in the position
+// buffer, so the average once the transform is available includes it.
+TEST(GnssPoser, Tf_MissingTransform_FixStaysInPositionBuffer)
+{
+ // Arrange
+ // no transform until it is assigned
+ tl::expected available =
+ tl::unexpected(TransformLookupError::Unavailable);
+ GnssPoser poser(
+ make_buffer_params(1, 2), [&available](const std::string &) { return available; });
+ poser.set_projector_info(make_mgrs_projector_info());
+ const auto fixes = make_average_fixes();
+ input_fixes(poser, {fixes[0], fixes[1]});
+ available = Transform{};
+
+ // Act
+ const auto result = poser.input_fix(fixes[2]);
+
+ // Assert
+ expect_point_near(
+ pose_of(result).position, mean_of({project_mgrs(fixes[1]), project_mgrs(fixes[2])}));
+}
+
+// Likewise a dropped fix is the previous position of the motion heading: the first fix with the
+// transform heads along the step from the last dropped fix, not from an older one.
+TEST(GnssPoser, Tf_MissingTransform_FixAdvancesMotionHeading)
+{
+ // Arrange
+ GnssPoserParams params;
+ params.gnss_pose_pub_method = GnssPosePubMethod::Instant;
+ params.use_gnss_ins_orientation = false;
+ // no transform until it is assigned
+ tl::expected available =
+ tl::unexpected(TransformLookupError::Unavailable);
+ GnssPoser poser(params, [&available](const std::string &) { return available; });
+ poser.set_projector_info(make_mgrs_projector_info());
+ const auto fixes = make_motion_fixes();
+ input_fixes(poser, {fixes[0], fixes[1]});
+ available = Transform{};
+ const auto p2 = project_mgrs(fixes[1]);
+ const auto p3 = project_mgrs(fixes[2]);
+
+ // Act
+ const auto result = poser.input_fix(fixes[2]);
+
+ // Assert
+ EXPECT_NEAR(
+ yaw_of(pose_of(result).orientation), std::atan2(p3.y - p2.y, p3.x - p2.x), angle_tolerance);
+}
+
+// Right after startup /tf_static may not have arrived yet, so a missing transform is not reported
+// within the grace period from the first fix.
+TEST_F(GnssPoserAntennaTransformReport, Tf_UnavailableWithinGracePeriod_NotReported)
+{
+ // Act
+ const std::optional first = input_fix_at(0s);
+ const std::optional at_grace_period = input_fix_at(grace_period);
+
+ // Assert
+ EXPECT_EQ(first, std::nullopt);
+ EXPECT_EQ(at_grace_period, std::nullopt);
+}
+
+// Past the grace period a missing transform is reported, once: the fixes after it, still without
+// the transform, do not report it again.
+TEST_F(GnssPoserAntennaTransformReport, Tf_UnavailableBeyondGracePeriod_ReportedOnce)
+{
+ // Act
+ const std::optional first = input_fix_at(0s);
+ const std::optional beyond_grace_period_fix =
+ input_fix_at(beyond_grace_period);
+ const std::optional next = input_fix_at(beyond_grace_period + 1s);
+
+ // Assert
+ EXPECT_EQ(first, std::nullopt);
+ EXPECT_EQ(beyond_grace_period_fix, unavailable);
+ EXPECT_EQ(next, std::nullopt);
+}
+
+// The grace period is measured from the first fix of all, not from the first fix without the
+// transform: a transform missing only after the grace period is reported at once.
+TEST_F(GnssPoserAntennaTransformReport, Tf_UnavailableAfterGracePeriod_ReportedAtOnce)
+{
+ // Arrange
+ available = Transform{};
+ input_fix_at(0s);
+ available = tl::unexpected(unavailable);
+
+ // Act
+ const std::optional reported = input_fix_at(beyond_grace_period);
+
+ // Assert
+ EXPECT_EQ(reported, unavailable);
+}
+
+// A fix that gets the transform ends the outage, so a transform missing again is reported again.
+TEST_F(GnssPoserAntennaTransformReport, Tf_UnavailableAgainAfterAvailable_ReportedAgain)
+{
+ // Arrange
+ input_fix_at(0s);
+ ASSERT_EQ(input_fix_at(beyond_grace_period), unavailable);
+ available = Transform{};
+ input_fix_at(beyond_grace_period + 1s);
+ available = tl::unexpected(unavailable);
+
+ // Act
+ const std::optional reported = input_fix_at(beyond_grace_period + 2s);
+
+ // Assert
+ EXPECT_EQ(reported, unavailable);
+}
+
+// A lookup that fails although TF is ready does not resolve by waiting, so it is reported at once,
+// without the grace period.
+TEST_F(GnssPoserAntennaTransformReport, Tf_LookupFailed_ReportedAtOnce)
+{
+ // Arrange
+ available = tl::unexpected(failed);
+
+ // Act
+ const std::optional first = input_fix_at(0s);
+
+ // Assert
+ EXPECT_EQ(first, failed);
+}
diff --git a/sensing/autoware_gnss_poser/test/test_gnss_poser_node.cpp b/sensing/autoware_gnss_poser/test/test_gnss_poser_node.cpp
index 960883079b..0453e9c5cd 100644
--- a/sensing/autoware_gnss_poser/test/test_gnss_poser_node.cpp
+++ b/sensing/autoware_gnss_poser/test/test_gnss_poser_node.cpp
@@ -63,6 +63,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -509,12 +510,15 @@ class GnssPoserNodeIntegration : public ::testing::Test
// Waits until `gnss_fixed` has been received `count` times. The node publishes it for every fix
// that passes the projector gates, fixed or not, so it marks that fix as processed. Then pumps
// for one more delivery budget so that the remaining outputs of the same callback, if any, have
- // landed before a count is asserted.
- void wait_for_gnss_fixed(std::size_t count)
+ // landed before a count is asserted. Returns the latest `gnss_fixed`, or std::nullopt when fewer
+ // than `count` arrived within the wait budget.
+ std::optional wait_for_gnss_fixed(std::size_t count)
{
- ASSERT_TRUE(pump_until([this, count] { return peer_->fixed_flags.size() >= count; }))
- << "expected " << count << " gnss_fixed messages, got " << peer_->fixed_flags.size();
+ if (!pump_until([this, count] { return peer_->fixed_flags.size() >= count; })) {
+ return std::nullopt;
+ }
pump(delivery_budget);
+ return peer_->fixed_flags.back();
}
// Waits until every output of an accepted fix (gnss_fixed, gnss_pose, gnss_pose_cov and the
@@ -624,7 +628,9 @@ class GnssPoserNodeIntegration : public ::testing::Test
for (const auto & fix : fixes) {
const std::size_t processed = peer_->fixed_flags.size();
send_fix(fix);
- ASSERT_NO_FATAL_FAILURE(wait_for_gnss_fixed(processed + 1));
+ ASSERT_TRUE(wait_for_gnss_fixed(processed + 1).has_value())
+ << "expected " << processed + 1 << " gnss_fixed messages, got "
+ << peer_->fixed_flags.size();
}
}
@@ -917,6 +923,9 @@ TEST_F(GnssPoserNodeIntegration, Gate_FirstFixAfterMgrsProjector_PublishesOneOfE
{
// Arrange
ASSERT_NO_FATAL_FAILURE(build_node({}));
+ // The antenna transform of the fixes: the identity, so that the processed fix gets a pose.
+ ASSERT_NO_FATAL_FAILURE(
+ broadcast_static_tf("gnss", "base_link", make_point(0.0, 0.0, 0.0), yaw_to_quaternion(0.0)));
// No projector info yet: the fix is dropped, and not even gnss_fixed is published.
send_fix(make_reference_fix());
// A LOCAL projector arriving changes nothing, neither by itself nor for the next fix.
@@ -946,6 +955,9 @@ TEST_P(GnssPoserBufferedPubMethod, MethodBuffered_PubMethodParameter_SelectsTheM
// Arrange
ASSERT_NO_FATAL_FAILURE(
build_node_with_mgrs_projector(make_buffer_params(GetParam().gnss_pose_pub_method, 3)));
+ // The antenna transform of the fixes: the identity, so that the pose is the combined position.
+ ASSERT_NO_FATAL_FAILURE(
+ broadcast_static_tf("gnss", "base_link", make_point(0.0, 0.0, 0.0), yaw_to_quaternion(0.0)));
const auto fixes = make_average_fixes();
const auto expected =
GetParam().combine({project_mgrs(fixes[0]), project_mgrs(fixes[1]), project_mgrs(fixes[2])});
@@ -1028,29 +1040,25 @@ TEST_F(GnssPoserNodeIntegration, Tf_StaticAntennaToBaseTransform_IsComposedAndBr
EXPECT_EQ(peer_->broadcast_tfs.size(), 1U);
}
-// The antenna frame is the fix's `header.frame_id`. A frame with no transform to base_frame, or a
-// frame equal to base_frame, yields the antenna pose unchanged (identity fallback); a known frame
-// gets the transform applied.
-//
-// NOTE(characterization): the unknown-frame case is a configuration error (the driver's frame_id
-// does not match any TF frame) that never resolves by waiting, yet the node keeps publishing the
-// antenna position as base_link, with the receiver's covariance and only a throttled warning. The
-// node does not distinguish this from a transform that is merely not available yet. The
-// frame_id == base_frame shortcut, by contrast, is a legitimate configuration.
-TEST_F(GnssPoserNodeIntegration, Tf_AntennaFrameComesFromFixHeader_UnknownFrameFallsBackToIdentity)
+// The antenna frame is the fix's `header.frame_id`. A frame with no transform to base_frame drops
+// the fix: the pose cannot be expressed in base_link, and `gnss_fixed` still reports the receiver's
+// status. A frame equal to base_frame needs no lookup and yields the antenna pose unchanged; a
+// known frame gets the transform applied.
+TEST_F(GnssPoserNodeIntegration, Tf_AntennaFrameComesFromFixHeader_UnknownFrameDropsTheFix)
{
// Arrange
ASSERT_NO_FATAL_FAILURE(build_node_with_static_antenna_tf());
const auto fix_unknown = make_reference_fix(NavSatStatus::STATUS_FIX, "some_other_antenna");
// Act
- // Frame from the header is what gets looked up; a frame without TF yields the antenna pose.
+ // Frame from the header is what gets looked up; a frame without TF drops the fix.
send_fix(fix_unknown);
// Assert
- ASSERT_NO_FATAL_FAILURE(wait_for_outputs(1));
- expect_point_near(last_pose().pose.position, project_mgrs(fix_unknown));
- EXPECT_NEAR(yaw_of(last_pose().pose.orientation), M_PI / 2.0, angle_tolerance);
+ const auto fixed = wait_for_gnss_fixed(1);
+ ASSERT_TRUE(fixed.has_value()) << "gnss_fixed did not arrive";
+ expect_output_counts(1, 0, 0, 0);
+ EXPECT_TRUE(fixed->data);
}
TEST_F(GnssPoserNodeIntegration, Tf_AntennaFrameComesFromFixHeader_BaseFrameUsesIdentity)