15
15
#ifndef RCLCPP__WAIT_FOR_MESSAGE_HPP_
16
16
#define RCLCPP__WAIT_FOR_MESSAGE_HPP_
17
17
18
+ #include < future>
18
19
#include < memory>
19
20
#include < string>
20
21
23
24
#include " rclcpp/node.hpp"
24
25
#include " rclcpp/visibility_control.hpp"
25
26
#include " rclcpp/wait_set.hpp"
27
+ #include " rclcpp/qos.hpp"
26
28
27
29
namespace rclcpp
28
30
{
@@ -79,10 +81,11 @@ bool wait_for_message(
79
81
/* *
80
82
* Wait for the next incoming message to arrive on a specified topic before the specified timeout.
81
83
*
82
- * \param[out] out is the message to be filled when a new message is arriving.
84
+ * \param[out] out is the message to be filled when a new message is arriving
83
85
* \param[in] node the node pointer to initialize the subscription on.
84
86
* \param[in] topic the topic to wait for messages.
85
87
* \param[in] time_to_wait parameter specifying the timeout before returning.
88
+ * \param[in] qos parameter specifying QoS settings for the subscription.
86
89
* \return true if a message was successfully received, false if message could not
87
90
* be obtained or shutdown was triggered asynchronously on the context.
88
91
*/
@@ -91,9 +94,10 @@ bool wait_for_message(
91
94
MsgT & out,
92
95
rclcpp::Node::SharedPtr node,
93
96
const std::string & topic,
94
- std::chrono::duration<Rep, Period> time_to_wait = std::chrono::duration<Rep, Period>(-1 ))
97
+ std::chrono::duration<Rep, Period> time_to_wait = std::chrono::duration<Rep, Period>(-1 ),
98
+ const rclcpp::QoS & qos = rclcpp::SystemDefaultsQoS())
95
99
{
96
- auto sub = node->create_subscription <MsgT>(topic, 1 , [](const std::shared_ptr<const MsgT>) {});
100
+ auto sub = node->create_subscription <MsgT>(topic, qos , [](const std::shared_ptr<const MsgT>) {});
97
101
return wait_for_message<MsgT, Rep, Period>(
98
102
out, sub, node->get_node_options ().context (), time_to_wait);
99
103
}
0 commit comments