co2.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
22 #include <stdr_robot/sensors/co2.h>
23 
24 namespace stdr_robot {
25 
35  const nav_msgs::OccupancyGrid& map,
36  const stdr_msgs::CO2SensorMsg& msg,
37  const std::string& name,
38  ros::NodeHandle& n)
39  : Sensor(map, name, n, msg.pose, msg.frame_id, msg.frequency)
40  {
41  _description = msg;
42 
43  _publisher = n.advertise<stdr_msgs::CO2SensorMeasurementMsg>
44  ( _namespace + "/" + msg.frame_id, 1 );
45 
47  "stdr_server/co2_sources_list",
48  1,
50  this);
51  }
52 
58  {
59 
60  }
61 
67  {
68  if (co2_sources_.co2_sources.size() == 0) return;
69 
70  stdr_msgs::CO2SensorMeasurementMsg measuredSourcesMsg;
71 
72  measuredSourcesMsg.header.frame_id = _description.frame_id;
73 
74  float max_range = _description.maxRange;
76  for(unsigned int i = 0 ; i < co2_sources_.co2_sources.size() ; i++)
77  {
79  float sensor_x = _sensorTransform.getOrigin().x();
80  float sensor_y = _sensorTransform.getOrigin().y();
81  float dist = sqrt(
82  pow(sensor_x - co2_sources_.co2_sources[i].pose.x, 2) +
83  pow(sensor_y - co2_sources_.co2_sources[i].pose.y, 2)
84  );
85  if(dist > max_range)
86  {
87  continue;
88  }
89  if(dist > 0.5)
90  {
91  measuredSourcesMsg.co2_ppm += co2_sources_.co2_sources[i].ppm *
92  pow(0.5, 2) / pow(dist, 2);
93  }
94  else
95  {
96  measuredSourcesMsg.co2_ppm += co2_sources_.co2_sources[i].ppm;
97  }
98  }
99 
100  measuredSourcesMsg.header.stamp = ros::Time::now();
101  measuredSourcesMsg.header.frame_id = _namespace + "_" + _description.frame_id;
102  _publisher.publish( measuredSourcesMsg );
103  }
104 
108  void CO2Sensor::receiveCO2Sources(const stdr_msgs::CO2SourceVector& msg)
109  {
110  co2_sources_ = msg;
111  }
112 
113 } // namespace stdr_robot
const std::string & _namespace
< The base for the sensor frame_id
Definition: sensor_base.h:114
stdr_msgs::CO2SensorMsg _description
< CO2 sensor description
Definition: co2.h:82
virtual void updateSensorCallback()
Updates the sensor measurements.
Definition: co2.cpp:66
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
The main namespace for STDR Robot.
Definition: exceptions.h:27
ros::Subscriber co2_sources_subscriber_
The currently existent sources.
Definition: co2.h:85
~CO2Sensor(void)
Default destructor.
Definition: co2.cpp:57
A class that provides sensor abstraction.
Definition: sensor_base.h:40
TFSIMD_FORCE_INLINE const tfScalar & x() const
CO2Sensor(const nav_msgs::OccupancyGrid &map, const stdr_msgs::CO2SensorMsg &msg, const std::string &name, ros::NodeHandle &n)
Default constructor.
Definition: co2.cpp:34
tf::StampedTransform _sensorTransform
True if sensor got the _sensorTransform.
Definition: sensor_base.h:135
TFSIMD_FORCE_INLINE const tfScalar & y() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
stdr_msgs::CO2SourceVector co2_sources_
Definition: co2.h:88
static Time now()
ros::Publisher _publisher
ROS tf listener.
Definition: sensor_base.h:131
void receiveCO2Sources(const stdr_msgs::CO2SourceVector &msg)
Receives the existent co2 sources.
Definition: co2.cpp:108


stdr_robot
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Mon Jun 10 2019 15:15:10