rfid_reader.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002    STDR Simulator - Simple Two DImensional Robot Simulator
00003    Copyright (C) 2013 STDR Simulator
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3 of the License, or
00007    (at your option) any later version.
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015    
00016    Authors : 
00017    * Manos Tsardoulias, etsardou@gmail.com
00018    * Aris Thallas, aris.thallas@gmail.com
00019    * Chris Zalidis, zalidis@gmail.com 
00020 ******************************************************************************/
00021 
00022 #include <stdr_robot/sensors/rfid_reader.h>
00023 
00024 namespace stdr_robot {
00025   
00034   RfidReader::RfidReader(const nav_msgs::OccupancyGrid& map,
00035       const stdr_msgs::RfidSensorMsg& msg, 
00036       const std::string& name,
00037       ros::NodeHandle& n)
00038   : 
00039     Sensor(map, name, n, msg.pose, msg.frame_id, msg.frequency)
00040   {
00041     _description = msg;
00042 
00043     _publisher = n.advertise<stdr_msgs::RfidSensorMeasurementMsg>
00044       ( _namespace + "/" + msg.frame_id, 1 );
00045       
00046     rfids_subscriber_ = n.subscribe(
00047       "stdr_server/rfid_list", 
00048       1, 
00049       &RfidReader::receiveRfids,
00050       this);
00051   }
00052   
00057   RfidReader::~RfidReader(void)
00058   {
00059     
00060   }
00061 
00066   void RfidReader::updateSensorCallback() 
00067   {
00068     if (rfid_tags_.rfid_tags.size() == 0) return;    
00069 
00070     stdr_msgs::RfidSensorMeasurementMsg measuredTagsMsg;
00071 
00072     measuredTagsMsg.header.frame_id = _description.frame_id;
00073 
00074     
00075     float max_range = _description.maxRange;
00076     float sensor_th = tf::getYaw(_sensorTransform.getRotation());
00077     float min_angle = sensor_th - _description.angleSpan / 2.0;
00078     float max_angle = sensor_th + _description.angleSpan / 2.0;
00079     
00081     for(unsigned int i = 0 ; i < rfid_tags_.rfid_tags.size() ; i++)
00082     {
00084       float sensor_x = _sensorTransform.getOrigin().x();
00085       float sensor_y = _sensorTransform.getOrigin().y();
00086       float dist = sqrt(
00087         pow(sensor_x - rfid_tags_.rfid_tags[i].pose.x, 2) +
00088         pow(sensor_y - rfid_tags_.rfid_tags[i].pose.y, 2)
00089       );
00090       if(dist > max_range)
00091       {
00092         continue;
00093       }
00094       
00096       float ang = atan2(rfid_tags_.rfid_tags[i].pose.y - sensor_y,
00097         rfid_tags_.rfid_tags[i].pose.x - sensor_x);
00098       
00099       if(!stdr_robot::angCheck(ang, min_angle, max_angle))
00100       {
00101         continue;
00102       }
00103       
00104       measuredTagsMsg.rfid_tags_ids.push_back(rfid_tags_.rfid_tags[i].tag_id);
00105       measuredTagsMsg.rfid_tags_msgs.push_back(rfid_tags_.rfid_tags[i].message);
00106       measuredTagsMsg.rfid_tags_dbs.push_back(1.0); 
00107     }
00108     
00109     measuredTagsMsg.header.stamp = ros::Time::now();
00110     measuredTagsMsg.header.frame_id = _namespace + "_" + _description.frame_id;
00111     _publisher.publish( measuredTagsMsg );
00112   }
00113   
00117   void RfidReader::receiveRfids(const stdr_msgs::RfidTagVector& msg)
00118   {
00119     rfid_tags_ = msg;
00120   }
00121 
00122 }  // namespace stdr_robot


stdr_robot
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Wed Sep 2 2015 03:36:25