4 #include <std_msgs/Float32.h> 5 #include <std_msgs/Float64.h> 6 #include <std_msgs/Int16.h> 7 #include <std_msgs/Int32.h> 8 #include <std_msgs/Int64.h> 9 #include <std_msgs/Int8.h> 10 #include <std_msgs/UInt16.h> 11 #include <std_msgs/UInt32.h> 12 #include <std_msgs/UInt64.h> 13 #include <std_msgs/UInt8.h> 15 std::unique_ptr<ros::NodeHandle>
nh;
16 std::unique_ptr<ros::Publisher>
pub;
23 template <
class T,
class U>
34 if (delta > window_length)
45 mean.data = sum / time_values_d.size();
51 callbackI<std_msgs::Int8ConstPtr, std_msgs::Int8>(msg);
56 callbackI<std_msgs::Int16ConstPtr, std_msgs::Int16>(msg);
61 callbackI<std_msgs::Int32ConstPtr, std_msgs::Int32>(msg);
66 callbackI<std_msgs::Int64ConstPtr, std_msgs::Int64>(msg);
69 template <
class T,
class U>
80 if (delta > window_length)
87 long long unsigned sum(0);
91 mean.data = sum / time_values_d.size();
97 callbackU<std_msgs::UInt8ConstPtr, std_msgs::UInt8>(msg);
102 callbackU<std_msgs::UInt16ConstPtr, std_msgs::UInt16>(msg);
107 callbackU<std_msgs::UInt32ConstPtr, std_msgs::UInt32>(msg);
112 callbackU<std_msgs::UInt64ConstPtr, std_msgs::UInt64>(msg);
115 template <
class T,
class U>
121 if (!std::isnan(msg->data))
128 if (delta > window_length)
139 mean.data = sum / time_values_d.size();
145 callbackD<std_msgs::Float32ConstPtr, std_msgs::Float32>(msg);
150 callbackD<std_msgs::Float64ConstPtr, std_msgs::Float64>(msg);
159 nh = std::make_unique<ros::NodeHandle>(
"~");
161 std::string in_topic, out_topic;
162 nh->getParam(
"in_topic", in_topic);
163 nh->getParam(
"out_topic", out_topic);
166 double window_length_tmp(2);
167 nh->getParam(
"window_length", window_length_tmp);
168 window_length.
sec = (int) window_length_tmp;
169 window_length.
nsec = (window_length_tmp - (int) window_length_tmp) * 1e9;
176 if (in_topic.empty())
182 if (out_topic.empty())
188 std::string topic_type;
194 ROS_ERROR_STREAM(
"Error getting topics: Could not retrieve the topics names");
198 ros::master::V_TopicInfo::iterator topic =
201 return ti.name == in_topic;
204 if (topic != topics.end())
206 topic_type = topic->datatype;
219 if (topic_type ==
"std_msgs/Float32")
222 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Float32>(out_topic, 5));
224 else if (topic_type ==
"std_msgs/Float64")
227 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Float64>(out_topic, 5));
229 else if (topic_type ==
"std_msgs/Int8")
232 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Int8>(out_topic, 5));
234 else if (topic_type ==
"std_msgs/Int16")
237 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Int16>(out_topic, 5));
239 else if (topic_type ==
"std_msgs/Int32")
242 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Int32>(out_topic, 5));
244 else if (topic_type ==
"std_msgs/Int64")
247 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::Int64>(out_topic, 5));
249 else if (topic_type ==
"std_msgs/UInt8")
252 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::UInt8>(out_topic, 5));
254 else if (topic_type ==
"std_msgs/UInt16")
257 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::UInt16>(out_topic, 5));
259 else if (topic_type ==
"std_msgs/UInt32")
262 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::UInt32>(out_topic, 5));
264 else if (topic_type ==
"std_msgs/UInt64")
267 pub = std::make_unique<ros::Publisher>(
nh->advertise<std_msgs::UInt64>(out_topic, 5));
ros::Duration window_length
#define ROS_WARN_STREAM_THROTTLE(period, args)
int main(int argc, char *argv[])
void callbackI(const T &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
void callbackUInt8(const std_msgs::UInt8ConstPtr &msg)
std::vector< TopicInfo > V_TopicInfo
void callbackU(const T &msg)
void callbackUInt16(const std_msgs::UInt16ConstPtr &msg)
std::vector< std::pair< ros::Time, uint64_t > > time_values_u
void callbackInt8(const std_msgs::Int8ConstPtr &msg)
void callbackInt32(const std_msgs::Int32ConstPtr &msg)
void callbackUInt64(const std_msgs::UInt64ConstPtr &msg)
std::vector< std::pair< ros::Time, int64_t > > time_values_i
std::vector< std::pair< ros::Time, double > > time_values_d
void callbackUInt32(const std_msgs::UInt32ConstPtr &msg)
#define ROS_DEBUG_STREAM(args)
std::unique_ptr< ros::NodeHandle > nh
void callbackFloat32(const std_msgs::Float32ConstPtr &msg)
#define ROS_ERROR_STREAM(args)
void callbackInt16(const std_msgs::Int16ConstPtr &msg)
std::unique_ptr< ros::Publisher > pub
void callbackFloat64(const std_msgs::Float64ConstPtr &msg)
void callbackD(const T &msg)
ROSCPP_DECL void waitForShutdown()
void callbackInt64(const std_msgs::Int64ConstPtr &msg)