13#include <common_msgs/msg/status.hpp>
15#include <rclcpp/rclcpp.hpp>
30template <
typename MsgT>
32 rclcpp::Node * node, std::mutex & mutex, std::shared_ptr<timer::Timeout> & timeout,
33 typename rclcpp::Publisher<MsgT>::SharedPtr & pub,
const std::string & sensor_name)
39 std::lock_guard<std::mutex> lock(mutex);
40 is_timeout = timeout->is_timeout(node->get_clock()->now());
41 timeout_ns = timeout->get_timeout();
42 elapsed_time = timeout->get_elapsed_time();
46 auto msg = std::make_unique<MsgT>();
47 msg->header.stamp = node->get_clock()->now();
48 msg->status.id = common_msgs::msg::Status::ERROR;
50 pub->publish(std::move(msg));
52 RCLCPP_ERROR_THROTTLE(
53 node->get_logger(), *node->get_clock(), timeout_ns * 1e-6,
"%s driver timeout: %lu [ms]",
54 sensor_name.c_str(), (uint64_t)(timeout->get_elapsed_time() * 1e-6));
55 }
else if (elapsed_time > timeout_ns * 0.5) {
57 node->get_logger(), *node->get_clock(), timeout_ns * 1e-6 / 2,
"Failed to get %s data",
void check_timeout(rclcpp::Node *node, std::mutex &mutex, std::shared_ptr< timer::Timeout > &timeout, typename rclcpp::Publisher< MsgT >::SharedPtr &pub, const std::string &sensor_name)
Template function for checking timeouts.
Definition: utils.hpp:31