hector_co2_processing_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <std_msgs/Float32.h>
3 #include <std_msgs/Bool.h>
4 
7 
8 float avg;
9 
10 float threshold;
11 
12 float scale;
13 
14 void co2_callback(const std_msgs::Float32::ConstPtr &msg){
15  ROS_DEBUG("CO2 Callback");
16  ROS_DEBUG("avg_old: %f", avg);
17  avg = 0.9 * avg + 0.1 * msg->data;
18 
19  ROS_DEBUG("avg: %f", avg);
20  double value = fabs(msg->data - avg);
21 
22  ROS_DEBUG("Value: %f", value);
23  std_msgs::Float32 value_msg;
24  value_msg.data = scale * value;
25  co2Pub.publish(value_msg);
26 
27  std_msgs::Bool bool_msg;
28  bool_msg.data = value > threshold;
29  detectedPub.publish(bool_msg);
30 
31 }
32 
33 int main(int argc, char **argv)
34 {
35  ros::init(argc, argv, "hector_barrel_detection");
36 
37  ros::NodeHandle nh_;
38 
39  avg = 0;
40  threshold = 50;
41  scale = 75.0;
42 
43  ros::Subscriber co2Sub = nh_.subscribe("/co2raw", 100, &co2_callback);
44 
45  co2Pub = nh_.advertise<std_msgs::Float32>("/co2", 100);
46  detectedPub = nh_.advertise<std_msgs::Bool>("/co2detected", 100);
47 
48  ros::spin();
49  exit(0);
50 }
ros::Publisher co2Pub
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
void co2_callback(const std_msgs::Float32::ConstPtr &msg)
ros::Publisher detectedPub
#define ROS_DEBUG(...)


hector_co2_processing
Author(s):
autogenerated on Mon Jun 10 2019 13:36:32