Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdr_robot/sensors/co2.h>
00023
00024 namespace stdr_robot {
00025
00034 CO2Sensor::CO2Sensor(
00035 const nav_msgs::OccupancyGrid& map,
00036 const stdr_msgs::CO2SensorMsg& msg,
00037 const std::string& name,
00038 ros::NodeHandle& n)
00039 : Sensor(map, name, n, msg.pose, msg.frame_id, msg.frequency)
00040 {
00041 _description = msg;
00042
00043 _publisher = n.advertise<stdr_msgs::CO2SensorMeasurementMsg>
00044 ( _namespace + "/" + msg.frame_id, 1 );
00045
00046 co2_sources_subscriber_ = n.subscribe(
00047 "stdr_server/co2_sources_list",
00048 1,
00049 &CO2Sensor::receiveCO2Sources,
00050 this);
00051 }
00052
00057 CO2Sensor::~CO2Sensor(void)
00058 {
00059
00060 }
00061
00066 void CO2Sensor::updateSensorCallback()
00067 {
00068 if (co2_sources_.co2_sources.size() == 0) return;
00069
00070 stdr_msgs::CO2SensorMeasurementMsg measuredSourcesMsg;
00071
00072 measuredSourcesMsg.header.frame_id = _description.frame_id;
00073
00074 float max_range = _description.maxRange;
00076 for(unsigned int i = 0 ; i < co2_sources_.co2_sources.size() ; i++)
00077 {
00079 float sensor_x = _sensorTransform.getOrigin().x();
00080 float sensor_y = _sensorTransform.getOrigin().y();
00081 float dist = sqrt(
00082 pow(sensor_x - co2_sources_.co2_sources[i].pose.x, 2) +
00083 pow(sensor_y - co2_sources_.co2_sources[i].pose.y, 2)
00084 );
00085 if(dist > max_range)
00086 {
00087 continue;
00088 }
00089 if(dist > 0.5)
00090 {
00091 measuredSourcesMsg.co2_ppm += co2_sources_.co2_sources[i].ppm *
00092 pow(0.5, 2) / pow(dist, 2);
00093 }
00094 else
00095 {
00096 measuredSourcesMsg.co2_ppm += co2_sources_.co2_sources[i].ppm;
00097 }
00098 }
00099
00100 measuredSourcesMsg.header.stamp = ros::Time::now();
00101 measuredSourcesMsg.header.frame_id = _namespace + "_" + _description.frame_id;
00102 _publisher.publish( measuredSourcesMsg );
00103 }
00104
00108 void CO2Sensor::receiveCO2Sources(const stdr_msgs::CO2SourceVector& msg)
00109 {
00110 co2_sources_ = msg;
00111 }
00112
00113 }