Skip to content

Commit

Permalink
feat(tier4_autoware_utils): add the API to check if taken data is sta…
Browse files Browse the repository at this point in the history
…le (#7404)

Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
  • Loading branch information
soblin authored Jun 10, 2024
1 parent c89cd08 commit cb557db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class InterProcessPollingSubscriber<T, N, typename std::enable_if<N == 1>::type>
"serialization while updateLatestData()");
}
};
/*
* @brief take and return the latest data from DDS queue if such data existed, otherwise return
* previous taken data("stale" data)
* @note if you want to ignore "stale" data, you should use takeNewData()
* instead
*/
typename T::ConstSharedPtr takeData()
{
auto new_data = std::make_shared<T>();
Expand All @@ -75,6 +81,25 @@ class InterProcessPollingSubscriber<T, N, typename std::enable_if<N == 1>::type>

return data_;
};

/*
* @brief take and return the latest data from DDS queue if such data existed, otherwise return
* nullptr instead
* @note this API allows you to avoid redundant computation on the taken data which is unchanged
* since the previous cycle
*/
typename T::ConstSharedPtr takeNewData()
{
auto new_data = std::make_shared<T>();
rclcpp::MessageInfo message_info;
const bool success = subscriber_->take(*new_data, message_info);
if (success) {
data_ = new_data;
return data_;
} else {
return nullptr;
}
}
};

template <typename T, int N>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void LaneDepartureCheckerNode::onTimer()
reference_trajectory_ = sub_reference_trajectory_.takeData();
predicted_trajectory_ = sub_predicted_trajectory_.takeData();

const auto lanelet_map_bin_msg = sub_lanelet_map_bin_.takeData();
const auto lanelet_map_bin_msg = sub_lanelet_map_bin_.takeNewData();
if (lanelet_map_bin_msg) {
lanelet_map_ = std::make_shared<lanelet::LaneletMap>();
lanelet::utils::conversion::fromBinMsg(
Expand Down

0 comments on commit cb557db

Please sign in to comment.