00001 /* 00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are met: 00007 * Redistributions of source code must retain the above copyright 00008 notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright 00010 notice, this list of conditions and the following disclaimer in the 00011 documentation and/or other materials provided with the distribution. 00012 * Neither the name of the Universite de Sherbrooke nor the 00013 names of its contributors may be used to endorse or promote products 00014 derived from this software without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 #include "PreferencesDialogROS.h" 00029 #include <rtabmap/core/Parameters.h> 00030 #include <QtCore/QDir> 00031 #include <QtCore/QFileInfo> 00032 #include <QtCore/QSettings> 00033 #include <QtGui/QHBoxLayout> 00034 #include <QtCore/QTimer> 00035 #include <QtGui/QLabel> 00036 #include <rtabmap/core/RtabmapEvent.h> 00037 #include <QtGui/QMessageBox> 00038 #include <ros/exceptions.h> 00039 00040 using namespace rtabmap; 00041 00042 PreferencesDialogROS::PreferencesDialogROS(const QString & configFile) : 00043 configFile_(configFile) 00044 { 00045 00046 } 00047 00048 PreferencesDialogROS::~PreferencesDialogROS() 00049 { 00050 QFile::remove(getTmpIniFilePath()); 00051 } 00052 00053 QString PreferencesDialogROS::getIniFilePath() const 00054 { 00055 if(configFile_.isEmpty()) 00056 { 00057 return PreferencesDialog::getIniFilePath(); 00058 } 00059 return configFile_; 00060 } 00061 00062 QString PreferencesDialogROS::getTmpIniFilePath() const 00063 { 00064 return QDir::homePath()+"/.ros/"+QFileInfo(configFile_).fileName()+".tmp"; 00065 } 00066 00067 void PreferencesDialogROS::readCameraSettings(const QString & filePath) 00068 { 00069 this->setInputRate(0); 00070 } 00071 00072 QString PreferencesDialogROS::getParamMessage() 00073 { 00074 return tr("Reading parameters from the ROS server..."); 00075 } 00076 00077 bool PreferencesDialogROS::readCoreSettings(const QString & filePath) 00078 { 00079 if(filePath.isEmpty() || filePath.compare(getTmpIniFilePath()) == 0) 00080 { 00081 ros::NodeHandle nh; 00082 ROS_INFO("%s", this->getParamMessage().toStdString().c_str()); 00083 bool validParameters = true; 00084 int readCount = 0; 00085 rtabmap::ParametersMap parameters = rtabmap::Parameters::getDefaultParameters(); 00086 for(rtabmap::ParametersMap::iterator i=parameters.begin(); i!=parameters.end(); ++i) 00087 { 00088 std::string value; 00089 if(nh.getParam((*i).first,value)) 00090 { 00091 PreferencesDialog::setParameter((*i).first, value); 00092 ++readCount; 00093 } 00094 else 00095 { 00096 validParameters = false; 00097 } 00098 } 00099 00100 ROS_INFO("Parameters read = %d", readCount); 00101 00102 if(validParameters) 00103 { 00104 ROS_INFO("Parameters successfully read."); 00105 } 00106 else 00107 { 00108 if(this->isVisible()) 00109 { 00110 QString warning = tr("Failed to get some RTAB-Map parameters from ROS server, the rtabmap node may be not started or some parameters won't work..."); 00111 ROS_WARN("%s", warning.toStdString().c_str()); 00112 QMessageBox::warning(this, tr("Can't read parameters from ROS server."), warning); 00113 } 00114 return false; 00115 } 00116 return true; 00117 } 00118 else 00119 { 00120 return PreferencesDialog::readCoreSettings(filePath); 00121 } 00122 00123 } 00124 00125 void PreferencesDialogROS::writeSettings(const QString & filePath) 00126 { 00127 writeGuiSettings(filePath); 00128 00129 // This will tell the MainWindow that the 00130 //parameters are updated. The MainWindow will send an Event that 00131 // will be handled by the GuiWrapper where we will write 00132 // parameters in ROS and the rtabmap_node will be notified. 00133 if(_parameters.size()) 00134 { 00135 emit settingsChanged(_parameters); 00136 } 00137 00138 if(_obsoletePanels) 00139 { 00140 emit settingsChanged(_obsoletePanels); 00141 } 00142 00143 _parameters = rtabmap::ParametersMap(); 00144 _obsoletePanels = kPanelDummy; 00145 } 00146