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/ros.h>
23 #include <ros/duration.h>
24 
26 
27 namespace pilz_utils
28 {
29 
33 template<class T>
34 static void waitForMessage(const std::string topic_name,
35  const double retry_timeout = DEFAULT_RETRY_TIMEOUT,
36  const double msg_output_period = DEFAULT_MSG_OUTPUT_PERIOD)
37 {
38  while ( (ros::topic::waitForMessage<T>(topic_name, ros::Duration(retry_timeout)) == nullptr) && ros::ok())
39  {
40  ROS_DEBUG_STREAM_DELAYED_THROTTLE(msg_output_period,
41  "Waiting for message on topic \""
42  + topic_name + "\"...");
43  }
44 }
45 
46 }
47 
48 #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(rate, args)


pilz_utils
Author(s):
autogenerated on Tue Feb 2 2021 03:50:14