wait_for_message.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PILZ_UTILS_WAIT_FOR_MESSAGE_H
18 #define PILZ_UTILS_WAIT_FOR_MESSAGE_H
19 
20 #include <string>
21 
22 #include <ros/duration.h>
23 #include <ros/ros.h>
24 
26 
27 namespace pilz_utils
28 {
32 template <class T>
33 static void waitForMessage(const std::string topic_name,
34  const double retry_timeout = DEFAULT_RETRY_TIMEOUT,
35  const double msg_output_period = DEFAULT_MSG_OUTPUT_PERIOD)
36 {
37  while ((ros::topic::waitForMessage<T>(topic_name, ros::Duration(retry_timeout)) == nullptr) && ros::ok())
38  {
39  ROS_DEBUG_STREAM_DELAYED_THROTTLE(msg_output_period, "Waiting for message on topic \"" + topic_name + "\"...");
40  }
41 }
42 
43 } // namespace pilz_utils
44 
45 #endif // PILZ_UTILS_WAIT_FOR_MESSAGE_H
static constexpr double DEFAULT_MSG_OUTPUT_PERIOD
static void waitForMessage(const std::string topic_name, const double retry_timeout=DEFAULT_RETRY_TIMEOUT, const double msg_output_period=DEFAULT_MSG_OUTPUT_PERIOD)
Waits (infinitely) until a message arrives on the specified topic.
static constexpr double DEFAULT_RETRY_TIMEOUT
ROSCPP_DECL bool ok()
#define ROS_DEBUG_STREAM_DELAYED_THROTTLE(period, args)


pilz_utils
Author(s):
autogenerated on Sun Jan 24 2021 03:55:46