stdr_sonar_visualization.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_gui/stdr_visualization/stdr_sonar_visualization.h"
00023 
00024 namespace stdr_gui
00025 {
00032   CSonarVisualisation::CSonarVisualisation(QString name,float resolution):
00033     name_(name),
00034     resolution_(resolution)
00035   {
00036     setupUi(this);
00037     setWindowTitle(name_);
00038     active_ = true;
00039     
00040     ros::NodeHandle n;
00041     
00042     subscriber_ = n.subscribe(
00043       name_.toStdString().c_str(), 
00044       1, 
00045       &CSonarVisualisation::callback,
00046       this);
00047       
00048     
00049   }
00050   
00055   CSonarVisualisation::~CSonarVisualisation(void)
00056   {
00057     
00058   }
00059   
00064   void CSonarVisualisation::destruct(void)
00065   {
00066     hide();
00067     delete sonarDistBar;
00068     delete sonarDist;
00069     delete sonarMaxDist;
00070     delete sonarMinDist;
00071   }
00072   
00078   void CSonarVisualisation::closeEvent(QCloseEvent *event)
00079   {
00080     destruct();
00081     active_ = false;
00082     subscriber_.shutdown();
00083   }
00084   
00089   bool CSonarVisualisation::getActive(void)
00090   {
00091     return active_;
00092   }
00093   
00099   void CSonarVisualisation::setSonar(stdr_msgs::SonarSensorMsg msg)
00100   {
00101     msg_ = msg;
00102     sonarMaxDist->setText(QString().setNum(msg.maxRange) + QString(" m"));
00103     sonarMinDist->setText(QString().setNum(msg.minRange) + QString(" m"));
00104   }
00105   
00111   void CSonarVisualisation::callback(const sensor_msgs::Range& msg)
00112   {
00113     range_ = msg;
00114   }
00115   
00120   void CSonarVisualisation::paint(void)
00121   {
00122           
00123         float real_dist = range_.range;
00124     if(real_dist > msg_.maxRange)
00125     {
00126       real_dist = msg_.maxRange;
00127     }
00128     else if(real_dist < msg_.minRange)
00129     {
00130       real_dist = msg_.minRange;
00131     }
00132       
00133     sonarDist->setText(QString().setNum(real_dist) + QString(" m"));
00134     sonarDistBar->setValue(sonarDistBar->maximum() * real_dist / msg_.maxRange);
00135   }
00136 }


stdr_gui
Author(s): Manos Tsardoulias
autogenerated on Tue Feb 7 2017 03:46:43