stdr_gui_rfid.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_gui
25 {
29  CGuiRfid::CGuiRfid(stdr_msgs::RfidSensorMsg msg,std::string baseTopic):
30  msg_(msg)
31  {
32  topic_ = baseTopic + "/" + msg_.frame_id;
33  tf_frame_ = baseTopic + "_" + msg_.frame_id;
35  lock_ = false;
36  subscriber_ = n.subscribe(topic_.c_str(), 1, &CGuiRfid::callback,this);
38  }
39 
43  void CGuiRfid::callback(const stdr_msgs::RfidSensorMeasurementMsg& msg)
44  {
45  if(lock_)
46  {
47  return;
48  }
49  tags_ = msg;
50  }
51 
56  QImage *m,
57  float ocgd,
58  tf::TransformListener *listener)
59  {
60  lock_ = true;
61  QPainter painter(m);
62 
64  tf::StampedTransform transform;
65 
66  try
67  {
68  listener->waitForTransform("map_static",
69  tf_frame_.c_str(),
70  ros::Time(0),
71  ros::Duration(0.2));
72  listener->lookupTransform("map_static",
73  tf_frame_.c_str(), ros::Time(0), transform);
74  }
75  catch (tf::TransformException ex)
76  {
77  ROS_DEBUG("%s",ex.what());
78  }
79  tfScalar roll,pitch,yaw;
80  float pose_x = transform.getOrigin().x();
81  float pose_y = transform.getOrigin().y();
82  transform.getBasis().getRPY(roll,pitch,yaw);
83  float pose_theta = yaw;
84 
86  QBrush brush(QColor(50,100,50,75 * (2 - visualization_status_)));
87  painter.setBrush(brush);
88 
89  for(unsigned int j = 0 ; j < tags_.rfid_tags_ids.size() ; j++)
90  {
91  for(unsigned int i = 0 ; i < env_tags_.rfid_tags.size() ; i++)
92  {
93  if(tags_.rfid_tags_ids[j] == env_tags_.rfid_tags[i].tag_id)
94  {
95  int x1 = pose_x / ocgd;
96  int y1 = pose_y / ocgd;
97  int x2 = env_tags_.rfid_tags[i].pose.x / ocgd;
98  int y2 = env_tags_.rfid_tags[i].pose.y / ocgd;
99  painter.drawLine(x1, y1, x2, y2);
100  break;
101  }
102  }
103  }
104 
105  QBrush brush_cone(QColor(50,100,50, 20 * (2 - visualization_status_)));
106  painter.setBrush(brush_cone);
107  QPen pen(QColor(0,0,0,0));
108  painter.setPen(pen);
109 
110  painter.drawPie(
111  pose_x / ocgd - msg_.maxRange / ocgd,
112 
113  pose_y / ocgd - msg_.maxRange / ocgd,
114 
115  msg_.maxRange / ocgd * 2,
116  msg_.maxRange / ocgd * 2,
117 
118  - (pose_theta - msg_.angleSpan / 2.0)
119  * 180.0 / STDR_PI * 16,
120 
121  - msg_.angleSpan * 180.0 / STDR_PI * 16);
122 
123  lock_ = false;
124  }
125 
130  {
131 
132  }
133 
138  {
139  return visualization_status_;
140  }
141 
146  {
148  }
149 
154  {
156  }
157 
162  std::string CGuiRfid::getFrameId(void)
163  {
164  return msg_.frame_id;
165  }
166 
172  void CGuiRfid::setEnvironmentalTags(stdr_msgs::RfidTagVector env_tags)
173  {
174  while(lock_)
175  {
176  usleep(100);
177  }
178  lock_ = true;
179  env_tags_ = env_tags;
180  lock_ = false;
181  }
182 }
void setEnvironmentalTags(stdr_msgs::RfidTagVector env_tags)
Sets the tags existent in the environment.
bool lock_
The ROS tf frame.
Definition: stdr_gui_rfid.h:51
std::string tf_frame_
Visualization status of the specific sonar.
Definition: stdr_gui_rfid.h:53
void callback(const stdr_msgs::RfidSensorMeasurementMsg &msg)
Callback for the rfid measurement message.
stdr_msgs::RfidSensorMsg msg_
A ros subscriber.
Definition: stdr_gui_rfid.h:47
std::string getFrameId(void)
Returns the frame id of the specific sensor.
stdr_msgs::RfidSensorMeasurementMsg tags_
The tags that exist in the environment.
Definition: stdr_gui_rfid.h:57
ros::Subscriber subscriber_
Used to avoid drawing when a new sonar message arives.
Definition: stdr_gui_rfid.h:49
double tfScalar
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void toggleVisualizationStatus(void)
Toggles the visibility status of the specific sensor.
TFSIMD_FORCE_INLINE Matrix3x3 & getBasis()
void setVisualizationStatus(char vs)
Sets the visibility status of the specific sensor.
stdr_msgs::RfidTagVector env_tags_
Definition: stdr_gui_rfid.h:60
CGuiRfid(stdr_msgs::RfidSensorMsg msg, std::string baseTopic)
Default contructor.
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
char visualization_status_
The stdr rfid sensor measurement msg.
Definition: stdr_gui_rfid.h:55
TFSIMD_FORCE_INLINE const tfScalar & y() const
#define STDR_PI
Definition: stdr_tools.h:100
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
The main namespace for STDR GUI.
std::string topic_
< The topic from which the new RFID tags will be got
Definition: stdr_gui_rfid.h:45
~CGuiRfid(void)
Default destructor.
char getVisualizationStatus(void)
Returns the visibility status of the specific sensor.
void paint(QImage *m, float ocgd, tf::TransformListener *listener)
Paints the rfid measurements in the map image.
#define ROS_DEBUG(...)


stdr_gui
Author(s): Manos Tsardoulias
autogenerated on Mon Jun 10 2019 15:15:16