stdr_gui_thermal.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  CGuiThermal::CGuiThermal(stdr_msgs::ThermalSensorMsg 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, &CGuiThermal::callback,this);
38  }
39 
43  void CGuiThermal::callback(const stdr_msgs::ThermalSensorMeasurementMsg& msg)
44  {
45  if(lock_)
46  {
47  return;
48  }
49  thermal_sources_ = 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 
85  QBrush brush_cone(QColor(100,50,50, 20 * (2 - visualization_status_)));
86  painter.setBrush(brush_cone);
87  QPen pen(QColor(0,0,0,0));
88  painter.setPen(pen);
89 
90  painter.drawPie(
91  pose_x / ocgd - msg_.maxRange / ocgd,
92 
93  pose_y / ocgd - msg_.maxRange / ocgd,
94 
95  msg_.maxRange / ocgd * 2,
96  msg_.maxRange / ocgd * 2,
97 
98  - (pose_theta - msg_.angleSpan / 2.0)
99  * 180.0 / STDR_PI * 16,
100 
101  - msg_.angleSpan * 180.0 / STDR_PI * 16);
102 
103  lock_ = false;
104  }
105 
110  {
111 
112  }
113 
118  {
119  return visualization_status_;
120  }
121 
126  {
128  }
129 
134  {
136  }
137 
142  std::string CGuiThermal::getFrameId(void)
143  {
144  return msg_.frame_id;
145  }
146 
153  stdr_msgs::ThermalSourceVector env_thermal_sources)
154  {
155  while(lock_)
156  {
157  usleep(100);
158  }
159  lock_ = true;
160  env_thermal_sources_ = env_thermal_sources;
161  lock_ = false;
162  }
163 }
std::string getFrameId(void)
Returns the frame id of the specific sensor.
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.
double tfScalar
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
TFSIMD_FORCE_INLINE Matrix3x3 & getBasis()
std::string topic_
< The topic from which the new RFID tags will be got
std::string tf_frame_
Visualization status of the specific sonar.
void toggleVisualizationStatus(void)
Toggles the visibility status of the specific sensor.
stdr_msgs::ThermalSourceVector env_thermal_sources_
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
~CGuiThermal(void)
Default destructor.
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool lock_
The ROS tf frame.
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
stdr_msgs::ThermalSensorMsg msg_
A ros subscriber.
void setEnvironmentalThermalSources(stdr_msgs::ThermalSourceVector env_thermal_sources)
Sets the tags existent in the environment.
TFSIMD_FORCE_INLINE const tfScalar & y() const
#define STDR_PI
Definition: stdr_tools.h:100
ros::Subscriber subscriber_
Used to avoid drawing when a new sonar message arives.
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.
CGuiThermal(stdr_msgs::ThermalSensorMsg msg, std::string baseTopic)
Default contructor.
char visualization_status_
The stdr rfid sensor measurement msg.
void callback(const stdr_msgs::ThermalSensorMeasurementMsg &msg)
Callback for the rfid measurement message.
void setVisualizationStatus(char vs)
Sets the visibility status of the specific sensor.
stdr_msgs::ThermalSensorMeasurementMsg thermal_sources_
The tags that exist in the environment.
#define ROS_DEBUG(...)


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