stdr_sonar_visualization.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 {
32  CSonarVisualisation::CSonarVisualisation(QString name,float resolution):
33  name_(name),
34  resolution_(resolution)
35  {
36  setupUi(this);
37  setWindowTitle(name_);
38  active_ = true;
39 
41 
43  name_.toStdString().c_str(),
44  1,
46  this);
47 
48 
49  }
50 
56  {
57 
58  }
59 
65  {
66  hide();
67  delete sonarDistBar;
68  delete sonarDist;
69  delete sonarMaxDist;
70  delete sonarMinDist;
71  }
72 
78  void CSonarVisualisation::closeEvent(QCloseEvent *event)
79  {
80  destruct();
81  active_ = false;
83  }
84 
90  {
91  return active_;
92  }
93 
99  void CSonarVisualisation::setSonar(stdr_msgs::SonarSensorMsg msg)
100  {
101  msg_ = msg;
102  sonarMaxDist->setText(QString().setNum(msg.maxRange) + QString(" m"));
103  sonarMinDist->setText(QString().setNum(msg.minRange) + QString(" m"));
104  }
105 
111  void CSonarVisualisation::callback(const sensor_msgs::Range& msg)
112  {
113  range_ = msg;
114  }
115 
121  {
122 
123  float real_dist = range_.range;
124  if(real_dist > msg_.maxRange)
125  {
126  real_dist = msg_.maxRange;
127  }
128  else if(real_dist < msg_.minRange)
129  {
130  real_dist = msg_.minRange;
131  }
132 
133  sonarDist->setText(QString().setNum(real_dist) + QString(" m"));
134  sonarDistBar->setValue(sonarDistBar->maximum() * real_dist / msg_.maxRange);
135  }
136 }
void closeEvent(QCloseEvent *event)
Called when the close event is triggered.
CSonarVisualisation(QString name, float resolution)
Default contructor.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
~CSonarVisualisation(void)
Default destructor.
void callback(const sensor_msgs::Range &msg)
Called when new laser data are available.
void destruct(void)
Destroys the visualizer.
void paint(void)
Paints the visualizer.
sensor_msgs::Range range_
Subscriber for getting the sonar ranges.
stdr_msgs::SonarSensorMsg msg_
The laser frame id.
The main namespace for STDR GUI.
void setSonar(stdr_msgs::SonarSensorMsg msg)
Sets the sonar description message.
ros::Subscriber subscriber_
Description of the sonar sensor.
bool getActive(void)
Returns true if the visualizer is active.
bool active_
< True if the visualizer is active


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