-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaggregator_node.cpp
More file actions
41 lines (36 loc) · 1.4 KB
/
aggregator_node.cpp
File metadata and controls
41 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <chrono>
#include <memory>
#include "aggregator_node.hpp"
AggregatorNode::AggregatorNode()
: Node("aggregator"),
aggregator_(samples::AggregatorCore(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count())) {
raw_sub_ = this->create_subscription<sample_msgs::msg::Unfiltered>(
"/unfiltered_topic", ADVERTISING_FREQ,
std::bind(&AggregatorNode::unfiltered_callback, this,
std::placeholders::_1));
filtered_sub_ = this->create_subscription<sample_msgs::msg::FilteredArray>(
"/filtered_topic", ADVERTISING_FREQ,
std::bind(&AggregatorNode::filtered_callback, this,
std::placeholders::_1));
}
void AggregatorNode::unfiltered_callback(
const sample_msgs::msg::Unfiltered::SharedPtr msg) {
aggregator_.add_raw_msg(msg);
RCLCPP_INFO(this->get_logger(), "Raw Frequency(msg/s): %f",
aggregator_.raw_frequency() * 1000);
}
void AggregatorNode::filtered_callback(
const sample_msgs::msg::FilteredArray::SharedPtr msg) {
aggregator_.add_filtered_msg(msg);
RCLCPP_INFO(this->get_logger(), "Filtered Frequency(msg/s): %f",
aggregator_.filtered_frequency() * 1000);
}
int main(int argc, char **argv) {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<AggregatorNode>());
rclcpp::shutdown();
return 0;
}