rfid_reader.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 
23 
24 namespace stdr_robot {
25 
34  RfidReader::RfidReader(const nav_msgs::OccupancyGrid& map,
35  const stdr_msgs::RfidSensorMsg& msg,
36  const std::string& name,
37  ros::NodeHandle& n)
38  :
39  Sensor(map, name, n, msg.pose, msg.frame_id, msg.frequency)
40  {
41  _description = msg;
42 
43  _publisher = n.advertise<stdr_msgs::RfidSensorMeasurementMsg>
44  ( _namespace + "/" + msg.frame_id, 1 );
45 
47  "stdr_server/rfid_list",
48  1,
50  this);
51  }
52 
58  {
59 
60  }
61 
67  {
68  if (rfid_tags_.rfid_tags.size() == 0) return;
69 
70  stdr_msgs::RfidSensorMeasurementMsg measuredTagsMsg;
71 
72  measuredTagsMsg.header.frame_id = _description.frame_id;
73 
74 
75  float max_range = _description.maxRange;
76  float sensor_th = tf::getYaw(_sensorTransform.getRotation());
77  float min_angle = sensor_th - _description.angleSpan / 2.0;
78  float max_angle = sensor_th + _description.angleSpan / 2.0;
79 
81  for(unsigned int i = 0 ; i < rfid_tags_.rfid_tags.size() ; i++)
82  {
84  float sensor_x = _sensorTransform.getOrigin().x();
85  float sensor_y = _sensorTransform.getOrigin().y();
86  float dist = sqrt(
87  pow(sensor_x - rfid_tags_.rfid_tags[i].pose.x, 2) +
88  pow(sensor_y - rfid_tags_.rfid_tags[i].pose.y, 2)
89  );
90  if(dist > max_range)
91  {
92  continue;
93  }
94 
96  float ang = atan2(rfid_tags_.rfid_tags[i].pose.y - sensor_y,
97  rfid_tags_.rfid_tags[i].pose.x - sensor_x);
98 
99  if(!stdr_robot::angCheck(ang, min_angle, max_angle))
100  {
101  continue;
102  }
103 
104  measuredTagsMsg.rfid_tags_ids.push_back(rfid_tags_.rfid_tags[i].tag_id);
105  measuredTagsMsg.rfid_tags_msgs.push_back(rfid_tags_.rfid_tags[i].message);
106  measuredTagsMsg.rfid_tags_dbs.push_back(1.0);
107  }
108 
109  measuredTagsMsg.header.stamp = ros::Time::now();
110  measuredTagsMsg.header.frame_id = _namespace + "_" + _description.frame_id;
111  _publisher.publish( measuredTagsMsg );
112  }
113 
117  void RfidReader::receiveRfids(const stdr_msgs::RfidTagVector& msg)
118  {
119  rfid_tags_ = msg;
120  }
121 
122 } // namespace stdr_robot
const std::string & _namespace
< The base for the sensor frame_id
Definition: sensor_base.h:114
void publish(const boost::shared_ptr< M > &message) const
stdr_msgs::RfidSensorMsg _description
< Sonar rfid reader description
Definition: rfid_reader.h:80
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
static double getYaw(const Quaternion &bt_q)
A class that provides sensor abstraction.
Definition: sensor_base.h:40
virtual void updateSensorCallback()
Updates the sensor measurements.
Definition: rfid_reader.cpp:66
ros::Subscriber rfids_subscriber_
The currently existent RFID tags.
Definition: rfid_reader.h:83
TFSIMD_FORCE_INLINE const tfScalar & x() const
~RfidReader(void)
Default destructor.
Definition: rfid_reader.cpp:57
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()
void receiveRfids(const stdr_msgs::RfidTagVector &msg)
Receives the existent rfid tags.
static bool angCheck(float target_, float min_, float max_)
Checks if an angle is between two others. Supposes that min < max.
Definition: helper.h:37
stdr_msgs::RfidTagVector rfid_tags_
Definition: rfid_reader.h:86
Quaternion getRotation() const
RfidReader(const nav_msgs::OccupancyGrid &map, const stdr_msgs::RfidSensorMsg &msg, const std::string &name, ros::NodeHandle &n)
Default constructor.
Definition: rfid_reader.cpp:34
static Time now()
ros::Publisher _publisher
ROS tf listener.
Definition: sensor_base.h:131


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